Impersonation: enforce target-role checks & cache#246
Merged
Conversation
Unifies and tightens EXECUTE AS USER (impersonation) authorization and hot-path optimizations. Key changes: - Introduces can_impersonate_target_user as the shared gate that allows self-targeting or role-matrix checks. - Uses the new helper across API handlers, SQL impersonation service, and session permissions to centralize authorization decisions and produce clearer audit/errors. - UsersTableProvider now maintains an in-memory privileged-role cache (Service/Dba/System) with role_for_impersonation_target to avoid per-request lookups for high-cardinality users; cache is refreshed at startup and updated on user changes. - SqlImpersonationService resolves target IDs and checks target-role via the privileged-role cache, auditing allowed/denied attempts and returning clearer Unauthorized errors. - ExecutionContext and table/provider comments updated to clarify explicit identity boundaries and cross-user authorization requirements. - API: file download endpoint now enforces impersonation authorization for user-table downloads and documents default subject scoping. - Tests and docs updated to reflect the role matrix (self-target allowed as no-op) and to exercise allowed/denied EXECUTE AS USER edges. - Minor formatting and test ergonomics fixes elsewhere. Rationale: centralize impersonation policy, make cross-user checks fast and auditable, and ensure ordinary user-table reads remain subject-scoped unless an explicit, authorized EXECUTE AS USER is performed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unifies and tightens EXECUTE AS USER (impersonation) authorization and hot-path optimizations.
Key changes:
Rationale: centralize impersonation policy, make cross-user checks fast and auditable, and ensure ordinary user-table reads remain subject-scoped unless an explicit, authorized EXECUTE AS USER is performed.