Skip to content

Commit fcadc30

Browse files
committed
support GOFIPS140=latest
The previous version of the code did not correctly build with `GOFIPS140=latest`, and namely did not link the binary such that FIPS mode was on-by-default, which it should. This fixes that. We also revert some misleading/incorrect changes from the prior in-progress commit `7c5c55d859d1518f963a79abec87af34876cc2ee`. See discussion [here](bazel-contrib#4449), and specifically [this comment](bazel-contrib#4449 (comment)).
1 parent d853058 commit fcadc30

File tree

13 files changed

+31
-26
lines changed

13 files changed

+31
-26
lines changed

docs/go/core/rules.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
[config_setting]: https://docs.bazel.build/versions/master/be/general.html#config_setting
1212
[data dependencies]: https://bazel.build/concepts/dependencies#data-dependencies
1313
[goarch]: /go/modes.rst#goarch
14-
[gofips140]: /go/modes.rst#gofips140
1514
[goos]: /go/modes.rst#goos
1615
[mode attributes]: /go/modes.rst#mode-attributes
1716
[nogo]: /go/nogo.rst#nogo
@@ -59,7 +58,6 @@ sufficient to match the capabilities of the normal go tools.
5958
- [config_setting]
6059
- [data dependencies]
6160
- [goarch]
62-
- [gofips140]
6361
- [goos]
6462
- [mode attributes]
6563
- [nogo]

go/core.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Core Go rules
1313
.. _config_setting: https://docs.bazel.build/versions/master/be/general.html#config_setting
1414
.. _data dependencies: https://bazel.build/concepts/dependencies#data-dependencies
1515
.. _goarch: modes.rst#goarch
16-
.. _gofips140: modes.rst#gofips140
1716
.. _goos: modes.rst#goos
1817
.. _mode attributes: modes.rst#mode-attributes
1918
.. _nogo: nogo.rst#nogo

go/modes.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ or using `Bazel configuration transitions`_.
6969
| ``CGO_ENABLED=0``). Packages that contain cgo code may still be built, but |
7070
| the cgo code will be filtered out, and the ``cgo`` build tag will be false. |
7171
+------------------------+---------------------+-------------------------------+
72-
| :param:`gofips140` | :type:`string` | :value:`"off"` |
73-
+------------------------+---------------------+-------------------------------+
74-
| Controls the ``GOFIPS140`` environment variable used by Go 1.24+ to select |
75-
| the version of the Go Cryptographic Module. Can be set to ``"off"`` |
76-
| (default), ``"latest"``, or a specific version like ``"v1.0.0"``. |
77-
| See the `Go 1.24 FIPS 140-3 documentation`_ for more details. |
78-
+------------------------+---------------------+-------------------------------+
7972
| :param:`debug` | :type:`bool` | :value:`false` |
8073
+------------------------+---------------------+-------------------------------+
8174
| Includes debugging information in compiled packages (using the ``-N`` and |

go/private/BUILD.sdk.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ filegroup(
2424
filegroup(
2525
name = "srcs",
2626
srcs = glob(
27-
["src/**/*"],
27+
[
28+
"lib/fips140/**",
29+
"src/**/*",
30+
],
2831
exclude = [
2932
"src/**/*_test.go",
3033
"src/**/testdata/**",

go/private/actions/link.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def emit_link(
167167
builder_args.add("-o", executable)
168168
builder_args.add("-main", archive.data.file)
169169
builder_args.add("-p", archive.data.importmap)
170+
builder_args.add("-work", "-v")
170171
tool_args.add_all(gc_linkopts)
171172
tool_args.add_all(go.toolchain.flags.link)
172173

go/private/actions/stdlib.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _should_use_sdk_stdlib(go):
5959
not go.mode.race and # TODO(jayconrod): use precompiled race
6060
not go.mode.msan and
6161
not go.mode.pure and
62+
go.mode.gofips140 == "off" and
6263
not go.mode.gc_goopts and
6364
go.mode.linkmode == LINKMODE_NORMAL)
6465

@@ -93,6 +94,9 @@ def _build_stdlib_list_json(go):
9394
def _build_env(go):
9495
env = go.env
9596

97+
if go.mode.gofips140 != "off":
98+
env.update({"GOFIPS140": go.mode.gofips140})
99+
96100
if go.mode.pure:
97101
env.update({"CGO_ENABLED": "0"})
98102
return env

go/private/context.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ def go_context(
564564
if mode.arm:
565565
env["GOARM"] = mode.arm
566566

567+
if mode.gofips140 != "off":
568+
env["GOFIPS140"] = mode.gofips140
569+
567570
if cgo_context_info:
568571
env.update(cgo_context_info.env)
569572
cc_toolchain_files = cgo_context_info.cc_toolchain_files

go/private/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ GoSDK = provider(
3535
fields = {
3636
"goos": "The host OS the SDK was built for.",
3737
"goarch": "The host architecture the SDK was built for.",
38+
"gofips140": "The value of GOFIPS140 to build with",
3839
"experiments": "Comma-separated Go experiments to enable via GOEXPERIMENT.",
3940
"root_file": "A file in the SDK root directory",
4041
"libs": ("Depset of pre-compiled .a files for the standard library " +

go/private/rules/binary.bzl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,6 @@ def _go_binary_kwargs(go_cc_aspects = []):
367367
[pure].
368368
""",
369369
),
370-
"gofips140": attr.string(
371-
default = "off",
372-
doc = """Controls the GOFIPS140 environment variable. May be any string value.
373-
Common values include `"off"` (default), `"latest"`, and specific versions like `"v1.0.0"`.
374-
See [mode attributes], specifically [gofips140].
375-
""",
376-
),
377370
"static": attr.string(
378371
default = "auto",
379372
doc = """Controls whether a binary is statically linked. May be one of `on`,

go/private/rules/sdk.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _go_sdk_impl(ctx):
3535
GoSDK(
3636
goos = ctx.attr.goos,
3737
goarch = ctx.attr.goarch,
38+
gofips140 = ctx.attr.gofips140,
3839
experiments = ",".join(ctx.attr.experiments),
3940
root_file = ctx.file.root_file,
4041
package_list = package_list,
@@ -58,6 +59,13 @@ go_sdk = rule(
5859
mandatory = True,
5960
doc = "The host architecture the SDK was built for",
6061
),
62+
"gofips140": attr.string(
63+
default = "off",
64+
doc = """Controls the GOFIPS140 environment variable. May be any string value.
65+
Common values include `"off"` (default), `"latest"`, and specific versions like `"v1.0.0"`.
66+
See [mode attributes], specifically [gofips140].
67+
""",
68+
),
6169
"experiments": attr.string_list(
6270
mandatory = False,
6371
doc = "Go experiments to enable via GOEXPERIMENT",

0 commit comments

Comments
 (0)