Skip to content

Commit ee15efa

Browse files
authored
chore: Add GODEBUG environment variable for FIPS compliance for KLM and Watcher image (#2805)
* chore: Add GODEBUG environment variable for FIPS compliance in manager deployment * chore: Add GODEBUG environment variable for FIPS compliance in skr-webhook deployment * fix: Update FIPS mode metric expectation to match new configuration * chore: Remove GODEBUG environment variable from manager deployment and add FIPS mode patch for local testing * feat: Add GODEBUG environment variable support in deployment configuration and corresponding test * test: Add verification for GODEBUG environment variable in SKR Cluster webhook deployment * feat: Initialize Kyma instance in FIPS Mode metric test * fix: Replace fmt.Errorf with errors.New for GODEBUG env error handling
1 parent 6c40003 commit ee15efa

File tree

7 files changed

+122
-2
lines changed

7 files changed

+122
-2
lines changed

config/watcher_local_test/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ components:
2929
patches:
3030
- path: patches/deployment_resources.yaml
3131
- path: patches/unique_deployment_webhook_patch.yaml
32+
- path: patches/fips_only_mode.yaml
3233
- target:
3334
kind: Deployment
3435
patch: |-
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: manager
10+
env:
11+
- name: GODEBUG
12+
value: "fips140=only,tlsmlkem=0"

config/watcher_local_test_gcm/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ components:
2525
patches:
2626
- path: patches/deployment_resources.yaml
2727
- path: patches/unique_deployment_webhook_patch.yaml
28+
- path: patches/fips_only_mode.yaml
2829
- target:
2930
kind: Deployment
3031
patch: |-
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: manager
10+
env:
11+
- name: GODEBUG
12+
value: "fips140=only,tlsmlkem=0"

internal/service/watcher/resources/resource_configurator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"net"
7+
"os"
78
"strconv"
89

910
apiappsv1 "k8s.io/api/apps/v1"
@@ -44,6 +45,7 @@ var (
4445
const (
4546
// PodRestartLabelKey is used to trigger a rolling update of the watcher pod when the SKR's certificate changes.
4647
PodRestartLabelKey = shared.OperatorGroup + shared.Separator + "pod-restart-trigger"
48+
goDebugEnvName = "GODEBUG"
4749
kcpAddressEnvName = "KCP_ADDR"
4850
ApiServerNetworkPolicyName = "kyma-project.io--watcher-to-apiserver"
4951
SeedToWatcherNetworkPolicyName = "kyma-project.io--seed-to-watcher"
@@ -136,6 +138,12 @@ func (rc *ResourceConfigurator) ConfigureDeployment(obj *unstructured.Unstructur
136138
shared.ManagedBy: shared.ManagedByLabelValue,
137139
}))
138140

141+
goDebug, ok := os.LookupEnv(goDebugEnvName)
142+
if ok && goDebug != "" {
143+
deployment.Spec.Template.Spec.Containers[0].Env = append(
144+
deployment.Spec.Template.Spec.Containers[0].Env,
145+
apicorev1.EnvVar{Name: goDebugEnvName, Value: goDebug})
146+
}
139147
return deployment, nil
140148
}
141149

internal/service/watcher/resources/resource_configurator_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,62 @@ func toUnstructured(obj interface{}) *unstructured.Unstructured {
2222
return &unstructured.Unstructured{Object: m}
2323
}
2424

