Skip to content

Commit 1de42b9

Browse files
committed
cmd-build: only copy allowed files into final build dir
Over time we seem to have accumulated all sorts of crud in the build dir that were never meant to be uploaded: ``` $ aws s3 ls s3://.../$buildid/x86_64/ ... 2024-10-26 10:49:16 1027 cmd.sh 2024-10-26 10:49:15 540 image.json 2024-10-26 10:49:15 8436 manifest.json 2024-10-26 10:49:15 2267 platforms.json 2024-10-26 10:49:15 2621 platforms.json.all 2024-10-26 10:49:16 2 rc 2024-10-26 10:49:16 97896 runvm-console.txt ``` There are no secrets in there, but still we should be more conscious of what we upload and keep artifacts in public build dirs to strictly what we intend. Historically, `$tmp_builddir` was meant to be the staging area for the final contents of the build dir we would move into place and `$TMPDIR` was the truly temporary directory for that build. Over time, that distinction has been lost a bit and things that shouldn't have been placed there were. In the end, I think it's cleaner to instead operate on an allowlist of files we know belong in the build dir, so let's do that.
1 parent 6813e3f commit 1de42b9

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/cmd-build

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,24 @@ mv -T tmp "${saved_build_tmpdir}"
623623
# just keep the last 3 commits as a rough guideline; this matches
624624
# DEFAULT_KEEP_LAST_N in `cmd-prune`
625625
ostree prune --repo="${tmprepo}" --refs-only --depth=2
626-
# Back to the toplevel work directory, so we can rename this one
627-
cd "${workdir}"
628-
# We create a .build-commit file to note that we're in the
629-
# middle of a "commit". This may be useful in the future
630-
# for having things be transactional. If for example we
631-
# were interrupted between the rename() and linkat() below,
632-
# things would be inconsistent and future builds would fail
633-
# on the `mv`.
634-
touch builds/.build-commit
635626
builddir=$(get_build_dir "${buildid}")
627+
# And now mv the final artifacts to the build dir
636628
mkdir -p "${builddir}"
637-
mv -T "${tmp_builddir}" "${builddir}"
629+
# "loose" objects; i.e. untracked by meta.json
630+
loose_objs=()
631+
# commit metadata
632+
loose_objs+=("commitmeta.json" "ostree-commit-object")
633+
loose_objs+=("manifest-lock.generated.$basearch.json")
634+
# source metadata
635+
loose_objs+=("coreos-assembler-config-git.json" "coreos-assembler-config.tar.gz")
636+
mv -vt "${builddir}" "${loose_objs[@]}"
637+
# official more public artifacts; tracked by meta.json
638+
jq -r .images[].path meta.json | xargs mv -vt "${builddir}"
639+
# and finally, meta.json itself
640+
mv -vt "${builddir}" meta.json
641+
# and now go back to the workdir so we can nuke this dir
642+
cd "${workdir}"
643+
rm -rf "${tmp_builddir}"
638644
# Replace the latest link
639645
ln -Tsf "${buildid}" builds/latest
640646

@@ -643,7 +649,6 @@ if [ "${SKIP_PRUNE}" == 1 ]; then
643649
else
644650
"${dn}"/cmd-prune --workdir "${workdir}"
645651
fi
646-
rm builds/.build-commit
647652

648653
if [ -n "${TAG}" ]; then
649654
# ideally, we'd do this atomically before moving to builds/latest, but

0 commit comments

Comments
 (0)