-
-
Notifications
You must be signed in to change notification settings - Fork 722
feat(mode): Add gofips140 mode #4449
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
base: master
Are you sure you want to change the base?
Changes from all commits
d9f9c2e
c61febb
c7aef0e
64c60ee
7df4294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ TRANSITIONED_GO_SETTING_KEYS = [ | |
| "//go/config:msan", | ||
| "//go/config:race", | ||
| "//go/config:pure", | ||
| "//go/config:gofips140", | ||
| "//go/config:linkmode", | ||
| "//go/config:tags", | ||
| "//go/config:pgoprofile", | ||
|
|
@@ -109,6 +110,10 @@ def _go_transition_impl(settings, attr): | |
| if tags: | ||
| settings["//go/config:tags"] = _deduped_and_sorted(tags) | ||
|
|
||
| gofips140 = getattr(attr, "gofips140", "off") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this mean that it's impossible to disable fips for a binary if it is enabled globally?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option just determines what gets built into the crypto module (see: https://go.dev/doc/security/fips140#the-gofips140-environment-variable). Essentially:
|
||
| if gofips140 != "off": | ||
| settings["//go/config:gofips140"] = gofips140 | ||
fmeum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| linkmode = getattr(attr, "linkmode", "auto") | ||
| if linkmode != "auto": | ||
| if linkmode not in LINKMODES: | ||
|
|
@@ -198,6 +203,7 @@ _common_reset_transition_dict = dict({ | |
| "//go/config:msan": False, | ||
| "//go/config:race": False, | ||
| "//go/config:pure": False, | ||
| "//go/config:gofips140": "off", | ||
| "//go/config:debug": False, | ||
| "//go/config:linkmode": LINKMODE_NORMAL, | ||
| "//go/config:tags": [], | ||
|
|
@@ -214,6 +220,7 @@ _stdlib_keep_keys = sorted([ | |
| "//go/config:msan", | ||
| "//go/config:race", | ||
| "//go/config:pure", | ||
| "//go/config:gofips140", | ||
| "//go/config:linkmode", | ||
| "//go/config:tags", | ||
| "//go/config:pgoprofile", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright 2025 The Bazel Authors. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package gofips140_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/bazelbuild/rules_go/go/tools/bazel_testing" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| bazel_testing.TestMain(m, bazel_testing.Args{ | ||
| Main: ` | ||
| -- BUILD.bazel -- | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_binary") | ||
|
|
||
| go_binary( | ||
| name = "gofips140_off", | ||
| srcs = ["gofips140.go"], | ||
| gofips140 = "off", | ||
| ) | ||
|
|
||
| go_binary( | ||
| name = "gofips140_latest", | ||
| srcs = ["gofips140.go"], | ||
| gofips140 = "latest", | ||
| ) | ||
|
|
||
| go_binary( | ||
| name = "gofips140_version", | ||
| srcs = ["gofips140.go"], | ||
| gofips140 = "v1.0.0", | ||
| ) | ||
|
|
||
| -- gofips140.go -- | ||
| package main | ||
|
|
||
| import ( | ||
| "crypto/fips140" | ||
| "fmt" | ||
| ) | ||
|
|
||
| func main() { | ||
| fmt.Printf("%t", fips140.Enabled()) | ||
| } | ||
| `, | ||
| }) | ||
| } | ||
|
|
||
| // TestGOFIPS140Attribute checks that the gofips140 attribute on go_binary | ||
| // controls the GOFIPS140 environment variable. | ||
| func TestGOFIPS140Attribute(t *testing.T) { | ||
| tests := []struct { | ||
| target string | ||
| want string | ||
| }{ | ||
| {"//:gofips140_off", "false"}, | ||
| {"//:gofips140_latest", "true"}, | ||
| {"//:gofips140_version", "true"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.target, func(t *testing.T) { | ||
| out, err := bazel_testing.BazelOutput("run", tt.target) | ||
| if err != nil { | ||
| t.Fatalf("running %s: %v", tt.target, err) | ||
| } | ||
| got := string(bytes.TrimSpace(out)) | ||
| if got != tt.want { | ||
| t.Fatalf("got %q; want %q", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.