Skip to content

Commit

Permalink
sql/builtins: remove the root special case
Browse files Browse the repository at this point in the history
Release note (sql change): The buil-in functions
`crdb_internal.force_panic`, `crdb_internal.force_log_fatal`,
`crdb_internal.set_vmodule`, `crdb_internal.get_vmodule` are now
available to all `admin` users, not just `root`.
  • Loading branch information
knz authored and RajivTS committed Mar 6, 2022
1 parent 387877b commit 1fbb406
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4448,9 +4448,7 @@ value if you rely on the HLC for accuracy.`,
return nil, err
}
if !isAdmin {
if err := checkPrivilegedUser(ctx); err != nil {
return nil, err
}
return nil, errInsufficientPriv
}

sp := tracing.SpanFromContext(ctx.Context)
Expand Down Expand Up @@ -4486,9 +4484,7 @@ value if you rely on the HLC for accuracy.`,
return nil, err
}
if !isAdmin {
if err := checkPrivilegedUser(ctx); err != nil {
return nil, err
}
return nil, errInsufficientPriv
}

traceID := tracingpb.TraceID(*(args[0].(*tree.DInt)))
Expand Down Expand Up @@ -4979,9 +4975,13 @@ value if you rely on the HLC for accuracy.`,
Types: tree.ArgTypes{{"msg", types.String}},
ReturnType: tree.FixedReturnType(types.Int),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
if err := checkPrivilegedUser(ctx); err != nil {
isAdmin, err := ctx.SessionAccessor.HasAdminRole(ctx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}
s, ok := tree.AsDString(args[0])
if !ok {
return nil, errors.Newf("expected string value, got %T", args[0])
Expand All @@ -5008,9 +5008,13 @@ value if you rely on the HLC for accuracy.`,
Types: tree.ArgTypes{{"msg", types.String}},
ReturnType: tree.FixedReturnType(types.Int),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
if err := checkPrivilegedUser(ctx); err != nil {
isAdmin, err := ctx.SessionAccessor.HasAdminRole(ctx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}
s, ok := tree.AsDString(args[0])
if !ok {
return nil, errors.Newf("expected string value, got %T", args[0])
Expand Down Expand Up @@ -5301,9 +5305,14 @@ value if you rely on the HLC for accuracy.`,
Types: tree.ArgTypes{{"vmodule_string", types.String}},
ReturnType: tree.FixedReturnType(types.Int),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
if err := checkPrivilegedUser(ctx); err != nil {
isAdmin, err := ctx.SessionAccessor.HasAdminRole(ctx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}

s, ok := tree.AsDString(args[0])
if !ok {
return nil, errors.Newf("expected string value, got %T", args[0])
Expand All @@ -5328,9 +5337,14 @@ value if you rely on the HLC for accuracy.`,
Types: tree.ArgTypes{},
ReturnType: tree.FixedReturnType(types.String),
Fn: func(ctx *tree.EvalContext, _ tree.Datums) (tree.Datum, error) {
if err := checkPrivilegedUser(ctx); err != nil {
// The user must be an admin to use this builtin.
isAdmin, err := ctx.SessionAccessor.HasAdminRole(ctx.Context)
if err != nil {
return nil, err
}
if !isAdmin {
return nil, errInsufficientPriv
}
return tree.NewDString(log.GetVModule()), nil
},
Info: "Returns the vmodule configuration on the gateway node processing this request.",
Expand Down Expand Up @@ -8878,13 +8892,6 @@ var errInsufficientPriv = pgerror.New(
pgcode.InsufficientPrivilege, "insufficient privilege",
)

func checkPrivilegedUser(ctx *tree.EvalContext) error {
if !ctx.SessionData().User().IsRootUser() {
return errInsufficientPriv
}
return nil
}

// EvalFollowerReadOffset is a function used often with AS OF SYSTEM TIME queries
// to determine the appropriate offset from now which is likely to be safe for
// follower reads. It is injected by followerreadsccl. An error may be returned
Expand Down

0 comments on commit 1fbb406

Please sign in to comment.