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

feat(crypto): Enable FIPS-only mode #2723

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ go-test-app-dir := ./src/acceptance/assets/app/go_app
go_modules := $(shell find . -maxdepth 6 -name "*.mod" -exec dirname {} \; | sed 's|\./src/||' | sort)
all_modules := $(go_modules) db scheduler

# Enable the boringcrypto experiment to use the Go BoringCrypto library, which implements FIPS 140-2 validated cryptographic algorithms.
export GOEXPERIMENT = boringcrypto

MVN_OPTS = "-Dmaven.test.skip=true"
OS := $(shell . /etc/lsb-release &>/dev/null && echo $${DISTRIB_ID} || uname)
db_type := postgres
Expand Down
2 changes: 1 addition & 1 deletion jobs/scheduler/templates/scheduler.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ client:
key-store: /var/vcap/jobs/scheduler/config/certs/scalingengine/client.p12
key-store-password: 123456
key-store-type: PKCS12
protocol: TLSv1.3
protocol: TLSv1.2
trust-store: /var/vcap/jobs/scheduler/config/certs/scalingengine/cacerts
trust-store-password: 123456
############################################################
Expand Down
17 changes: 16 additions & 1 deletion src/autoscaler/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
MAKEFLAGS := -s
aes_terminal_font_yellow := \e[38;2;255;255;0m
aes_terminal_reset := \e[0m
Expand All @@ -11,6 +12,10 @@ PACKAGE_DIRS = $(shell go list './...' | grep --invert-match --regexp='/vendor/'

# `CGO_ENABLED := 1` is required to enforce dynamic linking which is a requirement of dynatrace.
CGO_ENABLED := 1

# Enable the boringcrypto experiment to use the Go BoringCrypto library, which implements FIPS 140-2 validated cryptographic algorithms.
export GOEXPERIMENT = boringcrypto

BUILDTAGS :=
export GOWORK=off
BUILDFLAGS := -ldflags '-linkmode=external'
Expand Down Expand Up @@ -93,7 +98,7 @@ build-%: ${openapi-generated-clients-and-servers-dir} ${openapi-generated-client
@CGO_ENABLED=$(CGO_ENABLED) go build $(BUILDTAGS) $(BUILDFLAGS) -o build/$* $*/cmd/$*/main.go


build: $(addprefix build-,$(binaries))
build: $(addprefix build-,$(binaries)) validate-fips-only-mode

build_tests: $(addprefix build_test-,$(test_dirs))

Expand All @@ -109,6 +114,16 @@ build_test-%: generate-fakes
go test -c -o $${test_file} $${package};\
done;

validate-fips-only-mode: $(binaries)
@echo "# Validating that the binaries are built with boringcrypto in FIPS-only mode"
@for binary in $(binaries); do
# See https://pkg.go.dev/crypto/internal/boring/sig for details on the signature checked here.
if [[ $$(go tool nm build/$$binary | grep -c 'crypto/internal/boring/sig.FIPSOnly') -eq 0 ]]; then
echo "Binary $$binary is not built with boringcrypto in FIPS-only mode";
exit 1;
fi;
done

check: fmt lint build test

test: generate-fakes
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/eventgenerator/cmd/eventgenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ client:
key-store: {{ .TestCertDir }}/scheduler.p12
key-store-password: 123456
key-store-type: PKCS12
protocol: TLSv1.3
protocol: TLSv1.2
trust-store: {{ .TestCertDir }}/autoscaler.truststore
trust-store-password: 123456
endpoints:
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/metricsforwarder/cmd/metricsforwarder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/tedsuo/ifrit/sigmon"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/metricsforwarder/manager"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/metricsgateway/cmd/metricsgateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/metricsserver/cmd/metricsserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/operator/cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions src/autoscaler/scalingengine/cmd/scalingengine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/grouper"
"github.com/tedsuo/ifrit/sigmon"

_ "crypto/tls/fipsonly"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
could not import crypto/tls/fipsonly (-: build constraints exclude all Go files in /__t/go/1.21.3/x64/src/crypto/tls/fipsonly) (typecheck)

)

func main() {
Expand Down
Loading