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: require SELECT and UPDATE privileges for SELECT FOR UPDATE #57309

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

nvanbenschoten
Copy link
Member

Fixes #57282.

Before this change, SELECT ... FOR [KEY] UPDATE/SHARE statements replaced
the SELECT privilege check with an UPDATE privilege check. This was incorrect,
as the desired behavior is that the statement requires both SELECT and UPDATE
privileges. This commit fixes that bug.

I intend to backport this PR to v20.2 and v20.1.

Release note (bug fix): SELECT FOR UPDATE now requires both SELECT
and UPDATE privileges, instead of just UPDATE privileges.

Fixes cockroachdb#57282.

Before this change, `SELECT ... FOR [KEY] UPDATE/SHARE` statements replaced
the SELECT privilege check with an UPDATE privilege check. This was incorrect,
as the desired behavior is that the statement requires both SELECT and UPDATE
privileges. This commit fixes that bug.

Release note (bug fix): SELECT FOR UPDATE now requires both SELECT
and UPDATE privileges, instead of just UPDATE privileges.
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/sql/opt/optbuilder/select.go, line 108 at r1 (raw file):

		if locking.isSet() {
			// SELECT ... FOR [KEY] UPDATE/SHARE also requires UPDATE privileges.
			b.checkPrivilege(depName, ds, privilege.UPDATE)

It'd be nice to be able to pass a bitmask union of the two privileges to resolveDataSource, but it looks like that'd snowball into a much larger change, so probably not worth it.

Copy link
Member Author

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/sql/opt/optbuilder/select.go, line 108 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

It'd be nice to be able to pass a bitmask union of the two privileges to resolveDataSource, but it looks like that'd snowball into a much larger change, so probably not worth it.

Yeah, I was hoping this would be as easy as a pair of s/=/|=/, but it was more involved. This comes up in the mutation paths as well, so we may want to revisit the representation of these privileges at some point to allow for such operations.

@craig
Copy link
Contributor

craig bot commented Dec 1, 2020

Build succeeded:

@craig craig bot merged commit 3d0f281 into cockroachdb:master Dec 1, 2020
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/sfuPerms branch December 2, 2020 01:01
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: SELECT FOR UPDATE doen't perform a SELECT privilege check
3 participants