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

release-22.1: builtins: check privileges for crdb_internal builtins #83972

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/row_level_ttl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ SELECT crdb_internal.repair_ttl_table_scheduled_job('tbl'::regclass::oid)
statement ok
SELECT crdb_internal.validate_ttl_scheduled_jobs()

let $tbl_oid
SELECT 'tbl'::regclass::oid

user testuser

statement error insufficient privilege
SELECT crdb_internal.repair_ttl_table_scheduled_job($tbl_oid)

statement error insufficient privilege
SELECT crdb_internal.validate_ttl_scheduled_jobs()

user root

statement error resetting "ttl_expire_after" is not permitted\nHINT: use `RESET \(ttl\)` to remove TTL from the table
ALTER TABLE tbl RESET (ttl_expire_after)

Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6571,6 +6571,13 @@ table's zone configuration this will return NULL.`,
Types: tree.ArgTypes{},
ReturnType: tree.FixedReturnType(types.Void),
Fn: func(evalCtx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
isAdmin, err := evalCtx.SessionAccessor.HasAdminRole(evalCtx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}
return tree.DVoidDatum, evalCtx.Planner.ValidateTTLScheduledJobsInCurrentDB(evalCtx.Context)
},
Info: `Validate all TTL tables have a valid scheduled job attached.`,
Expand All @@ -6586,6 +6593,13 @@ table's zone configuration this will return NULL.`,
Types: tree.ArgTypes{{"oid", types.Oid}},
ReturnType: tree.FixedReturnType(types.Void),
Fn: func(evalCtx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
isAdmin, err := evalCtx.SessionAccessor.HasAdminRole(evalCtx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}
oid := tree.MustBeDOid(args[0])
if err := evalCtx.Planner.RepairTTLScheduledJobForTable(evalCtx.Ctx(), int64(oid.DInt)); err != nil {
return nil, err
Expand Down