Skip to content

Commit 1b46c01

Browse files
authored
fix: Ensure the team broker api key and secret are not templated when not defined (#901)
1 parent 1cd1be8 commit 1b46c01

4 files changed

Lines changed: 70 additions & 13 deletions

File tree

helm/flowfuse/templates/_helpers.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ Resolve Team Broker API URL: user-provided value, or default to the in-cluster E
373373
Create Team Broker API secret
374374
*/}}
375375
{{- define "forge.teamBrokerApiSecret" -}}
376-
{{- if (.Values.forge.broker.teamBroker).enabled -}}
377-
{{- $_ := required "A valid .Values.forge.broker.teamBroker.api.key is required!" ((.Values.forge.broker.teamBroker).api).key -}}
378-
{{- $token := required "A valid .Values.forge.broker.teamBroker.api.secret is required!" ((.Values.forge.broker.teamBroker).api).secret -}}
376+
{{- if and (.Values.forge.broker.teamBroker).enabled (.Values.forge.broker.teamBroker).api -}}
377+
{{- $_ := required "A valid .Values.forge.broker.teamBroker.api.key is required!" .Values.forge.broker.teamBroker.api.key -}}
378+
{{- $token := required "A valid .Values.forge.broker.teamBroker.api.secret is required!" .Values.forge.broker.teamBroker.api.secret -}}
379379
teamBrokerApiSecret: {{ $token | b64enc | quote }}
380380
{{- end -}}
381381
{{- end -}}

helm/flowfuse/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
key: expertToken
9191
optional: true
9292
{{- end }}
93-
{{- if (.Values.forge.broker.teamBroker).enabled }}
93+
{{- if and (.Values.forge.broker.teamBroker).enabled (.Values.forge.broker.teamBroker).api }}
9494
- name: TEAM_BROKER_API_SECRET
9595
valueFrom:
9696
secretKeyRef:

helm/flowfuse/tests/team_broker_api_test.yaml

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@ tests:
4444
path: data["flowforge.yml"]
4545
pattern: "secret: team-broker-secret"
4646

47+
- it: should render teamBroker block without api sub-block when teamBroker is enabled but api is missing
48+
template: configmap.yaml
49+
set:
50+
forge.broker.enabled: true
51+
forge.broker.teamBroker:
52+
enabled: true
53+
asserts:
54+
- matchRegex:
55+
path: data["flowforge.yml"]
56+
pattern: "teamBroker:"
57+
- notMatchRegex:
58+
path: data["flowforge.yml"]
59+
pattern: "api:"
60+
- notMatchRegex:
61+
path: data["flowforge.yml"]
62+
pattern: "TEAM_BROKER_API_SECRET"
63+
64+
- it: should render teamBroker block without api sub-block when teamBroker is enabled but api is empty
65+
template: configmap.yaml
66+
set:
67+
forge.broker.enabled: true
68+
forge.broker.teamBroker:
69+
enabled: true
70+
api: {}
71+
asserts:
72+
- matchRegex:
73+
path: data["flowforge.yml"]
74+
pattern: "teamBroker:"
75+
- notMatchRegex:
76+
path: data["flowforge.yml"]
77+
pattern: "api:"
78+
4779
# Deployment tests
4880
- it: should not include TEAM_BROKER_API_SECRET env var by default
4981
template: deployment.yaml
@@ -80,6 +112,25 @@ tests:
80112
key: teamBrokerApiSecret
81113
optional: true
82114

115+
- it: should not include TEAM_BROKER_API_SECRET env var when teamBroker is enabled but api is missing
116+
template: deployment.yaml
117+
set:
118+
forge.broker.teamBroker:
119+
enabled: true
120+
asserts:
121+
- notExists:
122+
path: spec.template.spec.initContainers[0].env[?(@.name == "TEAM_BROKER_API_SECRET")]
123+
124+
- it: should not include TEAM_BROKER_API_SECRET env var when teamBroker is enabled but api is empty
125+
template: deployment.yaml
126+
set:
127+
forge.broker.teamBroker:
128+
enabled: true
129+
api: {}
130+
asserts:
131+
- notExists:
132+
path: spec.template.spec.initContainers[0].env[?(@.name == "TEAM_BROKER_API_SECRET")]
133+
83134
# Secrets tests
84135
- it: should not include teamBrokerApiSecret in secrets by default
85136
template: secrets.yaml
@@ -126,14 +177,16 @@ tests:
126177
- failedTemplate:
127178
errorMessage: "A valid .Values.forge.broker.teamBroker.api.secret is required!"
128179

129-
- it: should fail when teamBroker is enabled but api block is missing
180+
- it: should not include teamBrokerApiSecret when teamBroker is enabled but api block is missing
130181
template: secrets.yaml
131182
set:
132183
forge.broker.teamBroker:
133184
enabled: true
134185
asserts:
135-
- failedTemplate:
136-
errorMessage: "A valid .Values.forge.broker.teamBroker.api.key is required!"
186+
- isKind:
187+
of: Secret
188+
- notExists:
189+
path: data.teamBrokerApiSecret
137190

138191
# Coexistence with other secrets
139192
- it: should include teamBrokerApiSecret alongside other tokens when multiple features are enabled

helm/flowfuse/tests/team_broker_helpers_test.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,29 @@ tests:
117117
- failedTemplate:
118118
errorMessage: "A valid .Values.forge.broker.teamBroker.api.secret is required!"
119119

120-
- it: should require api fields when teamBroker is enabled but api is empty
120+
- it: should skip teamBrokerApiSecret rendering when teamBroker is enabled but api is empty
121121
template: secrets.yaml
122122
set:
123123
forge.broker.teamBroker:
124124
enabled: true
125125
api: {}
126126
asserts:
127-
- failedTemplate:
128-
errorMessage: "A valid .Values.forge.broker.teamBroker.api.key is required!"
127+
- isKind:
128+
of: Secret
129+
- notExists:
130+
path: data.teamBrokerApiSecret
129131

130-
- it: should require api fields when teamBroker is enabled but api is missing
132+
- it: should skip teamBrokerApiSecret rendering when teamBroker is enabled but api is missing
131133
template: secrets.yaml
132134
set:
133135
forge.broker.teamBroker:
134136
enabled: true
135137
# api is missing
136138
asserts:
137-
- failedTemplate:
138-
errorMessage: "A valid .Values.forge.broker.teamBroker.api.key is required!"
139+
- isKind:
140+
of: Secret
141+
- notExists:
142+
path: data.teamBrokerApiSecret
139143

140144
# forge.teamBrokerApiUrl helper - verified indirectly through the rendered configmap
141145
- it: should default api.url to in-cluster EMQX dashboard when not provided

0 commit comments

Comments
 (0)