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: prevent dropped user from accessing the cluster #104215

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Jun 1, 2023

fixes #20718

Release note (bug fix): Previously if a user was logged in while a different session dropped that user, the dropped user would still inherit privileges from the public role. Now, CockroachDB checks that the user exists before allowing it to inherit privileges from the public role.

In addition, any active web sessions are now revoked when a user is dropped.

@rafiss rafiss requested a review from andyyang890 June 1, 2023 17:03
@rafiss rafiss requested a review from a team as a code owner June 1, 2023 17:03
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this! Just had one minor question

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


pkg/sql/authorization.go line 178 at r1 (raw file):

	// Check if the 'public' pseudo-role has privileges.
	if privs.CheckPrivilege(username.PublicRoleName(), privilegeKind) {
		// Before returning true, make sure the user actually exists.

Is there a reason we don't check that the user exists if the public pseudo-role does not have privileges? i.e. why not unnest this check and move it before checking the public pseudo-role?


pkg/sql/drop_role.go line 454 at r1 (raw file):

		numRoleSettingsRowsDeleted += rowsDeleted

		rowsDeleted, err = params.p.InternalSQLTxn().ExecEx(

The compiler is complaining that this value for rowsDeleted isn't being used. Maybe replace it with an underscore?


pkg/sql/tests/drop_role_concurrent_session_test.go line 31 at r1 (raw file):

// Test that if a user is dropped while a session is active, the session can
// no longer access objects in the cluster.
func TestDropRoleConcurrentSession(t *testing.T) {

Nice test!

Copy link
Collaborator Author

@rafiss rafiss 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 @andyyang890)


pkg/sql/authorization.go line 178 at r1 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

Is there a reason we don't check that the user exists if the public pseudo-role does not have privileges? i.e. why not unnest this check and move it before checking the public pseudo-role?

my reasoning was that inheriting from public is the only way that a dropped user can end up passing this privilege check. if the public role does not have privileges, then the next check below (p.checkRolePredicate) is guaranteed to fail since the dropped user will not be anywhere in the role hierarchy. it's better to avoid the call to RoleExists unless it's needed, since it does cause an extra lookup.

i'll add some comments


pkg/sql/drop_role.go line 454 at r1 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

The compiler is complaining that this value for rowsDeleted isn't being used. Maybe replace it with an underscore?

done


pkg/sql/tests/drop_role_concurrent_session_test.go line 31 at r1 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

Nice test!

thanks!

@rafiss rafiss force-pushed the remove-dropped-user-access branch from ce3a459 to 605f06a Compare June 5, 2023 19:16
@rafiss rafiss requested a review from andyyang890 June 5, 2023 19:16
@rafiss rafiss force-pushed the remove-dropped-user-access branch from 605f06a to 749f10d Compare June 5, 2023 21:51
Copy link
Collaborator

@andyyang890 andyyang890 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

@rafiss rafiss force-pushed the remove-dropped-user-access branch 2 times, most recently from 4ec3db7 to a4ade35 Compare June 7, 2023 15:18
Release note (bug fix): Previously if a user was logged in while a
different session dropped that user, the dropped user would still
inherit privileges from the `public` role. Now, CockroachDB checks that
the user exists before allowing it to inherit privileges from the
`public` role.

In addition, any active web sessions are now revoked when a user is dropped.
@rafiss rafiss force-pushed the remove-dropped-user-access branch from a4ade35 to 12ec26f Compare June 7, 2023 18:33
@rafiss rafiss requested a review from a team as a code owner June 7, 2023 18:33
@rafiss rafiss requested review from dt and removed request for a team June 7, 2023 18:33
@rafiss
Copy link
Collaborator Author

rafiss commented Jun 7, 2023

tftr!

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 7, 2023

Build succeeded:

@craig craig bot merged commit 618a893 into cockroachdb:master Jun 7, 2023
@rafiss rafiss deleted the remove-dropped-user-access branch June 8, 2023 03:58
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: ensures that users can't access the DB after DROP USER
3 participants