Skip to content

ci: attest, sign and scan published images - #414

Merged
uniqueg merged 10 commits into
devfrom
ci/403-attest-sign-scan
Oct 22, 2026
Merged

uniqueg merged 10 commits into
devfrom
ci/403-attest-sign-scan

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Closes #403. Close it by hand after merging, as dev is not the default branch.

This uses the same setup as cloud-registry (elixir-cloud-aai/cloud-registry#181): the same scan action, ignore file format, pins, step names and verification docs. The differences come from FOCA's four Python image variants and its OCI chart on GHCR.

Summary

Build, attest, sign

  • Dev images (checks.yml, job docker):
    • built with Buildx (docker/build-push-action), with SBOM (sbom: true) and provenance (provenance: mode=max) attestations;
    • attested with actions/attest-build-provenance, with push-to-registry: true;
    • signed with cosign keyless signing, using the workflow's OIDC token.
  • Release images (release.yml, job docker):
    • pushed by digest (untagged, with SBOM and provenance), then attested and signed;
    • checked to report the release version before it is attested and signed;
    • only then tagged with docker buildx imagetools create, and each tag is checked against the signed digest;
    • the tags are unchanged. As in cloud-registry, latest is now decided from freshly fetched tags that are merged into main, so stray tags are ignored; the weekly scan does the same.
  • Chart (release-chart.yml): foca-common gets the same attestation and signature. The digest is parsed from helm push. A Docker login to GHCR is added, because the attestation and signature are pushed with Docker's credentials.
  • Permissions: id-token: write and attestations: write are granted only on these publishing jobs.

Scan

  • Scanner: Trivy, through the composite action .github/actions/scan-image, copied from cloud-registry:
    • pins: trivy-action 0.36.0 with Trivy v0.75.0, and upload-sarif 4.38.3;
    • one pass uploads all findings to code scanning (SARIF), a second fails on fixable critical and high findings;
    • Trivy also scans for secrets.
  • PRs and pushes: a new scan job in checks.yml builds and scans the images of Python 3.11 to 3.14. The SARIF upload is skipped for fork PRs. The dev docker job needs this job.
  • Release: a new scan job in release.yml builds and scans the release commit's images again:
    • it has contents: read only, no environment and no secrets, so Trivy never runs next to publishing credentials or id-token;
    • both PyPI publish and docker need it, so a failing scan stops the release before anything immutable is published.
  • Weekly: scan.yml scans elixircloud/foca:<latest final>-py3.x. The images are public, so it needs no secrets. Scheduled runs use the default branch (main), so the workflow takes .trivyignore.yaml from dev.
  • Ignore file: .trivyignore.yaml, copied from cloud-registry. It accepts pip's vendored copies of setuptools 70.3.0, urllib3 2.7.0 and msgpack 1.1.2 by purl, each with a statement and an expiry date of 2027-01-31. Trivy reports vendored copies without a path, so the entries can't be limited by path.
  • Dependabot also updates the composite action.

Dockerfile

The image no longer contains setuptools and wheel, which only the Python 3.11 base image ships.

  • They have known vulnerabilities: the published 0.16.0-py3.11 image has wheel 0.45.1 (GHSA-8rrh-rw8j-w5fx, high, fixable), and the current base image has setuptools 79.0.1.
  • FOCA needs neither, because pip builds packages in isolated environments, and the 3.12+ images already lack them.
  • Derived images that build with --no-build-isolation or python setup.py must install setuptools themselves, as they already must on 3.12+.

Docs

  • A new section, "Verifying images and charts", in docs/deployment.md:
    • gh attestation verify and cosign verify (cosign 3 or later), with exact per-version identities and the issuer;
    • the identities for dev images and the chart;
    • pinning the verified digest;
    • reading the SBOM and provenance with docker buildx imagetools inspect.
  • A new section, "Image scan", in docs/contributing.md, on how to handle a failed scan.
  • Pointers in README.md and docs/helm-chart.md.
  • A line for the 0.17.0 release notes, in the notes draft.

Everything is free for public repositories and needs no new secrets: the existing DOCKERHUB_* secrets and GITHUB_TOKEN are enough.

How it was verified

  • actionlint 1.7.7 on all workflows, including the local composite action: no findings.
  • Earlier commits of this PR (with Grype) ran a dry-run build of the release settings into an OCI archive. All four Python versions produced both attestations (https://spdx.dev/Document and https://slsa.dev/provenance/v1), and the SARIF upload to code scanning worked.
  • The py3.11 build log shows setuptools and wheel being removed.
  • Review: adversarial and quality reviewer subagents (round 1), an adversarial review of the fixes (round 2), and an adversarial review of the alignment with cloud-registry.
  • CI on the final commit (833d372): all checks pass, including Scan image (Python 3.11-3.14) (Trivy, no fixable critical or high findings with the accepted pip-vendored entries), the Trivy code scanning check, Sourcery review, codecov and Read the Docs.

Not exercised

  • Publishing paths: nothing can run before a tag or a push to dev:

    • the push to Docker Hub, by digest and with tags;
    • attest-build-provenance with push-to-registry;
    • cosign sign;
    • tagging with imagetools create and the digest check;
    • for the chart: the digest parsing, the GHCR Docker login, the attestation and the signing.

    The same digest and tag flow is merged and in use in cloud-registry. The dev image path runs for the first time once this PR is merged.

  • Documented commands: gh attestation verify, cosign verify and imagetools inspect have not been run against a FOCA image, as no FOCA image is signed yet.

  • Release scan job: it is the same as the PR scan job, plus FOCA_VERSION.

  • Weekly scan: it starts only once scan.yml reaches main with 0.17.0. A manual workflow_dispatch on dev before then would fail for 0.16.0-py3.11 (wheel 0.45.1).

Declined review findings

  • Recover the chart's digest on reruns and attest and sign it (Sourcery, medium): if the run attested and signed a digest recovered from the registry, it would vouch for an artifact it didn't build. This failure (push succeeds, then attest or sign fails) is rare, and docs/helm-chart.md says to release a new version in that case.

  • Grype-specific findings from earlier rounds: these are void now that the PR uses Trivy. The Grype ignore-file checker is gone too, as Trivy enforces expired_at itself.

  • OCI labels via docker/metadata-action, as in cloud-registry (adversarial, low): FOCA's images never had version or commit labels; the provenance attestation records the commit. Adding them is a separate change that this PR doesn't need.

Open questions

None.

What the user must set up

Nothing. Optionally, add the new Scan image (Python 3.x) checks to the required checks of the dev ruleset.

🤖 Generated with Claude Code

uniqueg and others added 5 commits October 23, 2026 00:23
Build the release and dev images with Buildx, with SBOM and provenance
(mode=max) attestations, and attest (GitHub artifact attestation, pushed
to the registry) and sign (cosign keyless) the pushed digests; the same
for the foca-common chart on GHCR. Publishing jobs get id-token and
attestations write permissions only.

Add an image scan workflow (Grype): on pull requests and pushes, build
the images of all Python versions (a dry run of the release build that
checks the attestations), report all vulnerabilities to code scanning
and fail on fixable critical or high ones; weekly, scan the images of
the latest release. Accepted findings go into .grype.yaml with a reason
and an expiry date, which the workflow checks.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Explain how operators verify images and charts (gh attestation verify,
cosign verify with the expected identity and issuer) and read SBOMs and
provenance, and how contributors handle failed image scans.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Python 3.11 base images ship setuptools 79 and wheel 0.45, which
have known vulnerabilities (wheel: GHSA-8rrh-rw8j-w5fx, high, fixed in
0.46.2), so that the image scan fails for them. FOCA needs neither at
runtime, and pip builds packages in isolated environments; images of
Python 3.12 and later do not ship them either.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep scheduled scans on the triggering commit, using only dev's ignore
file, so that code scanning gets results for the right commit; reject
impossible expiry dates; show Helm's output if pushing the chart fails;
explain the dry run and the two scans; rewrap comments and docs; give
the image scan docs a heading of their own.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR upgrades image and chart publishing with Buildx SBOM/provenance attestations, GitHub attestations, and keyless Cosign signatures; introduces Grype-based vulnerability scanning with expiring ignore rules; removes vulnerable unused Python packages; and documents verification and scan workflows.

Sequence diagram for attested and signed image publishing

sequenceDiagram
    participant Workflow as GitHub Actions workflow
    participant Buildx as Docker Buildx
    participant Registry as Docker Hub
    participant Attest as actions/attest
    participant Cosign as cosign

    Workflow->>Buildx: build-push-action
    Buildx->>Registry: push image tags and digest
    Buildx-->>Workflow: outputs.digest
    Workflow->>Attest: attest(subject-name, subject-digest)
    Attest->>Registry: push GitHub artifact attestation
    Workflow->>Cosign: cosign sign --yes image@digest
    Cosign->>Registry: push keyless signature
Loading

Sequence diagram for image vulnerability scanning

sequenceDiagram
    participant Trigger as PR or dev push
    participant Buildx as Docker Buildx
    participant Archive as OCI archive
    participant Docker as Docker image store
    participant Grype as Grype
    participant CodeScanning as GitHub code scanning

    Trigger->>Buildx: build-push-action with sbom and provenance
    Buildx->>Archive: write image and attestations
    Trigger->>Archive: Check attestations
    Trigger->>Buildx: build-push-action with load
    Buildx->>Docker: load image
    Trigger->>Grype: scan image
    Grype-->>CodeScanning: upload SARIF findings
    Trigger->>Grype: scan with only-fixed and severity-cutoff high
    Grype-->>Trigger: fail on fixable high or critical findings
Loading

Sequence diagram for chart attestation and signing

sequenceDiagram
    participant Workflow as release-chart workflow
    participant Helm as Helm
    participant GHCR as GitHub Container Registry
    participant Attest as actions/attest
    participant Cosign as cosign

    Workflow->>Helm: helm push chart
    Helm->>GHCR: publish chart OCI artifact
    Helm-->>Workflow: chart digest
    Workflow->>GHCR: Docker login
    Workflow->>Attest: attest chart digest
    Attest->>GHCR: push chart attestation
    Workflow->>Cosign: cosign sign --yes chart@digest
    Cosign->>GHCR: push keyless signature
Loading

Flow diagram for expiring vulnerability ignore rules

flowchart TD
    A[Load .grype.yaml] --> B[Check reason]
    B --> C[Parse expires as YYYY-MM-DD]
    C --> D{Date from today to three months ahead?}
    D -->|Yes| E[Run image scan]
    D -->|No| F[Fail ignores job]
Loading

File-Level Changes

Change Details Files
Publishing workflows now build images with Buildx and attach verifiable supply-chain metadata and signatures.
  • Replaced direct Docker build/push commands with pinned Buildx actions and single-build multi-tag publishing.
  • Enabled SBOM and maximum-mode provenance attestations.
  • Added GitHub artifact attestations and keyless Cosign signatures using narrowly scoped OIDC and attestation permissions.
  • Extended the same attestation and signing flow to the Helm chart, including Helm digest extraction and Docker authentication to GHCR.
.github/workflows/checks.yml
.github/workflows/release.yml
.github/workflows/release-chart.yml
Added vulnerability scanning for development builds and published release images with controlled reporting and failure behavior.
  • Added matrix builds and Grype scans for Python 3.11–3.14 on pull requests and pushes to dev.
  • Added an OCI dry run that verifies SPDX SBOM and SLSA provenance manifests before scanning a loaded image.
  • Uploaded all findings to code scanning while failing only on fixable high or critical findings.
  • Added scheduled and manually triggered scans of the latest final release images, with release-specific SARIF categories.
  • Added validation for ignore-rule reasons and expiry dates, including use of dev's ignore file for scheduled release scans.
.github/workflows/images.yml
.grype.yaml
Reduced known image vulnerabilities by removing unnecessary Python build packages.
  • Uninstalled setuptools and wheel from the base image, which are unnecessary for FOCA and vulnerable in the Python 3.11 base image.
docker/Dockerfile
Documented image and chart verification, scanning operations, and the updated release behavior.
  • Documented GitHub attestation and Cosign verification commands, expected workflow identities, digest pinning, and SBOM/provenance inspection.
  • Documented how contributors should remediate or temporarily accept scan findings.
  • Added links and release/chart workflow guidance, including the post-publish failure behavior for chart attestation or signing.
README.md
docs/contributing.md
docs/deployment.md
docs/helm-chart.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7344801) to head (833d372).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #414   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         2777      2777           
=========================================
  Hits          2777      2777           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 22, 2026 22:48

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/release-chart.yml" line_range="149-151" />
<code_context>
+          fi
+          echo "${output}"
+          digest="$(sed -n 's/^Digest: \(sha256:[0-9a-f]\{64\}\)$/\1/p' <<< "${output}")"
+          if [ -z "${digest}" ]; then
+              echo "::error::Could not find the digest of the pushed chart"
+              exit 1
+          fi
+          echo "digest=${digest}" >> "${GITHUB_OUTPUT}"
</code_context>
<issue_to_address>
**Published chart cannot be verified**

When the chart push succeeds but digest parsing, attestation, or signing fails, the workflow exits after publishing the chart, and the already-published check rejects the rerun, leaving the version without its attestation or signature; callers cannot verify it as documented.

Make reruns recover the pushed chart's digest and continue attestation and signing instead of rejecting an already-published version.

Also at `.github/workflows/release-chart.yml:162`.
</issue_to_address>

### Comment 2
<location path=".github/workflows/images.yml" line_range="155" />
<code_context>
         uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
         with:
           python-version: "3.13"
-      - name: Determine version
</code_context>
<issue_to_address>
**Accepted vulnerabilities still fail scans**

When a fixable high or critical vulnerability is added to `.grype.yaml` as an accepted finding, the scan invocations do not pass `.grype.yaml` as Grype’s configuration. Grype therefore does not apply the repository’s ignore rules, so a vulnerability accepted there still appears in the results and can fail the fixable high/critical scan.

Pass `.grype.yaml` to every scan invocation as Grype’s configuration.

Also at `.github/workflows/images.yml:174`, `.github/workflows/images.yml:229`, `.github/workflows/images.yml:244`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and this adds Sigstore signatures and provenance attestations to published image and chart digests, so a mistaken build or signer configuration could leave externally distributed artifacts carrying a misleading trust claim. Reverting stops future runs but does not remove artifacts, signatures, or attestations already published; those need separate remediation.

Blocking findings: .github/workflows/release-chart.yml:151, .github/workflows/images.yml:155


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .github/workflows/release-chart.yml Resolved
Comment thread .github/workflows/images.yml Resolved
uniqueg and others added 5 commits October 23, 2026 00:54
Grype finds .grype.yaml in the working directory on its own; passing it
makes the scans independent of that lookup.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	README.md
#	docs/contributing.md
Use the setup of cloud-registry (#181) instead of Grype: the composite
action .github/actions/scan-image (Trivy 0.75.0 via trivy-action 0.36.0)
and .trivyignore.yaml (accepted findings by purl, with a statement and
an expiry date). CI scans the images of all Python versions in a new
`scan` job of checks.yml, which the dev image job needs; the release
workflow scans the release commit's images again in a job without
credentials before anything is published, and pushes the images by
digest, attests and signs them, and only then tags that digest; the
weekly scan of the latest release moves to scan.yml. Use
actions/attest-build-provenance and step names as in cloud-registry.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before attesting and signing a release image, check that it reports the
release version; decide `latest` from freshly fetched tags merged into
main, and scan the images of the highest such tag weekly, as
cloud-registry does, so that stray tags are ignored.

Refs #403

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit d843c63 into dev Oct 22, 2026
21 checks passed
@uniqueg
uniqueg deleted the ci/403-attest-sign-scan branch October 22, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants