Skip to content

Fetch Trivy directly rather than through setup-trivy - #1

Merged
rad-pat merged 1 commit into
mainfrom
trivy-install-without-tag-lookup
Sep 7, 2026
Merged

rad-pat merged 1 commit into
mainfrom
trivy-install-without-tag-lookup

Conversation

@rad-pat

@rad-pat rad-pat commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

The failure

A plaid license job failed with:

aquasecurity/trivy info checking GitHub for tag 'v0.70.0'
aquasecurity/trivy crit unable to find 'v0.70.0'

The message is a red herring. v0.70.0 was never gone — it returns 200 today, and the same job installed it successfully twice before losing the third attempt forty seconds later:

Step Result
rpc found version: 0.70.0
rpc-import found version: 0.70.0
udf unable to find 'v0.70.0'

setup-trivy shells out to Trivy's contrib/install.sh, which resolves a tag like this:

giturl="https://github.com/${owner_repo}/releases/${version}"
json=$(http_copy "$giturl" "Accept:application/json")
test -z "$json" && return 1        # any non-200 becomes "unable to find"

Unauthenticated, no retry, no token. A rate-limited moment arrives looking like a deleted release, and the error points at the version pin rather than the network.

Two things made it likely rather than rare: the action ran setup-trivy on every invocation, and plaid calls it seven times in one job — while setup-trivy's cache input defaults to false, which we never overrode. Seven unauthenticated lookups and seven tarball downloads per run, from a shared runner IP.

The change

A release asset URL needs no tag lookup, so the action installs Trivy itself:

  • Direct download with curl --retry 5 --retry-delay 2 --retry-all-errors --fail.
  • Verified against license-check/trivy-checksums.txt — the release's own checksums file, committed here.
  • The tarball is cached, under trivy-tarball-<version>-<os>-<arch>.
  • Installed once per job. The version names the install directory, so those seven invocations install Trivy once. Seven lookups become none.

Verification runs on every path, including a cache hit

This is the part worth reviewing. A cache entry is written by anyone who can run a workflow on the repo, so a Trivy trusted on sight is a scanner someone else chose — and one that fabricated a clean report would satisfy check_licenses.py's completeness check too, by reading the very same .dist-info the check counts.

setup-trivy skipped its own checksum on a cache hit for the same reason it skipped the download. This closes that path rather than reproducing it. The tarball is what gets cached precisely because it is the thing the committed checksums can vouch for.

The checksums are committed rather than fetched: pulled from the network beside the tarball they would vouch for transit only; read from the cache they would be chosen by whoever wrote the cache. So trivy-version must name a release whose checksums live here — which makes a scanner bump a reviewed change rather than a silent one, consistent with why the version was pinned in the first place.

Trivy is unpacked via mktemp + mv, so the install dir either has no binary or a whole verified one — never a half-extracted one the same-job check would read as installed.

Verified

Step scripts run against real Linux (WSL), not eyeballed:

Case Result
Cold: download → verify → unpack OK, binary -rwxr-xr-x, Version: 0.70.0
Second invocation, same job installed=true, short-circuits
Cache-restore path, no download step verified, unpacked, Version: 0.70.0
Tampered tarball FAILED, refused, no binary left behind
Version the committed checksums don't cover refused with a clear error
latest / unknown arch refused with a clear error

Plus a green CI run on the previous revision that showed the real-runner behaviour: cache miss → save → invocation 2 logged no cache lines and no download, then scanned all 9 packages 0.9s later.

The end-to-end job now calls the action twice. The repeat invocation is a real code path — it is what uv venv --clear exists for, and what decides whether Trivy installs once or once per file — and nothing covered it.

This is not a version bump

The pin stays at v0.70.0. Bumping would not have fixed this: every version resolves through the same flaky lookup, and latest is worse, since setup-trivy refuses to cache it. Trivy is on 0.74.0 now and that is worth doing as its own reviewed decision — the diagnostics input exists for exactly that.

For a reviewer

  • Behaviour change: trivy-version: latest now fails fast. Nothing in the org appears to pass it.
  • Changing trivy-version now also needs that release's checksums committed here. Deliberate; it fails loudly, not quietly.
  • Dropped with setup-trivy: its github-server-url/token inputs (GHES only) and the contrib/*.tpl templates it staged beside the binary. We only use --format json. Noted in the README.
  • Not covered: Trivy publishes Sigstore signatures for its assets; neither the old nor the new install checks them. The ceiling here is SHA256, not release authenticity.
  • This needs the v1 tag moving to reach the ten repos on @v1.

🤖 Generated with Claude Code

https://claude.ai/code/session_016wvVVoc2oj2bof9gmq6ZED

setup-trivy resolves a tag by making one unauthenticated, un-retried
request to github.com and reporting any non-200 as "unable to find
<tag>", so a rate-limited moment arrives looking like a deleted release.
A plaid job installed v0.70.0 successfully twice and lost the third
attempt forty seconds later; the error named the pin rather than the
network, which sent the reader after the wrong thing entirely.

A release asset URL needs no tag lookup. The install now downloads the
tarball directly with curl --retry and verifies it against this repo's
committed copy of the release checksums. The version also names the
install directory, which makes an earlier invocation in the same job
visible: a repo scanning several requirements files installs Trivy once
rather than once per file, so the seven lookups that job made become
none.

The tarball is what gets cached, and the verification runs on a cache
hit as well as a fresh download. A cache entry is written by anyone who
can run a workflow on the repo, so a Trivy trusted on sight is a scanner
someone else chose -- and one that fabricated a clean report would
satisfy the completeness check too, by reading the very same dist-info
the check counts. setup-trivy skipped its own checksum on a cache hit
for the same reason it skipped the download; this closes that path
rather than reproducing it.

The checksums are committed rather than fetched: pulled from the network
beside the tarball they would vouch for transit only, and read from the
cache they would be chosen by whoever wrote the cache. trivy-version
must therefore name a release whose checksums are committed here, which
makes a scanner bump a reviewed change rather than a silent one.

`latest` is refused. It was never a sensible thing for a compliance gate
to track, and there is no longer a tag to resolve.

Trivy is unpacked via mktemp and mv, so the install directory either has
no binary or a whole verified one -- never a half-extracted one that the
same-job check would read as installed.

The end-to-end job now calls the action twice. The repeat invocation is
a real code path -- it is what `uv venv --clear` exists for, and what
decides whether Trivy installs once or once per file -- and nothing
covered it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wvVVoc2oj2bof9gmq6ZED
@rad-pat
rad-pat force-pushed the trivy-install-without-tag-lookup branch from b45c307 to 4ad2886 Compare September 7, 2026 16:34
@rad-pat
rad-pat marked this pull request as ready for review September 7, 2026 18:35
@rad-pat
rad-pat merged commit 53a843c into main Sep 7, 2026
2 checks passed
@rad-pat
rad-pat deleted the trivy-install-without-tag-lookup branch September 7, 2026 18:37
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.

1 participant