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

Ensure authentication is randomized as expected #86188

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Apr 26, 2022

In #85255, some mocking of Authentication class got replaced by randomly
creating actual Authentication objects. This is a general direction we
want to head towards because Authentication object has plenty internal
logics which makes it hard to mock correctly (and also undesirable). The
recent change in #85590 adds a test helper which makes randomising
Authentication object easier for tests.

For ApiKeyServiceTests.testGetApiKeyMetadata, the randomisation is
however too broad (broader then what the mocking provided) and can
sometimes creates authentication object that does not pass the
assertion.

The assertion expects no API key authentication. But the randomisation
can generate such one because it randomises whether the authentication
has run-as even when the effective user is from a realm. Since API keys
can run-as, the resulted Authentication object can be an overall API key
authentication object.

This PR reduces the randomness by not allow run-as so that the resulted
Authentication cannot be API keys.

Relates: #85255
Resolves: #86179

In elastic#85255, some mocking of Authentication class got replaced by randomly
creating actual Authentication objects. This is a general direction we
want to head towards because Authentication object has plenty internal
logics which makes it hard to mock correctly (and also undesirable). The
recent change in elastic#85590 adds a test helper which makes randomising
Authentication object easier for tests.

For ApiKeyServiceTests.testGetApiKeyMetadata, the randomisation is
however too broad (broader then what the mocking provided) and can
sometimes creates authentication object that does not pass the
assertion.

The assertion expects no API key authentication. But the randomisation
can generate such one because it randomises whether the authentication
has run-as even when the effective user is from a realm. Since API keys
can run-as, the resulted Authentication object can be an overall API key
authentication object.

This PR reduces the randomness by not allow run-as so that the resulted
Authentication cannot be API keys.

Relates: elastic#85255
Resolves: elastic#86179
@ywangd ywangd added >test Issues or PRs that are addressing/adding tests :Security/Security Security issues without another label v8.3.0 labels Apr 26, 2022
@ywangd ywangd requested a review from n1v0lg April 26, 2022 13:53
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Apr 26, 2022
@elasticmachine
Copy link
Collaborator

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

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

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

LGTM

@ywangd ywangd merged commit fed8834 into elastic:master Apr 26, 2022
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Apr 27, 2022
Similar to elastic#86188, the test failure elastic#86211 is caused by incorrect
randomziation. In this case, the API metadata was expected to be null
in some cases. This PR fixes it by ensuring the correct randomisation.

Resolves: elastic#86211
elasticsearchmachine pushed a commit that referenced this pull request Apr 27, 2022
Similar to #86188, the test failure #86211 is also caused by incorrect
randomziation due to refactoring.  In this case, the API metadata was
expected to be null in some cases.  This PR fixes it by ensuring the
correct randomisation.

Resolves: #86211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Security/Security Security issues without another label Team:Security Meta label for security team >test Issues or PRs that are addressing/adding tests v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] ApiKeyServiceTests testGetApiKeyMetadata failing
3 participants