Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign buildpacksio/pack images using cosign and attach sbom generated from binaries #2287

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,47 +226,99 @@ jobs:
echo "PACK_MILESTONE=${milestone}" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Package artifacts - macos
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Package artifacts and Generate SBOM JSON file - macos
run: |
chmod +x pack-macos/pack
filename=pack-v${{ env.PACK_VERSION }}-macos.tgz
tar -C pack-macos -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - linux-arm64

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - linux-arm64
run: |
chmod +x pack-linux-arm64/pack
filename=pack-v${{ env.PACK_VERSION }}-linux-arm64.tgz
tar -C pack-linux-arm64 -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - linux-s390x

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - linux-s390x
run: |
chmod +x pack-linux-s390x/pack
filename=pack-v${{ env.PACK_VERSION }}-linux-s390x.tgz
tar -C pack-linux-s390x -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - linux-ppc64le

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - linux-ppc64le
run: |
chmod +x pack-linux-ppc64le/pack
filename=pack-v${{ env.PACK_VERSION }}-linux-ppc64le.tgz
tar -C pack-linux-ppc64le -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - macos-arm64

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - macos-arm64
run: |
chmod +x pack-macos-arm64/pack
filename=pack-v${{ env.PACK_VERSION }}-macos-arm64.tgz
tar -C pack-macos-arm64 -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - linux

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - linux
run: |
chmod +x pack-linux/pack
filename=pack-v${{ env.PACK_VERSION }}-linux.tgz
tar -C pack-linux -vzcf $filename pack
shasum -a 256 $filename > $filename.sha256
- name: Package artifacts - windows

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

tar -xzf $filename -C $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Package artifacts and Generate SBOM JSON file - windows
run: |
filename=pack-v${{ env.PACK_VERSION }}-windows.zip
zip -j $filename pack-windows/pack.exe
shasum -a 256 $filename > $filename.sha256

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

unzip $filename -d $temp_dir
syft "$temp_dir" -o cyclonedx-json > "${filename}-sbom.cdx.json"
shasum -a 256 "${filename}-sbom.cdx.json" > "${filename}-sbom.cdx.json.sha256"
- name: Extract lifecycle version
id: lifecycle_version
run: |
Expand Down
70 changes: 62 additions & 8 deletions .github/workflows/delivery-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
REGISTRY_NAME: 'docker.io'
USER_NAME: 'buildpacksio'
IMG_NAME: 'pack'
ARCHITECTURES: arm64,amd64,s390x,ppc64le

jobs:
deliver-docker:
Expand All @@ -33,6 +34,8 @@ jobs:
base_image: ubuntu:jammy
suffix: -base
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Determine version
uses: actions/github-script@v7
Expand All @@ -52,8 +55,10 @@ jobs:
uses: actions/checkout@v4
with:
ref: v${{ steps.version.outputs.result }}
- name: Determine App Name
run: 'echo "IMG_NAME=${{ env.REGISTRY_NAME }}/${{ env.USER_NAME }}/${{ env.IMG_NAME }}" >> $GITHUB_ENV'
- name: Setup Docker Build Environment
run: |
echo "IMG_NAME=${{ env.REGISTRY_NAME }}/${{ env.USER_NAME }}/${{ env.IMG_NAME }}" >> $GITHUB_ENV
echo "${{ env.ARCHITECTURES }}" | tr ',' '\n' > architectures.txt
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
Expand All @@ -71,11 +76,60 @@ jobs:
--build-arg base_image=${{ matrix.base_image }} \
--provenance=false \
--push
- name: Tag Image as Base
if: ${{ (github.event.release != '' || github.event.inputs.tag_latest) && matrix.config == 'base' }}
echo "IMG_DIGEST=$(crane digest ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }})" >> $GITHUB_ENV
- name: Download SBOMs
run: |
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }} ${{ env.IMG_NAME }}:base
- name: Tag Image as Latest
if: ${{ (github.event.release != '' || github.event.inputs.tag_latest) && matrix.config != 'base' }}
while IFS= read -r arch; do
pattern=$([ "$arch" = "amd64" ] && echo "pack-v${{ steps.version.outputs.result }}-linux-sbom.cdx.json" || echo "pack-v${{ steps.version.outputs.result }}-linux-${arch}-sbom.cdx.json")
gh release download --pattern "${pattern}" ${{ github.event.release.tag_name }} &
done < architectures.txt
wait
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Attach SBOMs, Sign and Verify Images using cosign
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }} ${{ env.IMG_NAME }}:latest
secure_image_release() {
local tag=$1
local alias=${2:-}

while IFS= read -r arch; do
sbom_json_file=$([ "$arch" = "amd64" ] && echo "pack-v${{ steps.version.outputs.result }}-linux-sbom.cdx.json" || echo "pack-v${{ steps.version.outputs.result }}-linux-${arch}-sbom.cdx.json")

cosign attach sbom --sbom "$sbom_json_file" \
--type cyclonedx \
--platform "linux/${arch}" \
"$tag@${IMG_DIGEST}"
done < architectures.txt

cosign sign -r -y \
-a version=${{ steps.version.outputs.result }} \
-a config=${{ matrix.config }} \
${alias:+-a alias=$alias} \
--attachment sbom \
"$tag@${IMG_DIGEST}"

cosign verify \
--certificate-identity-regexp "https://github.com/${{ github.repository_owner }}/pack/.github/workflows/delivery-docker.yml" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
-a version=${{ steps.version.outputs.result }} \
-a config=${{ matrix.config }} \
${alias:+-a alias=$alias} \
--attachment sbom \
"$tag@${IMG_DIGEST}"
}

secure_image_release "${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }}"

if [[ ("${{ github.event.release }}" != "" || "${{ github.event.inputs.tag_latest }}" == "true") ]]; then
if [[ "${{ matrix.config }}" == "base" ]]; then
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }} ${{ env.IMG_NAME }}:base
secure_image_release "${{ env.IMG_NAME }}:base" "base"
fi

if [[ "${{ matrix.config }}" != "base" ]]; then
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }} ${{ env.IMG_NAME }}:latest
secure_image_release "${{ env.IMG_NAME }}:latest" "latest"
fi
fi
Loading