Skip to content

Commit

Permalink
Allow configuration of mandatory PQ KEM: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo Landau <[email protected]>
  • Loading branch information
hlandau committed Nov 7, 2024
1 parent a754fc2 commit 4257939
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
27 changes: 27 additions & 0 deletions cmd/spire-agent/cli/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,16 @@ func TestMergeInput(t *testing.T) {
require.Equal(t, "bar", c.Agent.TrustDomain)
},
},
{
msg: "require_pq_kem should be configurable by file",
fileInput: func(c *Config) {
c.Agent.Experimental.RequirePQKEM = true
},
cliInput: func(c *agentConfig) {},
test: func(t *testing.T, c *Config) {
require.True(t, c.Agent.Experimental.RequirePQKEM)
},
},
}
cases = append(cases, mergeInputCasesOS()...)

Expand Down Expand Up @@ -1012,6 +1022,23 @@ func TestNewAgentConfig(t *testing.T) {
require.Nil(t, c)
},
},

{
msg: "require PQ KEM is disabled (default)",
input: func(c *Config) {},
test: func(t *testing.T, c *agent.Config) {
require.Equal(t, false, c.TLSPolicy.RequirePQKEM)
},
},
{
msg: "require PQ KEM is enabled",
input: func(c *Config) {
c.Agent.Experimental.RequirePQKEM = true
},
test: func(t *testing.T, c *agent.Config) {
require.Equal(t, true, c.TLSPolicy.RequirePQKEM)
},
},
}
cases = append(cases, newAgentConfigCasesOS(t)...)
for _, testCase := range cases {
Expand Down
27 changes: 27 additions & 0 deletions cmd/spire-server/cli/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestParseConfigGood(t *testing.T) {
_, ok := trustDomainConfig.EndpointProfile.(bundleClient.HTTPSWebProfile)
assert.True(t, ok)
assert.True(t, c.Server.AuditLogEnabled)
assert.True(t, c.Server.Experimental.RequirePQKEM)
testParseConfigGoodOS(t, c)

// Parse/reprint cycle trims outer whitespace
Expand Down Expand Up @@ -455,6 +456,16 @@ func TestMergeInput(t *testing.T) {
require.True(t, c.Server.AuditLogEnabled)
},
},
{
msg: "require_pq_kem should be configurable by file",
fileInput: func(c *Config) {
c.Server.Experimental.RequirePQKEM = true
},
cliFlags: []string{},
test: func(t *testing.T, c *Config) {
require.True(t, c.Server.Experimental.RequirePQKEM)
},
},
}
cases = append(cases, mergeInputCasesOS(t)...)

Expand Down Expand Up @@ -1160,6 +1171,22 @@ func TestNewServerConfig(t *testing.T) {
}, c.AdminIDs)
},
},
{
msg: "require PQ KEM is disabled (default)",
input: func(c *Config) {},
test: func(t *testing.T, c *server.Config) {
require.Equal(t, false, c.TLSPolicy.RequirePQKEM)
},
},
{
msg: "require PQ KEM is enabled",
input: func(c *Config) {
c.Server.Experimental.RequirePQKEM = true
},
test: func(t *testing.T, c *server.Config) {
require.Equal(t, true, c.TLSPolicy.RequirePQKEM)
},
},
}
cases = append(cases, newServerConfigCasesOS(t)...)

