From 3aefd640472d3e63dcb30c099038c61790f078bd Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Sun, 15 Nov 2026 13:14:13 +0100 Subject: [PATCH 1/7] Design a reviewer-only Kubernetes install for any cluster Part of #391 --- .../2026-11-15-k8s-any-cluster-design.md | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md diff --git a/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md b/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md new file mode 100644 index 00000000..8059d393 --- /dev/null +++ b/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md @@ -0,0 +1,116 @@ +# Kubernetes on any cluster: reviewer-only install with external Postgres and identity provider + +Status: design, 2026-11-15. Part of #391. + +## Why + +The operator will run Code Spire on a home k3s cluster, with sign-in on a production Keycloak in another +cluster (DigitalOcean). The deployment itself lives in the operator's own DevOps repository and pulls the +public GHCR images. This repository must give **anyone** what they need to do the same on any cluster: a chart +that installs without hand patches, and documents that say what to create first. + +The first install is **reviewer only**: gateway, orchestrator, review worker and dashboard. Agent work (harness +reviews, `/fix`, the factory) needs the run worker, which today needs a Docker daemon. It waits for M5, whose +Kubernetes runtime runs one pod per run inside the cluster (operator decision 2026-11-15). So this design adds +no run worker, no factory values and no Kafka listener outside the cluster. + +## What the home cluster taught (measured 2026-11-15) + +- No ingress controller. TLS ends at nginx proxy manager, which runs **as a pod** in the cluster + (`dnsPolicy: ClusterFirst`), so it can forward to `spire-ui..svc.cluster.local:8080` and the + Service can stay `ClusterIP`. +- Postgres runs on CloudNativePG (17 clusters, storage class `longhorn-cnpg`). A CloudNativePG application + owner cannot `CREATE ROLE`, so the chart's gateway-role job cannot run against it. +- No Kafka in the cluster. The chart's bundled Redpanda is enough while every Kafka client is in-cluster. +- The identity provider is public; pods and browsers reach it under one name. + +## Goals + +1. `helm install` with `values-production.yaml` plus bundled Kafka works against CloudNativePG Postgres and an + external identity provider, with no hand patch. +2. A cluster with no ingress controller can expose the dashboard through chart values, not `kubectl patch`. +3. A per-service escape hatch for settings the chart does not model. +4. A production realm template: the three clients, roles and mappers, with placeholders and no users or secrets. +5. The README says, in order, what to create before `helm install`. + +## Non-goals + +- The run worker, factory values, harness reviews (M5). +- Kafka outside the cluster, Kafka SASL or TLS (after M5, when a client outside the cluster exists again). +- Anything specific to the operator's cluster: host names, realm names, IPs. Those live in the DevOps repository. +- Creating secrets in the chart. The chart keeps taking Secret names only (values.yaml explains why). + +## Design + +### 1. `ui.service` + +```yaml +ui: + service: + type: ClusterIP # ClusterIP | NodePort | LoadBalancer + annotations: {} # e.g. a MetalLB address-pool or loadBalancerIPs annotation + loadBalancerSourceRanges: [] +``` + +The defaults render exactly today's Service. `loadBalancerSourceRanges` renders only for `LoadBalancer`. +TLS.md "Reaching the dashboard from outside the cluster" is rewritten: values, not a patch; and an +in-cluster terminator forwarding to the ClusterIP Service stays the first recommendation, because a +NodePort or LoadBalancer re-opens requirement 3 (a plaintext port beside the terminator). + +### 2. `extraEnv` and `extraEnvFrom` + +Per service: `orchestrator`, `gateway`, `worker`, `ui`. Each takes a list of Kubernetes `EnvVar` / +`EnvFromSource`, appended after the chart's own entries. Empty by default. The README warns that `extraEnvFrom` +on the gateway must never name the main Secret: the master keyset must not reach the internet-facing edge. +`render.sh` keeps asserting that for the presets; it cannot police an operator's own values, and says so. + +### 3. CloudNativePG example + +`deploy/examples/cloudnative-pg/` with: + +- `cluster.yaml`: a `Cluster` whose application database is `spire`, owner `spire`, a managed role `gateway` + (login, password from a Secret), and `postInitApplicationSQL` that creates the `gateway` schema owned by + `gateway`. Exactly the two statements in README "gateway role", never a broader grant. +- `values.yaml`: chart values for it: `postgres.bundled: false`, `host: -rw..svc.cluster.local`, + `provisionGatewayRole: false`, `kafka.bundled: true`, `oidc.bundled: false`, `ingress.enabled: false`. + +How the role and schema are created in CloudNativePG (`postInitApplicationSQL` ordering against managed roles) +is the builder's to settle, and it must be proven on a real CloudNativePG cluster before this example is called +working: the home install is that proof. Until then the README marks it "not yet run". + +### 4. Production realm template + +`deploy/keycloak/realm-spire-production.json`: derived from `realm-spire.json`. Three confidential clients with +audience mappers, the two realm roles on the access token, redirect URIs `https://SPIRE_HOST/{api,gw,wk}/auth/callback` +as literal placeholders, no users, no client secrets (Keycloak generates them on import). A test asserts the +template has no `users`, no `secret` values and no wildcard redirect URI, and that it names the same clients +and roles as the dev realm. + +### 5. README: "Install on any cluster" + +One ordered section in `deploy/README.md`: create the namespace; Postgres (bundled, external, or CloudNativePG +with the example); the two Secrets and their keys; the realm (template + four placeholders to replace); +`helm install` with the example values; point the terminator at the Service; verify with `deploy/e2e.sh`. +The "Bringing your own identity provider" section links the template. + +### Tests (CI only) + +- `render.sh`: default render has `type: ClusterIP` and no `loadBalancerSourceRanges`; a render with + `ui.service.type=LoadBalancer` and ranges has both; `extraEnv` on each service appears in that service only; + the example values render. +- `render-manifests.sh --check`: the shipped rendered manifests do not change (defaults unchanged). +- The realm template test above. + +### Docs + +UNVERIFIED.md: the chart has never been installed on a real cluster with external Postgres and an external +identity provider; the CloudNativePG example has not run. The home install closes both. HISTORY.md entry. + +## After this PR + +1. Push tag `v0.1.0`: the first real release (images and the chart with this PR in it). +2. DevOps repository: the `code-spire` realm on the production Keycloak at `auth.spire.stukans.com` + (it needs its own certificate: `*.stukans.com` does not cover a second-level name) and DNS. +3. DevOps repository: the home install at `v0.1.0`, plain Secrets made by hand, CloudNativePG with backups, + nginx proxy manager forwarding `spire.stukans.com` to the Service. Live review on `spire-test` as the proof. +4. M5: the Kubernetes runtime, then agent work inside the cluster. From 0da39aa2ce22762f00557ed62964f087874df8b5 Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Sun, 15 Nov 2026 13:42:25 +0100 Subject: [PATCH 2/7] Revise the any-cluster design after review Part of #391 --- .../2026-11-15-k8s-any-cluster-design.md | 148 ++++++++++++------ 1 file changed, 103 insertions(+), 45 deletions(-) diff --git a/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md b/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md index 8059d393..f484368a 100644 --- a/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md +++ b/docs/superpowers/specs/2026-11-15-k8s-any-cluster-design.md @@ -1,6 +1,6 @@ # Kubernetes on any cluster: reviewer-only install with external Postgres and identity provider -Status: design, 2026-11-15. Part of #391. +Status: design, 2026-11-15, revised after review the same day. Part of #391. ## Why @@ -19,24 +19,31 @@ no run worker, no factory values and no Kafka listener outside the cluster. - No ingress controller. TLS ends at nginx proxy manager, which runs **as a pod** in the cluster (`dnsPolicy: ClusterFirst`), so it can forward to `spire-ui..svc.cluster.local:8080` and the Service can stay `ClusterIP`. -- Postgres runs on CloudNativePG (17 clusters, storage class `longhorn-cnpg`). A CloudNativePG application - owner cannot `CREATE ROLE`, so the chart's gateway-role job cannot run against it. +- Postgres runs on CloudNativePG, operator 1.28.1 (17 clusters, storage class `longhorn-cnpg`). Its `Database` + object has a `schemas` field. A CloudNativePG application owner cannot `CREATE ROLE`, so the chart's + gateway-role job cannot run against it. - No Kafka in the cluster. The chart's bundled Redpanda is enough while every Kafka client is in-cluster. - The identity provider is public; pods and browsers reach it under one name. ## Goals 1. `helm install` with `values-production.yaml` plus bundled Kafka works against CloudNativePG Postgres and an - external identity provider, with no hand patch. + external identity provider, with no hand patch and no password stored twice. 2. A cluster with no ingress controller can expose the dashboard through chart values, not `kubectl patch`. -3. A per-service escape hatch for settings the chart does not model. -4. A production realm template: the three clients, roles and mappers, with placeholders and no users or secrets. -5. The README says, in order, what to create before `helm install`. +3. A per-service escape hatch for settings the chart does not model, that cannot break the chart's own + security invariants. +4. A production realm template: the three reviewer clients, roles and mappers, with placeholders and no users + or secrets. +5. The README says, in order, what to create before `helm install`, and how to check the result on a real + cluster. ## Non-goals -- The run worker, factory values, harness reviews (M5). +- The run worker, factory values, harness reviews (M5). The dev realm's fourth client, `spire-run-worker`, is + left out of the template on purpose; M5 adds it. - Kafka outside the cluster, Kafka SASL or TLS (after M5, when a client outside the cluster exists again). +- A NetworkPolicy. Today any pod in the cluster can reach a service port and forge forwarded headers; that is + existing, written down in one sentence in the README and as a techdebt entry, not fixed here. - Anything specific to the operator's cluster: host names, realm names, IPs. Those live in the DevOps repository. - Creating secrets in the chart. The chart keeps taking Secret names only (values.yaml explains why). @@ -52,59 +59,110 @@ ui: loadBalancerSourceRanges: [] ``` -The defaults render exactly today's Service. `loadBalancerSourceRanges` renders only for `LoadBalancer`. -TLS.md "Reaching the dashboard from outside the cluster" is rewritten: values, not a patch; and an -in-cluster terminator forwarding to the ClusterIP Service stays the first recommendation, because a -NodePort or LoadBalancer re-opens requirement 3 (a plaintext port beside the terminator). +The defaults render exactly today's Service. `loadBalancerSourceRanges` renders only for `LoadBalancer`. No +`loadBalancerIP` field (deprecated upstream; use the annotation). TLS.md "Reaching the dashboard from outside the +cluster" is rewritten: values, not a patch; an in-cluster terminator forwarding to the ClusterIP Service stays +the first recommendation, because a NodePort or LoadBalancer re-opens requirement 3. The nginx proxy manager +table gets a row for the in-cluster case: Forward Hostname `spire-ui..svc.cluster.local`, port `8080`. -### 2. `extraEnv` and `extraEnvFrom` +### 2. `extraEnv` and `extraEnvFrom`, with render-time refusals Per service: `orchestrator`, `gateway`, `worker`, `ui`. Each takes a list of Kubernetes `EnvVar` / -`EnvFromSource`, appended after the chart's own entries. Empty by default. The README warns that `extraEnvFrom` -on the gateway must never name the main Secret: the master keyset must not reach the internet-facing edge. -`render.sh` keeps asserting that for the presets; it cannot police an operator's own values, and says so. +`EnvFromSource`, appended after the chart's own entries. Empty by default. -### 3. CloudNativePG example +The chart **fails the render** (Helm `fail`, naming the value) when: -`deploy/examples/cloudnative-pg/` with: +- an `extraEnv` entry repeats a name the chart already sets on that container (duplicates override chart-owned + settings such as the gateway's database user, and server-side apply rejects them anyway); +- gateway `extraEnv` has a `secretKeyRef` or gateway `extraEnvFrom` has a `secretRef` naming + `secrets.existingSecret` (the main Secret, which holds the master keyset); +- gateway `extraEnv` sets `SPIRE_ENCRYPTION_KEYSET` by any means. -- `cluster.yaml`: a `Cluster` whose application database is `spire`, owner `spire`, a managed role `gateway` - (login, password from a Secret), and `postInitApplicationSQL` that creates the `gateway` schema owned by - `gateway`. Exactly the two statements in README "gateway role", never a broader grant. -- `values.yaml`: chart values for it: `postgres.bundled: false`, `host: -rw..svc.cluster.local`, - `provisionGatewayRole: false`, `kafka.bundled: true`, `oidc.bundled: false`, `ingress.enabled: false`. +`render.sh` greps env names, so it cannot see `envFrom`; these refusals are the guard, and `--self-test` renders +each forbidden shape and requires the render to fail. The README says what remains the operator's own +responsibility (a different Secret that also holds the master keyset). -How the role and schema are created in CloudNativePG (`postInitApplicationSQL` ordering against managed roles) -is the builder's to settle, and it must be proven on a real CloudNativePG cluster before this example is called -working: the home install is that proof. Until then the README marks it "not yet run". +### 3. Database passwords from any Secret -### 4. Production realm template +```yaml +postgres: + passwordSecret: {name: "", key: ""} # empty: POSTGRES_PASSWORD from secrets.existingSecret (today) + gatewayPasswordSecret: {name: "", key: ""} # empty: GATEWAY_POSTGRES_PASSWORD from gatewayExistingSecret +``` + +Set, the services read the password from that Secret and key, e.g. the CloudNativePG basic-auth Secret's +`password`. So a password lives once. The gateway password Secret must never be the main Secret's name (render +refusal, like section 2). Defaults render exactly today's manifests. + +### 4. Smaller chart values + +- `kafka.storageClass` and `postgres.storageClass` (empty: cluster default) for the bundled PVCs. +- `image.tag` empty by default, falling back to the chart's `appVersion`, so the chart packaged at a release + pulls that release. The repository's rendered manifests and dev presets set `edge` explicitly so they do not + drift. + +### 5. CloudNativePG example + +`deploy/examples/cloudnative-pg/`: + +- `cluster.yaml`: a `Cluster` (application database `spire`, owner `spire`, Postgres 15 or later: the + migrations use `NULLS NOT DISTINCT`), a managed role `gateway` (login, password from a basic-auth Secret), and a + `Database` object for `spire` with `schemas: [{name: gateway, owner: gateway}]`. Not `postInitApplicationSQL`: + it runs at bootstrap, before managed roles exist, so the schema's owner would be missing. The gateway needs + nothing more (no grants, extensions or search path in any migration). +- `values.yaml`: `postgres.bundled: false`, `host: -rw..svc.cluster.local` (the read-write service; + no transaction-mode pooler, the orchestrator uses `LISTEN`), `provisionGatewayRole: false`, both + `passwordSecret`s pointing at the CloudNativePG Secrets, `kafka.bundled: true`, `oidc.bundled: false`, + `ingress.enabled: false`, `publicHost`, `trustedProxies`. + +The home install is the first real run of this example. Until then the README marks it "not yet run". + +### 6. Production realm template + +`deploy/keycloak/realm-spire-production.json`: three confidential clients (`spire-orchestrator`, +`spire-gateway`, `spire-review-worker`) with audience mappers, the realm roles `spire-viewer` and `spire-admin` +on the access token. Four placeholders, literal strings: `SPIRE_REALM`, `SPIRE_HOST` (in redirect URIs +`https://SPIRE_HOST/{api,gw,wk}/auth/callback`, web origins and post-logout URIs). Compared with +`realm-spire.json`, it has: no users; no client secrets; `sslRequired: external`; `directAccessGrantsEnabled: +false`; no `http://` or `localhost` URI or web origin; no wildcard in any redirect or post-logout URI; no +"(dev)" display name; no `spire-run-worker` client. + +Whether Keycloak generates a confidential client's secret on import when the JSON has none is **not proven**. +The README says: after import, open each client's Credentials tab and press Regenerate, then copy the secret +into the main Secret. -`deploy/keycloak/realm-spire-production.json`: derived from `realm-spire.json`. Three confidential clients with -audience mappers, the two realm roles on the access token, redirect URIs `https://SPIRE_HOST/{api,gw,wk}/auth/callback` -as literal placeholders, no users, no client secrets (Keycloak generates them on import). A test asserts the -template has no `users`, no `secret` values and no wildcard redirect URI, and that it names the same clients -and roles as the dev realm. +### 7. README: "Install on any cluster" -### 5. README: "Install on any cluster" +One ordered section in `deploy/README.md`: namespace; Postgres (bundled, external, or CloudNativePG with the +example); the two Secrets and their keys; the realm (template, placeholders, Regenerate); `helm install` with +the example values; point the terminator at the Service; check it worked. The "Bringing your own identity +provider" section links the template. NOTES.txt points to the same checks. -One ordered section in `deploy/README.md`: create the namespace; Postgres (bundled, external, or CloudNativePG -with the example); the two Secrets and their keys; the realm (template + four placeholders to replace); -`helm install` with the example values; point the terminator at the Service; verify with `deploy/e2e.sh`. -The "Bringing your own identity provider" section links the template. +`deploy/e2e.sh` cannot check this install (it signs in with the password grant and dev users, fixes realm +`spire` and runs `docker compose exec`). The real-cluster checks are: all pods Ready; `/q/health/ready` of each +service through `kubectl port-forward`; the dashboard at `https://` signs in through the identity provider +and shows the operator's roles; the gateway answers a forge's webhook ping; one review on a test pull request. -### Tests (CI only) +## Tests (CI only: `manifests.yml`, and `testFast` for the realm test) -- `render.sh`: default render has `type: ClusterIP` and no `loadBalancerSourceRanges`; a render with - `ui.service.type=LoadBalancer` and ranges has both; `extraEnv` on each service appears in that service only; - the example values render. -- `render-manifests.sh --check`: the shipped rendered manifests do not change (defaults unchanged). -- The realm template test above. +- `render.sh` positives: default render has `type: ClusterIP`, no `loadBalancerSourceRanges`, today's password + references and `image.tag` resolution as before; a render with `ui.service.type=LoadBalancer` and ranges has + both; `extraEnv` on each service appears in that service only; the `passwordSecret`s become `secretKeyRef`s to + the named Secret and key. +- `render.sh` CloudNativePG example: render `deploy/examples/cloudnative-pg/values.yaml` **with no `--set`** + and assert: no gateway-role Job, no Ingress, a Redpanda StatefulSet, no Postgres StatefulSet, both passwords + from the CloudNativePG Secrets. +- `render.sh --self-test`: each refusal in sections 2 and 3 renders its forbidden shape and the render fails. +- kubeconform validates `cluster.yaml` (with the CloudNativePG CRD schemas, or skip-missing-schemas stated). +- A realm template test in `spire-arch` (runs in `testFast`; render.sh has no JSON tool) asserting every point + of section 6's list, and that its clients and roles are the dev realm's minus `spire-run-worker`. +- `render-manifests.sh --check`: the shipped rendered manifests do not change. -### Docs +## Docs UNVERIFIED.md: the chart has never been installed on a real cluster with external Postgres and an external -identity provider; the CloudNativePG example has not run. The home install closes both. HISTORY.md entry. +identity provider; the CloudNativePG example has not run; secret generation on realm import is unproven. The +home install closes the first two. HISTORY.md entry. Techdebt entry: no NetworkPolicy. ## After this PR From 6a1b74fb6e2d8feed43f40c69967b75167a3bd5a Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Sun, 15 Nov 2026 14:29:10 +0100 Subject: [PATCH 3/7] Let the Helm chart install on any cluster without patches A reviewer-only install on a cluster with CloudNativePG Postgres, no ingress controller and an external identity provider needed hand patches. The chart now models what that install needs, and every default renders exactly today's manifests (deploy/k8s does not drift): - ui.service: type, annotations and loadBalancerSourceRanges for the dashboard Service, so it can leave the cluster through values. Ranges render only for a LoadBalancer. - .extraEnv / extraEnvFrom on the four services. The render fails on a name the chart already sets (read from the rendered env itself), and on the gateway for SPIRE_ENCRYPTION_KEYSET or any reference to the main Secret, which holds the master keyset. - postgres.passwordSecret / gatewayPasswordSecret: read each database password from any Secret and key, such as a CloudNativePG basic-auth Secret, so a password lives once. Half a reference, or the gateway's password from the main Secret, is refused. - kafka.storageClass and postgres.storageClass for the bundled PVCs. - image.tag empty falls back to the chart's appVersion, so a chart packaged at a release pulls that release. The kustomize inputs, which also drive deploy/k8s, set edge explicitly. deploy/examples/cloudnative-pg holds a Cluster with the managed role gateway, a Database object that makes the gateway schema (post-init SQL runs before managed roles exist), and values that render with no --set. render.sh asserts the new values set and unset, the example's shape, and that only spire-ui may be external; --self-test renders each refused shape and requires the refusal's own message. kubeconform checks cluster.yaml against the CloudNativePG CRD schemas. Part of #391 --- .github/workflows/manifests.yml | 8 +- deploy/examples/cloudnative-pg/cluster.yaml | 67 ++++ deploy/examples/cloudnative-pg/values.yaml | 65 ++++ deploy/helm/spire/templates/NOTES.txt | 15 +- deploy/helm/spire/templates/_helpers.tpl | 97 ++++++ .../helm/spire/templates/bundled-infra.yaml | 10 +- .../spire/templates/gateway-role-job.yaml | 8 +- deploy/helm/spire/templates/gateway.yaml | 74 ++-- deploy/helm/spire/templates/orchestrator.yaml | 53 +-- deploy/helm/spire/templates/ui.yaml | 59 +++- deploy/helm/spire/templates/worker.yaml | 53 +-- deploy/helm/spire/tests/render.sh | 316 +++++++++++++++++- deploy/helm/spire/values.yaml | 58 +++- .../overlays/production/values-required.yaml | 5 + .../overlays/simple/values-required.yaml | 5 + 15 files changed, 769 insertions(+), 124 deletions(-) create mode 100644 deploy/examples/cloudnative-pg/cluster.yaml create mode 100644 deploy/examples/cloudnative-pg/values.yaml diff --git a/.github/workflows/manifests.yml b/.github/workflows/manifests.yml index cde6c307..a8cd0d87 100644 --- a/.github/workflows/manifests.yml +++ b/.github/workflows/manifests.yml @@ -124,12 +124,18 @@ jobs: echo "$preset: $(grep -c '^kind:' "/tmp/$preset.yaml") resources" done + # The CloudNativePG example's Cluster and Database are custom resources, not in the default schema + # set. They are validated against the CRD schemas in the datreeio CRDs-catalog (the second + # location: postgresql.cnpg.io/cluster_v1.json and database_v1.json), NOT skipped with + # -ignore-missing-schemas: a wrong field name in the example must fail here. -strict rejects an + # unknown field. - name: Schemas run: | kubeconform -strict -summary \ -schema-location default \ -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \ - deploy/k8s/simple/spire.yaml deploy/k8s/production/spire.yaml + deploy/k8s/simple/spire.yaml deploy/k8s/production/spire.yaml \ + deploy/examples/cloudnative-pg/cluster.yaml kind-install: name: kind install (simple preset) diff --git a/deploy/examples/cloudnative-pg/cluster.yaml b/deploy/examples/cloudnative-pg/cluster.yaml new file mode 100644 index 00000000..3c7b2ed4 --- /dev/null +++ b/deploy/examples/cloudnative-pg/cluster.yaml @@ -0,0 +1,67 @@ +# A CloudNativePG Postgres for Code Spire. An example: read it, change the names and the size, then apply +# it in the SAME namespace as Code Spire (a pod can read a Secret only from its own namespace, and the +# services read the passwords from the Secrets below): +# +# kubectl -n spire apply -f deploy/examples/cloudnative-pg/cluster.yaml +# +# NOT YET RUN on a real cluster (docs/UNVERIFIED.md). The field names are checked against the +# CloudNativePG 1.28 schemas by kubeconform in CI (.github/workflows/manifests.yml). +# +# Needs: the CloudNativePG operator 1.26 or later (the Database object's `schemas` field), and +# Postgres 15 or later (the migrations use NULLS NOT DISTINCT). The image is the operator's default +# unless you set spec.imageName. +# +# What this makes: +# - the database `spire`, owned by the role `spire`. CloudNativePG makes the role and its password and +# writes them to the basic-auth Secret `spire-db-app` (keys `username`, `password`). The chart reads +# that Secret (postgres.passwordSecret), so the password is stored once. +# - the role `gateway`, login, password from the basic-auth Secret `spire-db-gateway`, which YOU make +# first (deploy/README.md, "Install on any cluster"). The chart reads the same Secret +# (postgres.gatewayPasswordSecret). +# - the schema `gateway` in the database `spire`, owned by `gateway`. That is the only thing the +# gateway role gets: no grant on any other schema, no membership in `spire` (deploy/README.md, "The +# gateway's database role"). +# +# Why a Database object and not bootstrap.initdb.postInitApplicationSQL: post-init SQL runs once, at +# bootstrap, BEFORE the managed role exists, so `CREATE SCHEMA gateway AUTHORIZATION gateway` would fail +# and the cluster would not come up. The Database object is reconciled after the role exists, and it +# works on a cluster that already exists too. +# +# Connect the services to `spire-db-rw` (the read-write Service). Do not put a transaction-mode Pooler +# between them: the orchestrator holds a LISTEN session. +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: spire-db +spec: + instances: 1 + storage: + size: 10Gi + # storageClass: your-storage-class # empty means the cluster's default + bootstrap: + initdb: + database: spire + owner: spire + managed: + roles: + - name: gateway + ensure: present + login: true + passwordSecret: + name: spire-db-gateway +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: spire-db-spire +spec: + cluster: + name: spire-db + name: spire + owner: spire + # Keep the database when this object is deleted. + databaseReclaimPolicy: retain + schemas: + - name: gateway + owner: gateway + ensure: present diff --git a/deploy/examples/cloudnative-pg/values.yaml b/deploy/examples/cloudnative-pg/values.yaml new file mode 100644 index 00000000..2d6ee063 --- /dev/null +++ b/deploy/examples/cloudnative-pg/values.yaml @@ -0,0 +1,65 @@ +# Code Spire on any cluster: Postgres on CloudNativePG (cluster.yaml beside this file), the chart's +# bundled Redpanda, and an identity provider you already run. Use it on top of the production preset: +# +# helm install spire deploy/helm/spire -n spire \ +# -f deploy/helm/spire/values-production.yaml \ +# -f deploy/examples/cloudnative-pg/values.yaml +# +# Every value here is a placeholder (example.invalid, a sample pod CIDR). Change each one. The steps, +# in order, are in deploy/README.md, "Install on any cluster". NOT YET RUN on a real cluster +# (docs/UNVERIFIED.md). +# +# tests/render.sh renders this file with NO --set, so it must stay complete: a value the chart +# requires that is missing here fails CI. + +# The two Secrets you make before the install (deploy/README.md lists their keys). With the passwords +# below read from the CloudNativePG Secrets, neither needs a database password key. +secrets: + existingSecret: spire-secrets + gatewayExistingSecret: spire-gateway-secrets + +# Your cluster's pod CIDR (k3s uses 10.42.0.0/16 by default). The services believe forwarded headers only +# from this network (docs/TLS.md requirement 4). +trustedProxies: 10.244.0.0/16 + +# The host the browser uses. Set it whenever the Ingress is off: nothing else pins the Host that the +# login redirect is built from. +publicHost: spire.example.invalid + +postgres: + bundled: false + # The CloudNativePG read-write Service: -rw..svc.cluster.local. Not a Pooler in + # transaction mode: the orchestrator holds a LISTEN session. + host: spire-db-rw.spire.svc.cluster.local + database: spire + user: spire + gatewayUser: gateway + # CloudNativePG's application owner cannot CREATE ROLE, and cluster.yaml makes the role and the schema + # already, so the chart's role Job must not run. + provisionGatewayRole: false + # The basic-auth Secret CloudNativePG made for the owner `spire` (-app). + passwordSecret: + name: spire-db-app + key: password + # The basic-auth Secret you made for the managed role `gateway` (cluster.yaml). + gatewayPasswordSecret: + name: spire-db-gateway + key: password + +# The chart's single-replica Redpanda. Enough while every Kafka client is in the cluster. +kafka: + bundled: true + # storageClass: your-storage-class # empty means the cluster's default + +oidc: + bundled: false + # Must be reachable from the pods AND be the issuer the browser sees. The realm: + # deploy/keycloak/realm-spire-production.json. + authServerUrl: https://auth.example.invalid/realms/spire + +# No ingress controller: a TLS terminator in the cluster forwards to the spire-ui Service +# (spire-ui..svc.cluster.local:8080). See docs/TLS.md. +ingress: + enabled: false + +# image.tag is left empty: the chart's appVersion. A chart from a release pulls that release's images. diff --git a/deploy/helm/spire/templates/NOTES.txt b/deploy/helm/spire/templates/NOTES.txt index aa1a6f54..c4021779 100644 --- a/deploy/helm/spire/templates/NOTES.txt +++ b/deploy/helm/spire/templates/NOTES.txt @@ -18,6 +18,9 @@ Dashboard: {{- if .Values.ingress.enabled }} http{{ if .Values.ingress.tls.enabled }}s{{ end }}://{{ .Values.ingress.host }} {{- else }} + No Ingress. Point your TLS terminator at the spire-ui Service + (spire-ui.{{ .Release.Namespace }}.svc.cluster.local:8080, type {{ .Values.ui.service.type }}). + See docs/TLS.md. For a quick look without TLS: kubectl port-forward svc/spire-ui 34700:8080 then http://localhost:34700 {{- end }} @@ -33,15 +36,23 @@ is what puts all four services on one origin. Two things follow: Check it: kubectl get pods -l app.kubernetes.io/name=spire +{{- if .Values.oidc.bundled }} kubectl port-forward svc/spire-ui 34700:8080 ./deploy/e2e.sh http://localhost:34700 +{{- else }} + + deploy/e2e.sh cannot check this install: it signs in with the bundled realm's + dev users. Use the checks in deploy/README.md, "Install on any cluster": + every pod Ready, /q/health/ready of each service, a sign-in at the dashboard + through your identity provider, a webhook ping, and one review. +{{- end }} {{ if not .Values.oidc.bundled }} Using your own identity provider. It must offer three confidential clients (spire-orchestrator, spire-gateway, spire-review-worker), each with an audience mapper, plus the roles spire-viewer and spire-admin readable from the ACCESS -token. See deploy/README.md; deploy/keycloak/realm-spire.json is a worked -example. +token. See deploy/README.md. deploy/keycloak/realm-spire-production.json is a +template for a production realm. {{ end }} {{- if .Values.gateway.giveMasterKeyset }} diff --git a/deploy/helm/spire/templates/_helpers.tpl b/deploy/helm/spire/templates/_helpers.tpl index 0ca79d4e..40eac56f 100644 --- a/deploy/helm/spire/templates/_helpers.tpl +++ b/deploy/helm/spire/templates/_helpers.tpl @@ -61,6 +61,103 @@ at boot and silently falls back to localhost for the broker. value: {{ include "spire.trustedProxies" . | quote }} {{- end -}} +{{/* +One service image. An empty image.tag means the chart's appVersion, so a chart packaged at a release +(release.yml sets --app-version) pulls that release's images rather than a moving tag. +*/}} +{{- define "spire.image" -}} +"{{ .root.Values.image.registry }}/{{ .name }}:{{ .root.Values.image.tag | default .root.Chart.AppVersion }}" +{{- end -}} + +{{/* +A password reference: the chart's own Secret and key, or the Secret and key the operator names (a +CloudNativePG basic-auth Secret's `password`, so a password lives in one place). Half a reference is +refused: a name without a key, or a key without a name, would silently read the wrong place. + + include "spire.passwordRef" (dict "value" "postgres.passwordSecret" "ref" .Values.postgres.passwordSecret + "secret" (include "spire.secretName" .) "key" "POSTGRES_PASSWORD") +*/}} +{{- define "spire.passwordRef" -}} +{{- $ref := .ref | default dict -}} +{{- $name := $ref.name | default "" -}} +{{- $key := $ref.key | default "" -}} +{{- if ne (empty $name) (empty $key) -}} +{{- fail (printf "%s needs both name and key, or neither. Got name=%q key=%q." .value $name $key) -}} +{{- end -}} +secretKeyRef: + name: {{ $name | default .secret }} + key: {{ $key | default .key }} +{{- end -}} + +{{- define "spire.dbPasswordRef" -}} +{{ include "spire.passwordRef" (dict "value" "postgres.passwordSecret" "ref" .Values.postgres.passwordSecret "secret" (include "spire.secretName" .) "key" "POSTGRES_PASSWORD") }} +{{- end -}} + +{{/* +The gateway's database password. Its Secret may never be the main one: the main Secret holds the +master keyset, and the gateway is the internet-facing edge (ADR-015). +*/}} +{{- define "spire.gatewayDbPasswordRef" -}} +{{- $ref := .Values.postgres.gatewayPasswordSecret | default dict -}} +{{- if and $ref.name (eq $ref.name .Values.secrets.existingSecret) -}} +{{- fail (printf "postgres.gatewayPasswordSecret.name is %q, the main Secret (secrets.existingSecret). That Secret holds the master keyset, and the gateway must never reference it. Name the Secret that holds only the gateway role's password." $ref.name) -}} +{{- end -}} +{{ include "spire.passwordRef" (dict "value" "postgres.gatewayPasswordSecret" "ref" $ref "secret" (include "spire.gatewaySecretName" .) "key" "GATEWAY_POSTGRES_PASSWORD") }} +{{- end -}} + +{{/* +A container's env: the chart's own entries, then .extraEnv. The chart's names are read from +the rendered list itself, not from a second list kept by hand, so a new chart entry is protected the +moment it exists. A repeated name is refused: the later entry would override a chart-owned setting +(the gateway's database user, for one) and server-side apply rejects the object anyway. + + include "spire.env" (dict "root" . "service" "orchestrator" "own" (include "spire.orchestrator.env" .)) +*/}} +{{- define "spire.env" -}} +{{- $svc := index .root.Values .service | default dict -}} +{{- $names := list -}} +{{- range (fromYamlArray .own) -}} +{{- if not (and (kindIs "map" .) (hasKey . "name")) -}} +{{- fail (printf "internal: the chart's own env could not be read as a list of named entries: %v" .) -}} +{{- end -}} +{{- $names = append $names .name -}} +{{- end -}} +{{- range $i, $e := $svc.extraEnv -}} +{{- if has $e.name $names -}} +{{- fail (printf "%s.extraEnv[%d] sets %s, which this container already has. extraEnv may only add names; it cannot override a setting the chart owns." $.service $i $e.name) -}} +{{- end -}} +{{- $names = append $names $e.name -}} +{{- end -}} +{{ .own }} +{{- with $svc.extraEnv }} +{{ toYaml . }} +{{- end -}} +{{- end -}} + +{{/* +The refusals that keep the master keyset off the gateway when extraEnv and extraEnvFrom are used. +render.sh greps env NAMES, so it cannot see an envFrom; these refusals are the guard. A different +Secret that also holds the master keyset cannot be policed here, and deploy/README.md says so. +*/}} +{{- define "spire.gatewayExtraGuards" -}} +{{- $main := .Values.secrets.existingSecret -}} +{{- range $i, $e := .Values.gateway.extraEnv -}} +{{- if eq $e.name "SPIRE_ENCRYPTION_KEYSET" -}} +{{- fail (printf "gateway.extraEnv[%d] sets SPIRE_ENCRYPTION_KEYSET. The gateway is the internet-facing edge and must never hold the master keyset (ADR-015)." $i) -}} +{{- end -}} +{{- $ref := dig "valueFrom" "secretKeyRef" "name" "" $e -}} +{{- if and $main (eq $ref $main) -}} +{{- fail (printf "gateway.extraEnv[%d] reads from %q, the main Secret (secrets.existingSecret), which holds the master keyset. The gateway must never reference it." $i $main) -}} +{{- end -}} +{{- end -}} +{{- range $i, $e := .Values.gateway.extraEnvFrom -}} +{{- $ref := dig "secretRef" "name" "" $e -}} +{{- if and $main (eq $ref $main) -}} +{{- fail (printf "gateway.extraEnvFrom[%d] loads %q, the main Secret (secrets.existingSecret), which holds the master keyset. The gateway must never reference it." $i $main) -}} +{{- end -}} +{{- end -}} +{{- end -}} + {{- define "spire.probes" -}} livenessProbe: httpGet: diff --git a/deploy/helm/spire/templates/bundled-infra.yaml b/deploy/helm/spire/templates/bundled-infra.yaml index e774d3eb..56279cd0 100644 --- a/deploy/helm/spire/templates/bundled-infra.yaml +++ b/deploy/helm/spire/templates/bundled-infra.yaml @@ -38,9 +38,7 @@ spec: value: {{ .Values.postgres.user | quote }} - name: POSTGRES_PASSWORD valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: POSTGRES_PASSWORD + {{- include "spire.dbPasswordRef" . | nindent 16 }} # postgres:18+ wants the PARENT directory mounted: data lives in a versioned subdirectory, # which is what makes an in-place pg_upgrade --link possible later. - name: PGDATA @@ -65,6 +63,9 @@ spec: name: data spec: accessModes: ["ReadWriteOnce"] + {{- with .Values.postgres.storageClass }} + storageClassName: {{ . | quote }} + {{- end }} resources: requests: storage: {{ .Values.postgres.storage }} @@ -146,6 +147,9 @@ spec: name: data spec: accessModes: ["ReadWriteOnce"] + {{- with .Values.kafka.storageClass }} + storageClassName: {{ . | quote }} + {{- end }} resources: requests: storage: {{ .Values.kafka.storage }} diff --git a/deploy/helm/spire/templates/gateway-role-job.yaml b/deploy/helm/spire/templates/gateway-role-job.yaml index 5f33e0a5..a71c9b8c 100644 --- a/deploy/helm/spire/templates/gateway-role-job.yaml +++ b/deploy/helm/spire/templates/gateway-role-job.yaml @@ -64,16 +64,12 @@ spec: value: {{ .Values.postgres.user | quote }} - name: PGPASSWORD valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: POSTGRES_PASSWORD + {{- include "spire.dbPasswordRef" . | nindent 16 }} - name: GATEWAY_USER value: {{ .Values.postgres.gatewayUser | quote }} - name: GATEWAY_PASSWORD valueFrom: - secretKeyRef: - name: {{ include "spire.gatewaySecretName" . }} - key: GATEWAY_POSTGRES_PASSWORD + {{- include "spire.gatewayDbPasswordRef" . | nindent 16 }} command: - /bin/sh - -c diff --git a/deploy/helm/spire/templates/gateway.yaml b/deploy/helm/spire/templates/gateway.yaml index fec79b7f..a8074ead 100644 --- a/deploy/helm/spire/templates/gateway.yaml +++ b/deploy/helm/spire/templates/gateway.yaml @@ -11,6 +11,39 @@ Two things about it are deliberate and easy to undo by accident: Both are asserted by tests/render.sh, because flattening either would fail nothing and break everything. */}} +{{- define "spire.gateway.env" -}} +{{ include "spire.commonEnv" . }} +- name: QUARKUS_DATASOURCE_USERNAME + valueFrom: + configMapKeyRef: + name: spire-config + key: GATEWAY_POSTGRES_USER +- name: QUARKUS_DATASOURCE_PASSWORD + valueFrom: + {{- include "spire.gatewayDbPasswordRef" . | nindent 4 }} +- name: SPIRE_ENCRYPTION_WEBHOOK_KEYSET + valueFrom: + secretKeyRef: + name: {{ include "spire.gatewaySecretName" . }} + key: SPIRE_ENCRYPTION_WEBHOOK_KEYSET +{{- if .Values.gateway.giveMasterKeyset }} +# TEST-ONLY, and forbidden in any real install. Present so tests/render.sh --self-test can +# render the shape assertion 1 must catch: a negative assertion passes trivially when a key +# is renamed, so it has to be shown failing. +- name: SPIRE_ENCRYPTION_KEYSET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_ENCRYPTION_KEYSET +{{- end }} +- name: SPIRE_OIDC_CLIENT_ID + value: spire-gateway +- name: SPIRE_OIDC_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_OIDC_GATEWAY_SECRET +{{- end -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -32,45 +65,18 @@ spec: spec: containers: - name: gateway - image: "{{ .Values.image.registry }}/spire-gateway:{{ .Values.image.tag }}" + image: {{ include "spire.image" (dict "root" . "name" "spire-gateway") }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: 8080 + {{- include "spire.gatewayExtraGuards" . }} env: - {{- include "spire.commonEnv" . | nindent 12 }} - - name: QUARKUS_DATASOURCE_USERNAME - valueFrom: - configMapKeyRef: - name: spire-config - key: GATEWAY_POSTGRES_USER - - name: QUARKUS_DATASOURCE_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "spire.gatewaySecretName" . }} - key: GATEWAY_POSTGRES_PASSWORD - - name: SPIRE_ENCRYPTION_WEBHOOK_KEYSET - valueFrom: - secretKeyRef: - name: {{ include "spire.gatewaySecretName" . }} - key: SPIRE_ENCRYPTION_WEBHOOK_KEYSET - {{- if .Values.gateway.giveMasterKeyset }} - # TEST-ONLY, and forbidden in any real install. Present so tests/render.sh --self-test can - # render the shape assertion 1 must catch: a negative assertion passes trivially when a key - # is renamed, so it has to be shown failing. - - name: SPIRE_ENCRYPTION_KEYSET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_ENCRYPTION_KEYSET - {{- end }} - - name: SPIRE_OIDC_CLIENT_ID - value: spire-gateway - - name: SPIRE_OIDC_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_OIDC_GATEWAY_SECRET + {{- include "spire.env" (dict "root" . "service" "gateway" "own" (include "spire.gateway.env" .)) | nindent 12 }} + {{- with .Values.gateway.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} {{- include "spire.probes" . | nindent 10 }} {{- include "spire.securityContext" . | nindent 10 }} resources: diff --git a/deploy/helm/spire/templates/orchestrator.yaml b/deploy/helm/spire/templates/orchestrator.yaml index 6e054c99..a0118ced 100644 --- a/deploy/helm/spire/templates/orchestrator.yaml +++ b/deploy/helm/spire/templates/orchestrator.yaml @@ -2,6 +2,29 @@ The orchestrator: deciders, sagas, the event store and the operator API. Holds the MASTER keyset, which decrypts event payloads and provider credentials. */}} +{{- define "spire.orchestrator.env" -}} +{{ include "spire.commonEnv" . }} +- name: QUARKUS_DATASOURCE_USERNAME + valueFrom: + configMapKeyRef: + name: spire-config + key: POSTGRES_USER +- name: QUARKUS_DATASOURCE_PASSWORD + valueFrom: + {{- include "spire.dbPasswordRef" . | nindent 4 }} +- name: SPIRE_ENCRYPTION_KEYSET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_ENCRYPTION_KEYSET +- name: SPIRE_OIDC_CLIENT_ID + value: spire-orchestrator +- name: SPIRE_OIDC_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_OIDC_ORCHESTRATOR_SECRET +{{- end -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -23,35 +46,17 @@ spec: spec: containers: - name: orchestrator - image: "{{ .Values.image.registry }}/spire-orchestrator:{{ .Values.image.tag }}" + image: {{ include "spire.image" (dict "root" . "name" "spire-orchestrator") }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: 8080 env: - {{- include "spire.commonEnv" . | nindent 12 }} - - name: QUARKUS_DATASOURCE_USERNAME - valueFrom: - configMapKeyRef: - name: spire-config - key: POSTGRES_USER - - name: QUARKUS_DATASOURCE_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: POSTGRES_PASSWORD - - name: SPIRE_ENCRYPTION_KEYSET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_ENCRYPTION_KEYSET - - name: SPIRE_OIDC_CLIENT_ID - value: spire-orchestrator - - name: SPIRE_OIDC_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_OIDC_ORCHESTRATOR_SECRET + {{- include "spire.env" (dict "root" . "service" "orchestrator" "own" (include "spire.orchestrator.env" .)) | nindent 12 }} + {{- with .Values.orchestrator.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} {{- include "spire.probes" . | nindent 10 }} {{- include "spire.securityContext" . | nindent 10 }} resources: diff --git a/deploy/helm/spire/templates/ui.yaml b/deploy/helm/spire/templates/ui.yaml index 49ed6fd1..8258890d 100644 --- a/deploy/helm/spire/templates/ui.yaml +++ b/deploy/helm/spire/templates/ui.yaml @@ -8,6 +8,24 @@ asserts over directly because it is baked into the image rather than templated h This is the only workload reachable from outside the cluster. */}} +{{- define "spire.ui.env" -}} +# Service DNS, resolved at REQUEST time by the template's resolver — so this pod does not +# crash-loop when it starts before its siblings, and does not pin a stale address if a +# Service is recreated. +- name: SPIRE_ORCHESTRATOR_URL + value: http://spire-orchestrator:8080 +- name: SPIRE_GATEWAY_URL + value: http://spire-gateway:8080 +- name: SPIRE_WORKER_URL + value: http://spire-worker:8080 +{{- with .Values.publicHost }} +# Pins the Host the proxy forwards, which is what OIDC builds redirect_uri from. Omitted +# entirely when unset, so the image's own empty default applies and every Host is +# forwarded as sent — including the pod IP a kubelet probe addresses. +- name: SPIRE_PUBLIC_HOST + value: {{ . | quote }} +{{- end }} +{{- end -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -29,28 +47,17 @@ spec: spec: containers: - name: ui - image: "{{ .Values.image.registry }}/spire-ui:{{ .Values.image.tag }}" + image: {{ include "spire.image" (dict "root" . "name" "spire-ui") }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: 8080 env: - # Service DNS, resolved at REQUEST time by the template's resolver — so this pod does not - # crash-loop when it starts before its siblings, and does not pin a stale address if a - # Service is recreated. - - name: SPIRE_ORCHESTRATOR_URL - value: http://spire-orchestrator:8080 - - name: SPIRE_GATEWAY_URL - value: http://spire-gateway:8080 - - name: SPIRE_WORKER_URL - value: http://spire-worker:8080 - {{- with .Values.publicHost }} - # Pins the Host the proxy forwards, which is what OIDC builds redirect_uri from. Omitted - # entirely when unset, so the image's own empty default applies and every Host is - # forwarded as sent — including the pod IP a kubelet probe addresses. - - name: SPIRE_PUBLIC_HOST - value: {{ . | quote }} - {{- end }} + {{- include "spire.env" (dict "root" . "service" "ui" "own" (include "spire.ui.env" .)) | nindent 12 }} + {{- with .Values.ui.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} livenessProbe: httpGet: path: /healthz @@ -78,8 +85,24 @@ metadata: name: spire-ui labels: {{- include "spire.labels" . | nindent 4 }} + {{- with .Values.ui.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} spec: - type: ClusterIP + {{- $type := .Values.ui.service.type | default "ClusterIP" }} + {{- if not (has $type (list "ClusterIP" "NodePort" "LoadBalancer")) }} + {{- fail (printf "ui.service.type is %q. It must be ClusterIP, NodePort or LoadBalancer." $type) }} + {{- end }} + {{- /* The only Service that may leave the cluster. A NodePort or LoadBalancer publishes plaintext + beside the TLS terminator (docs/TLS.md requirement 3), so ClusterIP stays the default. */}} + type: {{ $type }} + {{- if eq $type "LoadBalancer" }} + {{- with .Values.ui.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- end }} selector: app.kubernetes.io/name: spire app.kubernetes.io/component: ui diff --git a/deploy/helm/spire/templates/worker.yaml b/deploy/helm/spire/templates/worker.yaml index 2ba9ac11..df8b5bdf 100644 --- a/deploy/helm/spire/templates/worker.yaml +++ b/deploy/helm/spire/templates/worker.yaml @@ -3,6 +3,29 @@ The review worker: diff, context and review work, plus the assembled-context rea Context card needs. Holds the master keyset because it decrypts the per-command SCM credential the orchestrator brokers to it (ADR-015). */}} +{{- define "spire.worker.env" -}} +{{ include "spire.commonEnv" . }} +- name: QUARKUS_DATASOURCE_USERNAME + valueFrom: + configMapKeyRef: + name: spire-config + key: POSTGRES_USER +- name: QUARKUS_DATASOURCE_PASSWORD + valueFrom: + {{- include "spire.dbPasswordRef" . | nindent 4 }} +- name: SPIRE_ENCRYPTION_KEYSET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_ENCRYPTION_KEYSET +- name: SPIRE_OIDC_CLIENT_ID + value: spire-review-worker +- name: SPIRE_OIDC_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: {{ include "spire.secretName" . }} + key: SPIRE_OIDC_WORKER_SECRET +{{- end -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -24,35 +47,17 @@ spec: spec: containers: - name: worker - image: "{{ .Values.image.registry }}/spire-review-worker:{{ .Values.image.tag }}" + image: {{ include "spire.image" (dict "root" . "name" "spire-review-worker") }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: 8080 env: - {{- include "spire.commonEnv" . | nindent 12 }} - - name: QUARKUS_DATASOURCE_USERNAME - valueFrom: - configMapKeyRef: - name: spire-config - key: POSTGRES_USER - - name: QUARKUS_DATASOURCE_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: POSTGRES_PASSWORD - - name: SPIRE_ENCRYPTION_KEYSET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_ENCRYPTION_KEYSET - - name: SPIRE_OIDC_CLIENT_ID - value: spire-review-worker - - name: SPIRE_OIDC_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: {{ include "spire.secretName" . }} - key: SPIRE_OIDC_WORKER_SECRET + {{- include "spire.env" (dict "root" . "service" "worker" "own" (include "spire.worker.env" .)) | nindent 12 }} + {{- with .Values.worker.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} {{- include "spire.probes" . | nindent 10 }} {{- include "spire.securityContext" . | nindent 10 }} resources: diff --git a/deploy/helm/spire/tests/render.sh b/deploy/helm/spire/tests/render.sh index 25257a6b..0e3ea7c8 100755 --- a/deploy/helm/spire/tests/render.sh +++ b/deploy/helm/spire/tests/render.sh @@ -21,9 +21,11 @@ pass() { printf ' PASS %s\n' "$1"; } fail() { printf ' FAIL %s\n' "$1"; FAILED=1; } # render [extra helm args...] +# RENDER_CHART renders a copy of the chart instead (the appVersion check edits one); values still come +# from the real chart. render() { local values="$1"; shift - helm template spire "$CHART" -f "$CHART/$values" \ + helm template spire "${RENDER_CHART:-$CHART}" -f "$CHART/$values" \ --set secrets.existingSecret=TEST-spire-secrets \ --set secrets.gatewayExistingSecret=TEST-spire-gateway-secrets \ --set trustedProxies=10.244.0.0/16 \ @@ -50,6 +52,55 @@ absent() { # absent if deployment "$1" "$2" | grep -q -- "$3"; then fail "$3 must NOT reach $2"; else pass "$3 absent from $2"; fi } +# One rendered object of any kind, by its metadata name (indented two spaces, so a container or port +# called the same does not match). +object() { # object + printf '%s' "$1" | awk -v kind="$2" -v want="$3" ' + BEGIN { RS = "\n---\n" } + $0 ~ ("\nkind: " kind "\n") && $0 ~ ("\n name: " want "\n") { print } + ' +} + +# The Secret and key an env entry of a Deployment reads, as "/". +secret_ref() { # secret_ref + deployment "$1" "$2" | grep -A4 -- "- name: $3\$" \ + | awk '/secretKeyRef:/ { f = 1 } f && /^ *name:/ { n = $2 } f && /^ *key:/ { k = $2 } END { print n "/" k }' +} + +expect_ref() { # expect_ref + local got; got="$(secret_ref "$1" "$2" "$3")" + if [ "$got" = "$4" ]; then pass "$2 reads $3 from $4"; else fail "$2 reads $3 from '$got', expected $4"; fi +} + +# The names of the Services whose type reaches outside the cluster. +external_services() { # external_services + printf '%s' "$1" | awk ' + BEGIN { RS = "\n---\n" } + { + n = split($0, l, "\n"); svc = 0; ext = 0; name = "" + for (i = 1; i <= n; i++) { + if (l[i] == "kind: Service") svc = 1 + if (name == "" && l[i] ~ /^ name: /) name = substr(l[i], 9) + if (l[i] ~ /^ type: (NodePort|LoadBalancer)$/) ext = 1 + } + if (svc && ext) print name + } + ' +} + +# 5 — the dashboard is the only Service that may leave the cluster. trusted-proxies means nothing if a +# service port is reachable directly, because anything that reaches it can forge X-Forwarded-For. +# ui.service.type makes spire-ui external through values; nothing may make another Service external. +only_ui_external() { # only_ui_external