fix(backupstrategy-controller): run backup clients on a package-owned image (#4756)

## What this PR does

The Altinity (ClickHouse) and RabbitMQ backup strategy Pods ran
`platform-migrations`: a 349 MB image carrying `kubectl`, `helm`, `git`,
`cozyhr` and `etcd-migrate`, whose `ENTRYPOINT` is `run-migrations.sh`.
Both pins were stamped from `packages/core/platform/Makefile`, so any
migration change re-digested the backup clients too, and only the
`command:` override kept the Pods from running platform migrations
(#3420).

- New
`packages/system/backupstrategy-controller/images/backup-http-client/`:
`alpine:3.24` (digest-pinned, the same base the tree already uses) +
`curl` + `jq` + `ca-certificates`, `USER 65532:65532`, no `ENTRYPOINT`.
Everything is installed at build time, so the Pods still never run `apk
add` and keep working air-gapped.
- New `image-backup-http-client` target in the package's own `Makefile`,
chained after `image-redis-backup` like the existing ones so only one
`yq -i` writes `values.yaml` at a time. It stamps `chBackupClientImage`
and `rabbitmqBackupClientImage` with the same ref.
- Removed the cross-package stamps from
`packages/core/platform/Makefile`, the WORKAROUND/TODO comments in the
chart and the RabbitMQ example, and the stale "live violation" line in
`docs/agents/image-refs.md`.
- `hack/image-pin-consistency.bats`: dropped the
`platform-migrations`-specific test, whose subject no longer exists. The
general check (no repository pinned at more than one digest, computed
from `hack/promote-retag.sh --dry-run`) still covers the two keys
sharing one image.

**Why one image for both strategies rather than `ch-backup-client` as
the issue named it.** The RabbitMQ strategy had the same reuse and the
same cross-package stamp; leaving it would have kept the stamp alive.
Its script needs `curl --aws-sigv4` + `ca-certificates`, a subset of the
ClickHouse one, so one image serves both. The two values keys stay
separate so either strategy can move to its own image later.

**Initial pin.** The image does not exist in ghcr until CI builds it, so
both keys are committed as `backup-http-client:v1.6.0` without a digest,
the same way `redis-backup` was introduced. PR CI rebuilds touched
packages and overlays the fresh refs for e2e; release preparation's
`make image` stamps tag+digest.

Image size: 6.9 MB vs 349 MB. Verified locally:
- `docker buildx build` for `linux/amd64,linux/arm64`; in the image as
uid 65532: curl 8.22 with `--aws-sigv4`, jq 1.8.2, `date`, `seq`, writes
to `/tmp` (the RabbitMQ script's only write), TLS verification against
the bundled CA store.
- `helm unittest` (23/23), `helm template` renders both strategies with
`backup-http-client` and no `platform-migrations` reference.
- `hack/cozytest.sh hack/image-pin-consistency.bats` and
`hack/build-matrix_test.bats` pass.

Not yet run end to end on a cluster; the e2e backup round-trips will
exercise it.

Fixes #3420

### Screenshots

N/A — no UI changes.

### Downstream repositories

Walked the trigger map against the diff: it touches
`packages/system/backupstrategy-controller` (new image, Makefile target,
values comments/pins, template comments),
`packages/core/platform/Makefile` (stamp removal only, no `values.yaml`
key change), `hack/image-pin-consistency.bats`,
`docs/agents/image-refs.md` and a comment in
`examples/backups/rabbitmq`. No app package, schema, CRD, variant,
asset, platform values key or `hack/package.mk` change. The website does
not list first-party image repositories (searched for
`platform-migrations` and `redis-backup`), so no mirror list needs the
new one.

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

<!--  Write a release note:
- Explain what has changed internally and for users.
- Start with the same `type(scope):` prefix as in the PR title
- Follow the guidelines at
https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md.
-->

```release-note
fix(backupstrategy-controller): the ClickHouse (Altinity) and RabbitMQ backup strategy Pods now run a dedicated `backup-http-client` image (alpine + curl + jq + ca-certificates, non-root, ~7 MB) instead of the 349 MB `platform-migrations` image. Air-gapped mirrors need the new `ghcr.io/cozystack/cozystack/backup-http-client` repository.
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Improvements**
* Altinity and RabbitMQ backups now use a dedicated backup HTTP client
image, configured separately from the platform migrations image.
* The client image includes the tools required for backup operations and
runs with a non-root identity.
* Both backup configurations receive the same digest-pinned image
reference when the image is built.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Backported-from: 7c46ffff12
This commit is contained in:
Myasnikov Daniil committed 2026-11-10 13:16:50 +00:00
commit 76b7c6b9cd
9 files changed
+51 -131

No files matched your search

+2 -2
View File
@@ -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 `<repo>:<tag>` 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.
@@ -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:
- |
+8 -39
View File
@@ -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
}
-19
View File
@@ -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
@@ -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 .
@@ -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
@@ -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}"
@@ -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:
- |
@@ -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.