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: enforce admin role for resetting sql stats and index usage stats #79810

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

Azhng
Copy link
Contributor

@Azhng Azhng commented Apr 11, 2022

Resolves #79688

Previously, SQL Stats and Index Usage Stats can be reset through SQL CLI
using crdb_internal.reset_sql_stats() and
crdb_internal.reset_index_usage_stats() builtins. However, these two
builtins were not checking for users admin role. Hence, any user can
reset SQL Stats and Index Usage Stats.
This commit enforces the permission check.

Release note (security update): crdb_internal.reset_sql_stats() and
crdb_internal.reset_index_usage_stats() builtins now check if user has
admin role.

@Azhng Azhng requested a review from a team April 11, 2022 23:21
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Azhng Azhng marked this pull request as ready for review April 12, 2022 16:45
@Azhng Azhng requested a review from a team as a code owner April 12, 2022 16:45
@Azhng Azhng requested a review from a team April 12, 2022 16:45
Copy link
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

LGTM after comments are addressed

return nil, err
}
if !isAdmin {
return nil, errors.New("crdb_internal.reset_index_usage_stats() require admin privilege")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: requires admin privilege

return nil, err
}
if !isAdmin {
return nil, errors.New("crdb_internal.reset_sql_stats() require admin privilege")
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

// TestResetIndexUsageStatsOnRemoteSQLNode asserts that the built-in for
// resetting index usage statistics works when it's being set up on a remote
// node via DistSQL.
func TestResetIndexUsageStatsOnRemoteSQLNode(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unfamiliar with the terminology here - does remote node mean not gateway?

I don't think we have a test here to run crdb_internal.reset_index_usage_stats() on a gateway node either.

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Do we really want to restrict this to admin role only? Doesn't VIEWACTIVITY and VIEWACTIVITYREDACTED should be able to do this?
Otherwise we might want to hide all the reset options on the ui if that is indeed the decision.
@kevin-v-ngo thoughts?

Reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @Azhng, @maryliag, and @RichardJCai)


pkg/sql/sem/builtins/builtins.go, line 6425 at r1 (raw file):

		tree.FunctionProperties{
			Category:         categorySystemInfo,
			DistsqlBlocklist: true, // applicable only on the gateway

nit: DistSQLBlocklist

Copy link
Contributor Author

@Azhng Azhng left a comment

Choose a reason for hiding this comment

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

@RichardJCai the reset_index_usage_stats() is tested on the tenant_status_test.go.

I'm unfamiliar with the terminology here - does remote node mean not gateway?

Yes. This was because previously, DistSQL can potentially push down the filter, which means the builtin can be executed on the remote node. Now this behavior is disallowed by setting DistsqlBlocklist to true. So it's a case we don't have to worry about.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @RichardJCai)


pkg/sql/sem/builtins/builtins.go, line 6425 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: DistSQLBlocklist

Hmm this is an existing field owned by a different team. I'll make a separate PR for this change, since this will change all the builtins.


pkg/sql/sem/builtins/builtins.go, line 6436 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

nit: requires admin privilege

Done.


pkg/sql/sem/builtins/builtins.go, line 6465 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

ditto

Done.

Resolves cockroachdb#79688

Previously, SQL Stats and Index Usage Stats can be reset through SQL CLI
using crdb_internal.reset_sql_stats() and
crdb_internal.reset_index_usage_stats() builtins. However, these two
builtins were not checking for users admin role. Hence, any user can
reset SQL Stats and Index Usage Stats.
This commit enforces the permission check.

Release note (security update): crdb_internal.reset_sql_stats() and
crdb_internal.reset_index_usage_stats() builtins now check if user has
admin role.
Copy link
Contributor

@maryliag maryliag 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 2 of 5 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RichardJCai)

@Azhng
Copy link
Contributor Author

Azhng commented Apr 20, 2022

bors r=maryliag

@craig
Copy link
Contributor

craig bot commented Apr 20, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Apr 20, 2022

Build succeeded:

@Azhng
Copy link
Contributor Author

Azhng commented Apr 22, 2022

blather backport 22.1.0

@Azhng
Copy link
Contributor Author

Azhng commented Apr 22, 2022

blathers backport release-22.1.0

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: security issue in sql stats
4 participants