mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-05 23:57:12 +00:00
support building with GOFIPS140
Signed-off-by: Ryan Richard <richardry@vmware.com>
This commit is contained in:
@@ -1542,7 +1542,9 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl
|
||||
stdout, stderr := testlib.RunNmapSSLEnum(t, "127.0.0.1", 10445)
|
||||
|
||||
require.Empty(t, stderr)
|
||||
require.Contains(t, stdout, testlib.GetExpectedCiphers(ptls.Default(nil), testlib.DefaultCipherSuitePreference), "stdout:\n%s", stdout)
|
||||
expectedCiphers := testlib.GetExpectedCiphers(ptls.Default(nil), testlib.DefaultCipherSuitePreference())
|
||||
require.Contains(t, stdout, expectedCiphers, "wantedToContain:\n%s\nactual stdout:\n%s", expectedCiphers, stdout)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2024 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2024-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build !fips_strict
|
||||
@@ -8,12 +8,16 @@ package integration
|
||||
import (
|
||||
"crypto/tls"
|
||||
"testing"
|
||||
|
||||
"go.pinniped.dev/test/testlib"
|
||||
)
|
||||
|
||||
// TestLimitedCiphersNotFIPS_Disruptive will confirm that the Pinniped Supervisor and Concierge expose only those
|
||||
// ciphers listed in configuration, when compiled in non-FIPS mode.
|
||||
// This does not test the CLI, since it does not have a feature to limit cipher suites.
|
||||
func TestLimitedCiphersNotFIPS_Disruptive(t *testing.T) {
|
||||
testlib.SkipTestWhenUsingGOFIPS140(t)
|
||||
|
||||
performLimitedCiphersTest(t,
|
||||
// The user-configured ciphers for both the Supervisor and Concierge.
|
||||
// This is a subset of the hardcoded ciphers from profiles.go.
|
||||
@@ -41,3 +45,40 @@ func TestLimitedCiphersNotFIPS_Disruptive(t *testing.T) {
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// TestLimitedCiphersFIPS_Disruptive will confirm that the Pinniped Supervisor and Concierge expose only those
|
||||
// ciphers listed in configuration, when compiled in GOFIPS140 mode.
|
||||
// This does not test the CLI, since it does not have a feature to limit cipher suites.
|
||||
func TestLimitedCiphersGOFIPS140_Disruptive(t *testing.T) {
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
performLimitedCiphersTest(t,
|
||||
// The user-configured ciphers for both the Supervisor and Concierge.
|
||||
// This is a subset of the hardcoded ciphers from profiles_fips_strict.go.
|
||||
[]string{
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
|
||||
},
|
||||
// Expected server configuration for the Supervisor's OIDC endpoints.
|
||||
&tls.Config{
|
||||
MinVersion: tls.VersionTLS12, // Supervisor OIDC always allows TLS 1.2 clients to connect
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: []uint16{
|
||||
// Supervisor OIDC endpoints configured with EC certs use only EC ciphers.
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
},
|
||||
},
|
||||
// Expected server configuration for the Supervisor and Concierge aggregated API endpoints.
|
||||
&tls.Config{
|
||||
MinVersion: tls.VersionTLS12, // always allow TLS 1.2 in fips mode
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2021-2025 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2021-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// This file overrides ptls_gofips140_test.go when Pinniped is built in FIPS-only mode using the legacy boring crypto compiler.
|
||||
//go:build fips_strict
|
||||
|
||||
package integration
|
||||
@@ -59,15 +60,17 @@ func TestFIPSCipherSuites_Parallel(t *testing.T) {
|
||||
}
|
||||
|
||||
// Every profile should use the same cipher suites in FIPS mode, because FIPS requires these ciphers.
|
||||
// Please treat this as a read-only const.
|
||||
var expectedFIPSCipherSuites = []uint16{
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
func expectedFIPSCipherSuites() []uint16 {
|
||||
// These are the expected values for boring crypto.
|
||||
return []uint16{
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefault_Parallel(t *testing.T) {
|
||||
func TestFIPSDefault_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
@@ -76,7 +79,7 @@ func TestDefault_Parallel(t *testing.T) {
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
@@ -84,7 +87,7 @@ func TestDefault_Parallel(t *testing.T) {
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDefaultLDAP_Parallel(t *testing.T) {
|
||||
func TestFIPSDefaultLDAP_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
@@ -93,7 +96,7 @@ func TestDefaultLDAP_Parallel(t *testing.T) {
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
@@ -101,7 +104,7 @@ func TestDefaultLDAP_Parallel(t *testing.T) {
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSecure_Parallel(t *testing.T) {
|
||||
func TestFIPSSecure_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
@@ -110,7 +113,7 @@ func TestSecure_Parallel(t *testing.T) {
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12, // allow TLS 1.2 in FIPS mode
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
@@ -118,14 +121,14 @@ func TestSecure_Parallel(t *testing.T) {
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSecureServing_Parallel(t *testing.T) {
|
||||
func TestFIPSSecureServing_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
|
||||
opts := &options.SecureServingOptionsWithLoopback{SecureServingOptions: &options.SecureServingOptions{}}
|
||||
ptls.SecureServing(opts)
|
||||
|
||||
expectedFIPSCipherSuiteNames := make([]string, len(expectedFIPSCipherSuites))
|
||||
for i, suite := range expectedFIPSCipherSuites {
|
||||
expectedFIPSCipherSuiteNames := make([]string, len(expectedFIPSCipherSuites()))
|
||||
for i, suite := range expectedFIPSCipherSuites() {
|
||||
expectedFIPSCipherSuiteNames[i] = tls.CipherSuiteName(suite)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
// Copyright 2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build !fips_strict
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apiserver/pkg/server/options"
|
||||
"k8s.io/client-go/util/cert"
|
||||
|
||||
"go.pinniped.dev/internal/crypto/ptls"
|
||||
"go.pinniped.dev/internal/testutil/tlsserver"
|
||||
"go.pinniped.dev/test/testlib"
|
||||
)
|
||||
|
||||
// Note: Everything in this file is an integration test only because we do not support build tags on unit tests.
|
||||
// These are effectively unit tests for the ptls package when compiled in FIPS mode.
|
||||
|
||||
// TestFIPSCipherSuites_Parallel ensures that if the list of default FIPS cipher suites changes, then we will know.
|
||||
// If this test ever fails during a golang upgrade, then we may need to change which ciphers we are using in
|
||||
// the ptls package in FIPS mode.
|
||||
func TestFIPSCipherSuites_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
server, ca := tlsserver.TestServerIPv4(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// use the default fips config which contains a hard coded list of cipher suites
|
||||
// that should be equal to the default list of fips cipher suites.
|
||||
// assert that the client hello response has the same tls config as this test server.
|
||||
tlsserver.AssertTLS(t, r, ptls.Default)
|
||||
}), tlsserver.RecordTLSHello)
|
||||
|
||||
pool, err := cert.NewPoolFromBytes(ca)
|
||||
require.NoError(t, err)
|
||||
// create a tls config that does not explicitly set cipher suites,
|
||||
// and therefore uses goboring or native fips's default fips ciphers.
|
||||
defaultConfig := &tls.Config{
|
||||
RootCAs: pool,
|
||||
NextProtos: ptls.Default(nil).NextProtos, // we do not care about field for this test, so just make it match
|
||||
}
|
||||
transport := http.Transport{
|
||||
TLSClientConfig: defaultConfig,
|
||||
ForceAttemptHTTP2: true,
|
||||
}
|
||||
// make a request against the test server, which will validate that the
|
||||
// tls config of the client without explicitly set ciphers
|
||||
// is the same as the tls config of the test server with explicitly
|
||||
// set ciphers from ptls.
|
||||
request, _ := http.NewRequest("GET", server.URL, nil)
|
||||
response, err := transport.RoundTrip(request)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, response.StatusCode)
|
||||
}
|
||||
|
||||
// Every profile should use the same cipher suites in FIPS mode, because FIPS requires these ciphers.
|
||||
func expectedFIPSCipherSuites() []uint16 {
|
||||
// These are the expected values for Go's "native" GOFIPS140.
|
||||
return []uint16{
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
}
|
||||
}
|
||||
|
||||
func TestFIPSDefault_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
|
||||
actual := ptls.Default(aCertPool)
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFIPSDefaultLDAP_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
|
||||
actual := ptls.DefaultLDAP(aCertPool)
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFIPSSecure_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
aCertPool := x509.NewCertPool()
|
||||
|
||||
actual := ptls.Secure(aCertPool)
|
||||
expected := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12, // allow TLS 1.2 in FIPS mode
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
CipherSuites: expectedFIPSCipherSuites(),
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
RootCAs: aCertPool,
|
||||
}
|
||||
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestFIPSSecureServing_Parallel(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t) // this function call is required for integration tests
|
||||
testlib.SkipTestUnlessUsingGOFIPS140(t)
|
||||
|
||||
opts := &options.SecureServingOptionsWithLoopback{SecureServingOptions: &options.SecureServingOptions{}}
|
||||
ptls.SecureServing(opts)
|
||||
|
||||
expectedFIPSCipherSuiteNames := make([]string, len(expectedFIPSCipherSuites()))
|
||||
for i, suite := range expectedFIPSCipherSuites() {
|
||||
expectedFIPSCipherSuiteNames[i] = tls.CipherSuiteName(suite)
|
||||
}
|
||||
|
||||
require.Equal(t, options.SecureServingOptionsWithLoopback{
|
||||
SecureServingOptions: &options.SecureServingOptions{
|
||||
CipherSuites: expectedFIPSCipherSuiteNames,
|
||||
MinTLSVersion: "VersionTLS12", // allow TLS 1.2 in FIPS mode
|
||||
},
|
||||
}, *opts)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021-2025 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2021-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package integration
|
||||
@@ -94,7 +94,9 @@ func TestSecureTLSConciergeAggregatedAPI_Parallel(t *testing.T) {
|
||||
stdout, stderr := testlib.RunNmapSSLEnum(t, "127.0.0.1", 10446)
|
||||
|
||||
require.Empty(t, stderr)
|
||||
require.Contains(t, stdout, testlib.GetExpectedCiphers(ptls.Secure(nil), testlib.DefaultCipherSuitePreference), "stdout:\n%s", stdout)
|
||||
expectedCiphers := testlib.GetExpectedCiphers(ptls.Secure(nil), testlib.DefaultCipherSuitePreference())
|
||||
require.Contains(t, stdout, expectedCiphers,
|
||||
"wantedToContain:\n%s\nactual stdout:\n%s", expectedCiphers, stdout)
|
||||
}
|
||||
|
||||
// TLS checks safe to run in parallel with serial tests, see main_test.go.
|
||||
@@ -109,7 +111,9 @@ func TestSecureTLSSupervisorAggregatedAPI_Parallel(t *testing.T) {
|
||||
stdout, stderr := testlib.RunNmapSSLEnum(t, "127.0.0.1", 10447)
|
||||
|
||||
require.Empty(t, stderr)
|
||||
require.Contains(t, stdout, testlib.GetExpectedCiphers(ptls.Secure(nil), testlib.DefaultCipherSuitePreference), "stdout:\n%s", stdout)
|
||||
expectedCiphers := testlib.GetExpectedCiphers(ptls.Secure(nil), testlib.DefaultCipherSuitePreference())
|
||||
require.Contains(t, stdout, expectedCiphers,
|
||||
"wantedToContain:\n%s\nactual stdout:\n%s", expectedCiphers, stdout)
|
||||
}
|
||||
|
||||
func TestSecureTLSSupervisor(t *testing.T) {
|
||||
@@ -151,7 +155,9 @@ func TestSecureTLSSupervisor(t *testing.T) {
|
||||
defaultECDSAOnly.CipherSuites = ciphers
|
||||
|
||||
require.Empty(t, stderr)
|
||||
require.Contains(t, stdout, testlib.GetExpectedCiphers(defaultECDSAOnly, testlib.DefaultCipherSuitePreference), "stdout:\n%s", stdout)
|
||||
expectedCiphers := testlib.GetExpectedCiphers(defaultECDSAOnly, testlib.DefaultCipherSuitePreference())
|
||||
require.Contains(t, stdout, expectedCiphers,
|
||||
"wantedToContain:\n%s\nactual stdout:\n%s", expectedCiphers, stdout)
|
||||
}
|
||||
|
||||
type fakeT struct {
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Copyright 2022-2024 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2022-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// This file overrides securetls_preference_nonfips.go when Pinniped is built in FIPS-only mode using the legacy boring crypto compiler.
|
||||
//go:build fips_strict
|
||||
|
||||
package testlib
|
||||
|
||||
// DefaultCipherSuitePreference returns an expected value for tests.
|
||||
// Because of a bug in nmap, the cipher suite preference is
|
||||
// incorrectly shown as 'client' in some cases.
|
||||
// in fips-only mode, it correctly shows the cipher preference
|
||||
// as 'server', while in non-fips mode it shows as 'client'.
|
||||
const DefaultCipherSuitePreference = "server"
|
||||
func DefaultCipherSuitePreference() string {
|
||||
return "server"
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
// Copyright 2022-2024 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2022-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build !fips_strict
|
||||
|
||||
package testlib
|
||||
|
||||
import "crypto/fips140"
|
||||
|
||||
// DefaultCipherSuitePreference returns an expected value for tests.
|
||||
// Because of a bug in nmap, the cipher suite preference is
|
||||
// incorrectly shown as 'client' in some cases.
|
||||
// in fips-only mode, it correctly shows the cipher preference
|
||||
// as 'server', while in non-fips mode it shows as 'client'.
|
||||
const DefaultCipherSuitePreference = "client"
|
||||
func DefaultCipherSuitePreference() string {
|
||||
if fips140.Enabled() {
|
||||
return "server"
|
||||
}
|
||||
return "client"
|
||||
}
|
||||
|
||||
+21
-2
@@ -1,9 +1,12 @@
|
||||
// Copyright 2020-2024 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2020-2026 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package testlib
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"crypto/fips140"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// SkipUnlessIntegration skips the current test if `-short` has been passed to `go test`.
|
||||
func SkipUnlessIntegration(t *testing.T) {
|
||||
@@ -14,6 +17,22 @@ func SkipUnlessIntegration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func SkipTestWhenUsingGOFIPS140(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
if fips140.Enabled() {
|
||||
t.Skip("this test is skipped when using GOFIPS140")
|
||||
}
|
||||
}
|
||||
|
||||
func SkipTestUnlessUsingGOFIPS140(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
if !fips140.Enabled() {
|
||||
t.Skip("this test requires GOFIPS140")
|
||||
}
|
||||
}
|
||||
|
||||
func SkipTestWhenLDAPIsUnavailable(t *testing.T, env *TestEnv) {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user