GitOps-safe: generateSecrets, and Argo CD hook order (K-C14) #40

Merged
jcoffey-dev merged 1 commits from feat/gitops-safe into main 2026-11-20 08:16:38 +00:00
15 changed files with 135 additions and 13 deletions

No files matched your search

+9
View File
@@ -123,3 +123,12 @@ runs, pinned by digest.
signatures check out; the chart pushed to GHCR and the Gitea registry and
signed keyless with cosign; rendered manifests; a minisign-signed
`SHA256SUMS`. `tools/verify-release.sh` checks all of it.
- GitOps (K-C14): `generateSecrets: false` makes the chart refuse to render
without `webmail.existingSecret` and
`server.metrics.prometheus.existingSecret`, for Argo CD and
`helm template | kubectl apply`, which can't read back the secrets the
chart makes and would replace them on every sync. Every hook also carries
Argo CD's own annotations, so the order there is safe: the hook network
policies, then the upgrade check (nothing to do on a new store), then the
seed, which Argo runs on every sync and which does nothing on a seeded
store.
+4
View File
@@ -21,6 +21,10 @@ outside these limits, before anything is applied.
- **`imagePullSecrets`** (list of object)\
Default: `[]`.
- **`generateSecrets`** (boolean)\
Default: `true`.\
The chart makes two secrets itself when you don't name your own: the webmail's (webmail.existingSecret) and the metrics password (server.metrics.prometheus.existingSecret). It makes each once and then reads it back from the cluster, which only Helm itself can do. Argo CD, and `helm template | kubectl apply`, render without the cluster, so they'd get new ones on every sync: the app never shows Synced, and every webmail user is signed out. Set this to false there, and the chart refuses to render until both are named.
## `server`
### `server.image`
+3 -1
View File
@@ -173,7 +173,9 @@ spec:
{{- include "inbuxa.networkPolicy.frontEndIngress" $root | nindent 4 }}
{{- end }}
{{- /* The two the hook Jobs need, as hooks; see the top of this file */}}
{{- $hook := dict "helm.sh/hook" "pre-install,pre-upgrade,pre-rollback" "helm.sh/hook-weight" "-20" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }}
{{- /* Argo CD runs Helm's pre-install and pre-upgrade hooks as PreSync; its
own annotations give the same order there: these first (see server/upgrade.yaml) */}}
{{- $hook := dict "helm.sh/hook" "pre-install,pre-upgrade,pre-rollback" "helm.sh/hook-weight" "-20" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" "argocd.argoproj.io/hook" "PreSync" "argocd.argoproj.io/sync-wave" "-30" "argocd.argoproj.io/hook-delete-policy" "BeforeHookCreation,HookSucceeded" }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
@@ -20,7 +20,7 @@ Its token may create events in this namespace and nothing else.
{{- fail "server.egress.checkUrl is required with server.egress.expectedAddresses: a URL that answers with the caller's address as plain text" }}
{{- end }}
{{- $name := printf "%s-egress-check" (include "inbuxa.fullname" $root) }}
{{- $hook := dict "helm.sh/hook" "post-install,post-upgrade" "helm.sh/hook-delete-policy" "before-hook-creation" }}
{{- $hook := dict "helm.sh/hook" "post-install,post-upgrade" "helm.sh/hook-delete-policy" "before-hook-creation" "argocd.argoproj.io/hook" "PostSync" "argocd.argoproj.io/hook-delete-policy" "BeforeHookCreation" }}
apiVersion: v1
kind: ServiceAccount
metadata:
@@ -30,7 +30,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: egress-check
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-10") $hook) | nindent 4 }}
automountServiceAccountToken: false
---
apiVersion: rbac.authorization.k8s.io/v1
@@ -42,7 +42,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: egress-check
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-10") $hook) | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["events"]
@@ -57,7 +57,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: egress-check
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-10") $hook) | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
@@ -76,7 +76,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: egress-check
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-5") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-5" "argocd.argoproj.io/sync-wave" "-5") $hook) | nindent 4 }}
data:
egress-check.sh: |
{{- $root.Files.Get "files/egress-check.sh" | nindent 4 }}
@@ -90,7 +90,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: egress-check
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "0") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "0" "argocd.argoproj.io/sync-wave" "0") $hook) | nindent 4 }}
ignore-check.kube-linter.io/no-liveness-probe: "A one-shot that serves nothing; activeDeadlineSeconds bounds it"
ignore-check.kube-linter.io/no-readiness-probe: "A one-shot that serves nothing"
ignore-check.kube-linter.io/restart-policy: "Never on purpose: one answer is enough, and the script never fails"
@@ -25,6 +25,9 @@ queued and delivered since the last count.
{{- end }}
{{- if $prom.enabled }}
{{- $secret := include "inbuxa.server.metricsSecret" . }}
{{- if and (not $prom.existingSecret) (not .Values.generateSecrets) }}
{{- fail "server.metrics.prometheus.existingSecret: generateSecrets is off, so name a Secret with username and password" }}
{{- end }}
{{- if not $prom.existingSecret }}
{{- /* Random once, then kept, so Prometheus and the pods agree across upgrades */}}
{{- $existing := (lookup "v1" "Secret" .Release.Namespace $secret).data | default dict }}
+10
View File
@@ -33,6 +33,11 @@ metadata:
annotations:
helm.sh/hook: pre-install
helm.sh/hook-weight: "-5"
# Under Argo CD: every sync, after the upgrade (see upgrade.yaml); a
# seeded store makes it a no-op
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/sync-wave: "-15"
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
data:
config.json: {{ toJson $server.dataStore | quote }}
@@ -51,6 +56,11 @@ metadata:
annotations:
helm.sh/hook: pre-install
helm.sh/hook-weight: "0"
# Under Argo CD: every sync, after the upgrade (see upgrade.yaml); a
# seeded store makes it a no-op
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/sync-wave: "-10"
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded
# A failed run stays, for its log, until the next install or a day
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
ignore-check.kube-linter.io/no-liveness-probe: "A one-shot that serves nothing; activeDeadlineSeconds bounds it"
+13 -6
View File
@@ -23,7 +23,14 @@ the older release can't read.
{{- $deployments = append $deployments (printf "%s-%s" (include "inbuxa.fullname" $root) $group) }}
{{- end }}
{{- end }}
{{- $hook := dict "helm.sh/hook" "pre-upgrade,pre-rollback" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }}
{{- /*
Argo CD runs these, and the seed, as PreSync on every sync, the first one
included. So there the upgrade goes first: on a new store it finds nothing
to do and changes nothing, and the seed after it still sees a new store.
Seed first would be wrong: --seed upgrades the store's layout before it
seeds, past the acknowledgement and the stop below.
*/}}
{{- $hook := dict "helm.sh/hook" "pre-upgrade,pre-rollback" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" "argocd.argoproj.io/hook" "PreSync" "argocd.argoproj.io/hook-delete-policy" "BeforeHookCreation,HookSucceeded" }}
{{- if $upgrade.stopServers }}
apiVersion: v1
kind: ServiceAccount
@@ -34,7 +41,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: upgrade
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-25") $hook) | nindent 4 }}
automountServiceAccountToken: false
---
apiVersion: rbac.authorization.k8s.io/v1
@@ -46,7 +53,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: upgrade
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-25") $hook) | nindent 4 }}
rules:
# Scale this release's server Deployments, and nothing else
- apiGroups: ["apps"]
@@ -68,7 +75,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: upgrade
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-10" "argocd.argoproj.io/sync-wave" "-25") $hook) | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
@@ -88,7 +95,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: upgrade
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "-5") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "-5" "argocd.argoproj.io/sync-wave" "-22") $hook) | nindent 4 }}
data:
config.json: {{ toJson $server.dataStore | quote }}
upgrade.sh: |
@@ -103,7 +110,7 @@ metadata:
{{- include "inbuxa.labels" $root | nindent 4 }}
app.kubernetes.io/component: upgrade
annotations:
{{- toYaml (merge (dict "helm.sh/hook-weight" "0") $hook) | nindent 4 }}
{{- toYaml (merge (dict "helm.sh/hook-weight" "0" "argocd.argoproj.io/sync-wave" "-20") $hook) | nindent 4 }}
ignore-check.kube-linter.io/no-liveness-probe: "A one-shot that serves nothing; activeDeadlineSeconds bounds it"
ignore-check.kube-linter.io/no-readiness-probe: "A one-shot that serves nothing"
ignore-check.kube-linter.io/restart-policy: "Never on purpose: a failed upgrade is for a person to look at, not to retry"
+3
View File
@@ -19,6 +19,9 @@ the server inside the cluster, through the HTTP Service.
{{- if and $wm.previousAppSecret (not $wm.existingSecret) }}
{{- fail "webmail.previousAppSecret needs webmail.existingSecret: the chart's own Secret keeps only the two keys it makes" }}
{{- end }}
{{- if and (not $wm.existingSecret) (not $root.Values.generateSecrets) }}
{{- fail "webmail.existingSecret: generateSecrets is off, so name a Secret with app-secret and oauth-client-secret (48 random characters each)" }}
{{- end }}
{{- if not $wm.existingSecret }}
{{- /* Random once, then kept: a new APP_SECRET would sign everybody out */}}
{{- $existing := (lookup "v1" "Secret" $root.Release.Namespace $name).data | default dict }}
+20
View File
@@ -326,3 +326,23 @@ tests:
asserts:
- failedTemplate:
errorPattern: "turn on routes.gateway or routes.ingress"
- it: refuses to make the webmail's Secret when generateSecrets is off (K-C14)
template: webmail.yaml
set:
generateSecrets: false
asserts:
- failedTemplate:
errorPattern: "webmail.existingSecret: generateSecrets is off"
- it: renders with generateSecrets off once the Secret is named
template: webmail.yaml
set:
generateSecrets: false
webmail.existingSecret: my-webmail
asserts:
- notFailedTemplate: {}
# No Secret of its own: the Deployment comes first
- isKind:
of: Deployment
documentIndex: 0
+18
View File
@@ -241,3 +241,21 @@ tests:
- contains:
path: spec.ingress[1].from
content: {namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: monitoring}}}
- it: refuses to make the metrics Secret when generateSecrets is off (K-C14)
template: server/metrics.yaml
set:
generateSecrets: false
server.metrics.prometheus.enabled: true
asserts:
- failedTemplate:
errorPattern: "server.metrics.prometheus.existingSecret: generateSecrets is off"
- it: renders with generateSecrets off once the metrics Secret is named
template: server/metrics.yaml
set:
generateSecrets: false
server.metrics.prometheus.enabled: true
server.metrics.prometheus.existingSecret: my-metrics
asserts:
- notFailedTemplate: {}
@@ -160,6 +160,10 @@ tests:
helm.sh/hook: pre-install,pre-upgrade,pre-rollback
helm.sh/hook-weight: "-20"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
# K-C14: first under Argo CD too, before the upgrade (-25)
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/sync-wave: "-30"
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation,HookSucceeded
- equal:
path: spec.podSelector.matchLabels
value: {app.kubernetes.io/name: inbuxa, app.kubernetes.io/instance: mail}
+14
View File
@@ -104,3 +104,17 @@ tests:
asserts:
- failedTemplate:
errorPattern: the chart makes a ConfigMap of that name
- it: runs after the upgrade under Argo CD (K-C14)
asserts:
- equal:
path: metadata.annotations["argocd.argoproj.io/hook"]
value: PreSync
- equal:
path: metadata.annotations["argocd.argoproj.io/sync-wave"]
value: "-15"
documentIndex: 0
- equal:
path: metadata.annotations["argocd.argoproj.io/sync-wave"]
value: "-10"
documentIndex: 1
+14
View File
@@ -88,3 +88,17 @@ tests:
asserts:
- hasDocuments:
count: 0
- it: runs first under Argo CD, PreSync, before the seed (K-C14)
asserts:
- equal:
path: metadata.annotations["argocd.argoproj.io/hook"]
value: PreSync
- equal:
path: metadata.annotations["argocd.argoproj.io/sync-wave"]
value: "-25"
documentIndex: 0
- equal:
path: metadata.annotations["argocd.argoproj.io/sync-wave"]
value: "-20"
documentIndex: 4
+4
View File
@@ -282,6 +282,10 @@
}
}
},
"generateSecrets": {
"type": "boolean",
"description": "Make the webmail's and the metrics Secrets when they aren't named. Set false under Argo CD or kubectl apply, which can't read them back: the chart then requires webmail.existingSecret and server.metrics.prometheus.existingSecret."
},
"server": {
"type": "object",
"additionalProperties": false,
+10
View File
@@ -12,6 +12,16 @@ fullnameOverride: ""
imagePullSecrets: []
# The chart makes two secrets itself when you don't name your own: the
# webmail's (webmail.existingSecret) and the metrics password
# (server.metrics.prometheus.existingSecret). It makes each once and then
# reads it back from the cluster, which only Helm itself can do. Argo CD,
# and `helm template | kubectl apply`, render without the cluster, so they'd
# get new ones on every sync: the app never shows Synced, and every webmail
# user is signed out. Set this to false there, and the chart refuses to
# render until both are named.
generateSecrets: true
server:
image:
repository: ghcr.io/inbuxa/inbuxa-server