-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Feature] Support EXECUTE AS chaining via original user privilege check #68180
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
base: main
Are you sure you want to change the base?
[Feature] Support EXECUTE AS chaining via original user privilege check #68180
Conversation
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c658bfda90
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
fe/fe-spi/src/main/java/com/starrocks/authentication/AccessControlContext.java
Show resolved
Hide resolved
c658bfd to
383dd16
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 383dd16e72
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Enable multiple sequential EXECUTE AS statements on the same connection by checking IMPERSONATE privileges based on the original login user instead of the current impersonated user. - Store original user context (identity, groups, roles) in AccessControlContext - Initialize original context during authentication - Use original context for IMPERSONATE checks in AuthorizationMgr.canExecuteAs() - Add test case for EXECUTE AS chaining scenario - Fix security issue: reset original context on re-authentication to prevent new user from inheriting IMPERSONATE privileges from previous login user Maintains backward compatibility with fallback to current user behavior. Signed-off-by: Hoang Quoc Viet <[email protected]>
383dd16 to
3aa121b
Compare
Enable multiple sequential EXECUTE AS statements on the same connection by checking IMPERSONATE privileges based on the original login user instead of the current impersonated user.
new user from inheriting IMPERSONATE privileges from previous login user
Maintains backward compatibility with fallback to current user behavior.
Why I'm doing:
Currently, when using
EXECUTE AS user WITH NO REVERT, the system checks IMPERSONATE privileges based on the current impersonated user (currentUserIdentity), not the original login user (qualifiedUser). This creates a limitation where:EXECUTE AS user1 WITH NO REVERT, the connection context switches touser1EXECUTE AS user2 WITH NO REVERTon the same connection, the system checks ifuser1has IMPERSONATE privilege onuser2user1doesn't have IMPERSONATE privilege onuser2, the operation fails, even though the original login user (e.g.,admin_user) might have IMPERSONATE privileges on bothuser1anduser2This limitation prevents applications using connection pooling from chaining multiple
EXECUTE ASstatements on the same connection, forcing them to either:What I'm doing:
This PR enables
EXECUTE ASto check IMPERSONATE privileges based on the original login user instead of the current impersonated user, allowing multiple sequentialEXECUTE ASstatements on the same connection.Implementation details:
Store original user context in
AccessControlContext:originalUserIdentity,originalGroups, andoriginalRoleIdsfields to store the original login user context snapshotInitialize original context in
AuthenticationHandler:initOriginalUserContext()after setting groups and roles during authenticationModify privilege checking in
AuthorizationMgr.canExecuteAs():Add test case to verify the feature:
testExecuteAsChainUsesOriginalLoginUserForImpersonateCheck()verifies that chainingEXECUTE ASstatements works correctly based on original user privilegesExample usage:
-- Login as admin_user (has IMPERSONATE on user1 and user2)
EXECUTE AS user1 WITH NO REVERT;-- Checks: admin_user has IMPERSONATE on user1 ✓-- ... execute queries with user1 permissions ...
EXECUTE AS user2 WITH NO REVERT;-- Checks: admin_user has IMPERSONATE on user2 ✓ (now works!)Fixes #68149
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: