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

sql: support the GRANT ON SCHEMA command #53344

Merged
merged 1 commit into from
Aug 25, 2020
Merged

Conversation

rohany
Copy link
Contributor

@rohany rohany commented Aug 24, 2020

Fixes #50879.

This commit adds support for the GRANT ... ON SCHEMA ... TO ...
command and adds the necessary permissions checks that were missing.
Note that the USAGE permission is not implemented and will be done as
a follow up (#53342).

Release note (sql change): Add support for the GRANT ... ON SCHEMA command.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Generally LGTM. It would be nice if @ajwerner or @lucy-zhang could have a look at the resolver.go changes.

Random thought: we have that wildcard GRANT syntax for tables (GRANT SELECT ON TABLE db.* TO user`). Do we want to support that for schemas too? It's kind of weird and non-standard so I think it's ok if the answer is no.

Reviewed 7 of 16 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @lucy-zhang, @rohany, and @solongordon)


pkg/sql/resolver.go, line 308 at r1 (raw file):

		}

		if len(descs) == 0 {

How can descs be empty here? We just iterated over a non-empty Databases slice and appended a descriptor for each. Doesn't hurt anything I guess but I was confused by it. I think this applies below as well.


pkg/sql/logictest/testdata/logic_test/schema, line 246 at r1 (raw file):


# Test privilege interactions with schemas.
subtest privileges

Could you test REVOKE FROM SCHEMA as well?

@rohany
Copy link
Contributor Author

rohany commented Aug 24, 2020

Random thought: we have that wildcard GRANT syntax for tables (GRANT SELECT ON TABLE db.* TO user`). Do we want to support that for schemas too? It's kind of weird and non-standard so I think it's ok if the answer is no.

No, I don't think so. There are some postgres extensions for this that we should adopt instead (like grant.. on all tables in schema`)

Copy link
Contributor Author

@rohany rohany left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @lucy-zhang, and @solongordon)


pkg/sql/resolver.go, line 308 at r1 (raw file):

Previously, solongordon (Solon) wrote…

How can descs be empty here? We just iterated over a non-empty Databases slice and appended a descriptor for each. Doesn't hurt anything I guess but I was confused by it. I think this applies below as well.

Not sure, I was just cargo culting from the other cases. Removed


pkg/sql/logictest/testdata/logic_test/schema, line 246 at r1 (raw file):

Previously, solongordon (Solon) wrote…

Could you test REVOKE FROM SCHEMA as well?

Done

Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

That sounds right to me, thanks.

Reviewed 1 of 8 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @lucy-zhang, and @solongordon)

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

We should add docs to clarify what GRANT ... ON <db>.* means now.

@ericharmeling is this your domain?

Reviewed 1 of 16 files at r1, 4 of 8 files at r2, 1 of 6 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @lucy-zhang, and @rohany)


pkg/sql/logictest/testdata/logic_test/grant_database, line 104 at r3 (raw file):

SHOW GRANTS ON DATABASE a
----
a  crdb_internal       admin      ALL

I'm not clear on what part of this PR changed this set of privileges

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

err didn't mean to block, just want to see how this plays into the information schema better

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @lucy-zhang, and @rohany)

@rohany
Copy link
Contributor Author

rohany commented Aug 24, 2020

Yeah, grant * really means grant on all tables.

Those tests changed because I adjusted what privileges schemas are allowed to have — the entries removed correspond to privileges no longer allowed on schemas

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @lucy-zhang and @rohany)

Copy link
Contributor

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

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

Oops, I started with #53358 and looked at it all at once without noticing that this was the parent.

Reviewed 9 of 16 files at r1, 8 of 8 files at r2, 6 of 6 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rohany)

@rohany
Copy link
Contributor Author

rohany commented Aug 25, 2020

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 25, 2020

Merge conflict.

Fixes cockroachdb#50879.

This commit adds support for the `GRANT ... ON SCHEMA ... TO ...`
command and adds the necessary permissions checks that were missing.
Note that the `USAGE` permission is not implemented and will be done as
a follow up (cockroachdb#53342).

Release note (sql change): Add support for the `GRANT ... ON SCHEMA
command`.
@rohany
Copy link
Contributor Author

rohany commented Aug 25, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 25, 2020

Build succeeded:

@craig craig bot merged commit 38987bc into cockroachdb:master Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: support the GRANT .. TO SCHEMA command
5 participants