Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controllers/ztunnel/ztunnel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func (r *Reconciler) installHelmChart(ctx context.Context, ztunnel *v1.ZTunnel)
return fmt.Errorf("failed to apply profile: %w", err)
}

// apply FipsValues on top of mergedHelmValues from profile
mergedHelmValues, err = istiovalues.ApplyZTunnelFipsValues(mergedHelmValues)
if err != nil {
return fmt.Errorf("failed to apply FIPS values: %w", err)
}

// Apply any user Overrides configured as part of values.ztunnel
// This step was not required for the IstioCNI resource because the Helm templates[*] automatically override values.cni
// [*]https://github.com/istio/istio/blob/0200fd0d4c3963a72f36987c2e8c2887df172abf/manifests/charts/istio-cni/templates/zzy_descope_legacy.yaml#L3
Expand Down
10 changes: 10 additions & 0 deletions pkg/istiovalues/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ func ApplyFipsValues(values helm.Values) (helm.Values, error) {
}
return values, nil
}

// ApplyZTunnelFipsValues sets value ztunnel.env.TLS12_ENABLED if FIPS mode is enabled in the system.
func ApplyZTunnelFipsValues(values helm.Values) (helm.Values, error) {
if FipsEnabled {
if err := values.SetIfAbsent("ztunnel.env.TLS12_ENABLED", "true"); err != nil {
return nil, fmt.Errorf("failed to set ztunnel.env.TLS12_ENABLED: %w", err)
}
}
return values, nil
}
45 changes: 45 additions & 0 deletions pkg/istiovalues/fips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func TestApplyFipsValues(t *testing.T) {
values := helm.Values{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
originalFipsEnabled := FipsEnabled
t.Cleanup(func() { FipsEnabled = originalFipsEnabled })
FipsEnabled = tt.fipsEnabled
actual, err := ApplyFipsValues(values)
if (err != nil) != tt.expectErr {
Expand All @@ -101,3 +103,46 @@ func TestApplyFipsValues(t *testing.T) {
})
}
}

func TestApplyZTunnelFipsValues(t *testing.T) {
tests := []struct {
name string
fipsEnabled bool
expectValues helm.Values
expectErr bool
}{
{
name: "FIPS not enabled",
fipsEnabled: false,
expectValues: helm.Values{},
},
{
name: "FIPS enabled",
fipsEnabled: true,
expectValues: helm.Values{
"ztunnel": map[string]any{
"env": map[string]any{"TLS12_ENABLED": string("true")},
},
},
},
}

values := helm.Values{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
originalFipsEnabled := FipsEnabled
t.Cleanup(func() { FipsEnabled = originalFipsEnabled })
FipsEnabled = tt.fipsEnabled
actual, err := ApplyZTunnelFipsValues(values)
if (err != nil) != tt.expectErr {
t.Errorf("applyFipsValues() error = %v, expectErr %v", err, tt.expectErr)
}

if err == nil {
if diff := cmp.Diff(tt.expectValues, actual); diff != "" {
t.Errorf("TLS12_ENABLED env wasn't applied properly; diff (-expected, +actual):\n%v", diff)
}
}
})
}
}
2 changes: 2 additions & 0 deletions pkg/revision/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ apiVersion: sailoperator.io/v1
kind: IstioRevision
spec:`)), 0o644))

originalFipsEnabled := istiovalues.FipsEnabled
t.Cleanup(func() { istiovalues.FipsEnabled = originalFipsEnabled })
istiovalues.FipsEnabled = true
values := &v1.Values{}
result, err := ComputeValues(values, namespace, version, config.PlatformOpenShift, "default", "",
Expand Down