diff --git a/docs/agents/image-refs.md b/docs/agents/image-refs.md index 5de2b820c..0d22e120d 100644 --- a/docs/agents/image-refs.md +++ b/docs/agents/image-refs.md @@ -42,8 +42,8 @@ If a package stamps a reference somewhere the two globs do not cover, add that f ## Invariants -- **Every first-party reference is tag+digest.** A bare tag with no digest is not reproducible and must not be committed. `securitygroup-controller:v0.0.0` is a live violation. -- **Exactly one producer stamps each reference.** A reference no `Makefile` writes will never be refreshed by anything, including release preparation — `chBackupClientImage` in `packages/system/backupstrategy-controller/values.yaml` is a live violation, still pinned to `platform-migrations:v1.4.0-rc.2`. +- **Every first-party reference is tag+digest.** A bare tag with no digest is not reproducible and must not be committed. The one exception is the first commit of a new image: it has no digest until it is built, so it lands as a bare `:` that the producing `make image` replaces. PR CI and release preparation both stamp it before anything pulls it, but a tree applied without a build pulls a tag that does not exist. +- **Exactly one producer stamps each reference.** A reference no `Makefile` writes will never be refreshed by anything, including release preparation. - **A package that stamps a reference is in the root `Makefile` `build:` list.** `build-matrix.sh`, the main build and release preparation all iterate that one list, so a package outside it is never rebuilt by any path and its pin freezes permanently. `hack/build-matrix_test.bats` computes the set of packages whose Makefile runs `docker buildx build` and fails on any the list misses. - **Every consumer of references reads all three storage shapes**, via `hack/lib/image-refs.sh`. - **Scan wider than you rewrite.** A rewrite is deliberately narrow to avoid corrupting vendored defaults, so the check that follows it must not share that blind spot. `hack/promote-rewrite-tags.sh` rewrites the enumerated files, then greps the whole tree and fails if any reference to the release candidate survives. diff --git a/examples/backups/rabbitmq/03-rabbitmq-strategy.yaml b/examples/backups/rabbitmq/03-rabbitmq-strategy.yaml index a8ae0637f..1533ee092 100644 --- a/examples/backups/rabbitmq/03-rabbitmq-strategy.yaml +++ b/examples/backups/rabbitmq/03-rabbitmq-strategy.yaml @@ -92,8 +92,6 @@ spec: - name: s3-ca mountPath: /etc/ssl/rabbitmq-backup-ca readOnly: true - # command is load-bearing: the reused platform-migrations image's - # ENTRYPOINT is run-migrations.sh. command: ["/bin/sh", "-c"] args: - | diff --git a/hack/image-pin-consistency.bats b/hack/image-pin-consistency.bats index e3d9508d6..ac5be652a 100644 --- a/hack/image-pin-consistency.bats +++ b/hack/image-pin-consistency.bats @@ -8,17 +8,12 @@ # tag. The first wins, the second hits the write-once guard, and the promotion # fails — on release day, in a workflow that runs once per release. # -# This is not hypothetical. platform-migrations was pinned twice: once in -# packages/core/platform/values.yaml (stamped by its Makefile) and once as -# .backupStrategyController.chBackupClientImage, which had no producer at all -# and so froze at v1.4.0-rc.2 while the other advanced to v1.5.0. v1.6.0 is the -# first release cut through the promote path rather than a full rebuild, so it -# would have been the first to hit it. -# -# The general invariant is cheaper to hold than the specific one: a duplicate -# pin can arise from any package reusing another's image, which the tree does -# deliberately (backupstrategy-controller reuses platform-migrations as a -# curl+jq runner rather than shipping a second one-binary tag). +# This is not hypothetical. platform-migrations was once pinned twice, the +# second copy by a key that had no producer: it froze at v1.4.0-rc.2 while the +# other advanced to v1.5.0, and v1.6.0, the first release cut through the +# promote path, would have been the first to hit it. A chart that renders one +# image under several keys (backupstrategy-controller's backup client) must +# have them stamped together. # # Harness compatibility note: CI runs this file under Bats through # `make bats-unit-tests`. It also remains compatible with the narrower legacy @@ -65,36 +60,10 @@ load test_helper -- "${repo#ghcr.io/cozystack/cozystack/}" packages/ >&2 || true done echo >&2 - echo "Give the duplicate key a producer that stamps the same ref (see" >&2 - echo "packages/core/platform/Makefile), or drop the duplicate pin." >&2 + echo "Give the duplicate key a producer that stamps the same ref, or drop" >&2 + echo "the duplicate pin." >&2 rm -rf "$tmp" return 1 fi rm -rf "$tmp" } - -@test "platform-migrations is pinned identically in both consumers" { - # The specific instance, pinned separately so a regression names its cause - # rather than only tripping the general check above. The two must match - # exactly, not merely resolve to the same digest: backupstrategy-controller - # renders its copy into a Pod spec, so a stale tag string there is what an - # operator reads when asking what is running. - a=$(yq -r '.migrations.image' packages/core/platform/values.yaml) - b=$(yq -r '.backupStrategyController.chBackupClientImage' \ - packages/system/backupstrategy-controller/values.yaml) - c=$(yq -r '.backupStrategyController.rabbitmqBackupClientImage' \ - packages/system/backupstrategy-controller/values.yaml) - - if [ "$a" != "$b" ] || [ "$a" != "$c" ]; then - echo "platform-migrations pins have drifted:" >&2 - echo " packages/core/platform/values.yaml .migrations.image" >&2 - echo " $a" >&2 - echo " backupstrategy-controller/values.yaml .chBackupClientImage" >&2 - echo " $b" >&2 - echo " backupstrategy-controller/values.yaml .rabbitmqBackupClientImage" >&2 - echo " $c" >&2 - echo >&2 - echo "packages/core/platform/Makefile stamps all three; do not hand-edit any." >&2 - return 1 - fi -} diff --git a/packages/core/platform/Makefile b/packages/core/platform/Makefile index 99ce9307d..94a6c17e5 100644 --- a/packages/core/platform/Makefile +++ b/packages/core/platform/Makefile @@ -42,25 +42,6 @@ image-migrations: --metadata-file images/migrations.json \ $(BUILDX_ARGS) rm -rf images/migrations/etcd-operator-crds - # Stamp BOTH consumers of this image. backupstrategy-controller renders it - # into the Altinity strategy Pod as a curl+jq runner — a WORKAROUND, not a - # design: that Pod needs only curl/jq/sleep/date but gets 349 MB including - # kubectl, helm and etcd-migrate, and this image's ENTRYPOINT is the - # migration runner itself. It should get a dedicated ~23 MB image owned by - # its own package, which would delete this cross-package stamp; see the TODO - # in ../../system/backupstrategy-controller/values.yaml. - # - # Until then the two pins MUST move together. The second copy had no - # producer, so it silently froze at v1.4.0-rc.2 while this one advanced, and - # a promotion then tried to retag two different digests to the same stable - # tag — which the write-once guard in hack/promote-retag.sh turns into a - # failed release. hack/image-pin-consistency.bats keeps them in lockstep. IMAGE="$(REGISTRY)/platform-migrations:$(IMAGE_TAG)@$$(yq -e -o json -r '.["containerimage.digest"]' images/migrations.json)" \ yq --inplace '.migrations.image = strenv(IMAGE)' values.yaml - IMAGE="$(REGISTRY)/platform-migrations:$(IMAGE_TAG)@$$(yq -e -o json -r '.["containerimage.digest"]' images/migrations.json)" \ - yq --inplace '.backupStrategyController.chBackupClientImage = strenv(IMAGE)' \ - ../../system/backupstrategy-controller/values.yaml - IMAGE="$(REGISTRY)/platform-migrations:$(IMAGE_TAG)@$$(yq -e -o json -r '.["containerimage.digest"]' images/migrations.json)" \ - yq --inplace '.backupStrategyController.rabbitmqBackupClientImage = strenv(IMAGE)' \ - ../../system/backupstrategy-controller/values.yaml rm -f images/migrations.json diff --git a/packages/system/backupstrategy-controller/Makefile b/packages/system/backupstrategy-controller/Makefile index 2e972b054..94b1931d9 100644 --- a/packages/system/backupstrategy-controller/Makefile +++ b/packages/system/backupstrategy-controller/Makefile @@ -6,9 +6,9 @@ include ../../../hack/package.mk # PHONY so a stray file/dir named `image` cannot mark the aggregate up to date # and skip both builds. -.PHONY: image image-backupstrategy-controller image-redis-backup +.PHONY: image image-backupstrategy-controller image-redis-backup image-backup-http-client -image: image-backupstrategy-controller image-redis-backup +image: image-backupstrategy-controller image-redis-backup image-backup-http-client image-backupstrategy-controller: docker buildx build -f images/backupstrategy-controller/Dockerfile ../../.. \ @@ -33,5 +33,18 @@ image-redis-backup: image-backupstrategy-controller yq -i '.backupStrategyController.redisBackupClientImage = strenv(IMAGE)' values.yaml rm -f images/redis-backup.json +# Chained after image-redis-backup for the same reason: one `yq -i` writer at a +# time. Both keys get the same ref, so the repository stays pinned at a single +# digest (hack/image-pin-consistency.bats). +image-backup-http-client: image-redis-backup + docker buildx build -f images/backup-http-client/Dockerfile images/backup-http-client \ + $(call image-tags,backup-http-client,v$(COZYSTACK_VERSION)) \ + $(call cache-args,backup-http-client) \ + --metadata-file images/backup-http-client.json \ + $(BUILDX_ARGS) + IMAGE="$(REGISTRY)/backup-http-client:$(IMAGE_TAG)@$$(yq e '."containerimage.digest"' images/backup-http-client.json -o json -r)" \ + yq -i '.backupStrategyController.chBackupClientImage = strenv(IMAGE) | .backupStrategyController.rabbitmqBackupClientImage = strenv(IMAGE)' values.yaml + rm -f images/backup-http-client.json + test: helm unittest . diff --git a/packages/system/backupstrategy-controller/images/backup-http-client/Dockerfile b/packages/system/backupstrategy-controller/images/backup-http-client/Dockerfile new file mode 100644 index 000000000..21f078f75 --- /dev/null +++ b/packages/system/backupstrategy-controller/images/backup-http-client/Dockerfile @@ -0,0 +1,10 @@ +# backup-http-client runs the Altinity (ClickHouse) and RabbitMQ strategy Pods: +# both scripts drive an HTTP API with curl and verify TLS against the bundled +# ca-certificates; the Altinity one also parses JSON with jq, and the RabbitMQ +# one moves its export to S3 with curl --aws-sigv4. Everything is installed at +# build time so the Pods never run `apk add` and work on air-gapped clusters. +FROM alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 + +RUN apk add --no-cache curl jq ca-certificates + +USER 65532:65532 diff --git a/packages/system/backupstrategy-controller/templates/strategy-altinity-default.yaml b/packages/system/backupstrategy-controller/templates/strategy-altinity-default.yaml index d9094c082..21d05f8a4 100644 --- a/packages/system/backupstrategy-controller/templates/strategy-altinity-default.yaml +++ b/packages/system/backupstrategy-controller/templates/strategy-altinity-default.yaml @@ -26,15 +26,6 @@ spec: restartPolicy: Never containers: - name: ch-backup-client - # WORKAROUND: this resolves to platform-migrations, which bundles - # curl + jq + ca-certificates on alpine — so the Pod needs no - # `apk add` and works air-gapped. That is the only reason it is - # here. It is a 349 MB migration image standing in for a curl+jq - # runner, and its own ENTRYPOINT is run-migrations.sh, so the - # `command:` override below is load-bearing: drop it and this Pod - # runs platform migrations with kubectl and helm on the PATH. - # Replace with a dedicated ch-backup-client image owned by this - # package; see the TODO in ../values.yaml. image: "{{ .Values.backupStrategyController.chBackupClientImage }}" imagePullPolicy: IfNotPresent # The clickhouse-backup HTTP API on :7171 enforces basic auth; @@ -57,9 +48,8 @@ spec: args: - | set -euo pipefail - # curl + jq are baked into the ch-backup-client image; no - # `apk add` here so the Pod stays runnable on air-gapped - # clusters. + # curl + jq are baked into the image; no `apk add` here so + # the Pod stays runnable on air-gapped clusters. host="chi-clickhouse-{{ printf "{{ .Release.Name }}" }}-clickhouse-0-0.{{ printf "{{ .Release.Namespace }}" }}.svc" api="http://${host}:7171" auth="-u ${API_USERNAME}:${API_PASSWORD}" diff --git a/packages/system/backupstrategy-controller/templates/strategy-rabbitmq-default.yaml b/packages/system/backupstrategy-controller/templates/strategy-rabbitmq-default.yaml index 562217a77..9515945d2 100644 --- a/packages/system/backupstrategy-controller/templates/strategy-rabbitmq-default.yaml +++ b/packages/system/backupstrategy-controller/templates/strategy-rabbitmq-default.yaml @@ -99,9 +99,6 @@ spec: value: {{ .Values.backupStorage.region | quote }} - name: S3_FORCE_PATH_STYLE value: {{ .Values.backupStorage.forcePathStyle | quote }} - # command is load-bearing: the reused platform-migrations image's - # ENTRYPOINT is run-migrations.sh. See rabbitmqBackupClientImage in - # ../values.yaml. command: ["/bin/sh", "-c"] args: - | diff --git a/packages/system/backupstrategy-controller/values.yaml b/packages/system/backupstrategy-controller/values.yaml index ad3dfd001..1cce1dbd1 100644 --- a/packages/system/backupstrategy-controller/values.yaml +++ b/packages/system/backupstrategy-controller/values.yaml @@ -1,54 +1,16 @@ backupStrategyController: image: "ghcr.io/cozystack/cozystack/backupstrategy-controller:v1.7.0@sha256:990c8ab93b9f14ee7f70473d199558c859fa5e9532d6b1f47a74698f34c07c1b" - # chBackupClientImage is the image rendered into the Altinity strategy - # Pod: it drives clickhouse-backup's HTTP API via curl + jq. - # - # WORKAROUND — platform-migrations is the wrong image for this job and - # should be replaced by a dedicated one (see the TODO below). It is - # reused here only because it happens to bundle curl + jq, and this - # release could not absorb a new image. What that reuse actually costs: - # - the strategy script needs exactly curl, jq, sleep and date, yet - # this image is 349 MB carrying kubectl, helm, git, cozyhr and the - # etcd-migrate binary into a tenant-adjacent backup Pod; - # - its ENTRYPOINT is run-migrations.sh, so only the `command:` - # override in strategy-altinity-default.yaml stands between this Pod - # and running platform migrations with kubectl and helm on the PATH; - # - it couples the backup client to migrations: bumping - # ETCD_OPERATOR_VERSION or editing any migration script re-digests - # this image, forcing this pin to move for reasons that have nothing - # to do with backups. That coupling is what broke — see below. - # - # TODO: replace with a dedicated ch-backup-client image built by THIS - # package's own Makefile (alpine + curl + jq + ca-certificates measures - # 23 MB, 15x smaller). That also removes the cross-package stamp - # entirely, because the pin would then be produced by the package that - # owns it. The often-cited objection — "a second tag release CI must - # re-digest each cut" — is not the real cost: every other first-party - # image already pays it, automatically. The real defect was a pin with - # NO producer, which a package-owned image cannot reproduce. - # - # DO NOT hand-edit: packages/core/platform/Makefile stamps this key with - # the same ref it writes to .migrations.image there, so the two stay in - # lockstep by construction. They previously did not — this key had no - # producer at all and froze at v1.4.0-rc.2 while the other advanced to - # v1.5.0. Two digests under one repository means a promotion tries to - # retag both to the same stable tag, and the write-once guard in - # hack/promote-retag.sh fails the release. hack/image-pin-consistency.bats - # asserts no repository is pinned at more than one digest. - chBackupClientImage: "ghcr.io/cozystack/cozystack/platform-migrations:v1.7.0@sha256:9018fba0873094431cf130cc949d4651a8d971d02e5925b70e6f22648818a4c5" - # rabbitmqBackupClientImage is the image rendered into the RabbitMQ Job - # strategy (strategy-rabbitmq-default.yaml): its script needs only curl + - # ca-certificates to call the RabbitMQ management API and push the - # definitions export to S3 (curl --aws-sigv4). It is a distinct key from - # chBackupClientImage so the RabbitMQ strategy carries its own upgrade - # cadence, but it reuses the same platform-migrations image for now — hence - # it is stamped in lockstep with the two keys above (packages/core/platform/ - # Makefile), so the repository stays pinned at a single digest - # (hack/image-pin-consistency.bats). Same TODO applies: replace with a - # dedicated alpine + curl + ca-certificates image built by this package's - # Makefile, which also lets this pin move on its own. - # DO NOT hand-edit: stamped by packages/core/platform/Makefile. - rabbitmqBackupClientImage: "ghcr.io/cozystack/cozystack/platform-migrations:v1.7.0@sha256:9018fba0873094431cf130cc949d4651a8d971d02e5925b70e6f22648818a4c5" + # chBackupClientImage is rendered into the Altinity strategy Pod, which drives + # clickhouse-backup's HTTP API with curl + jq. rabbitmqBackupClientImage is + # rendered into the RabbitMQ strategy Pod, which calls the management API and + # moves the definitions export to S3 with curl --aws-sigv4. Both run the + # images/backup-http-client/ image (alpine + curl + jq + ca-certificates) and + # must hold the same ref: one repository pinned at two digests fails the + # release promotion (hack/image-pin-consistency.bats). They are separate keys + # so either strategy can move to its own image later. + # DO NOT hand-edit: `make image` stamps both. + chBackupClientImage: "ghcr.io/cozystack/cozystack/backup-http-client:v1.6.0" + rabbitmqBackupClientImage: "ghcr.io/cozystack/cozystack/backup-http-client:v1.6.0" # redisBackupClientImage is rendered into the Redis strategy Pod. The # spotahome operator ships no backup CRD, so the strategy runs a one-shot Job # that dumps an RDB snapshot to S3 and, on restore, loads it into a throwaway @@ -76,9 +38,9 @@ backupStrategyController: memory: 1Gi ephemeral-storage: 4Gi # The Kafka metadata strategy carries no client image here: unlike the Altinity - # and RabbitMQ drivers (curl-only, so a shared platform-migrations image works), - # its driver runs the Kafka Admin-API CLI (kafka-topics / kafka-configs), which - # only the Strimzi broker image ships. So the controller resolves the image from + # and RabbitMQ drivers, which need only curl (plus jq for Altinity), its driver + # runs the Kafka Admin-API CLI (kafka-topics / kafka-configs), which only the + # Strimzi broker image ships. So the controller resolves the image from # the target Kafka broker at reconcile time (strategy-kafka-default.yaml renders # the container image as the "{{ .ClientImage }}" placeholder), and records it on # the Backup so cleanup can reuse it once the broker is gone. No pin to drift.