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

release-20.2: sql: Fix privilege checks to consider direct/indirect roles #58512

Merged
merged 1 commit into from
Jan 7, 2021

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Jan 6, 2021

Backport 1/1 commits from #58254.

/cc @cockroachdb/release


Resolves #57621

Previously, privilege inquiry functions only looked for whether
the user passed in in the first argument or current user had
privileges on schemas, databases, tables, etc. with the built-ins
such as has_schema_privileges, which was incorrect. This change
makes sure that all roles the user is a direct or indirect member
of are checked for privileges as well.

Release note (bug fix): The has_${OBJECT}_privilege built-in methods
such as has_schema_privilege now additionally checks whether roles
the user is a direct or indirect member of also have privileges on
the object. Previously only one user was checked which was incorrect.
This bug has been present since version 2.0 but became more
prominent as of v20.2 when role-based access control was included in
CockroachDB Core.

@rafiss rafiss requested review from angelapwen and a team January 6, 2021 20:54
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss force-pushed the backport20.2-58254 branch from 67f95cc to 059275c Compare January 6, 2021 22:41
statement ok
CREATE USER testuser2;
GRANT testuser TO testuser2;
GRANT ALL ON SCHEMA s TO testuser2
Copy link

@angelapwen angelapwen Jan 7, 2021

Choose a reason for hiding this comment

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

Seems to be failing here

testdata/logic_test/privilege_builtins:1104:
expected success, but found
(3F000) unknown schema "s"
errors.go:60: in NewUndefinedSchemaError()
logic.go:2693:
testdata/logic_test/privilege_builtins:1104: error while processing
logic.go:2693: pq: unknown schema "s"

Does it need to be my_db.s instead of just s? I'm not sure why it fails in 20.2 but not in the original PR.

Copy link
Collaborator Author

@rafiss rafiss Jan 7, 2021

Choose a reason for hiding this comment

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

ah i see... i had to remove that because this isn't (and won't be) backported to 20.2: #55647

hmm but i would have expected it to work since the current db is my_db... will investigate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah i see, probably because the user was switched to root.

Previously, privilege inquiry functions  only looked for whether
the user passed in in the first argument or current user had
privileges on schemas, databases, tables, etc. with the built-ins
such as `has_schema_privileges`, which was incorrect. This change
makes sure that all roles the user is a direct or indirect member
of are checked for privileges as well.

Release note (bug fix): The has_${OBJECT}_privilege built-in methods
such as `has_schema_privilege` now additionally checks whether roles
the user is a direct or indirect member of also have privileges on
the object. Previously only one user was checked which was incorrect.
This bug has been present since version 2.0 but became more
prominent as of v20.2 when role-based access control was included in
CockroachDB Core.
@rafiss rafiss force-pushed the backport20.2-58254 branch from 059275c to 4e2902c Compare January 7, 2021 05:38
@angelapwen angelapwen self-requested a review January 7, 2021 17:18
Copy link

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

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

Not sure if I was supposed to review before you merge, but LGTM!

@rafiss
Copy link
Collaborator Author

rafiss commented Jan 7, 2021

yes i needed your review! thank you :)

@rafiss rafiss merged commit 36a7014 into cockroachdb:release-20.2 Jan 7, 2021
@rafiss rafiss deleted the backport20.2-58254 branch January 7, 2021 17:32
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