Skip to content

Commit d011be7

Browse files
committed
fipsccl: Add a SQL function to check fips status
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.
1 parent 5db86ec commit d011be7

File tree

14 files changed

+146
-0
lines changed

14 files changed

+146
-0
lines changed

pkg/ccl/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go_library(
2222
"//pkg/ccl/partitionccl",
2323
"//pkg/ccl/pgcryptoccl",
2424
"//pkg/ccl/plpgsqlccl",
25+
"//pkg/ccl/securityccl/fipsccl",
2526
"//pkg/ccl/storageccl",
2627
"//pkg/ccl/storageccl/engineccl",
2728
"//pkg/ccl/streamingccl/streamingest",

pkg/ccl/ccl_init.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
_ "github.com/cockroachdb/cockroach/pkg/ccl/partitionccl"
2929
_ "github.com/cockroachdb/cockroach/pkg/ccl/pgcryptoccl"
3030
_ "github.com/cockroachdb/cockroach/pkg/ccl/plpgsqlccl"
31+
_ "github.com/cockroachdb/cockroach/pkg/ccl/securityccl/fipsccl"
3132
_ "github.com/cockroachdb/cockroach/pkg/ccl/storageccl"
3233
_ "github.com/cockroachdb/cockroach/pkg/ccl/storageccl/engineccl"
3334
_ "github.com/cockroachdb/cockroach/pkg/ccl/streamingccl/streamingest"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
subtest fips_ready
2+
3+
# We do not have the plumbing that would let test cases know whether they are
4+
# running in a fips environment or not so this is just a very basic test to
5+
# make sure that all the registration, oids, etc work properly.
6+
query _
7+
SELECT crdb_internal.fips_ready()
8+
----
9+
_
10+
11+
user testuser
12+
13+
statement error pq: crdb_internal\.fips_ready\(\): user testuser does not have VIEWCLUSTERSETTING system privilege
14+
SELECT crdb_internal.fips_ready()

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/fakedist-disk/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/fakedist-vec-off/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/fakedist/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-legacy-schema-changer/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-mixed-23.1/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-vec-off/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local/generated_test.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/securityccl/fipsccl/BUILD.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ go_library(
77
"build_noboring.go",
88
"fips_linux.go",
99
"fips_nolinux.go",
10+
"sql.go",
1011
],
1112
cgo = True,
1213
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/securityccl/fipsccl",
1314
visibility = ["//visibility:public"],
1415
deps = [
16+
"//pkg/ccl/utilccl",
17+
"//pkg/sql/privilege",
18+
"//pkg/sql/roleoption",
19+
"//pkg/sql/sem/eval",
20+
"//pkg/sql/sem/tree",
21+
"//pkg/sql/sem/volatility",
22+
"//pkg/sql/syntheticprivilege",
23+
"//pkg/sql/types",
1524
"@com_github_cockroachdb_errors//:errors",
1625
],
1726
)

pkg/ccl/securityccl/fipsccl/sql.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2023 The Cockroach Authors.
2+
//
3+
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
4+
// License (the "License"); you may not use this file except in compliance with
5+
// the License. You may obtain a copy of the License at
6+
//
7+
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
8+
9+
package fipsccl
10+
11+
import (
12+
"context"
13+
14+
"github.com/cockroachdb/cockroach/pkg/ccl/utilccl"
15+
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
16+
"github.com/cockroachdb/cockroach/pkg/sql/roleoption"
17+
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
18+
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
19+
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility"
20+
"github.com/cockroachdb/cockroach/pkg/sql/syntheticprivilege"
21+
"github.com/cockroachdb/cockroach/pkg/sql/types"
22+
)
23+
24+
func init() {
25+
overload := tree.Overload{
26+
Types: tree.ParamTypes{},
27+
ReturnType: tree.FixedReturnType(types.Bool),
28+
Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) {
29+
if err := utilccl.CheckEnterpriseEnabled(
30+
evalCtx.Settings, evalCtx.ClusterID, "fips_ready",
31+
); err != nil {
32+
return nil, err
33+
}
34+
// It's debatable whether we need a permission check here at all.
35+
// It's not very sensitive and is (currently) a very cheap function
36+
// call. However, it's something that regular users should have no
37+
// reason to look at so in the interest of least privilege we put it
38+
// behind the VIEWCLUSTERSETTING privilige.
39+
session := evalCtx.SessionAccessor
40+
isAdmin, err := session.HasAdminRole(ctx)
41+
if err != nil {
42+
return nil, err
43+
}
44+
if !isAdmin {
45+
hasView, err := session.HasRoleOption(ctx, roleoption.VIEWCLUSTERSETTING)
46+
if err != nil {
47+
return nil, err
48+
}
49+
if !hasView {
50+
if err := session.CheckPrivilege(ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.VIEWCLUSTERSETTING); err != nil {
51+
return nil, err
52+
}
53+
}
54+
}
55+
return tree.MakeDBool(tree.DBool(IsFIPSReady())), nil
56+
},
57+
Class: tree.NormalClass,
58+
Volatility: volatility.Stable,
59+
}
60+
61+
utilccl.RegisterCCLBuiltin("crdb_internal.fips_ready",
62+
`Returns true if all FIPS readiness checks pass.`,
63+
overload)
64+
}

pkg/sql/sem/builtins/fixed_oids.go

+1
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,7 @@ var builtinOidsArray = []string{
25062506
2535: `last_value(val: refcursor) -> refcursor`,
25072507
2536: `percentile_disc_impl(arg1: float, arg2: refcursor) -> refcursor`,
25082508
2537: `percentile_disc_impl(arg1: float[], arg2: refcursor) -> refcursor[]`,
2509+
2543: `crdb_internal.fips_ready() -> bool`,
25092510
}
25102511

25112512
var builtinOidsBySignature map[string]oid.Oid

0 commit comments

Comments
 (0)