25+
func TestResourceConfigurator_ConfigureDeployment_SetsGODEBUG(t *testing.T) {
26+
expectedEnvValue := "dummyvalue"
27+
expectedEnvName := "GODEBUG"
28+
t.Setenv(expectedEnvName, expectedEnvValue)
29+
30+
testDeploy := toUnstructured(&apiappsv1.Deployment{
31+
ObjectMeta: apimetav1.ObjectMeta{
32+
Name: "dbg-deploy",
33+
Labels: map[string]string{"dbg": "true"},
34+
},
35+
Spec: apiappsv1.DeploymentSpec{
36+
Template: apicorev1.PodTemplateSpec{
37+
ObjectMeta: apimetav1.ObjectMeta{
38+
Labels: map[string]string{"app": "dbg"},
39+
},
40+
Spec: apicorev1.PodSpec{
41+
Containers: []apicorev1.Container{
42+
{
43+
Name: "main",
44+
Image: "old-image",
45+
},
46+
},
47+
},
48+
},
49+
},
50+
})
51+
52+
configurator := skrwebhookresources.NewResourceConfigurator(
53+
"",
54+
"",
55+
"100m",
56+
"128Mi",
57+
skrwebhookresources.KCPAddr{Hostname: "dbg-host", Port: 4242},
58+
)
59+
configurator.SetSecretResVer("v1")
60+
61+
got, err := configurator.ConfigureDeployment(testDeploy)
62+
if err != nil {
63+
t.Fatalf("ConfigureDeployment() returned error: %v", err)
64+
}
65+
66+
found := false
67+
for _, env := range got.Spec.Template.Spec.Containers[0].Env {
68+
if env.Name == expectedEnvName {
69+
if env.Value != expectedEnvValue {
70+
t.Fatalf("GODEBUG value = %q, want %q", env.Value, expectedEnvValue)
71+
}
72+
found = true
73+
break
74+
}
75+
}
76+
if !found {
77+
t.Fatalf("GODEBUG env not found in container env: %+v", got.Spec.Template.Spec.Containers[0].Env)
78+
}
79+
}
80+
2581
//nolint:gocognit // test case is complex
2682
func TestResourceConfigurator_ConfigureDeployment(t *testing.T) {
2783
kcpAddr := skrwebhookresources.KCPAddr{Hostname: "test-host", Port: 8080}

tests/e2e/fipsMode_metric_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
package e2e_test
22

33
import (
4+
"errors"
5+
46
. "github.com/onsi/ginkgo/v2"
57
. "github.com/onsi/gomega"
68

9+
"github.com/kyma-project/lifecycle-manager/api/v1beta2"
10+
. "github.com/kyma-project/lifecycle-manager/pkg/testutils"
711
. "github.com/kyma-project/lifecycle-manager/tests/e2e/commontestutils"
812

913
"github.com/kyma-project/lifecycle-manager/internal/pkg/metrics"
14+
skrwebhookresources "github.com/kyma-project/lifecycle-manager/internal/service/watcher/resources"
1015
)
1116

1217
var _ = Describe("FIPS Mode metric", Ordered, func() {
18+
kyma := NewKymaWithNamespaceName("kyma-sample", ControlPlaneNamespace, v1beta2.DefaultChannel)
19+
InitEmptyKymaBeforeAll(kyma)
20+
1321
Context("Given KCP Cluster", func() {
1422
It("When KLM is initialized", func() {
15-
By("Then fipsMode metrics is set to \"enabled\"")
23+
By("Then fipsMode metrics is set to \"FipsModeOnly\"")
1624
Eventually(GetFipsModeGauge).
1725
WithContext(ctx).
18-
Should(Equal(metrics.FipsModeOn))
26+
Should(Equal(metrics.FipsModeOnly))
27+
})
28+
})
29+
30+
Context("Given SKR Cluster", func() {
31+
It("When Runtime Watcher is initialized", func() {
32+
By("Then fipsMode env exists in the webhook deployment")
33+
Eventually(func() error {
34+
skrWebhook, err := GetDeployment(ctx, skrClient, skrwebhookresources.SkrResourceName, RemoteNamespace)
35+
if err != nil {
36+
return err
37+
}
38+
for _, container := range skrWebhook.Spec.Template.Spec.Containers {
39+
if container.Name == "server" {
40+
for _, env := range container.Env {
41+
if env.Name == "GODEBUG" && env.Value == "fips140=only,tlsmlkem=0" {
42+
return nil
43+
}
44+
}
45+
}
46+
}
47+
return errors.New("GODEBUG env not found in the webhook deployment")
48+
}).Should(Succeed())
1949
})
2050
})
2151
})

0 commit comments

Comments
 (0)