-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This function provides a way to verify FIPS readiness without modifying the deployment to add the --enterprise-require-fips-ready flag. Updates #114344 Release note (enterprise change): New SQL function fips_ready can be used to verify the FIPS readiness of the gateway node.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
subtest fips_ready | ||
|
||
# We do not have the plumbing that would let test cases know whether they are | ||
# running in a fips environment or not so this is just a very basic test to | ||
# make sure that all the registration, oids, etc work properly. | ||
query _ | ||
SELECT crdb_internal.fips_ready() | ||
---- | ||
_ | ||
|
||
user testuser | ||
|
||
statement error pq: crdb_internal\.fips_ready\(\): user testuser does not have VIEWCLUSTERSETTING system privilege | ||
SELECT crdb_internal.fips_ready() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package fipsccl | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/utilccl" | ||
"github.com/cockroachdb/cockroach/pkg/sql/privilege" | ||
"github.com/cockroachdb/cockroach/pkg/sql/roleoption" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" | ||
"github.com/cockroachdb/cockroach/pkg/sql/syntheticprivilege" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
) | ||
|
||
func init() { | ||
overload := tree.Overload{ | ||
Types: tree.ParamTypes{}, | ||
ReturnType: tree.FixedReturnType(types.Bool), | ||
Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { | ||
if err := utilccl.CheckEnterpriseEnabled( | ||
evalCtx.Settings, evalCtx.ClusterID, "fips_ready", | ||
); err != nil { | ||
return nil, err | ||
} | ||
// It's debatable whether we need a permission check here at all. | ||
// It's not very sensitive and is (currently) a very cheap function | ||
// call. However, it's something that regular users should have no | ||
// reason to look at so in the interest of least privilege we put it | ||
// behind the VIEWCLUSTERSETTING privilige. | ||
session := evalCtx.SessionAccessor | ||
isAdmin, err := session.HasAdminRole(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !isAdmin { | ||
hasView, err := session.HasRoleOption(ctx, roleoption.VIEWCLUSTERSETTING) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !hasView { | ||
if err := session.CheckPrivilege(ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.VIEWCLUSTERSETTING); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
return tree.MakeDBool(tree.DBool(IsFIPSReady())), nil | ||
}, | ||
Class: tree.NormalClass, | ||
Volatility: volatility.Stable, | ||
} | ||
|
||
utilccl.RegisterCCLBuiltin("crdb_internal.fips_ready", | ||
`Returns true if all FIPS readiness checks pass.`, | ||
overload) | ||
} |