Skip to content

fix(reusable-trivy): authenticate to GHCR before scanning image-ref - #33

Merged
zircote merged 1 commit into
mainfrom
fix/trivy-image-scan-ghcr-auth
Jul 13, 2026
Merged

fix(reusable-trivy): authenticate to GHCR before scanning image-ref#33
zircote merged 1 commit into
mainfrom
fix/trivy-image-scan-ghcr-auth

Conversation

@zircote

@zircote zircote commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

reusable-trivy.yml's image job failed on go-htmx's v0.1.1 release run (job 86817144520), right after docker-sign/docker-verify both succeeded against the same image digest:

FATAL Fatal error run error: image scan error: scan error: unable to initialize a scan service: unable to initialize artifact: unable to initialize container image: unable to find the specified image "ghcr.io/attested-delivery/go-htmx@sha256:..." in ["docker" "containerd" "podman" "remote"]: 4 errors occurred:
  * docker error: unable to inspect the image: No such image
  * containerd error: permission denied
  * podman error: no podman socket found
  * remote error: GET https://ghcr.io/token?...: UNAUTHORIZED: authentication required

Root cause

image-ref is scanned by digest straight from the registry (there's no local docker/containerd/podman image on the runner), so Trivy falls through to the remote pull path — which needs credentials it never got. The job grants packages: read but never actually logs in to GHCR.

Fix

Add the identical docker/login-action step sign-and-attest.yml already uses for the same registry, before the scan step.

Verification

  • actionlint .github/workflows/reusable-trivy.yml passes clean.
  • Diff is additive-only (one new step); no other job/permission changed.

The `image` job scans `image-ref` by digest directly from the
registry, but never logs in first. Trivy's image-source resolution
tries docker/containerd/podman/remote in order; all four fail on a
runner with no local copy of the image, including the remote pull
("UNAUTHORIZED: authentication required") since it has no
credentials. Add the same docker/login-action step
sign-and-attest.yml already uses for the identical registry.

Confirmed on go-htmx's v0.1.1 release run: gate-image/image failed
with exactly this error immediately after docker-sign/docker-verify
both succeeded against the same image digest.
Copilot AI review requested due to automatic review settings July 13, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes reusable-trivy.yml’s image job failing to scan digest-based image-ref values from GHCR by authenticating to GHCR before running Trivy, enabling Trivy’s remote registry backend to fetch the image.

Changes:

  • Add a pinned docker/login-action step to log in to ghcr.io using GITHUB_TOKEN before the Trivy image scan.
  • Document why authentication is required for digest-based remote scans (and align with sign-and-attest.yml behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zircote
zircote merged commit ee1f93b into main Jul 13, 2026
2 checks passed
zircote added a commit to attested-delivery/go-htmx that referenced this pull request Jul 13, 2026
* changelog: add v0.1.2 — complete container attestation set

v0.1.1's container image is signed with SLSA provenance and an SBOM
attestation but is missing the vulnerability-scan attestation (the
reusable-trivy.yml GHCR-auth bug fixed at attested-delivery/.github#33
and picked up in this repo's pin bump). v0.1.2 ships the same code
with the pipeline fix, completing the attestation set.

* changelog: fix wording — gate-image is a job, not a step
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