-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Allow ViewExpression use session user explicitly #16436
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2279,7 +2279,7 @@ private void analyzeFiltersAndMasks(Table table, QualifiedObjectName name, Relat | |
| private void analyzeCheckConstraints(Table table, QualifiedObjectName name, Scope accessControlScope, List<String> constraints) | ||
| { | ||
| for (String constraint : constraints) { | ||
| ViewExpression expression = new ViewExpression(session.getIdentity().getUser(), Optional.of(name.getCatalogName()), Optional.of(name.getSchemaName()), constraint); | ||
| ViewExpression expression = new ViewExpression(Optional.empty(), Optional.of(name.getCatalogName()), Optional.of(name.getSchemaName()), constraint); | ||
| analyzeCheckConstraint(table, name, accessControlScope, expression); | ||
| } | ||
| } | ||
|
|
@@ -4663,9 +4663,11 @@ private void analyzeRowFilter(String currentIdentity, Table table, QualifiedObje | |
|
|
||
| ExpressionAnalysis expressionAnalysis; | ||
| try { | ||
| Identity filterIdentity = Identity.forUser(filter.getIdentity()) | ||
| .withGroups(groupProvider.getGroups(filter.getIdentity())) | ||
| .build(); | ||
| Identity filterIdentity = filter.getSecurityIdentity() | ||
| .map(filterUser -> Identity.forUser(filterUser) | ||
| .withGroups(groupProvider.getGroups(filterUser)) | ||
| .build()) | ||
| .orElseGet(session::getIdentity); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can there be any difference between cases
is it worth having a code comment why we don't check equality between them?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I tried to make it so that when the expression's identity is the same as the session's user then the latter is re-used, and it was vetoed. But I think making it explicit that it should be reused is a better way to go. Also, extending the view analogy, with views we do have special handling if the current session's user is the same as the view's owner (some restrictions are relaxed then). So there may be a difference between these two, but I don't think there would be any meaningful difference in semantics.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We used have that for views and it was also causing issues. When session had limited set of roles, so they couldn't select the view because view wanted more roles. It got removed. So now in views the there is no custom logic for when view owner is the same as same user. "Impersonation" works the same way for any user now for views. This commit is going to make something similar for filters and masks.
Yes. The former will impersonate the user to itself, and so the information about roles could change. |
||
| expressionAnalysis = ExpressionAnalyzer.analyzeExpression( | ||
| createViewSession(filter.getCatalog(), filter.getSchema(), filterIdentity, session.getPath()), // TODO: path should be included in row filter | ||
| plannerContext, | ||
|
|
@@ -4714,11 +4716,13 @@ private void analyzeCheckConstraint(Table table, QualifiedObjectName name, Scope | |
|
|
||
| ExpressionAnalysis expressionAnalysis; | ||
| try { | ||
| Identity filterIdentity = Identity.forUser(constraint.getIdentity()) | ||
| .withGroups(groupProvider.getGroups(constraint.getIdentity())) | ||
| .build(); | ||
| Identity constraintIdentity = constraint.getSecurityIdentity() | ||
| .map(user -> Identity.forUser(user) | ||
| .withGroups(groupProvider.getGroups(user)) | ||
| .build()) | ||
| .orElseGet(session::getIdentity); | ||
| expressionAnalysis = ExpressionAnalyzer.analyzeExpression( | ||
| createViewSession(constraint.getCatalog(), constraint.getSchema(), filterIdentity, session.getPath()), | ||
| createViewSession(constraint.getCatalog(), constraint.getSchema(), constraintIdentity, session.getPath()), | ||
| plannerContext, | ||
| statementAnalyzerFactory, | ||
| accessControl, | ||
|
|
@@ -4777,9 +4781,11 @@ private void analyzeColumnMask(String currentIdentity, Table table, QualifiedObj | |
| verifyNoAggregateWindowOrGroupingFunctions(session, metadata, expression, format("Column mask for '%s.%s'", table.getName(), column)); | ||
|
|
||
| try { | ||
| Identity maskIdentity = Identity.forUser(mask.getIdentity()) | ||
| .withGroups(groupProvider.getGroups(mask.getIdentity())) | ||
| .build(); | ||
| Identity maskIdentity = mask.getSecurityIdentity() | ||
| .map(maskUser -> Identity.forUser(maskUser) | ||
| .withGroups(groupProvider.getGroups(maskUser)) | ||
| .build()) | ||
| .orElseGet(session::getIdentity); | ||
| expressionAnalysis = ExpressionAnalyzer.analyzeExpression( | ||
| createViewSession(mask.getCatalog(), mask.getSchema(), maskIdentity, session.getPath()), // TODO: path should be included in row filter | ||
| plannerContext, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.