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

*: stop swallowing errors from privilege checks #95276

Merged
merged 5 commits into from
Jan 19, 2023

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Jan 16, 2023

sql: add HasPrivilege and HasAnyPrivilege to AuthorizationAccessor
*: stop swallowing errors from CheckPrivilegeForUser
*: stop swallowing errors from CheckAnyPrivilege
*: stop swallowing errors from CheckPrivilege
server: don't swallow error in hasGlobalPrivilege

Instead of swallowing errors, we use the new Has*Privilege functions. If
there was an error that causes the transaction to abort, it's important
to propagate it.

Epic: None
Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss changed the title sql: add HasPrivilege and HasAnyPrivilege to AuthorizationAccessor *: stop swallowing errors from privilege checks Jan 16, 2023
@rafiss rafiss force-pushed the refactor-check-privilege branch 3 times, most recently from 5cc31e3 to f0e4740 Compare January 17, 2023 19:05
@rafiss rafiss marked this pull request as ready for review January 17, 2023 21:43
@rafiss rafiss requested a review from a team as a code owner January 17, 2023 21:43
@rafiss rafiss requested a review from a team January 17, 2023 21:43
@rafiss rafiss requested a review from a team as a code owner January 17, 2023 21:43
@rafiss rafiss requested review from a team and rhu713 and removed request for a team January 17, 2023 21:43
Copy link
Contributor

@ecwall ecwall 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 @rafiss and @rhu713)


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

	// we don't get the risk to say "OK" to root requests
	// with an invalid API usage.
	if p.txn == nil {

This is a confusing place to check the txn since it looks like it is not used by this function.

Why is the function being called in the first place if there is no transaction?

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 @ecwall and @rhu713)


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

Previously, ecwall (Evan Wall) wrote…

This is a confusing place to check the txn since it looks like it is not used by this function.

Why is the function being called in the first place if there is no transaction?

i've just copied the existing check over from CheckAnyPrivilege

the txn is used in the function - the getPrivilegeDescriptor and MemberofWithAdminOption calls both use the txn.

the check was probably added as a defensive check since privilege checks occur early on during query planning and in the conn_executor, and it's better to have an assertion error instead of a panic if the txn was incorrectly set up. since it was already there, i think removing it should be done as a separate change after making sure it's ok to remove

Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

Just took a look at the status/admin server stuff. LGTM. My understanding is that the errs returned from any of the checks are not permission gates, but errors reading/retrieving the permission.

Reviewed 2 of 8 files at r1, 2 of 6 files at r2, 2 of 2 files at r5.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @rhu713)

@rafiss
Copy link
Collaborator Author

rafiss commented Jan 18, 2023

My understanding is that the errs returned from any of the checks are not permission gates, but errors reading/retrieving the permission.

tftr! yeah, that's the right understanding

@rafiss rafiss requested a review from ecwall January 18, 2023 16:34
@rafiss
Copy link
Collaborator Author

rafiss commented Jan 18, 2023

tftr!

bors r=ecwall

@craig
Copy link
Contributor

craig bot commented Jan 18, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 18, 2023

Build failed (retrying...):

@rafiss
Copy link
Collaborator Author

rafiss commented Jan 18, 2023

there's merge skew

  pkg/server/user.go:37:34: s.privilegeChecker.checkHasGlobalPrivilege undefined (type *adminPrivilegeChecker has no field or method checkHasGlobalPrivilege)

bors r-

@craig
Copy link
Contributor

craig bot commented Jan 18, 2023

Canceled.

The next commit will use these functions.

Release note: None
Instead of swallowing errors, we use the new HasPrivilege function. If
there was an error that causes the transaction to abort, it's important
to propagate it.

Release note: None
Instead of swallowing errors, we use the new HasAnyPrivilege function. If
there was an error that causes the transaction to abort, it's important
to propagate it.

Release note: None
Instead of swallowing errors, we use the new HasPrivilege function. If
there was an error that causes the transaction to abort, it's important
to propagate it.

Release note: None
The privilege check can return an internal error, so it should not be
swallowed.

Release note: None
@rafiss rafiss force-pushed the refactor-check-privilege branch from f0e4740 to 6fb8cc2 Compare January 18, 2023 21:51
@rafiss rafiss requested a review from a team as a code owner January 18, 2023 21:51
@rafiss
Copy link
Collaborator Author

rafiss commented Jan 18, 2023

bors r=ecwall

@craig
Copy link
Contributor

craig bot commented Jan 19, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 19, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 19, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 19, 2023

Build succeeded:

@craig craig bot merged commit b6434c9 into cockroachdb:master Jan 19, 2023
@rafiss rafiss deleted the refactor-check-privilege branch January 20, 2023 15:45
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.

4 participants