From 5273a993f2b38b031f68b255f4b19a136b01a2cf Mon Sep 17 00:00:00 2001 From: Lance Walters Date: Mon, 2 Nov 2026 17:17:36 -0500 Subject: [PATCH] apps: pin every first-party site image to an immutable ref Replace ':latest' + imagePullPolicy: Always on all seven site images with a pinned tag (or digest) and IfNotPresent, so the image a Deployment runs is chosen by this repo and rolled by Flux, not by CI patching restartedAt. Every pin is the image that was already running, so the change is a no-op for visitors: each pinned tag's manifest/config digest equals the running pod's imageID (siriusdevops-* f0dde2f4, growth-site ea306b7, growth-portal d9e558c4, phs-site 5b590cd). sirius-growth-contact and phs-contact have no CI build path (no workflow has ever pushed anything but :latest for them), so they are pinned by @sha256: digest rather than inventing a pipeline; documented in docs/site-image-pinning.md along with the operator flow. --- apps/base/piedmont/deployment-api.yaml | 6 +- apps/base/piedmont/deployment.yaml | 4 +- apps/base/sirius-growth/deployment-api.yaml | 6 +- .../base/sirius-growth/deployment-portal.yaml | 4 +- apps/base/sirius-growth/deployment.yaml | 4 +- apps/base/siriusdevops/deployment-api.yaml | 4 +- apps/base/siriusdevops/deployment-site.yaml | 4 +- docs/site-image-pinning.md | 110 ++++++++++++++++++ 8 files changed, 128 insertions(+), 14 deletions(-) create mode 100644 docs/site-image-pinning.md diff --git a/apps/base/piedmont/deployment-api.yaml b/apps/base/piedmont/deployment-api.yaml index f34ed5d..c6e643a 100644 --- a/apps/base/piedmont/deployment-api.yaml +++ b/apps/base/piedmont/deployment-api.yaml @@ -21,8 +21,10 @@ spec: kubernetes.io/hostname: siriussec containers: - name: contact-api - image: forgejo.siriusdevops.com/sirius/phs-contact:latest - imagePullPolicy: Always + # This contact API has no CI build path that publishes a tagged image + # (see docs/site-image-pinning.md), so it is pinned by digest. + image: forgejo.siriusdevops.com/sirius/phs-contact@sha256:da61fc7943881f801fe6201749c01e364df6475d2460d6d17c8a6b48009f0056 + imagePullPolicy: IfNotPresent command: ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8090"] ports: - containerPort: 8090 diff --git a/apps/base/piedmont/deployment.yaml b/apps/base/piedmont/deployment.yaml index 579cc52..7d6c735 100644 --- a/apps/base/piedmont/deployment.yaml +++ b/apps/base/piedmont/deployment.yaml @@ -21,8 +21,8 @@ spec: kubernetes.io/hostname: siriussec containers: - name: nginx - image: forgejo.siriusdevops.com/sirius/phs-site:latest - imagePullPolicy: Always + image: forgejo.siriusdevops.com/sirius/phs-site:5b590cddab6d7889fdd3c272255f28c4560e752e + imagePullPolicy: IfNotPresent ports: - containerPort: 80 name: http diff --git a/apps/base/sirius-growth/deployment-api.yaml b/apps/base/sirius-growth/deployment-api.yaml index 369f76e..df03f85 100644 --- a/apps/base/sirius-growth/deployment-api.yaml +++ b/apps/base/sirius-growth/deployment-api.yaml @@ -21,8 +21,10 @@ spec: kubernetes.io/hostname: siriussec containers: - name: contact-api - image: forgejo.siriusdevops.com/sirius/sirius-growth-contact:latest - imagePullPolicy: Always + # This contact API has no CI build path that publishes a tagged image + # (see docs/site-image-pinning.md), so it is pinned by digest. + image: forgejo.siriusdevops.com/sirius/sirius-growth-contact@sha256:cba0a5c67fee639dea78b568cbdf5889b2c78cc2c9cf85b02964ce17d60aab31 + imagePullPolicy: IfNotPresent command: ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8090"] ports: - containerPort: 8090 diff --git a/apps/base/sirius-growth/deployment-portal.yaml b/apps/base/sirius-growth/deployment-portal.yaml index fa16d1d..33f763e 100644 --- a/apps/base/sirius-growth/deployment-portal.yaml +++ b/apps/base/sirius-growth/deployment-portal.yaml @@ -21,8 +21,8 @@ spec: kubernetes.io/hostname: siriussec containers: - name: portal-api - image: forgejo.siriusdevops.com/sirius/sirius-growth-portal:latest - imagePullPolicy: Always + image: forgejo.siriusdevops.com/sirius/sirius-growth-portal:d9e558c4e0922d3ecd28214f7698ec0994170481 + imagePullPolicy: IfNotPresent ports: - containerPort: 8091 name: http diff --git a/apps/base/sirius-growth/deployment.yaml b/apps/base/sirius-growth/deployment.yaml index f884807..5a4dbec 100644 --- a/apps/base/sirius-growth/deployment.yaml +++ b/apps/base/sirius-growth/deployment.yaml @@ -21,8 +21,8 @@ spec: kubernetes.io/hostname: siriussec containers: - name: nginx - image: forgejo.siriusdevops.com/sirius/sirius-growth-site:latest - imagePullPolicy: Always + image: forgejo.siriusdevops.com/sirius/sirius-growth-site:ea306b73b0d7c9ae8c33393a420e6d1d452b802b + imagePullPolicy: IfNotPresent ports: - containerPort: 80 name: http diff --git a/apps/base/siriusdevops/deployment-api.yaml b/apps/base/siriusdevops/deployment-api.yaml index d1af0f2..43b5bba 100644 --- a/apps/base/siriusdevops/deployment-api.yaml +++ b/apps/base/siriusdevops/deployment-api.yaml @@ -21,8 +21,8 @@ spec: kubernetes.io/hostname: siriussec containers: - name: contact-api - image: forgejo.siriusdevops.com/sirius/siriusdevops-contact:latest - imagePullPolicy: Always + image: forgejo.siriusdevops.com/sirius/siriusdevops-contact:f0dde2f48c8224fb80d801ecb0d155c93332dc13 + imagePullPolicy: IfNotPresent command: ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8090"] ports: - containerPort: 8090 diff --git a/apps/base/siriusdevops/deployment-site.yaml b/apps/base/siriusdevops/deployment-site.yaml index 7fe6685..0bb6daa 100644 --- a/apps/base/siriusdevops/deployment-site.yaml +++ b/apps/base/siriusdevops/deployment-site.yaml @@ -21,8 +21,8 @@ spec: kubernetes.io/hostname: siriussec containers: - name: nginx - image: forgejo.siriusdevops.com/sirius/siriusdevops-site:latest - imagePullPolicy: Always + image: forgejo.siriusdevops.com/sirius/siriusdevops-site:f0dde2f48c8224fb80d801ecb0d155c93332dc13 + imagePullPolicy: IfNotPresent ports: - containerPort: 80 name: http diff --git a/docs/site-image-pinning.md b/docs/site-image-pinning.md new file mode 100644 index 0000000..8fd609d --- /dev/null +++ b/docs/site-image-pinning.md @@ -0,0 +1,110 @@ +# Site images: immutable sha tags pinned in git + +Every first-party site image runs from a **tag pinned in this repo** and is rolled +by Flux. CI builds and pushes `:` and prints the exact ref; the +operator copies that ref into the Deployment manifest. There are **no cluster +credentials in any site repo** — CI cannot roll a Deployment and cannot read a +kubeconfig. + +This replaces the old model (`:latest` + `imagePullPolicy: Always` + CI patching +`kubectl.kubernetes.io/restartedAt` through a `site-deployer` ServiceAccount +token). That path is gone: the SA/Role/RoleBinding were removed and the +`KUBE_CONFIG` action secrets deleted. + +## Operator flow + +1. Push to a site repo (or `workflow_dispatch` it). The workflow builds the + amd64 image, pushes `/:`, and ends with a + `### Pin this in sirius/homek8s …` step that prints the ref. It also pushes + `:latest`, but **nothing in the cluster reads `:latest`** — it is a + convenience pointer for humans only. +2. Edit the Deployment in `apps/base//deployment*.yaml`: + + ```yaml + image: forgejo.siriusdevops.com/sirius/: + imagePullPolicy: IfNotPresent + ``` + +3. Commit + push `master`, then force the Flux recheck (gitrepository **first**, + kustomization **second** — an `apps` annotate that still reports the previous + sha has not fetched the commit): + + ```bash + kubectl -n flux-system annotate gitrepository flux-system reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite + kubectl -n flux-system annotate kustomization apps reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite + ``` + +4. Verify: the pod template changed, so the Deployment rolls within ~1m and the + pod reports the pinned ref. + + ```bash + kubectl -n get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.containerStatuses[0].imageID}{"\n"}{end}' + ``` + + `imageID` must name `:` and carry the digest the registry returns for + that tag (`Docker-Content-Digest`, below). + +Rollback is `git revert` of the pin commit — Flux reconciles back in ~1m. + +## Why the site repos are not Flux sources + +The only `GitRepository` cluster-wide is `flux-system` → `sirius/homek8s`. Flux +owns the *manifests*; the site repos own only their image builds. The content +revision a visitor sees is therefore chosen by the tag committed here, not by +whatever CI pushed last. A site repo push alone changes nothing in the cluster. + +## Current pins + +| Namespace | Deployment | Image ref | +|---|---|---| +| siriusdevops | siriusdevops-site | `siriusdevops-site:f0dde2f48c8224fb80d801ecb0d155c93332dc13` | +| siriusdevops | siriusdevops-contact | `siriusdevops-contact:f0dde2f48c8224fb80d801ecb0d155c93332dc13` | +| sirius-growth | sirius-growth-site | `sirius-growth-site:ea306b73b0d7c9ae8c33393a420e6d1d452b802b` | +| sirius-growth | sirius-growth-portal | `sirius-growth-portal:d9e558c4e0922d3ecd28214f7698ec0994170481` | +| sirius-growth | sirius-growth-contact | `sirius-growth-contact@sha256:cba0a5c67fee639dea78b568cbdf5889b2c78cc2c9cf85b02964ce17d60aab31` | +| piedmont | piedmont-site | `phs-site:5b590cddab6d7889fdd3c272255f28c4560e752e` | +| piedmont | piedmont-contact | `phs-contact@sha256:da61fc7943881f801fe6201749c01e364df6475d2460d6d17c8a6b48009f0056` | + +Each pin was chosen as the tag whose manifest is **the image already running** +(identical config digest), so pinning was a no-op for visitors. + +### The two digest-pinned contact APIs + +`sirius-growth-contact` and `phs-contact` have **no CI build path**: neither +`sirius-growth/.forgejo/workflows/*` nor `sirius/websites/.forgejo/workflows/deploy-handyman.yml` +builds them (the source dirs `contact-api/` and `phs-contact-api/` exist, but no +workflow pushes them; the registry only ever held `:latest`). They were built by +hand before the workflows were trimmed. Per the no-invented-pipelines rule they +are pinned by `@sha256:` digest — immutable, but there is no tag for an operator +to bump. If a build step is ever added for them, move them to `:` like the +rest. Both deployments run the same image content their pods already ran. + +## Registry facts + +- Registry: `forgejo.siriusdevops.com` (Forgejo packages, `[packages] ENABLED = true`). +- Reads/writes need a `read:package` / `write:package` scoped token; the stored + `~/.git-credentials` oauth2 token is git-scoped and is rejected by `/v2/`. +- **Tags do not expire.** `package_cleanup_rule` has zero rows and `app.ini` has + no cleanup cron, so a pinned `:` stays resolvable. +- Prove a pin `T` for image `I` without pulling anything: + + ```bash + curl -s -u "sirius:$TOK" -H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json' \ + -D - -o /dev/null "https://forgejo.siriusdevops.com/v2/sirius/$I/manifests/$T" | grep -i docker-content-digest + ``` + +## Pitfalls + +- **`docker buildx imagetools create` (the `:latest` promote step) wraps a + single-arch image in an index**, so the `:latest` digest differs from the + `:` digest even though the content is identical. Compare the *config* + digest, or compare the running pod's digest to the `:` tag, never + `:latest` vs the sha tag. +- The amd64 runner's job image (`node:20-bullseye`) has no docker CLI, so the + site workflows download a static client each run. That download has been + observed to stall for the full 300s (`curl: (28) … 0 out of 0 bytes`) and fail + the run. It is transient — re-dispatch the workflow instead of debugging the + network. +- `runs-on` matters: site images are `linux/amd64` and only siriussec serves + them. Build them on `docker-amd64` / `deploy-arm64`, never on the arm64 + `docker` runner.