Skip to content

Commit 548b82b

Browse files
fix(ci): gate release tags/pushes off under OCI_EXPORT_DIR (defense-in-depth)
Belt-and-suspenders for the B2-class trap lexfrei flagged as latent in image-tags. PUBLISH_* are 0 on fork PRs, so today the export path never emits a versioned/floating tag — but if it ever did: - image-tags: multiple --tag under `--output type=oci` write >1 manifest into the archive's index.json, and `skopeo copy oci-archive:<f>` then refuses it ("more than one image in oci"). Suppress the versioned/floating tags when OCI_EXPORT_DIR is set (macro-level $(if …), so `make -n` prints only the taken branch). - packages/core/talos: gate its versioned/floating `skopeo copy docker://…` release copies on an empty OCI_EXPORT_DIR too. The release (non-export) path is unchanged — versioned + :latest still emitted. Covered by a new common-envs_test.bats case that forces PUBLISH_*=1 under export. Reported by gemini-code-assist on #3262. Assisted-By: Claude <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent cc6caa0 commit 548b82b

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎hack/common-envs.mk‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ comma := ,
102102
# caught loudly by the fork build's `if-no-files-found: error` upload.
103103
oci-output = $(if $(strip $(OCI_EXPORT_DIR)), --output type=oci$(comma)dest=$(OCI_EXPORT_DIR)/$(subst /,-,$(1)).oci.tar)
104104

105+
# image-tags <image-name> [<versioned-tag>] — the --tag/--output flags for one
106+
# image. Under OCI_EXPORT_DIR the versioned/floating tags are suppressed: a
107+
# multi-`--tag` `--output type=oci` build writes every ref into the archive's
108+
# index.json, and `skopeo copy oci-archive:<f>` then refuses it ("more than one
109+
# image in oci"). PUBLISH_* are 0 on fork PRs (the only export case today), so
110+
# this is belt-and-suspenders for that trap.
105111
define image-tags
106-
--tag $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), --tag $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), --tag $(REGISTRY)/$(1):latest)$(call oci-output,$(1))
112+
--tag $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(strip $(OCI_EXPORT_DIR)),,$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), --tag $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), --tag $(REGISTRY)/$(1):latest))$(call oci-output,$(1))
107113
endef
108114

109115
# cache-args <image-name> [<cache-tag>]

‎hack/common-envs_test.bats‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@
6060
pushes=$(echo "$out" | grep 'docker://' | grep -v '"0" = "1"' || true)
6161
if [ -n "$pushes" ]; then echo "FAIL: talos pushes an ungated image under OCI_EXPORT_DIR: $pushes"; false; fi
6262
}
63+
64+
@test "OCI_EXPORT_DIR suppresses release tags/pushes even with PUBLISH_*=1 (#3262 hardening)" {
65+
# The B2-class trap is latent: PUBLISH_* are 0 on fork PRs (the only export
66+
# case today), so force them on to prove the OCI_EXPORT_DIR gate holds anyway.
67+
# image-tags package: only the pr IMAGE_TAG survives — a versioned + :latest
68+
# multi-tag OCI archive holds >1 manifest and `skopeo copy oci-archive:` refuses it.
69+
out=$(make -n -C packages/system/cozystack-controller image OCI_EXPORT_DIR=/tmp/ocitest PUBLISH_VERSIONED=1 PUBLISH_FLOATING=1 IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b)
70+
tags=$(echo "$out" | grep -c -- '--tag' || true)
71+
[ "$tags" -eq 1 ]
72+
if echo "$out" | grep -q -- ':latest'; then echo "FAIL: image-tags emits :latest under OCI_EXPORT_DIR"; false; fi
73+
# talos: its versioned/floating skopeo copies are additionally gated on an
74+
# empty OCI_EXPORT_DIR (`[ -z … ]`), so no ungated docker:// push survives export.
75+
tout=$(make -n -C packages/core/talos image OCI_EXPORT_DIR=/tmp/ocitest PUBLISH_VERSIONED=1 PUBLISH_FLOATING=1 IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b)
76+
pushes=$(echo "$tout" | grep 'docker://' | grep -vF '[ -z ' || true)
77+
if [ -n "$pushes" ]; then echo "FAIL: talos pushes an ungated image under OCI_EXPORT_DIR with PUBLISH_*=1: $pushes"; false; fi
78+
}

‎packages/core/talos/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ image-talos:
1515
set -e; \
1616
SRC=docker-archive:../../../_out/assets/installer-amd64.tar; \
1717
$(if $(strip $(OCI_EXPORT_DIR)),mkdir -p "$(OCI_EXPORT_DIR)"; skopeo copy "$$SRC" "oci-archive:$(OCI_EXPORT_DIR)/talos.oci.tar:$(IMAGE_TAG)",skopeo copy "$$SRC" docker://$(REGISTRY)/talos:$(IMAGE_TAG)); \
18-
if [ "$(PUBLISH_VERSIONED)" = "1" ]; then skopeo copy "$$SRC" docker://$(REGISTRY)/talos:$(TALOS_VERSION); fi; \
19-
if [ "$(PUBLISH_FLOATING)" = "1" ]; then skopeo copy "$$SRC" docker://$(REGISTRY)/talos:latest; fi
18+
if [ -z "$(OCI_EXPORT_DIR)" ] && [ "$(PUBLISH_VERSIONED)" = "1" ]; then skopeo copy "$$SRC" docker://$(REGISTRY)/talos:$(TALOS_VERSION); fi; \
19+
if [ -z "$(OCI_EXPORT_DIR)" ] && [ "$(PUBLISH_FLOATING)" = "1" ]; then skopeo copy "$$SRC" docker://$(REGISTRY)/talos:latest; fi
2020

2121
image-matchbox:
2222
test -f ../../../_out/assets/kernel-amd64 || make talos-kernel

0 commit comments

Comments
 (0)