diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ebb4bc..abb3608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/charts/inbuxa/VALUES.md b/charts/inbuxa/VALUES.md index 6109b35..c97f6a2 100644 --- a/charts/inbuxa/VALUES.md +++ b/charts/inbuxa/VALUES.md @@ -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` diff --git a/charts/inbuxa/templates/networkpolicy.yaml b/charts/inbuxa/templates/networkpolicy.yaml index cbb7779..92889cd 100644 --- a/charts/inbuxa/templates/networkpolicy.yaml +++ b/charts/inbuxa/templates/networkpolicy.yaml @@ -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 diff --git a/charts/inbuxa/templates/server/egress-check.yaml b/charts/inbuxa/templates/server/egress-check.yaml index 2218bac..4410144 100644 --- a/charts/inbuxa/templates/server/egress-check.yaml +++ b/charts/inbuxa/templates/server/egress-check.yaml @@ -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" diff --git a/charts/inbuxa/templates/server/metrics.yaml b/charts/inbuxa/templates/server/metrics.yaml index 3571e05..4d53a56 100644 --- a/charts/inbuxa/templates/server/metrics.yaml +++ b/charts/inbuxa/templates/server/metrics.yaml @@ -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 }} diff --git a/charts/inbuxa/templates/server/seed.yaml b/charts/inbuxa/templates/server/seed.yaml index 09da4bc..b81df4b 100644 --- a/charts/inbuxa/templates/server/seed.yaml +++ b/charts/inbuxa/templates/server/seed.yaml @@ -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" diff --git a/charts/inbuxa/templates/server/upgrade.yaml b/charts/inbuxa/templates/server/upgrade.yaml index 650a0de..570358d 100644 --- a/charts/inbuxa/templates/server/upgrade.yaml +++ b/charts/inbuxa/templates/server/upgrade.yaml @@ -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" diff --git a/charts/inbuxa/templates/webmail.yaml b/charts/inbuxa/templates/webmail.yaml index eca0d91..ded090b 100644 --- a/charts/inbuxa/templates/webmail.yaml +++ b/charts/inbuxa/templates/webmail.yaml @@ -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 }} diff --git a/charts/inbuxa/tests/frontends_test.yaml b/charts/inbuxa/tests/frontends_test.yaml index 21750f3..59e73ea 100644 --- a/charts/inbuxa/tests/frontends_test.yaml +++ b/charts/inbuxa/tests/frontends_test.yaml @@ -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 diff --git a/charts/inbuxa/tests/metrics_test.yaml b/charts/inbuxa/tests/metrics_test.yaml index d96f1c5..622ec7e 100644 --- a/charts/inbuxa/tests/metrics_test.yaml +++ b/charts/inbuxa/tests/metrics_test.yaml @@ -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: {} diff --git a/charts/inbuxa/tests/networkpolicy_test.yaml b/charts/inbuxa/tests/networkpolicy_test.yaml index 1ad8cce..2f82be1 100644 --- a/charts/inbuxa/tests/networkpolicy_test.yaml +++ b/charts/inbuxa/tests/networkpolicy_test.yaml @@ -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} diff --git a/charts/inbuxa/tests/seed_test.yaml b/charts/inbuxa/tests/seed_test.yaml index b39c636..7c5836e 100644 --- a/charts/inbuxa/tests/seed_test.yaml +++ b/charts/inbuxa/tests/seed_test.yaml @@ -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 diff --git a/charts/inbuxa/tests/upgrade_test.yaml b/charts/inbuxa/tests/upgrade_test.yaml index 7d86f9b..4c7ffcc 100644 --- a/charts/inbuxa/tests/upgrade_test.yaml +++ b/charts/inbuxa/tests/upgrade_test.yaml @@ -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 diff --git a/charts/inbuxa/values.schema.json b/charts/inbuxa/values.schema.json index e950e8f..7839e71 100644 --- a/charts/inbuxa/values.schema.json +++ b/charts/inbuxa/values.schema.json @@ -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, diff --git a/charts/inbuxa/values.yaml b/charts/inbuxa/values.yaml index 699d2cf..2bdf3e7 100644 --- a/charts/inbuxa/values.yaml +++ b/charts/inbuxa/values.yaml @@ -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