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

server, sql: add VIEWCLUSTERSETTING user privilege #76012

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

koorosh
Copy link
Collaborator

@koorosh koorosh commented Feb 4, 2022

Before, only users with admin role or MODIFYCLUSTERSETTING
permission could view cluster settings.
Now, new role is added to provide users view-only permission
to view cluster settings from SQL shell and in Db Console (in
Advanced debugging > Cluster settings).
This change doesn't change behavior for MODIFYCLUSTERSETTING
option, it also allows view and modify cluster settings.

Release note (sql change): new user privileges are added: VIEWCLUSTERSETTING
and NOVIEWCLUSTERSETTING that allows users to view cluster settings
only.

Resolves: #74692

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@koorosh koorosh force-pushed the view-cluster-setting-role branch 6 times, most recently from 8726717 to c07ac06 Compare February 7, 2022 16:06
Copy link
Contributor

@Santamaura Santamaura left a comment

Choose a reason for hiding this comment

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

Reviewed 8 of 9 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dhartunian, @koorosh, and @zachlite)


pkg/server/admin.go, line 1702 at r1 (raw file):

	}

	if !hasModify && !hasView {

Perhaps here it would be better to check if there's no modify first so we can skip the no view check if they do have the role:

Code snippet:

if !hasModify {
	if !hasView {
		...
	}	
}

pkg/sql/crdb_internal.go, line 1467 at r1 (raw file):

				return err
			}
			if !hasModify && !hasView {

same as above if you think it's worth the change.


pkg/sql/set_cluster_setting.go, line 79 at r1 (raw file):

		return err
	}
	if action == "show" && !(hasModify || hasView) {

logic here is slightly tricky to wrap one's head around maybe refactor to do the action check first:

Code snippet:

if action == "show" {
	...
}

Copy link
Collaborator Author

@koorosh koorosh 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 @dhartunian, @Santamaura, and @zachlite)


pkg/server/admin.go, line 1702 at r1 (raw file):

Previously, Santamaura (Alex Santamaura) wrote…

Perhaps here it would be better to check if there's no modify first so we can skip the no view check if they do have the role:

&& logical operator does the same optimization. It doesn't check next condition if previous one returns false


pkg/sql/crdb_internal.go, line 1467 at r1 (raw file):

Previously, Santamaura (Alex Santamaura) wrote…

same as above if you think it's worth the change.

That will work in the same way


pkg/sql/set_cluster_setting.go, line 79 at r1 (raw file):

Previously, Santamaura (Alex Santamaura) wrote…

logic here is slightly tricky to wrap one's head around maybe refactor to do the action check first:

I would try to avoid nested conditions as well, because it introduces additional "empty" conditional branches and might be confusing as well.
Probably it can be fixed with a good comment to describe this condition :)

Copy link
Contributor

@Santamaura Santamaura 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 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @dhartunian and @zachlite)

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.

Reviewed 3 of 9 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @koorosh, @Santamaura, and @zachlite)


pkg/server/admin.go, line 1700 at r3 (raw file):

	if err != nil {
		return nil, err
	}

consider creating a helper like requireViewOrModifyClusterSetting(). although now that I look at other usages it seems tough to re-use the helper since the other code areas have their own implementations. maybe best to keep the PR simple.


pkg/sql/logictest/testdata/logic_test/cluster_settings, line 100 at r3 (raw file):

WHERE variable IN ('sql.defaults.default_int_size')
----
sql.defaults.default_int_size  4

I'm a bit confused about this test and the one below...is the user root here? how is it able to see the clusters settings without VIEWCLUSTERSETTING being applied? is it there by default?

Copy link
Collaborator Author

@koorosh koorosh 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 (and 1 stale) (waiting on @dhartunian, @Santamaura, and @zachlite)


pkg/server/admin.go, line 1700 at r3 (raw file):

Previously, dhartunian (David Hartunian) wrote…

consider creating a helper like requireViewOrModifyClusterSetting(). although now that I look at other usages it seems tough to re-use the helper since the other code areas have their own implementations. maybe best to keep the PR simple.

I'm inclined to keep it simple because it doesn't allow to verify presence of single role.


pkg/sql/logictest/testdata/logic_test/cluster_settings, line 100 at r3 (raw file):

Previously, dhartunian (David Hartunian) wrote…

I'm a bit confused about this test and the one below...is the user root here? how is it able to see the clusters settings without VIEWCLUSTERSETTING being applied? is it there by default?

User has VIEWCLUSTERSETTING privilege + NOMODIFYCLUSTERSETTING (removed privilege to modify settings). It is done to ensure that user has only VIEWCLUSTERSETTING role.

Code quote:

user root

statement ok
ALTER USER testuser NOMODIFYCLUSTERSETTING

statement ok
ALTER USER testuser VIEWCLUSTERSETTING

user testuser

pkg/sql/logictest/testdata/logic_test/cluster_settings, line 111 at r3 (raw file):


statement ok
ALTER USER testuser NOVIEWCLUSTERSETTING

@dhartunian , Tests below validate that user without VIEWCLUSTERSETTING cannot query settings.

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.

:lgtm:

Reviewed 3 of 9 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @koorosh, @Santamaura, and @zachlite)


pkg/sql/logictest/testdata/logic_test/cluster_settings, line 100 at r3 (raw file):

Previously, koorosh (Andrii Vorobiov) wrote…

User has VIEWCLUSTERSETTING privilege + NOMODIFYCLUSTERSETTING (removed privilege to modify settings). It is done to ensure that user has only VIEWCLUSTERSETTING role.

ah! I got confused. you need to be root user to set the other privileges. thanks for clarifying

@koorosh koorosh force-pushed the view-cluster-setting-role branch 5 times, most recently from 417339f to 1a0c28a Compare February 22, 2022 10:44
@koorosh koorosh requested a review from a team as a code owner February 22, 2022 10:44
Before, only users with `admin` role or `MODIFYCLUSTERSETTING`
permission could view cluster settings.
Now, new role is added to provide users view-only permission
to view cluster settings from SQL shell and in Db Console (in
Advanced debugging > Cluster settings).
This change doesn't change behavior for `MODIFYCLUSTERSETTING`
option, it also allows view and modify cluster settings.

Release note (sql change): new user privileges are added: `VIEWCLUSTERSETTING`
and `NOVIEWCLUSTERSETTING` that allows users to view cluster settings
only.
@koorosh
Copy link
Collaborator Author

koorosh commented Feb 22, 2022

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Build succeeded:

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.

A non-admin user is incorrectly able to see Cluster Settings from DB Console
4 participants