Skip to content

Commit 2808e2b

Browse files
Marketenclaude
andcommitted
fix: build releases on a BuildKit that honours rewrite-timestamp
The docker driver bundled with dockerd accepts the exporter's rewrite-timestamp option and then ignores it: layer mtimes keep the build clock, so two builds of one revision produce different images and different measurements. It still normalises the image config's created field, which is the only thing the old guard compared, so the check passed and unreproducible releases shipped anyway. Three builds of 96e1c23 demonstrate it -- CI attempt 1 measured PCR0 41459ff7, attempt 2 measured 98c3915c, and a local rebuild measured f8abaf0f. Only a docker-container BuildKit honours the option, so the release now runs on one and refuses to build otherwise. Replace the created-only guard with a real one: build the enclave image twice and require both to be identical. A normalised created field is not evidence that the layers were normalised, and the manifest's reproducibility claim should be tested by the release that makes it rather than merely asserted. verify-build.sh gets the same driver check. Without it a verifier on the docker driver sees a mismatch against an honest release, which reads as an accusation that the published measurements are dishonest. Both scripts now build the nitro-cli image with buildx --load: a docker-container builder leaves results in the build cache, so build-enclave would either fail on a clean machine or silently reuse a stale image of the same tag. Verified locally: verify-build.sh now reports PASS against a manifest produced by the fixed release path, and both scripts refuse to run on the docker driver. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 96e1c23 commit 2808e2b

3 files changed

Lines changed: 70 additions & 15 deletions

File tree

‎.github/workflows/release-and-push.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ jobs:
102102
echo "digest=$image_digest" >> "$GITHUB_OUTPUT"
103103
docker buildx imagetools inspect "$ECR_REGISTRY/$IMAGE_NAME@$image_digest"
104104
105+
# The docker driver silently ignores rewrite-timestamp, so every release
106+
# measures differently. Only docker-container honours it.
107+
- name: Set up Buildx (docker-container driver)
108+
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
109+
with:
110+
driver: docker-container
111+
105112
- name: Build EIF and release metadata
106113
id: enclave
107114
env:

‎deploy/nitro/build-release-assets.sh‎

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,35 @@ artifact_dir_absolute="$(realpath "$ARTIFACT_DIR")"
8888
# --provenance=false keeps a build-time attestation (which embeds the clock and
8989
# the runner identity) out of the image. Without both, two builds of identical
9090
# source produce different layers and therefore different measurements.
91-
docker buildx build --pull --no-cache --provenance=false \
92-
--label "org.opencontainers.image.source=https://github.com/${SOURCE_REPOSITORY}" \
93-
--label "org.opencontainers.image.revision=${SOURCE_REVISION}" \
94-
--label "org.opencontainers.image.version=${VERSION}" \
95-
--build-arg "SOURCE_REVISION=${SOURCE_REVISION}" \
96-
--build-arg "AWS_REGION=${AWS_REGION}" \
97-
--build-arg "KMS_KEY_ARN=${KMS_KEY_ARN}" \
98-
-f apps/gateway/Dockerfile.enclave \
99-
--output "type=docker,name=${enclave_image},rewrite-timestamp=true" \
100-
.
91+
#
92+
# The docker driver accepts rewrite-timestamp and ignores it, normalising only
93+
# the config's created field, so it must not be used to cut a release.
94+
# awk must not exit early here: SIGPIPE on docker would abort the script.
95+
builder_driver="$(docker buildx inspect --bootstrap 2>/dev/null | awk -F': *' '/^Driver:/{if (driver == "") driver = $2} END {print driver}')" || builder_driver=""
96+
if [[ "$builder_driver" != "docker-container" ]]; then
97+
printf 'reproducible build check failed: buildx driver is %s, need docker-container\n' \
98+
"${builder_driver:-unknown}" >&2
99+
printf 'The docker driver silently ignores rewrite-timestamp, so this build would\n' >&2
100+
printf 'produce measurements nobody else can reproduce. Create a builder with:\n' >&2
101+
printf ' docker buildx create --driver docker-container --use\n' >&2
102+
exit 1
103+
fi
104+
105+
build_enclave_image() {
106+
docker buildx build --pull --no-cache --provenance=false \
107+
--label "org.opencontainers.image.source=https://github.com/${SOURCE_REPOSITORY}" \
108+
--label "org.opencontainers.image.revision=${SOURCE_REVISION}" \
109+
--label "org.opencontainers.image.version=${VERSION}" \
110+
--build-arg "SOURCE_REVISION=${SOURCE_REVISION}" \
111+
--build-arg "AWS_REGION=${AWS_REGION}" \
112+
--build-arg "KMS_KEY_ARN=${KMS_KEY_ARN}" \
113+
-f apps/gateway/Dockerfile.enclave \
114+
--output "type=docker,name=$1,rewrite-timestamp=true" \
115+
.
116+
}
117+
118+
build_enclave_image "$enclave_image"
101119

