Skip to content

Conversation

@blerer
Copy link
Contributor

@blerer blerer commented Oct 11, 2021

In some cases it is useful to prevent users to alter or drop a keyspace
while allowing them to create new tables.
This patch add support for a new DataResource below KEYSPACE but above
TABLE. The syntax to grant permission at this level in ALL TABLES IN
KEYSPACE.

Comment on lines 63 to 78
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: there are a few double spaces around here

Suggested change
assertUnauthorizedQuery("User user has no SELECT permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "SELECT * FROM %s WHERE pk = 1 AND ck = 1"));
assertUnauthorizedQuery("User user has no MODIFY permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "TRUNCATE TABLE %s"));
assertUnauthorizedQuery("User user has no ALTER permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "ALTER TABLE %s ADD val_2 int"));
assertUnauthorizedQuery("User user has no DROP permission on <table " + table + "> or any of its parents",
assertUnauthorizedQuery("User user has no SELECT permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "SELECT * FROM %s WHERE pk = 1 AND ck = 1"));
assertUnauthorizedQuery("User user has no MODIFY permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "TRUNCATE TABLE %s"));
assertUnauthorizedQuery("User user has no ALTER permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "ALTER TABLE %s ADD val_2 int"));
assertUnauthorizedQuery("User user has no DROP permission on <table " + table + "> or any of its parents",

Comment on lines 150 to 205
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: there are a few double spaces around here

Suggested change
assertUnauthorizedQuery("User user has no SELECT permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "SELECT * FROM %s WHERE pk = 1 AND ck = 1"));
assertUnauthorizedQuery("User user has no MODIFY permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "TRUNCATE TABLE %s"));
assertUnauthorizedQuery("User user has no ALTER permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "ALTER TABLE %s ADD val_2 int"));
assertUnauthorizedQuery("User user has no DROP permission on <table " + table + "> or any of its parents",
assertUnauthorizedQuery("User user has no SELECT permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "SELECT * FROM %s WHERE pk = 1 AND ck = 1"));
assertUnauthorizedQuery("User user has no MODIFY permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "TRUNCATE TABLE %s"));
assertUnauthorizedQuery("User user has no ALTER permission on <table " + table + "> or any of its parents",
formatQuery(KEYSPACE_PER_TEST, "ALTER TABLE %s ADD val_2 int"));
assertUnauthorizedQuery("User user has no DROP permission on <table " + table + "> or any of its parents",

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that this is here to generate a new currentTable() for the calls to formatQuery below, although it seems incidentally no-op here, is this right? Could we add a brief inline comment like create a new table name for the next calls to formatQuery?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the changes in this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's great that we have this available! :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it should be ensureAllTablesPermission

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add coverage for some other queries, such as as UPDATE and DELETE as it's done here, and perhaps even create/drop indexes and MVs, wdyt?

NEWS.txt Outdated
Comment on lines 41 to 42
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- A new ALL TABLES IN KEYSPACE resource has been added. It allows to grant permission for all tables and user types
in a keyspace while preventing the user to use those permission on the keyspace itself.
- A new ALL TABLES IN KEYSPACE resource has been added. It allows to grant permissions for all tables and user types
in a keyspace while preventing the user to use those permissions on the keyspace itself.

Comment on lines 831 to 833
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.trycompletions(
"GR",
immediate='ANT ')
self.trycompletions("GR",
immediate='ANT ')

I would probably keep the formatting for this and all following invocations similar to the one used in the other tests in the same class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add before the class @SuppressWarnings("SingleCharacterStringConcatenation") to remove the noise from the warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is warning seems to be an IDEA warning so I am reluctant to add annotation for those things to the code base.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, didn't you mean it to be 0 actually for disable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any number less or equal to zero will disable caching. I will change it to zero if it makes things less confusing.

Copy link
Contributor

@ekaterinadimitrova2 ekaterinadimitrova2 Oct 18, 2021

Choose a reason for hiding this comment

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

Yes, while it works it is documented (both cassandra.yaml and the website documentation) to use 0 for disable and a quick check shows me that In other unit tests (JMXAuthTest, UFAuthTest) we use 0. So I think it will indeed make it less confusing and more consistent if we keep it 0. Thank you :-)

In some cases it is useful to prevent users to alter or drop a keyspace
while allowing them to create new tables.
This patch add support for a new DataResource below KEYSPACE but above
TABLE. The syntax to grant permission at this level in ALL TABLES IN
KEYSPACE.
@blerer
Copy link
Contributor Author

blerer commented Oct 20, 2021

Committed manually

@blerer blerer closed this Oct 20, 2021
@blerer blerer deleted the CASSANDRA-17027 branch October 20, 2021 12:36
michaeljmarshall added a commit to michaeljmarshall/cassandra that referenced this pull request Sep 13, 2024
We cannot go to DC yet
because we need a two phase roll
out where any component that reads
sai indexes can already read DC,
but we haven't deployed the DC
reading code yet (there are still
pending fixes).
michaelsembwever pushed a commit to thelastpickle/cassandra that referenced this pull request Sep 25, 2024
We cannot go to DC yet
because we need a two phase roll
out where any component that reads
sai indexes can already read DC,
but we haven't deployed the DC
reading code yet (there are still
pending fixes).
michaelsembwever pushed a commit to thelastpickle/cassandra that referenced this pull request Jan 7, 2026
We cannot go to DC yet
because we need a two phase roll
out where any component that reads
sai indexes can already read DC,
but we haven't deployed the DC
reading code yet (there are still
pending fixes).
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.

3 participants