Expand Down
29 changes: 24 additions & 5 deletions pkg/server/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
svidv1 "github.com/spiffe/spire-api-sdk/proto/spire/api/server/svid/v1"
trustdomainv1 "github.com/spiffe/spire-api-sdk/proto/spire/api/server/trustdomain/v1"
"github.com/spiffe/spire-api-sdk/proto/spire/api/types"
"github.com/spiffe/spire/pkg/common/tlspolicy"
"github.com/spiffe/spire/pkg/common/util"
"github.com/spiffe/spire/pkg/server/authpolicy"
"github.com/spiffe/spire/pkg/server/ca/manager"
Expand Down Expand Up @@ -102,6 +103,9 @@ func TestNew(t *testing.T) {
RateLimit: rateLimit,
Clock: clk,
AuthPolicyEngine: pe,
TLSPolicy: tlspolicy.Policy{
RequirePQKEM: true,
},
})
require.NoError(t, err)
assert.Equal(t, tcpAddr, endpoints.TCPAddr)
Expand All @@ -118,6 +122,7 @@ func TestNew(t *testing.T) {
assert.NotNil(t, endpoints.BundleEndpointServer)
assert.NotNil(t, endpoints.APIServers.LocalAUthorityServer)
assert.NotNil(t, endpoints.EntryFetcherPruneEventsTask)
assert.True(t, endpoints.TLSPolicy.RequirePQKEM)
assert.Equal(t, cat.GetDataStore(), endpoints.DataStore)
assert.Equal(t, log, endpoints.Log)
assert.Equal(t, metrics, endpoints.Metrics)
Expand Down Expand Up @@ -259,19 +264,27 @@ func TestListenAndServe(t *testing.T) {
require.NoError(t, err)
defer localConn.Close()

noauthConn := dialTCP(tlsconfig.TLSClientConfig(ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))
noauthConfig := tlsconfig.TLSClientConfig(ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
require.NoError(t, tlspolicy.ApplyPolicy(noauthConfig, endpoints.TLSPolicy))
noauthConn := dialTCP(noauthConfig)
defer noauthConn.Close()

agentConn := dialTCP(tlsconfig.MTLSClientConfig(agentSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))
agentConfig := tlsconfig.MTLSClientConfig(agentSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
require.NoError(t, tlspolicy.ApplyPolicy(agentConfig, endpoints.TLSPolicy))
agentConn := dialTCP(agentConfig)
defer agentConn.Close()

adminConn := dialTCP(tlsconfig.MTLSClientConfig(adminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))
adminConfig := tlsconfig.MTLSClientConfig(adminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
require.NoError(t, tlspolicy.ApplyPolicy(adminConfig, endpoints.TLSPolicy))
adminConn := dialTCP(adminConfig)
defer adminConn.Close()

downstreamConn := dialTCP(tlsconfig.MTLSClientConfig(downstreamSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))
defer downstreamConn.Close()

federatedAdminConn := dialTCP(tlsconfig.MTLSClientConfig(foreignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))
federatedAdminConfig := tlsconfig.MTLSClientConfig(foreignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
require.NoError(t, tlspolicy.ApplyPolicy(federatedAdminConfig, endpoints.TLSPolicy))
federatedAdminConn := dialTCP(federatedAdminConfig)
defer federatedAdminConn.Close()

t.Run("Bad Client SVID", func(t *testing.T) {
Expand All @@ -280,8 +293,12 @@ func TestListenAndServe(t *testing.T) {
badSVID := testca.New(t, testTD).CreateX509SVID(agentID)
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()

tlsConfig := tlsconfig.MTLSClientConfig(badSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
require.NoError(t, tlspolicy.ApplyPolicy(tlsConfig, endpoints.TLSPolicy))

badConn, err := grpc.DialContext(ctx, endpoints.TCPAddr.String(), grpc.WithBlock(), grpc.FailOnNonTempDialError(true), //nolint: staticcheck // It is going to be resolved on #5152
grpc.WithTransportCredentials(credentials.NewTLS(tlsconfig.MTLSClientConfig(badSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID)))),
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
)
if !assert.Error(t, err, "dialing should have failed") {
// close the conn if the dialing unexpectedly succeeded
Expand Down Expand Up @@ -337,6 +354,8 @@ func TestListenAndServe(t *testing.T) {
unfederatedConfig := tlsconfig.MTLSClientConfig(unfederatedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))

for _, config := range []*tls.Config{unauthenticatedConfig, unauthorizedConfig, unfederatedConfig} {
require.NoError(t, tlspolicy.ApplyPolicy(config, endpoints.TLSPolicy))

conn, err := grpc.NewClient(endpoints.TCPAddr.String(),
grpc.WithTransportCredentials(credentials.NewTLS(config)),
)
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/config/server_good_posix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ server {
bundle_endpoint_profile "https_web" {}
}
}
experimental {
require_pq_kem = true
}
}

plugins {
Expand Down
1 change: 1 addition & 0 deletions test/fixture/config/server_good_windows.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ server {
}
experimental {
named_pipe_name = "\\spire-server\\private\\api-test"
require_pq_kem = true
}
}

Expand Down

0 comments on commit 4257939

Please sign in to comment.