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

Always create new identity for view owner #15111

Merged
merged 3 commits into from
Dec 9, 2022

Conversation

kokosing
Copy link
Member

No description provided.

@cla-bot cla-bot bot added the cla-signed label Nov 18, 2022
@kokosing
Copy link
Member Author

Supersedes #13991 and #14130

@kokosing kokosing changed the title Always create new view owner's identity Always create new identity for view owner Nov 18, 2022
@kokosing kokosing force-pushed the origin/master/159_view branch from 5426e6a to 2d57b0f Compare November 18, 2022 21:07
@kokosing kokosing force-pushed the origin/master/159_view branch from 2d57b0f to 4cd7187 Compare November 19, 2022 20:54
identity = Identity.from(owner.get())
.withGroups(groupProvider.getGroups(owner.get().getUser()))
.build();
viewAccessControl = new ViewAccessControl(accessControl, session.getIdentity());
if (owner.get().getUser().equals(session.getIdentity().getUser())) {
Copy link
Member Author

Choose a reason for hiding this comment

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

thanks to this if view owner does not require GRANT OPTION to access base tables. Do you think I should update the comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, "don't restrict owner's access" is kinda vague... And this rule that view owner does not require grant option is kinda obscure. Probably a good idea to clarify.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that "Always create new identity for view owner" conveys no meaning. It's not terrible -- a person reading commit log may understand that the title doesn't hint and the change meaning and will proably read the full message. but we could do better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I improved commit message too.

@kokosing kokosing force-pushed the origin/master/159_view branch from 4cd7187 to bee9b03 Compare November 21, 2022 11:42
@kokosing kokosing requested review from martint and dain November 21, 2022 11:45
@kokosing kokosing requested a review from findepi November 24, 2022 10:33
identity = Identity.from(owner.get())
.withGroups(groupProvider.getGroups(owner.get().getUser()))
.build();
viewAccessControl = new ViewAccessControl(accessControl, session.getIdentity());
if (owner.get().getUser().equals(session.getIdentity().getUser())) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree that "Always create new identity for view owner" conveys no meaning. It's not terrible -- a person reading commit log may understand that the title doesn't hint and the change meaning and will proably read the full message. but we could do better.

.setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class)
.setBinding()
.to(TestingSystemSecurityMetadata.class)
Copy link
Member

Choose a reason for hiding this comment

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

Does this change meaning of all pre-existing tests in this class?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Other tests rely on TestingAccessControlManager which controls testing privileges.

Also notice that by default we were using DisabledSystemSecurityMetadata which was returning empty for getViewRunAsIdentity. This works the same way with TestingSystemSecurityMetadata as nobody calls setViewOwner directly.

Comment on lines 346 to 351
// TestingAccessControlManager works by denying accesses, so:
// * viewOwnerSession does not have deniedrole enabled
// * the owner has a role grant to deniedrole
// we deny access to deniedrole, so:
// * even though viewOwnerSession would be allowed,
// * the session created for view owner will be denied
Copy link
Member

Choose a reason for hiding this comment

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

Are we testing TestingAccessControlManager? I..e. testing the testing code?

Copy link
Member Author

Choose a reason for hiding this comment

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

No really. But we need mocks to work as real implementation. I will improve a comment. It is a bit scary and moves focus towards testing code.

