Skip to content

Commit

Permalink
feat: SLSA 3
Browse files Browse the repository at this point in the history
Updates the CI to make policy server SLSA 3 complaint by providing the
SBOM and provenance files.

Signed-off-by: José Guilherme Vanz <[email protected]>
  • Loading branch information
jvanz committed Oct 10, 2024
1 parent e7ca8f9 commit a047bfc
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 184 deletions.
138 changes: 138 additions & 0 deletions .github/workflows/attestation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Sign attestation files

on:
workflow_call:
inputs:
image-digest:
type: string
required: true

jobs:
sbom:
name: Fetch, sign and verify SBOM and provenance files
strategy:
matrix:
arch: [amd64, arm64]

permissions:
packages: write
id-token: write

runs-on: ubuntu-latest
steps:
- name: Install cosign
uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.0

- name: Install the crane command
uses: kubewarden/github-actions/crane-installer@d94509d260ee11a92b4f65bc0acd297feec24d7f # v3.3.5

- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Verify container image signature
run: |
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/sign-image.yml@${{ github.ref }}" \
ghcr.io/${{ github.repository_owner }}/policy-server@${{ inputs.image-digest }}
- name: Find platform digest
shell: bash
run: |
set -e
DIGEST=$(crane digest \
--platform "linux/${{ matrix.arch }}" \
ghcr.io/${{ github.repository_owner }}/policy-server@${{ inputs.image-digest }})
echo "PLATFORM_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Find attestation digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ inputs.image-digest }} \
| jq '.manifests[] | select(.annotations["vnd.docker.reference.type"]=="attestation-manifest") | select(.annotations["vnd.docker.reference.digest"]=="${{ env.PLATFORM_DIGEST }}") | .digest'
)
echo "ATTESTATION_MANIFEST_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Sign attestation manifest
run: |
cosign sign --yes \
ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}}
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \
ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}}
- name: Find provenance manifest digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \
jq '.layers[] | select(.annotations["in-toto.io/predicate-type"] == "https://slsa.dev/provenance/v0.2") | .digest')
echo "PROVENANCE_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Sign provenance manifest
run: |
cosign sign --yes \
ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}}
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \
ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}}
- name: Find SBOM manifest layers digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \
jq '.layers | map(select(.annotations["in-toto.io/predicate-type"] == "https://spdx.dev/Document")) | map(.digest) | join(" ")')
echo "SBOM_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Sign SBOM layers
run: |
for sbom_digest in "${{ env.SBOM_DIGEST }}"; do
cosign sign --yes \
ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest
done
- name: Verify SBOM layers
run: |
for sbom_digest in "${{ env.SBOM_DIGEST }}"; do
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \
ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest
done
- name: Download provenance and SBOM files
run: |
set -e
crane blob ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}} > policy-server-attestation-${{ matrix.arch }}-provenance.json
md5sum policy-server-attestation-${{ matrix.arch }}-provenance.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt
for sbom_digest in "${{ env.SBOM_DIGEST }}"; do
crane blob ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest > policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json
md5sum policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt
done
- name: Sign checksum file
run: |
cosign sign-blob --yes \
--bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \
policy-server-attestation-${{ matrix.arch }}-checksum.txt
cosign verify-blob \
--bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \
policy-server-attestation-${{ matrix.arch }}-checksum.txt
- name: Upload SBOMs as artifacts
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: attestation-${{ matrix.arch }}
path: policy-server-attestation-${{ matrix.arch }}*
6 changes: 4 additions & 2 deletions .github/workflows/container-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
image-digest: ${{ needs.build.outputs.digest }}

sbom:
needs: build
uses: ./.github/workflows/sbom.yml
needs:
- build
- sign
uses: ./.github/workflows/attestation.yml
permissions:
packages: write
id-token: write
Expand Down
63 changes: 10 additions & 53 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,10 @@ on:
value: ${{ jobs.build.outputs.digest }}

jobs:
cross-build:
name: Cross compile policy-server binary
runs-on: ubuntu-latest

strategy:
matrix:
targetarch:
- aarch64
- x86_64

steps:
- name: Checkout code
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: stable
target: ${{matrix.targetarch}}-unknown-linux-musl
override: true

- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
use-cross: true
command: build
args: --release --target ${{matrix.targetarch}}-unknown-linux-musl

- name: Upload policy-server binary
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: policy-server-${{ matrix.targetarch }}
path: |
target/${{ matrix.targetarch }}-unknown-linux-musl/release/policy-server
build:
name: Build container image
permissions:
packages: write
needs:
- cross-build
runs-on: ubuntu-latest
outputs:
repository: ${{ steps.setoutput.outputs.repository }}
Expand All @@ -57,55 +21,48 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1

- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Download the policy-server artifacts we've built inside of the previous job
- name: Download policy-server-x86_64 artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: policy-server-x86_64
path: artifacts-x86_64
- name: Download policy-server-aarch64 artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: policy-server-aarch64
path: artifacts-aarch64
- name: Move binaries to project root
run: |
mv artifacts-x86_64/policy-server policy-server-x86_64
mv artifacts-aarch64/policy-server policy-server-aarch64
- name: Retrieve tag name (main branch)
if: ${{ startsWith(github.ref, 'refs/heads/main') }}
run: |
echo TAG_NAME=latest >> $GITHUB_ENV
- name: Retrieve tag name (feat branch)
if: ${{ startsWith(github.ref, 'refs/heads/feat') }}
run: |
echo "TAG_NAME=latest-$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Retrieve tag name (tag)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
echo TAG_NAME=$(echo $GITHUB_REF | sed -e "s|refs/tags/||") >> $GITHUB_ENV
- name: Push and push container image
id: build-image
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
file: ./Dockerfile.github
file: ./Dockerfile
platforms: linux/amd64, linux/arm64
push: true
sbom: true
provenance: mode=max
tags: |
ghcr.io/${{github.repository_owner}}/policy-server:${{ env.TAG_NAME }}
- id: setoutput
name: Set output parameters
run: |
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,22 @@ jobs:
- name: Checkout code for kubewarden-dashboard.json
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Download SBOM artifact
- name: Download attestation artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: sbom-*
pattern: attestation-*
path: ./
merge-multiple: true

- name: Display structure of downloaded files
run: ls -R

- name: Create tarball for the attestation files
run: |
for arch in "amd64" "arm64"; do
tar -czf attestation-$arch.tar.gz $(ls policy-server-attestation-$arch-*)
done
- name: Upload release assets
id: upload_release_assets
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand All @@ -93,12 +99,8 @@ jobs:
let path = require('path');
let files = [
'policy-server-sbom-amd64.spdx',
'policy-server-sbom-amd64.spdx.cert',
'policy-server-sbom-amd64.spdx.sig',
'policy-server-sbom-arm64.spdx',
'policy-server-sbom-arm64.spdx.cert',
'policy-server-sbom-arm64.spdx.sig',
'attestation-amd64.tar.gz',
'attestation-arm64.tar.gz',
'kubewarden-dashboard.json']
const {RELEASE_ID} = process.env
Expand Down
87 changes: 0 additions & 87 deletions .github/workflows/sbom.yml

This file was deleted.

Loading

0 comments on commit a047bfc

Please sign in to comment.