102-
# A buildx too old to honour rewrite-timestamp would still succeed here and
103-
# publish a release that nobody can reproduce, so prove the normalisation
104-
# actually applied rather than assuming it did.
105120
image_created_epoch="$(date -u -d "$(docker image inspect --format '{{.Created}}' "$enclave_image")" +%s)"
106121
if [[ "$image_created_epoch" != "$SOURCE_DATE_EPOCH" ]]; then
107122
printf 'reproducible build check failed: image timestamp is %s, expected %s\n' \
@@ -111,7 +126,25 @@ if [[ "$image_created_epoch" != "$SOURCE_DATE_EPOCH" ]]; then
111126
exit 1
112127
fi
113128

114-
docker build --pull \
129+
# A normalised created field is not proof the layers were normalised, so test
130+
# determinism by building twice instead of asserting it in the manifest.
131+
determinism_image="${enclave_image}-determinism-check"
132+
build_enclave_image "$determinism_image"
133+
first_image_id="$(docker image inspect --format '{{.Id}}' "$enclave_image")"
134+
second_image_id="$(docker image inspect --format '{{.Id}}' "$determinism_image")"
135+
docker image rm -f "$determinism_image" >/dev/null 2>&1 || true
136+
if [[ "$first_image_id" != "$second_image_id" ]]; then
137+
printf 'reproducible build check failed: two builds of %s produced different images\n' \
138+
"$SOURCE_REVISION" >&2
139+
printf ' first: %s\n' "$first_image_id" >&2
140+
printf ' second: %s\n' "$second_image_id" >&2
141+
printf 'Publishing these measurements would break deploy/nitro/verify-build.sh.\n' >&2
142+
exit 1
143+
fi
144+
145+
# --load is required: a docker-container builder leaves results in the build
146+
# cache, and build-enclave below needs the image in the daemon.
147+
docker buildx build --pull --load \
115148
-f deploy/nitro/nitro-cli-builder.Dockerfile \
116149
-t "$nitro_cli_image" \
117150
deploy/nitro

‎deploy/nitro/verify-build.sh‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ docker buildx version >/dev/null 2>&1 || {
3838
printf 'docker buildx is required: the reproducible build depends on rewrite-timestamp\n' >&2
3939
exit 1
4040
}
41+
42+
# The docker driver ignores rewrite-timestamp and would report a mismatch
43+
# against an honest release, so refuse to run rather than accuse falsely.
44+
# awk must not exit early here: SIGPIPE on docker would abort the script.
45+
verify_builder_driver="$(docker buildx inspect --bootstrap 2>/dev/null | awk -F': *' '/^Driver:/{if (driver == "") driver = $2} END {print driver}')" || verify_builder_driver=""
46+
if [[ "$verify_builder_driver" != "docker-container" ]]; then
47+
printf 'cannot verify with the %s buildx driver: it ignores rewrite-timestamp\n' \
48+
"${verify_builder_driver:-unknown}" >&2
49+
printf 'and would report a mismatch for a correctly built release. Run:\n' >&2
50+
printf ' docker buildx create --driver docker-container --use\n' >&2
51+
printf 'and try again.\n' >&2
52+
exit 1
53+
fi
4154
[[ -f "$manifest_path" ]] || { printf 'no such manifest: %s\n' "$manifest_path" >&2; exit 1; }
4255

4356
# Newline-separated rather than @tsv: tab is an IFS whitespace character, so a
@@ -124,7 +137,9 @@ fail() {
124137
printf 'Rebuilding %s (source_date_epoch=%s)\nThis takes a few minutes.\n' \
125138
"${revision:0:12}" "$source_date_epoch"
126139

127-
docker build --pull -q \
140+
# --load: a docker-container builder keeps results in the build cache, and
141+
# build-enclave below needs the image in the daemon.
142+
docker buildx build --pull -q --load \
128143
-f "$context/deploy/nitro/nitro-cli-builder.Dockerfile" \
129144
-t "$nitro_cli_image" \
130145
"$context/deploy/nitro" >>"$build_log" 2>&1 || fail

0 commit comments

Comments
 (0)