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

Improve access control check for MV #18371

Merged

Conversation

homar
Copy link
Member

@homar homar commented Jul 21, 2023

Description

Add additional checks for access control for queries on materialized views that don't touch underlying data.

Additional context and related issues

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Jul 21, 2023
@@ -2193,6 +2193,7 @@ protected Scope visitTable(Table table, Optional<Scope> scope)
Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, name);
if (optionalMaterializedView.isPresent()) {
MaterializedViewDefinition materializedViewDefinition = optionalMaterializedView.get();
analysis.addEmptyColumnReferencesForTable(accessControl, session.getIdentity(), name);
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a test to TestAccessControl? This is a generic change for engine so we should have generic test coverage. I would even consider removing iceberg tests.

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 will add a test there but I'd prefer to leave an Iceberg test as it exactly covers what was the original problem

Copy link
Contributor

Choose a reason for hiding this comment

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

And perhaps also tests for regular views (if there aren't already), to make sure that they don't have the same issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

consider it done

Copy link
Member

@martint martint Jul 31, 2023

Choose a reason for hiding this comment

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

What’s the original problem? Please add motivation and details in the PR description.

@homar homar force-pushed the homar/add_missing_access_control_check branch from 42ee909 to 8a4d41e Compare July 21, 2023 11:53
@homar homar requested review from kokosing and ksobolew July 21, 2023 11:53
@homar homar force-pushed the homar/add_missing_access_control_check branch from 8a4d41e to bfda1d1 Compare July 21, 2023 12:04
Copy link
Contributor

@ksobolew ksobolew left a comment

Choose a reason for hiding this comment

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

I would consider the Iceberg tests redundant, too. For someone looking from the outside, it would seem strange why Iceberg and not all connectors?

@homar
Copy link
Member Author

homar commented Jul 21, 2023

I would consider the Iceberg tests redundant, too. For someone looking from the outside, it would seem strange why Iceberg and not all connectors?

ok i will remove them

@homar homar force-pushed the homar/add_missing_access_control_check branch from bfda1d1 to aa115bb Compare July 21, 2023 12:32
@homar homar requested a review from ksobolew July 21, 2023 12:32
@@ -158,15 +158,15 @@ protected SystemAccessControl delegate()
})
.withGetViews((connectorSession, prefix) -> {
ConnectorViewDefinition definitionRunAsDefiner = new ConnectorViewDefinition(
"select 1",
"select 1 as test",
Copy link
Member

Choose a reason for hiding this comment

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

Why? separate commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

It wont work without these changes so i think it can be in the same commit

Copy link
Member

Choose a reason for hiding this comment

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

this looks MV unrelated, so it looks unrelated to commit title, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Please tell me if current version is better

@homar homar force-pushed the homar/add_missing_access_control_check branch from aa115bb to ac39e50 Compare July 21, 2023 15:43
@@ -158,15 +158,15 @@ protected SystemAccessControl delegate()
})
.withGetViews((connectorSession, prefix) -> {
ConnectorViewDefinition definitionRunAsDefiner = new ConnectorViewDefinition(
"select 1",
Copy link
Member

Choose a reason for hiding this comment

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

Use capital letters for keywords

@@ -158,15 +158,15 @@ protected SystemAccessControl delegate()
})
Copy link
Member

Choose a reason for hiding this comment

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

Create views correctly

let's explain why it was incorrect

Not having a named column resulted in SemanticException
claiming that View is in invalid state:
"a column of type INTEGER projected from query view at position 1 has no name"
@homar homar force-pushed the homar/add_missing_access_control_check branch from ac39e50 to 311c39f Compare July 21, 2023 21:24
@homar
Copy link
Member Author

homar commented Jul 21, 2023

@kokosing commit message updated, upper case used

@homar homar requested a review from kokosing July 21, 2023 21:25
@@ -253,6 +253,18 @@ public void testAccessControl()
assertAccessAllowed("SELECT name AS my_alias FROM nation", privilege("my_alias", SELECT_COLUMN));
assertAccessAllowed("SELECT my_alias from (SELECT name AS my_alias FROM nation)", privilege("my_alias", SELECT_COLUMN));
assertAccessDenied("SELECT name AS my_alias FROM nation", "Cannot select from columns \\[name] in table .*.nation.*", privilege("nation.name", SELECT_COLUMN));
assertAccessAllowed("SELECT 1 FROM mock.default.test_materialized_view");
Copy link
Member

Choose a reason for hiding this comment

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

add a test also for SELECT count(*) FROM mock.default.test_materialized_view

Copy link
Member

@findepi findepi Jul 31, 2023

Choose a reason for hiding this comment

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

does this add anything on top of SELECT 1 FROM ..?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so, but that assumption is based on knowledge how semantic analyzer works. It is a another way of reading no column data, so maybe it could trigger different execution path too.

Copy link
Member

Choose a reason for hiding this comment

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

fine, but add a code comment explaining why we deem it worthwhile to fire up these two test queries, otherwise someone can just remove them saying they are redundant (because, in fact, they are)

@homar homar force-pushed the homar/add_missing_access_control_check branch from 311c39f to 74d8934 Compare August 1, 2023 09:00
@homar homar requested review from findepi and kokosing August 1, 2023 09:00
@homar homar force-pushed the homar/add_missing_access_control_check branch from 74d8934 to e7945f7 Compare August 1, 2023 09:41
@@ -2193,6 +2193,7 @@ protected Scope visitTable(Table table, Optional<Scope> scope)
Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, name);
if (optionalMaterializedView.isPresent()) {
MaterializedViewDefinition materializedViewDefinition = optionalMaterializedView.get();
analysis.addEmptyColumnReferencesForTable(accessControl, session.getIdentity(), name);
Copy link
Member

Choose a reason for hiding this comment

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

Improve access control check for views

change commit message to "Check materialized view access when no columns selected"

@homar homar force-pushed the homar/add_missing_access_control_check branch from e7945f7 to c103210 Compare August 1, 2023 09:51
@findepi findepi merged commit fa4a067 into trinodb:master Aug 1, 2023
@github-actions github-actions bot added this to the 423 milestone Aug 1, 2023
@findepi findepi mentioned this pull request Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

6 participants