Skip to content

Commit

Permalink
builtins: allow VIEWACTIVITY priv to use crdb_internal.request_statem…
Browse files Browse the repository at this point in the history
…ent_bundle

Previously only those with the VIEWACTIVITY role could use the
crdb_internal.request_statement_bundle builtin. We should allow
the VIEWACTIVITY privilege as well since role options are now
deprecated. This allow also allow stmt bundle requests to be made
from db-console for users with this granted privilege.

Epic: none
Fixes: #118759

Release note (bug fix): Those with VIEWACTIVITY privilege can now
request statement bundles using crdb_internal.requets_statement_bundle
or via db-console's sql activity page.
  • Loading branch information
xinhaoz committed Feb 23, 2024
1 parent 89b0b71 commit b268b65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/server/application_api/stmtdiag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestCreateStatementDiagnosticsReportWithViewActivityOptions(t *testing.T) {
require.Contains(t, err.Error(), "requesting statement bundle requires VIEWACTIVITY or ADMIN role option")

// Grant VIEWACTIVITY and all test should work.
db.Exec(t, fmt.Sprintf("ALTER USER %s VIEWACTIVITY", apiconstants.TestingUserNameNoAdmin().Normalized()))
db.Exec(t, fmt.Sprintf("GRANT SYSTEM VIEWACTIVITY TO %s", apiconstants.TestingUserNameNoAdmin().Normalized()))
req := &serverpb.CreateStatementDiagnosticsReportRequest{
StatementFingerprint: "INSERT INTO test VALUES (_)",
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestCreateStatementDiagnosticsReportWithViewActivityOptions(t *testing.T) {
`, [][]string{{"1"}})

// Grant VIEWACTIVITYREDACTED and all test should get permission errors.
db.Exec(t, fmt.Sprintf("ALTER USER %s VIEWACTIVITYREDACTED", apiconstants.TestingUserNameNoAdmin().Normalized()))
db.Exec(t, fmt.Sprintf("GRANT SYSTEM VIEWACTIVITYREDACTED TO %s", apiconstants.TestingUserNameNoAdmin().Normalized()))

if err := srvtestutils.PostStatusJSONProtoWithAdminOption(ts, "stmtdiagreports", req, &resp, false); err != nil {
if !testutils.IsError(err, "status: 403") {
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -11466,8 +11466,8 @@ true, then any plan other then the specified gist will be used`
Types: typs,
ReturnType: tree.FixedReturnType(types.Bool),
Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) {
hasViewActivity, err := evalCtx.SessionAccessor.HasRoleOption(
ctx, roleoption.VIEWACTIVITY)
hasViewActivity, err := evalCtx.SessionAccessor.HasGlobalPrivilegeOrRoleOption(
ctx, privilege.VIEWACTIVITY)
if err != nil {
return nil, err
}
Expand All @@ -11482,8 +11482,8 @@ true, then any plan other then the specified gist will be used`
return nil, err
}

hasViewActivityRedacted, err := evalCtx.SessionAccessor.HasRoleOption(
ctx, roleoption.VIEWACTIVITYREDACTED)
hasViewActivityRedacted, err := evalCtx.SessionAccessor.HasGlobalPrivilegeOrRoleOption(
ctx, privilege.VIEWACTIVITYREDACTED)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b268b65

Please sign in to comment.