Skip to content

Commit 8a04628

Browse files
committed
feat(cluster-storage-operator): inject centralized TLS configuration
Mount a configmap with an operator config injected with the HCP TLS security profile.
1 parent ca3d347 commit 8a04628

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: cluster-storage-operator-config
5+
data:
6+
config.yaml: ""

control-plane-operator/controllers/hostedcontrolplane/v2/assets/cluster-storage-operator/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ spec:
2020
- args:
2121
- start
2222
- -v=2
23+
- --config=/var/run/configmaps/config/config.yaml
2324
- --terminate-on-files=/var/run/secrets/serving-cert/tls.crt
2425
- --terminate-on-files=/var/run/secrets/serving-cert/tls.key
26+
- --terminate-on-files=/var/run/configmaps/config/config.yaml
2527
- --guest-kubeconfig=/etc/guest-kubeconfig/kubeconfig
2628
command:
2729
- cluster-storage-operator
@@ -132,6 +134,9 @@ spec:
132134
volumeMounts:
133135
- mountPath: /etc/guest-kubeconfig
134136
name: guest-kubeconfig
137+
- mountPath: /var/run/configmaps/config
138+
name: config
139+
readOnly: true
135140
securityContext:
136141
runAsNonRoot: true
137142
seccompProfile:
@@ -141,3 +146,6 @@ spec:
141146
- name: guest-kubeconfig
142147
secret:
143148
secretName: service-network-admin-kubeconfig
149+
- configMap:
150+
name: cluster-storage-operator-config
151+
name: config

control-plane-operator/controllers/hostedcontrolplane/v2/storage/component.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func NewComponent() component.ControlPlaneComponent {
6464
component.WithAdaptFunction(adaptAzureCSIFileSecretProvider),
6565
component.WithPredicate(isAroHCP),
6666
).
67+
WithManifestAdapter(
68+
"controller-config.yaml",
69+
component.WithAdaptFunction(adaptControllerConfig),
70+
).
6771
WithDependencies(oapiv2.ComponentName).
6872
InjectAvailabilityProberContainer(podspec.AvailabilityProberOpts{
6973
KubeconfigVolumeName: "guest-kubeconfig",

control-plane-operator/controllers/hostedcontrolplane/v2/storage/deployment.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package storage
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"strconv"
57

68
"github.com/openshift/hypershift/support/azureutil"
79
"github.com/openshift/hypershift/support/config"
810
component "github.com/openshift/hypershift/support/controlplane-component"
911
"github.com/openshift/hypershift/support/podspec"
1012

13+
configv1 "github.com/openshift/api/config/v1"
14+
1115
appsv1 "k8s.io/api/apps/v1"
1216
corev1 "k8s.io/api/core/v1"
17+
18+
"sigs.k8s.io/yaml"
1319
)
1420

1521
func adaptDeployment(cpContext component.WorkloadContext, deployment *appsv1.Deployment) error {
@@ -41,3 +47,41 @@ func adaptDeployment(cpContext component.WorkloadContext, deployment *appsv1.Dep
4147

4248
return nil
4349
}
50+
51+
func adaptControllerConfig(cpContext component.WorkloadContext, cm *corev1.ConfigMap) error {
52+
profile := cpContext.HCP.Spec.Configuration.GetTLSSecurityProfile()
53+
controllerConfig := configv1.GenericControllerConfig{
54+
ServingInfo: configv1.HTTPServingInfo{
55+
ServingInfo: configv1.ServingInfo{
56+
BindAddress: ":8443",
57+
CipherSuites: config.CipherSuites(profile),
58+
MinTLSVersion: config.MinTLSVersion(profile),
59+
},
60+
},
61+
}
62+
63+
asJSON, err := json.Marshal(controllerConfig)
64+
if err != nil {
65+
return fmt.Errorf("failed to json marshal config: %w", err)
66+
}
67+
68+
asMap := map[string]any{}
69+
if err := json.Unmarshal(asJSON, &asMap); err != nil {
70+
return fmt.Errorf("failed to json unmarshal config: %w", err)
71+
}
72+
73+
asMap["apiVersion"] = configv1.GroupVersion.String()
74+
asMap["kind"] = "GenericControllerConfig"
75+
76+
data, err := yaml.Marshal(asMap)
77+
if err != nil {
78+
return fmt.Errorf("failed to yaml marshal config: %w", err)
79+
}
80+
81+
if cm.Data == nil {
82+
cm.Data = map[string]string{}
83+
}
84+
85+
cm.Data["config.yaml"] = string(data)
86+
return nil
87+
}

0 commit comments

Comments
 (0)