From cf03077cebb4f055b4efdb04cf22cab3a010886b Mon Sep 17 00:00:00 2001 From: renner Date: Sat, 9 May 2026 15:00:06 +0200 Subject: [PATCH] fix(ci): generate SBOM after rechunking Because we are generating our SBOMs before rechunking, we still have leftover ostree objects which are getting picked up by syft and causes changelogs to report wrong versions of packages. fixes: https://github.com/ublue-os/aurora/issues/2077 --- .github/workflows/reusable-build.yml | 52 ++++++++++++---------------- .gitignore | 2 ++ Justfile | 31 +++++++++++++++-- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index f701600e..1081af1a 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -159,34 +159,6 @@ jobs: path: /var/tmp/buildah-cache-* key: ${{ runner.os }}-${{ runner.arch }}-buildah-${{ env.CACHE_NAME }}-${{ github.run_id }} - - name: Setup Syft - id: setup-syft - if: github.event_name != 'pull_request' - uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0 - with: - syft-version: v1.39.0 - - - name: Generate SBOM - if: github.event_name != 'pull_request' - id: generate-sbom - env: - IMAGE: ${{ env.IMAGE_NAME }} - STREAM_NAME: ${{ matrix.stream_name }} - SYFT_CMD: ${{ steps.setup-syft.outputs.cmd }} - OCI_DIR: "/tmp/image-oci-dir" - run: | - mkdir -p ${OCI_DIR}/rootfs - sudo podman container create --replace --name "${IMAGE}" "localhost/${IMAGE}:${STREAM_NAME}" - sudo podman export "${IMAGE}" | sudo tar -C ${OCI_DIR}/rootfs -xf - - sudo podman container rm "${IMAGE}" - - SBOM="$(mktemp -d)/sbom.json" - export SYFT_PARALLELISM=$(($(nproc)*2)) - sudo $SYFT_CMD --source-name "${IMAGE}"-"${STREAM_NAME}" ${OCI_DIR} -o syft-json=${SBOM} - du -sh ${SBOM} - echo "SBOM=${SBOM}" >> $GITHUB_OUTPUT - sudo rm -rf ${OCI_DIR} - - name: Rechunk Image with rpm-ostree id: rechunker env: @@ -203,6 +175,26 @@ jobs: "0" \ "${PREVIOUS_BUILD}" + - name: Setup Syft + id: setup-syft + if: github.event_name != 'pull_request' + uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 + + - name: Generate SBOM + if: github.event_name != 'pull_request' + id: generate-sbom + env: + MATRIX_BASE_NAME: ${{ matrix.base_name }} + MATRIX_STREAM_NAME: ${{ matrix.stream_name }} + MATRIX_IMAGE_FLAVOR: ${{ matrix.image_flavor }} + DEFAULT_TAG: ${{ env.DEFAULT_TAG }} + SYFT_CMD: ${{ steps.setup-syft.outputs.cmd }} + run: | + sudo -E $(command -v just) gen-sbom "${MATRIX_BASE_NAME}" \ + "${MATRIX_STREAM_NAME}" \ + "${MATRIX_IMAGE_FLAVOR}" \ + "${SYFT_CMD}" + - name: Secureboot Check id: secureboot shell: bash @@ -378,8 +370,10 @@ jobs: env: IMAGE: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} DIGEST: ${{ steps.push.outputs.digest }} - SBOM: ${{ steps.generate-sbom.outputs.SBOM }} + IMAGE_NAME: ${{ env.IMAGE_NAME }} run: | + SBOM="sbom_out/${IMAGE_NAME}/sbom.json" + cd "$(dirname "${SBOM}")" oras attach \ --artifact-type application/vnd.spdx+json \ diff --git a/.gitignore b/.gitignore index 9d706f46..a369df7f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ flatpaks_with_deps flatpak.* aurora*.oci +sbom_out +*.sbom previous.manifest.json changelog.md output.env diff --git a/Justfile b/Justfile index 9c7f588f..6822046f 100644 --- a/Justfile +++ b/Justfile @@ -56,10 +56,9 @@ fix: clean: #!/usr/bin/bash set -eoux pipefail - touch _build - find *_build* -exec rm -rf {} \; rm -f changelog.md rm -f output.env + rm -rf sbom_out # Check if valid combo [group('Utility')] @@ -612,6 +611,34 @@ tag-images image_name="" default_tag="" tags="": # Show Images ${PODMAN} images +# Extract Container and generate SBOM +[group('Utility')] +gen-sbom $image="aurora" $tag="latest" $flavor="main" $syft_cmd="syft": + #!/usr/bin/bash + set -eoux pipefail + + image_name=$({{ just }} image_name '{{ image }}' '{{ tag }}' '{{ flavor }}') + + OUT_DIR="sbom_out/${image_name}" + mkdir -p "${OUT_DIR}" + + # We have to do it this stupid way because we are OOMing on github runners + # https://github.com/anchore/syft/issues/3800 + ${PODMAN} container create --replace --name ${image_name} "${image_name}:${tag}" + + ROOTFS="${OUT_DIR}/rootfs" + mkdir -p "${ROOTFS}" + + ${PODMAN} export ${image_name} | tar -C "${ROOTFS}" -xf - + ${PODMAN} container rm ${image_name} + + SBOM="${OUT_DIR}/sbom.json" + + ${syft_cmd} --source-name "${image_name}:${tag}" "${OUT_DIR}" -o syft-json=${SBOM} + du -sh "${SBOM}" + + rm -rf "${ROOTFS}" + # DNF CI package cache [group('Utility')] setup-cache $image="aurora" $tag="latest" $flavor="main" $ghcr="0" $github_event="0":