Fix panics under GODEBUG=fips140=only in SSHKey/Certificate generation - #749
Open
sameerforge wants to merge 1 commit into
Open
Fix panics under GODEBUG=fips140=only in SSHKey/Certificate generation#749sameerforge wants to merge 1 commit into
sameerforge wants to merge 1 commit into
Conversation
Under Go's native FIPS 140-3 "only" enforcement mode, two vendored non-security primitives panic on every reconcile: - SSHKeyGenerator.fingerprintMD5 (github.com/cloudfoundry/config-server vendor/.../ssh_key_generator.go:72) uses crypto/md5 to compute the SSH public key fingerprint shown in SSHKey.PublicKeyFingerprint (the same convention as `ssh-keygen -l -E md5`). - CertificateGenerator.bigIntHash (vendor/.../certificate_generator.go:66) uses crypto/sha1 to derive the X.509 SubjectKeyId per RFC 5280 4.2.1.2 method (1). Neither is a cryptographic operation in the security sense - they're non-forgeability-sensitive identifiers, not signatures or authentication - but Go's fips140=only mode blocks the primitive itself regardless of call-site intent, so both panic unconditionally on every SSHKey and Certificate reconcile. Wrap both call sites (in our own pkg/generator code, not the vendored library) in crypto/fips140.WithoutEnforcement, added in Go 1.26. It scopes the FIPS 140-3 "only" exemption to just that call and is a documented no-op when strict enforcement isn't active, so this has no effect on non-FIPS builds. Found via a downstream FIPS build's real end-to-end run: the project's own test/e2e suite (TestSSHKey, TestSSHKeyTemplate, TestCertificate) against the actual shipped artifact, deployed to a real cluster. Added fips140_internal_test.go, gated on fips140.Enforced(), to exercise the same paths directly (skips as a no-op unless run with GOFIPS140=v1.0.0 GODEBUG=fips140=only). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Sameer <sameer.khan@broadcom.com>
Contributor
Author
|
@joaopapereira Please review. |
Contributor
Author
|
@joaopapereira Please review the PR. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running under Go's native FIPS 140-3 "only" enforcement mode (
GOFIPS140=v1.0.0+GODEBUG=fips140=only), reconciling anySSHKeyorCertificateresource panics unconditionally:SSHKeyGenerator.fingerprintMD5(github.com/cloudfoundry/config-server,vendor/.../ssh_key_generator.go:72) usescrypto/md5to compute the SSH public key fingerprint exposed asSSHKey.PublicKeyFingerprint— the same convention asssh-keygen -l -E md5.CertificateGenerator.bigIntHash(vendor/.../certificate_generator.go:66) usescrypto/sha1to derive the X.509SubjectKeyIdper RFC 5280 §4.2.1.2, method (1).Neither use is a cryptographic operation in the security sense — they're non-forgeability-sensitive identifiers, not signatures or authentication. But Go's
fips140=onlymode blocks the primitive itself regardless of call-site intent, so bothmd5.Sum/sha1.Sumcalls panic as soon as they execute, breaking everySSHKeyandCertificatereconcile under strict FIPS enforcement.Fix
Rather than touching the vendored
cloudfoundry/config-serverlibrary, this wraps the two call sites — in this project's ownpkg/generatorcode — withcrypto/fips140.WithoutEnforcement(added in Go 1.26):pkg/generator/ssh_key_reconciler.go: wrapgen.Generate(nil)inSSHKeyReconciler.generatepkg/generator/certificate_reconciler.go: wrapgen.Generate(params)inCertificateReconciler.generateWithoutEnforcementscopes the FIPS 140-3 "only" exemption to just the wrapped callback, and per its own documented semantics (and Go stdlib source) is a no-op whenever strictfips140=onlyenforcement isn't active. So this has no effect on non-FIPS builds, or onGODEBUG=fips140=on— confirmed both by readingcrypto/fips140's implementation and by empirical testing (identical behavior wrapped vs. unwrapped in both non-FIPS andfips140=onmodes; onlyfips140=onlydiverges, which is exactly the mode this fixes).Testing
pkg/generator/fips140_internal_test.gowith two tests exercisingSSHKeyReconciler.generateandCertificateReconciler.generatedirectly, gated onfips140.Enforced():GOFIPS140=v1.0.0 GODEBUG=fips140=only, where they previously would have panicked.pkg/generator,pkg/expansion,pkg/satoken,pkg/sharing,pkg/trackertest suites both at baseline and underGOFIPS140=v1.0.0 GODEBUG=fips140=only— all pass in both configurations.md5/sha1calls behave identically under no-FIPS andfips140=on, and diverge (panic vs. no panic) only underfips140=only.