Skip to content

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Feb 7, 2022

This PR updates the three existing profile APIs to work with the new
security domain concept:

  • Domain info gets recoreded when activating profile
  • Domain info is returned appropriately based on the context
  • "Same" profile is returned based on checking realm name and domain
    definition

This PR updates the three existing profile APIs to work with the new
security domain concept:
* Domain info gets recoreded when activating profile
* Domain info is returned appropriately based on the context
* "Same" profile is returned based on checking realm name and domain
  definition
@ywangd ywangd added >enhancement :Security/Security Security issues without another label v8.2.0 labels Feb 7, 2022
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Feb 7, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine
Copy link
Collaborator

Hi @ywangd, I've created a changelog YAML for you.


public Profile.ProfileUser toProfileUser(@Nullable String realmDomain) {
return new Profile.ProfileUser(username, roles, realm.getName(), realmDomain, email, fullName, displayName, active);
public Profile.ProfileUser toProfileUser(@Nullable String domainName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domainName can come from realm.getDomain().name(), no? Is there a reason we're not using that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer: We should just use the domain information from the ProfileDocument itself and I updated accordingly.

Long answer: Yes there was a reason. The domain recorded in the document is a snapshot of the configuration at the moment of creation. We agreed that the actual domain information will still be derived from the incoming authentication (if there is one). That is, the final domain info may not be the same as the one recorded in the doc.
That said, the use cases so far in this PR do not see any difference in the two because the document is either newly created or just updated with the incomig authentication. So the two should always have the identical domain info. For simplicity, I agree that this method should not take parameter and just uses the doc's domain info.

.getDomain()
.realms()
.stream()
.map(RealmConfig.RealmIdentifier::getName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to rely on the realm name-type tuple for these checks, no?
The fact that realm name is unique in a given node yml config file is not good enough to generally qualify a unique user, as I recall.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right. I had a different thought (along the direction that we may want ultimately rely only on name). But even that is a thing in the future and for now we should still use both name and type. I updated accordingly.

import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class ProfileDomainSingleNodeTests extends AbstractProfileSingleNodeTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the conscientiousness in these tests.

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a couple of comments, and I'll take another look afterwards to make sure I comprehend it all.

@albertzaharovits
Copy link
Contributor

Not part of this PR but do you think we should do another profile search after a new one has been created, in order to fail if there is a race?

@ywangd
Copy link
Member Author

ywangd commented Feb 8, 2022

Not part of this PR but do you think we should do another profile search after a new one has been created, in order to fail if there is a race?

We definitely need to handle potential racing condition. It should be of its own PR given the likely complexity. I have some idea and we can discuss about it offline.

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
GH is misbehaving for me, so I'll comment in here:

  • in tests (IT) it would be nice to cover the activate using the token grant
  • the query to search for profiles given a domain, can always use filter instead of should (later, in a follow-up, maybe we can cache it by domain, to avoid the query building on every activate call)

@albertzaharovits
Copy link
Contributor

always use filter instead of should

I mean instead of must.

@ywangd
Copy link
Member Author

ywangd commented Feb 11, 2022

  • in tests (IT) it would be nice to cover the activate using the token grant

Good point. I updated the test helper method to always randomly activate profile using each the user password or a token created from it.

  • the query to search for profiles given a domain, can always use filter instead of should (later, in a follow-up, maybe we can cache it by domain, to avoid the query building on every activate call)

Yes filter is better since we don't care about score. I have replaced all must with filter.

@ywangd ywangd merged commit 77ace23 into elastic:master Feb 11, 2022
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Feb 22, 2022
When locating existing profile document for the given authentication,
use only realm type to search for file and native realms. This is
because there can only ever be a single file or native realm and it does
not matter what name it takes.

Relates: elastic#83570
ywangd added a commit that referenced this pull request Feb 24, 2022
When locating existing profile document for the given authentication,
use only realm type to search for file and native realms. This is
because there can only ever be a single file or native realm and it does
not matter what name it takes.

Relates: #83570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Security/Security Security issues without another label Team:Security Meta label for security team v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants