Skip to content

Commit a3b035b

Browse files
committed
Push the hub CA via lookup() of a namespace
Currently we just push the hub ca in the golang-external-secrets namespace. This is problematic once we move to the downstream ESO because that uses different namespaces. In order to support both ESO versions (upstream - golang-external-secret and downstream - external-secrets) we tried different approaches. Initially, we checked if a specific application existed {{- $eso_ns := "golang-external-secrets" }} {{- range .Values.clusterGroup.applications }} {{- if or (eq .chart "openshift-external-secrets") (and (hasKey . "repoURL") .repoURL (hasSuffix "openshift-external-secrets" .repoURL)) (and (hasKey . "repoURL") .repoURL (hasSuffix "openshift-external-secrets-chart" .repoURL)) {{- $eso_ns = "external-secrets" }} {{- end }} {{- end }} The problem with the above is that is just too fragile. The approach we actually use here is the lookup functionality in ACM: If the "external-secrets-operator" namespace exists on the spoke, we can safely assume that we are using the downstream ESO, in which case the policy with the CA of the hub will be pushed to the external-secrets namespace (where the real ESO pods run). Tested this with both the old upstream golang-external-secrets and with the downstream ESO.
1 parent eb579da commit a3b035b

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

templates/policies/acm-hub-ca-policy.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ spec:
8989
spec:
9090
remediationAction: enforce
9191
severity: medium
92+
# Here we need to put any namespace that might be rendered in the template
9293
namespaceSelector:
9394
include:
94-
- default
95+
- external-secrets
96+
- golang-external-secrets
9597
object-templates:
9698
- complianceType: mustonlyhave
9799
objectDefinition:
@@ -100,7 +102,7 @@ spec:
100102
type: Opaque
101103
metadata:
102104
name: hub-ca
103-
namespace: golang-external-secrets
105+
namespace: '{{ `{{ if (lookup "v1" "Namespace" "" "external-secrets-operator") }}external-secrets{{ else }}golang-external-secrets{{ end }}` }}'
104106
data:
105107
hub-kube-root-ca.crt: '{{ `{{hub fromConfigMap "" "kube-root-ca.crt" "ca.crt" | base64enc hub}}` }}'
106108
hub-openshift-service-ca.crt: '{{ `{{hub fromConfigMap "" "openshift-service-ca.crt" "service-ca.crt" | base64enc hub}}` }}'

0 commit comments

Comments
 (0)