Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ jobs:
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: "1"
version: v0.70.0
version: v0.75.0


# Advisory only: reports newer upstream releases without gating any merge. Scheduled so
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ jobs:
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: "1"
version: v0.70.0
version: v0.75.0

# Pushed by digest only: the tags move to the digest once its provenance is attested, so
# a tag never names an unattested image and a failed attestation is retried by a re-run.
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/1499.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Fixed
- CI's and the release's Service image scans run Trivy 0.75.0, the version `tools.lock` pins for `devops install-tools`, instead of 0.70.0, and a workflow contract test fails whenever an `aquasecurity/trivy-action` step's `version` differs from the lock (#1499).
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Task: CI's Trivy scans run the Trivy version tools.lock pins (#1499)

**Issue**: [#1499](https://github.com/dan-petty/devops-cli/issues/1499)
**Status**: Done
**Milestone**: v0.2.32
**Scope**: type/bug, scope/ci

## Description

- Both `aquasecurity/trivy-action` steps, the Service Image scan in `.github/workflows/ci.yml` and in `.github/workflows/release.yml`, now pass `version: v0.75.0` instead of `v0.70.0`, so CI scans with the Trivy `devops install-tools` installs.
- `tools.lock`'s `[binary.trivy].version` is the single source for Trivy's version: a workflow contract test fails whenever a `trivy-action` step's `version` differs from it, so a lock bump fails CI until the workflows match. The lock's header names the workflows in its bump procedure.

## Acceptance Criteria

- [x] Both `trivy-action` steps pass `version: v0.75.0` (`ci.yml`, `release.yml`).
- [x] `test_every_trivy_scan_runs_the_trivy_tools_lock_pins` in `tests/test_workflow_contracts.py` failed on the unfixed tree with v0.70.0 against 0.75.0, and passes now.
- Pending a person: the Service image scan with Trivy v0.75.0. An item PR into release/v0.2.32 does not run ci.yml's Service Image job (it needs `base_ref == main` or `workflow_dispatch`). Run:
1. `gh workflow run ci.yml --ref fix/1499-ci-trivy-version-from-tools-lock`
2. `gh run list --workflow ci.yml --branch fix/1499-ci-trivy-version-from-tools-lock --event workflow_dispatch --limit 1`
3. `gh run watch <id>`

In the Service Image job, the "Scan Service Image for Vulnerabilities" step must install Trivy v0.75.0 and pass. Once #1486 has removed the release-PR skip, the v0.2.32 release PR into main runs the same scan by itself.

## Deliverables

- [x] `.github/workflows/ci.yml` and `.github/workflows/release.yml`: the Service Image scan's `trivy-action` step passes `version: v0.75.0`.
- [x] `tests/test_workflow_contracts.py`: `test_every_trivy_scan_runs_the_trivy_tools_lock_pins`.
- [x] `src/devops_cli/tools_lock/tools.lock` header: Trivy's version is also the `version` of every `aquasecurity/trivy-action` step in `.github/workflows/`, and the bump procedure runs `tests/test_workflow_contracts.py`.
- [x] `changelog.d/1499.md` under `### Fixed`.
9 changes: 5 additions & 4 deletions src/devops_cli/tools_lock/tools.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
# the release asset's `digest` (`gh api repos/<owner>/<repo>/releases/tags/<tag>`), checked
# against the publisher's checksum file. Where the release has no digest, the publisher's file
# alone gives it: popeye's `checksums.sha256`, get.helm.sh's `<archive>.sha256sum` and
# dl.k8s.io's `kubectl.sha256`.
# dl.k8s.io's `kubectl.sha256`. Trivy's version is also the `version` of every
# `aquasecurity/trivy-action` step in `.github/workflows/`.
#
# To bump a Python tool, set its `version` here and in `<name>.in`, then, in this directory, run
# uv pip compile --universal --generate-hashes --python-version 3.14 <name>.in -o <name>.txt
# Bandit's version is the project's dev dependency in pyproject.toml.
#
# Then run `uv run pytest tests/test_tools_lock.py tests/test_install_tools.py`, and
# `devops install-tools --target-dir <dir>` followed by `devops install-tools --check --target-dir
# <dir>` to install and confirm every pin.
# Then run `uv run pytest tests/test_tools_lock.py tests/test_install_tools.py
# tests/test_workflow_contracts.py`, and `devops install-tools --target-dir <dir>` followed by
# `devops install-tools --check --target-dir <dir>` to install and confirm every pin.

python_version = "3.14"

Expand Down
15 changes: 15 additions & 0 deletions tests/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import pytest
import yaml

from devops_cli.tools_lock import load_tools_lock

WORKFLOWS_DIR = Path(".github/workflows")
RELEASE_PATH = WORKFLOWS_DIR / "release.yml"

Expand Down Expand Up @@ -81,3 +83,16 @@ def test_release_workflow_attest_build_provenance_mutation() -> None:

with pytest.raises(AssertionError, match="has subject-digest without subject-name"):
_assert_attest_build_provenance_contract(mutated)


def test_every_trivy_scan_runs_the_trivy_tools_lock_pins() -> None:
"""CI's Trivy scans run the Trivy `devops install-tools` installs, so CI and local scans agree (#1499)."""
pinned = f"v{load_tools_lock().binary['trivy'].version}"

assert [
(path.name, job_id, step.get("with", {}).get("version"))
for path in sorted(WORKFLOWS_DIR.glob("*.yml"))
for job_id, step in _extract_steps_with_action(
_load_workflow(path), "aquasecurity/trivy-action"
)
] == [("ci.yml", "service-image", pinned), ("release.yml", "service-image", pinned)]
Loading