@@ -4522,7 +4522,7 @@ private void analyzeRowFilter(String currentIdentity, Table table, QualifiedObje
ExpressionAnalysis expressionAnalysis;
try {
expressionAnalysis = ExpressionAnalyzer.analyzeExpression(
createViewSession(filter.getCatalog(), filter.getSchema(), Identity.forUser(filter.getIdentity()).build(), session.getPath()), // TODO: path should be included in row filter
createViewSession(filter.getCatalog(), filter.getSchema(), Identity.ofUser(filter.getIdentity()), session.getPath()), // TODO: path should be included in row filter
Copy link
Member

Choose a reason for hiding this comment

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

👍
Let's maybe move it to separate PR?

@kokosing kokosing force-pushed the origin/master/159_view branch from bee9b03 to 11984c7 Compare December 2, 2022 14:38
Copy link
Member Author

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Addressed comments. Please take a look.

identity = Identity.from(owner.get())
.withGroups(groupProvider.getGroups(owner.get().getUser()))
.build();
viewAccessControl = new ViewAccessControl(accessControl, session.getIdentity());
if (owner.get().getUser().equals(session.getIdentity().getUser())) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I improved commit message too.

.setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class)
.setBinding()
.to(TestingSystemSecurityMetadata.class)
Copy link
Member Author

Choose a reason for hiding this comment

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

No. Other tests rely on TestingAccessControlManager which controls testing privileges.

Also notice that by default we were using DisabledSystemSecurityMetadata which was returning empty for getViewRunAsIdentity. This works the same way with TestingSystemSecurityMetadata as nobody calls setViewOwner directly.

Comment on lines 346 to 351
// TestingAccessControlManager works by denying accesses, so:
// * viewOwnerSession does not have deniedrole enabled
// * the owner has a role grant to deniedrole
// we deny access to deniedrole, so:
// * even though viewOwnerSession would be allowed,
// * the session created for view owner will be denied
Copy link
Member Author

Choose a reason for hiding this comment

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

No really. But we need mocks to work as real implementation. I will improve a comment. It is a bit scary and moves focus towards testing code.

@kokosing kokosing force-pushed the origin/master/159_view branch 2 times, most recently from 3743ed5 to f39a776 Compare December 7, 2022 12:57
ksobolew and others added 3 commits December 8, 2022 23:47
The rationale is that, in addition to the user name, all of these can
affect access control decisions for an `Identity`, so they should be
considered distinct if any of those attributes differ.

The `StatementAnalyzer`, during the analysis stage, collects all table
references along with their corresponding access controls and
identities. At the end of the analysis, this is used to do the access
checks. They are collected in a `Map`, where the key is the pair of
access control and `Identity`, so that we deduplicate the necessary
checks. But for this deduplication to work properly, `Identity`
instances that result in different accesses should be considered
distinct.

Remove obsolete AccessControlUtil.FullIdentityEquality.
Now `Identity` itself has full identity.
The test is single-threaded so using `executeExclusively`
is not much beneficial. Removing usage of that method makes a test way
simplified.
Session user may have not always all roles enabled. Reusing session when
session user equals view owner may end up with different access.

Notice, that we can still reuse access control and not use dedicated
view access control. This is because view owner does not need to grant
access to itself, having access is just enough. I mean view owner does
not requires privileges with GRANT OPTION to access objects used in the
view.

Co-authored-by: Grzegorz Kokosiński <grzegorz@starburstdata.com>
@kokosing kokosing force-pushed the origin/master/159_view branch from f39a776 to 36934db Compare December 8, 2022 22:47
return queries.stream()
.filter(queryInfo -> {
Identity queryIdentity = queryInfo.getSession().toIdentity();
return queryIdentity.getUser().equals(identity.getUser()) || allowedOwners.contains(new FullIdentityEquality(queryIdentity));
return queryIdentity.getUser().equals(identity.getUser()) || allowedOwners.contains(queryIdentity);
Copy link
Member

Choose a reason for hiding this comment

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

nit: previously it was a set whereas now it's just a collection so contains might be a bit slower (assuming the returned collection is not actually a set ofc)

@kokosing kokosing merged commit ebbb2fb into trinodb:master Dec 9, 2022
@kokosing kokosing deleted the origin/master/159_view branch December 9, 2022 14:07
@github-actions github-actions bot added this to the 404 milestone Dec 9, 2022
@colebow
Copy link
Member

colebow commented Dec 14, 2022

Does this need a release note? @kokosing

@kokosing
Copy link
Member Author

I don't think so.

@kokosing kokosing added the no-release-notes This pull request does not require release notes entry label Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

6 participants