-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Fix can access resource checks for API Keys with run as #84277
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
Fix can access resource checks for API Keys with run as #84277
Conversation
API Key can run-as since elastic#79809. There are places in the code where we assume API key cannot run-as. Most of them are corrected in elastic#81564. But there are still a few things got missed. This PR fixes the methods for checking owner user realm for API key. Note the resource sharing check (canAccessResourcesOf) also needs to be fixed, this will be handled by elastic#84277
...in/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationContext.java
Outdated
Show resolved
Hide resolved
Pinging @elastic/es-security (Team:Security) |
API Key can run-as since #79809. There are places in the code where we assume API key cannot run-as. Most of them are corrected in #81564. But there are still a few things got missed. This PR fixes the methods for checking owner user realm for API key. This means, when API Keys "running-as" (impersonating other users), we do not expose the authenticating key ID and name to the end-user such as the Authenticate API and the SetSecurityUseringest processor. Only the effective user is revealed, just like in the regular case of a realm user run as. For audit logging, the key's ID and name are not exposed either. But this is mainly because there are no existing fields suitable for these information. We do intend to add them later (#84394) because auditing logging is to consumed by system admin instead of end-users. Note the resource sharing check (canAccessResourcesOf) also needs to be fixed, this will be handled by #84277
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for handling this. Backport will be a challenge. 🙏
...ck/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Authentication.java
Show resolved
Hide resolved
if ((false == FileRealmSettings.TYPE.equals(realmRef.getType()) && false == FileRealmSettings.TYPE.equals(otherRealmRef.getType())) | ||
|| (false == NativeRealmSettings.TYPE.equals(realmRef.getType()) | ||
&& false == NativeRealmSettings.TYPE.equals(otherRealmRef.getType()))) { | ||
Authentication runAs4 = original.runAs(user, otherRealmRef); | ||
assertCannotAccessResources(original, runAs4); | ||
assertCannotAccessResources(original.token(), runAs4); | ||
assertCannotAccessResources(original, runAs4.token()); | ||
assertCannotAccessResources(original.token(), runAs4.token()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
check does not seem to be useful since otherRealmRef
is created as:
final RealmRef otherRealmRef = randomValueOtherThan(realmRef, () -> randomRealmRef(false));
So it is never equal to realmRef
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if is needed, but it was wrong. I've fixed it, and left a comment.
The idea is that the realm refs are different but if they're both file or both native, then the ownership check should pass.
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/async/AsyncTaskServiceTests.java
Outdated
Show resolved
Hide resolved
Btw, I think we probably can drop the |
API Key can run-as since elastic#79809. There are places in the code where we assume API key cannot run-as. Most of them are corrected in elastic#81564. But there are still a few things got missed. This PR fixes the methods for checking owner user realm for API key. This means, when API Keys "running-as" (impersonating other users), we do not expose the authenticating key ID and name to the end-user such as the Authenticate API and the SetSecurityUseringest processor. Only the effective user is revealed, just like in the regular case of a realm user run as. For audit logging, the key's ID and name are not exposed either. But this is mainly because there are no existing fields suitable for these information. We do intend to add them later (elastic#84394) because auditing logging is to consumed by system admin instead of end-users. Note the resource sharing check (canAccessResourcesOf) also needs to be fixed, this will be handled by elastic#84277
* Fix owner user realm check for API key authentication (#84325) API Key can run-as since #79809. There are places in the code where we assume API key cannot run-as. Most of them are corrected in #81564. But there are still a few things got missed. This PR fixes the methods for checking owner user realm for API key. This means, when API Keys "running-as" (impersonating other users), we do not expose the authenticating key ID and name to the end-user such as the Authenticate API and the SetSecurityUseringest processor. Only the effective user is revealed, just like in the regular case of a realm user run as. For audit logging, the key's ID and name are not exposed either. But this is mainly because there are no existing fields suitable for these information. We do intend to add them later (#84394) because auditing logging is to consumed by system admin instead of end-users. Note the resource sharing check (canAccessResourcesOf) also needs to be fixed, this will be handled by #84277 * fix test
I added a few helper methods to |
Okay, I'll label this |
This fixes two things for the "can access" authz check: * API Keys running as, have access to the resources created by the effective run as user * tokens created by API Keys (with the client credentials) have access to the API Key's resources In addition, this PR moves some of the authz plumbing code from the Async and Scroll services classes under the Security Context class (as a minor refactoring).
* Fix can access resource checks for API Keys with run as (#84277) This fixes two things for the "can access" authz check: * API Keys running as, have access to the resources created by the effective run as user * tokens created by API Keys (with the client credentials) have access to the API Key's resources In addition, this PR moves some of the authz plumbing code from the Async and Scroll services classes under the Security Context class (as a minor refactoring). * spotless * Merge fallout * AuthenticationTests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This fixes two things for the "can access" authz check:
In addition, this PR moves some of the authz plumbing code from the Async and Scroll services classes under the Security Context class (as a minor refactoring).