-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cliccl: Add debug enterprise-check-fips command
This command reports on the status of certain prerequisites for our fips-ready builds. Updates #114344 Release note (cli change): New command `cockroach debug enterprise-check-fips` diagnoses errors in FIPS deployments
- Loading branch information
Showing
9 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "fipsccl", | ||
srcs = [ | ||
"build_boring.go", # keep | ||
"build_noboring.go", | ||
"fips_linux.go", | ||
"fips_nolinux.go", | ||
], | ||
cgo = True, | ||
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/securityccl/fipsccl", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@com_github_cockroachdb_errors//:errors", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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 | ||
// | ||
//go:build boringcrypto | ||
|
||
package fipsccl | ||
|
||
/* | ||
#include <openssl/ossl_typ.h> | ||
static unsigned long _fipsccl_openssl_version_number() { | ||
return OPENSSL_VERSION_NUMBER; | ||
} | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"crypto/boring" | ||
"fmt" | ||
) | ||
|
||
// IsCompileTimeFIPSReady returns true if this binary was built with correct | ||
// toolchain and options, which is a prerequisite for FIPS-ready mode. | ||
// Note that we only support the golang-fips toolchain even though the | ||
// build tag we test for is "boringcrypto". The two are not actually | ||
// compatible because crypto/boring.Enabled is a bool in one and a function | ||
// in the other. | ||
func IsCompileTimeFIPSReady() bool { | ||
return true | ||
} | ||
|
||
// IsOpenSSLLoaded returns true if the OpenSSL library has been found and | ||
// loaded. | ||
func IsOpenSSLLoaded() bool { | ||
return boring.Enabled() | ||
} | ||
|
||
// IsFIPSReady returns true if all of our FIPS readiness checks succeed. | ||
func IsFIPSReady() bool { | ||
// The golang-fips toolchain only attempts to load OpenSSL if the kernel | ||
// fips mode is enabled. Therefore we only need this single check for our | ||
// overall fips-readiness status. We could redundantly call IsBoringBuild | ||
// and IsKernelEnabled, but doing so would risk some divergence between our | ||
// implementation and the toolchain itself so it's better at this time to | ||
// use the single check. | ||
return IsOpenSSLLoaded() | ||
} | ||
|
||
// BuildOpenSSLVersion returns the version number of OpenSSL that was used at | ||
// build time. The first return value is the hex value of the | ||
// OPENSSL_VERSION_NUMBER constant (for example, 10100000 for OpenSSL 1.1 and | ||
// 30000000 for OpenSSL 3.0), and the second is the versioned name of the | ||
// libcrypto.so file. | ||
func BuildOpenSSLVersion() (string, string, error) { | ||
buildVersion := uint64(C._fipsccl_openssl_version_number()) | ||
var soname string | ||
// Reference: | ||
// https://github.com/golang-fips/go/blob/7f64529ab80e5d394bb2496e982d6f6e11023902/patches/001-initial-openssl-for-fips.patch#L3476-L3482 | ||
if buildVersion < 0x10100000 { | ||
soname = "libcrypto.so.10" | ||
} else if buildVersion < 0x30000000 { | ||
soname = "libcrypto.so.1.1" | ||
} else { | ||
soname = "libcrypto.so.3" | ||
} | ||
return fmt.Sprintf("%x", buildVersion), soname, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 | ||
// | ||
//go:build !boringcrypto | ||
|
||
package fipsccl | ||
|
||
import "github.com/cockroachdb/errors" | ||
|
||
func IsCompileTimeFIPSReady() bool { | ||
return false | ||
} | ||
|
||
func IsOpenSSLLoaded() bool { | ||
return false | ||
} | ||
|
||
func IsFIPSReady() bool { | ||
return false | ||
} | ||
|
||
func BuildOpenSSLVersion() (string, string, error) { | ||
return "", "", errors.New("openssl support not present") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
const fipsSysctlFilename = "/proc/sys/crypto/fips_enabled" | ||
|
||
// IsKernelEnabled returns true if FIPS mode is enabled in the kernel | ||
// (by reading the crypto.fips_enabled sysctl). | ||
func IsKernelEnabled() (bool, error) { | ||
data, err := os.ReadFile(fipsSysctlFilename) | ||
if err != nil { | ||
return false, err | ||
} | ||
if len(data) == 0 { | ||
return false, errors.New("sysctl file empty") | ||
} | ||
if data[0] == '1' { | ||
return true, nil | ||
} | ||
return false, fmt.Errorf("sysctl value: %q", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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 | ||
// | ||
//go:build !linux | ||
|
||
package fipsccl | ||
|
||
import "github.com/cockroachdb/errors" | ||
|
||
func IsKernelEnabled() (bool, error) { | ||
return false, errors.New("only supported on linux") | ||
} |