Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce blank fields to null in ApiKey requests #66240

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Dec 14, 2020

API Key request objects (InvalidateApiKeyRequest and
GetApiKeyRequest) support multiple key-selection parameters such as
realm-name, user-name, key-id and key-name.

The specified behaviour is that if any of these are blank then they
act as a wildcard and do not restrict the search criteria.

This change moves the "is blank" logic into the constructor for these
requests so that there is a single consistent way to determine blank
(Strings.hasText(arg) == false) and all usage of these fields can
rely on the getter returning either null or a real value, and
never a non-null blank.

Relates: #62916

API Key request objects (`InvalidateApiKeyRequest` and
`GetApiKeyRequest`) support multiple key-selection parameters such as
realm-name, user-name, key-id and key-name.

The specified behaviour is that if any of these are _blank_ then they
act as a wildcard and do not restrict the search criteria.

This change moves the "is blank" logic into the constructor for these
requests so that there is a single consistent way to determine blank
(`Strings.hasText(arg) == false`) and all usage of these fields can
rely on the getter returning either `null` or a _real value_, and
never a non-null blank.

Relates: elastic#62916
@tvernum tvernum added >refactoring :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v8.0.0 v7.11.0 labels Dec 14, 2020
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Dec 14, 2020
@elasticmachine
Copy link
Collaborator

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

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM with a question.

Comment on lines +70 to 74
if (Strings.hasText(id)) {
this.ids = new String[]{id};
} else {
this.ids = ids;
}
Copy link
Member

Choose a reason for hiding this comment

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

Before I touched this class in 7.10, there is no check for id in either constructor. Last time I added

ids = Strings.hasText(id) == false ? null : new String[] { id };

in the constructor with StreamInput. Looking back now, this introduced a tiny inconsistency of how empty id is handled in different constructors. Your change here fixed this inconsistency. Thanks!

Now I have a new question: since a single empty string is now handled and excluded from the constructor, should we also apply the empty check for the string array of ids, i.e., should we move the validation logic of ids into here as well? On one hand, relocating the check for ids is good for consistency in that validate() is more about interactions between multiple fields. On the other hand, it complicates the constructors and also could be considered as a slight behaviour change. Overall, I think I prefer to not touch it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the cautious approach and decided to make this as close as possible to having zero visible changes.

Since the deserialisation code has a hasText check (as you note) I decided that this fix made sense, but chose not to try and filter empty values in the ids array. That seemed like a behavioural change that was outside the scope of this PR.

I'm not necessarily opposed to someone making that change I just wanted this PR to be quick and simple.

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

@tvernum tvernum merged commit fcf28c3 into elastic:master Dec 15, 2020
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Dec 15, 2020
API Key request objects (`InvalidateApiKeyRequest` and
`GetApiKeyRequest`) support multiple key-selection parameters such as
realm-name, user-name, key-id and key-name.

The specified behaviour is that if any of these are _blank_ then they
act as a wildcard and do not restrict the search criteria.

This change moves the "is blank" logic into the constructor for these
requests so that there is a single consistent way to determine blank
(`Strings.hasText(arg) == false`) and all usage of these fields can
rely on the getter returning either `null` or a _real value_, and
never a non-null blank.

Relates: elastic#62916
Backport of: elastic#66240
tvernum added a commit that referenced this pull request Dec 15, 2020
API Key request objects (`InvalidateApiKeyRequest` and
`GetApiKeyRequest`) support multiple key-selection parameters such as
realm-name, user-name, key-id and key-name.

The specified behaviour is that if any of these are _blank_ then they
act as a wildcard and do not restrict the search criteria.

This change moves the "is blank" logic into the constructor for these
requests so that there is a single consistent way to determine blank
(`Strings.hasText(arg) == false`) and all usage of these fields can
rely on the getter returning either `null` or a _real value_, and
never a non-null blank.

Backport of: #66240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants