Skip to content

7. Workflow security and supply chain ​

Home · Full index

7.1 S01 · Give verification jobs read-only access ​

GitHub Actions · Top-level and steps fragments. Set the default once. Give a separate trusted job the write scope it needs. Check the Gitea token table when porting permissions.

yaml
permissions:
  contents: read
yaml
- uses: actions/checkout@v4
  with:
    persist-credentials: false

Verify. In the job setup log check the reported token scopes. Fetch actions from an approved source and review what they run.

7.2 S02 · Treat pull request fields as data ​

GitHub Actions · Steps fragment. Use on a pull_request verification job. Pass the title through env and use a fixed format string.

yaml
- name: Log PR title as data
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
  shell: bash
  run: printf '%s\n' "$PR_TITLE"

Verify. Use an ordinary title containing quotes and percent signs. Confirm it prints literally. Keep external PR code separate from privileged events, secrets and deployment runners.

7.3 S03 · Generate an SBOM and gate image findings ​

Linux Bash · Script fragment. Requires a reviewed Trivy installation, a local Docker image called app:ci and access to the scanner's vulnerability database. This policy fails on HIGH or CRITICAL findings. Agree on how exceptions are reviewed and expired before adopting it as a release gate.

bash
set -euo pipefail
mkdir -p reports
trivy image --format cyclonedx --output reports/image.cdx.json app:ci
trivy image --scanners vuln --severity HIGH,CRITICAL --exit-code 1 app:ci

Verify. Preserve the SBOM as a build artifact and check the gate's exit status plus scanner logs. A database download failure is a scanner failure and gives a different troubleshooting path from a package finding.

7.4 S04 · Attest and verify an image ​

GitHub Actions · Job permissions and steps fragments. Add these permissions and the attestation step to the trusted publish job in B03. Check your GitHub plan and package support for attestations before adopting this. Retain registry write access when uploading to the registry.

yaml
permissions:
  contents: read
  packages: write
  id-token: write
  attestations: write
yaml
- uses: actions/attest-build-provenance@v2
  with:
    subject-name: ${{ steps.image.outputs.name }}
    subject-digest: ${{ steps.build.outputs.digest }}
    push-to-registry: true

Verifier. Requires GitHub CLI, access to the attestation and registry, the approved full IMAGE digest reference and the expected SOURCE_REPO as owner/repo. Set SIGNER_WORKFLOW to the approved workflow path including its repository, such as owner/repo/.github/workflows/publish.yml.

bash
gh attestation verify "oci://$IMAGE" --repo "$SOURCE_REPO" \
  --signer-workflow "$SIGNER_WORKFLOW" --source-ref refs/heads/main

Verify. Use the digest from a trusted publish workflow. The verifier must succeed before deployment proceeds. A provenance attestation identifies the build origin. The scan gate addresses a separate policy.

7.5 S05 · Ask for short-lived cloud credentials ​

GitHub Actions · Job permissions fragment. Add only to a dedicated, trusted deployment job. Configure the target provider to trust the intended repository, branch or protected environment, and to require the provider's expected audience. Pair this permission with the provider's official identity exchange action and a least-privilege role created outside the workflow.

yaml
permissions:
  id-token: write
  contents: read

Verify. The approved job can exchange an OIDC token for temporary credentials. A job with a different identity should be denied by the provider's trust policy. Check the caller identity or role rather than printing any token.

7.6 S06 · Verify an action version before pinning ​

Linux Bash · Script fragment. Requires Git and network access to a reviewed upstream action repository. Annotated tags dereference to a commit, while lightweight tags already point to a commit.

bash
git ls-remote https://github.com/actions/checkout.git \
  refs/tags/v4 'refs/tags/v4^{}'

Verify. Review the source and release for the resolved commit. For an annotated tag use the dereferenced commit shown on the ^{} line. Replace @v4 with that full reviewed commit SHA, and use an update process to keep pins current. The teaching examples use readable version tags and assume you review dependencies before production use.

Reference · Secure use, artifact attestations, OIDC in GitHub Actions, Trivy image scans.