Skip to content

Commit

Permalink
Add CA subject to Helm values
Browse files Browse the repository at this point in the history
This is required by Helm recommendations. We provide a default
CA subject, and this can be overridden using custom Helm values.
  • Loading branch information
markgoddard committed Jan 3, 2025
1 parent f9dd2d5 commit b58b48f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/config/testdata/config/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ trust_zones:
spire:
caSubject:
commonName: cn.example.com
country: UK
organization: acme-org
spire-server:
logLevel: INFO
nameOverride: custom-server-name
bundle_endpoint_profile: BUNDLE_ENDPOINT_PROFILE_HTTPS_SPIFFE
profile: kubernetes
external_server: false
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/test/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ var trustZoneFixtures map[string]*trust_zone_proto.TrustZone = map[string]*trust
ev := map[string]any{
"global": map[string]any{
"spire": map[string]any{
// Modify multiple values in the same map.
"caSubject": map[string]any{
"country": "UK",
"organization": "acme-org",
"commonName": "cn.example.com",
},
},
},
"spire-server": map[string]any{
// Modify an existing value.
"logLevel": "INFO",
// Customise a new value.
"nameOverride": "custom-server-name",
},
}
value, err := structpb.NewStruct(ev)
Expand Down
22 changes: 22 additions & 0 deletions pkg/provider/helm/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ type HelmValuesGenerator struct {
type globalValues struct {
deleteHooks bool
installAndUpgradeHooksEnabled bool
spireCASubject caSubject
spireClusterName string
spireJwtIssuer string
spireNamespacesCreate bool
spireRecommendationsEnabled bool
spireTrustDomain string
}

type caSubject struct {
commonName string
country string
organization string
}

type spireAgentValues struct {
agentConfig trustprovider.TrustProviderAgentConfig
fullnameOverride string
Expand Down Expand Up @@ -73,6 +80,11 @@ func (g *HelmValuesGenerator) GenerateValues() (map[string]any, error) {
}

gv := globalValues{
spireCASubject: caSubject{
commonName: "cofide.io",
country: "UK",
organization: "Cofide",
},
spireClusterName: g.trustZone.GetKubernetesCluster(),
spireJwtIssuer: g.trustZone.GetJwtIssuer(),
spireNamespacesCreate: true,
Expand Down Expand Up @@ -244,6 +256,7 @@ func (g *globalValues) generateValues() (map[string]any, error) {
values := map[string]any{
"global": map[string]any{
"spire": map[string]any{
"caSubject": g.spireCASubject.generateValues(),
"clusterName": g.spireClusterName,
"namespaces": map[string]any{
"create": g.spireNamespacesCreate,
Expand Down Expand Up @@ -279,6 +292,15 @@ func (g *globalValues) generateValues() (map[string]any, error) {
return values, nil
}

// generateValues generates the global.spire.caSubject Helm values map.
func (c *caSubject) generateValues() map[string]any {
return map[string]any{
"country": c.country,
"organization": c.organization,
"commonName": c.commonName,
}
}

// generateValues generates the spire-agent Helm values map.
func (s *spireAgentValues) generateValues() (map[string]any, error) {
if s.fullnameOverride == "" {
Expand Down
30 changes: 30 additions & 0 deletions pkg/provider/helm/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func TestHelmValuesGenerator_GenerateValues_success(t *testing.T) {
"enabled": false,
},
"spire": Values{
"caSubject": Values{
"commonName": "cofide.io",
"country": "UK",
"organization": "Cofide",
},
"clusterName": "local1",
"namespaces": Values{
"create": true,
Expand Down Expand Up @@ -256,6 +261,11 @@ func TestHelmValuesGenerator_GenerateValues_success(t *testing.T) {
"enabled": false,
},
"spire": Values{
"caSubject": Values{
"commonName": "cofide.io",
"country": "UK",
"organization": "Cofide",
},
"clusterName": "local4",
"namespaces": Values{
"create": true,
Expand Down Expand Up @@ -397,6 +407,11 @@ func TestHelmValuesGenerator_GenerateValues_AdditionalValues(t *testing.T) {
"enabled": false,
},
"spire": Values{
"caSubject": Values{
"commonName": "cofide.io",
"country": "UK",
"organization": "Cofide",
},
"clusterName": "local1",
"namespaces": Values{
"create": true,
Expand Down Expand Up @@ -987,6 +1002,11 @@ func TestGlobalValues_GenerateValues(t *testing.T) {
want: map[string]any{
"global": map[string]any{
"spire": map[string]any{
"caSubject": Values{
"commonName": "",
"country": "",
"organization": "",
},
"clusterName": "local1",
"namespaces": Values{
"create": false,
Expand Down Expand Up @@ -1016,6 +1036,11 @@ func TestGlobalValues_GenerateValues(t *testing.T) {
want: map[string]any{
"global": map[string]any{
"spire": map[string]any{
"caSubject": Values{
"commonName": "",
"country": "",
"organization": "",
},
"clusterName": "local1",
"namespaces": Values{
"create": false,
Expand Down Expand Up @@ -1045,6 +1070,11 @@ func TestGlobalValues_GenerateValues(t *testing.T) {
want: map[string]any{
"global": map[string]any{
"spire": map[string]any{
"caSubject": Values{
"commonName": "",
"country": "",
"organization": "",
},
"clusterName": "local1",
"jwtIssuer": "https://tz1.example.com",
"namespaces": Values{
Expand Down

0 comments on commit b58b48f

Please sign in to comment.