Repository navigation
ci: hash-check setuptools-scm in the push job - #378
Conversation
The push job holds the Docker Hub credentials and installed setuptools-scm unpinned. It now exports the dependency group build-system (the same as build-system.requires) from uv.lock with the uv image of the Dockerfile, pinned by digest and run without network, and installs it with `pip install --require-hashes --only-binary :all: --no-deps` into a virtual environment of its own. The uv stage is new and unused by the image build; Dependabot's docker entry updates it. Tests check that jobs with publishing credentials install only hash-checked requirements, that the push job derives the version from the exported lock before logging in, that the step finds the pinned uv image, and that the group matches build-system.requires. Closes #376 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test compares the locked group with the names of build-system.requires; the docs name the runner's pip as the one unchecked tool of the push job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR secures dev-image version derivation by exporting build requirements from uv.lock with a digest-pinned, network-isolated uv image, installing them hash-checked in an isolated environment before credential use, and adding dependency consistency, image-pin, and credential-job regression tests. Sequence diagram for hash-checked dev-image version derivationsequenceDiagram
participant Push as push job
participant Docker as Docker
participant UV as Digest-pinned uv image
participant Pip as Isolated pip environment
participant SCM as setuptools_scm
participant Hub as Docker Hub
Push->>Docker: docker run --network none
Docker->>UV: export --frozen --only-group build-system --no-emit-project
UV-->>Push: build-requirements.txt from uv.lock
Push->>Pip: pip install --require-hashes --only-binary :all: --no-deps -r
Pip->>SCM: python -m setuptools_scm
SCM-->>Push: version
Push->>Hub: Docker login
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #378 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 2217 2217
=========================================
Hits 2217 2217 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/development.md" line_range="135" />
<code_context>
+(`build-system.requires`) are locked the same way, as the dependency group
+`build-system`: CI's `push` job derives the version of dev images with
+them, exported by the uv image of the `Dockerfile` (pinned by digest) and
+installed with hash checks, so that no job that holds publishing
+credentials installs a package without hash checks (the tests check this;
+the pip that installs them is that of the runner's Python, `ensurepip`,
</code_context>
<issue_to_address>
**Credentialed builds install unhashed packages**
When a credentialed push or release job builds the image, the Docker build runs the Dockerfile's `pip install` commands for runtime dependencies without hash checks, while the test scans only workflow `run` commands. The stated credential-job guarantee is therefore false even when the test passes.
Add hash checks to the Dockerfile installs and extend the test to cover installs performed during image builds.
Also at `tests/test_workflows.py:629-630`, `docs/development.md:136-137`.
</issue_to_address>
### Comment 2
<location path="tests/test_workflows.py" line_range="680" />
<code_context>
+ (with hash checks, see `test_credential_jobs_install_hash_checked`).
+ """
+ script = " ".join(_commands(_derive_version()))
+ assert '"${uv_image}" export --frozen --only-group build-system' in script
+ assert "--no-emit-project" in script
+ assert "--network none" in script
</code_context>
<issue_to_address>
**Unpinned export can supply requirements**
When the script retains the expected pinned export but later overwrites its requirements file using an unpinned, network-enabled export, `test_dev_version_from_locked_build_requirements` checks for the pinned export, network restriction and output redirection as separate substrings, without checking that they belong to the same command or that this command is the final writer. A later export from an unpinned, network-enabled image can overwrite the requirements file and still pass, so pip installs requirements from an unverified exporter.
Parse the export commands and assert that the sole command producing the file pip reads uses the pinned image and network isolation.
</issue_to_address>
### Comment 3
<location path="tests/test_workflows.py" line_range="664" />
<code_context>
+ The step.
+ """
+ jobs = _load(WORKFLOWS / "ci.yml")["jobs"]
+ steps = {step["name"]: step for step in jobs["push"]["steps"]}
+ names = list(steps)
+ # Before the job logs in to Docker Hub
</code_context>
<issue_to_address>
**Duplicate names bypass login ordering**
When the `push` job contains a second step named `Derive version` after `Log in to Docker Hub`, `_derive_version` overwrites duplicate step names in `steps` but preserves the key’s first insertion position. `test_dev_version_from_locked_build_requirements` can therefore validate a later “Derive version” step while the ordering assertion sees the earlier one, allowing version derivation after Docker Hub login to pass.
Assert step-name uniqueness before building the dictionary, or compare the actual step indexes directly.
</issue_to_address>
### Comment 4
<location path="tests/test_workflows.py" line_range="654" />
<code_context>
+ file = options.index("-r")
+ assert options[file + 1].startswith("$"), where
+ rest = options[:file] + options[file + 2 :]
+ assert rest == HASH_CHECKED, where
+
+
</code_context>
<issue_to_address>
**Safe option reordering fails**
When a credentialed job uses the same required pip options in a different order, `test_credential_jobs_install_hash_checked` compares the parsed options to `HASH_CHECKED` in one fixed order. A valid `pip install` with the same hash, wheel-only and no-dependency options reordered fails this assertion despite preserving the tested behavior.
Compare the parsed options as an order-independent collection while still checking duplicates and the `:all:` argument.
</issue_to_address>Linked issues
#376 ci: hash-check setuptools-scm in the push job · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Lock build-system.requires as the build-system dependency group in uv.lock. | ✅ Met | The group matches build-system.requires, and the workflow test checks that its dependencies are present in the lock. |
| 2 | Export the locked group with a digest-pinned uv image, without network access. | ✅ Met | The push job extracts the digest-pinned uv image from the Dockerfile and runs the frozen export with networking disabled. |
| 3 | Install the exported requirements into their own virtual environment with hash checks, wheels only, and no dependency resolution. | ✅ Met | The job uses pip with --require-hashes, --only-binary :all:, and --no-deps, then runs setuptools-scm from that environment. |
| 4 | Check release.yml for the same pattern. | ✅ Met | The release workflow runs Python scripts but does not install Python packages. |
| 5 | Ensure no job holding publishing credentials installs Python packages without hash checks, and check this with tests. | ✅ Met | The new test scans credential-bearing jobs across the workflow files and requires pip installs to use hash-checked requirements. |
| 6 | Derive dev image versions as before. | ✅ Met | The push job still runs setuptools-scm from the repository checkout and passes its version to the image build; the new test checks that derivation uses the locked requirements. |
Sourcery assessment
Needs a human reviewer. 3 findings to address first, and if the locked build tools or version derivation produce the wrong value, the push job could publish a dev image under an incorrect version tag. That artifact can outlive a revert, but the tag can be removed or corrected by rebuilding and republishing.
Blocking findings: docs/development.md:135, tests/test_workflows.py:680, tests/test_workflows.py:664
The image build in the credential jobs still installs from ranges (#365); the docs say so. The test of the push job requires unique step names, so that the order checked is that of the step it validates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The
pushjob ofci.ymlholds the Docker Hub credentials (environmentdev-images) and ranpip install "setuptools-scm>=8", unpinned and without hash checks, to derive the version of dev images. Following cloud-registry#305 (#288 there), it now:build-system(new inpyproject.toml, equal tobuild-system.requires, locked inuv.lock) withuv export --frozen --only-group build-system --no-emit-project, run with the uv image pinned by digest in theDockerfile(ghcr.io/astral-sh/uv:0.13.6@sha256:…, as in cloud-registry). The container has no network and mountspyproject.tomlanduv.lockread-only;pip install --require-hashes --only-binary :all: --no-deps -rinto a virtual environment of its own, then runspython -m setuptools_scmfrom it.The
uvstage of theDockerfileis new and isn't used by the image build: no build passes atarget, so BuildKit skips it. It exists so that Dependabot'sdockerentry updates the tag and the digest together. Installing the image itself from the lock is still #365.release.ymlwas checked: its jobs install no Python packages.New tests (
tests/test_workflows.py):pip install --require-hashes --only-binary :all: --no-deps -r <exported file>, and no other installer;sedfinds the digest-pinned uv image in theDockerfile;build-systemgroup equalsbuild-system.requiresand is locked.Docs:
docs/development.md(Dependencies) and comments inDockerfile,pyproject.tomland.github/dependabot.yml.Closes #376
Verification
Derive versionscript, extracted fromci.ymland run locally withbash -e(Docker,RUNNER_TEMP,GITHUB_OUTPUTset): pulls the uv image by digest and installs packaging 26.3, setuptools 84.2.1, setuptools-scm 10.3.4 and vcs-versioning 2.6.0, all hash-checked. It outputs the same version as the old method on the same tree (0.3.1.dev37+gaa5da02a9.d20261101for both).tests/test_workflows.py: 67 passed (after review fixes).tests/test_build.pyandtests/test_check_release_pins.py: passed.uv lock --check: passed.pre-commit run --all-files: passed.dev, so this PR's CI doesn't run it. The firstdevrun after the merge will be checked: the version in the "Derive version" log and the image label.Push imageskipped on pull requests). Sourcery: four threads; docs scope and step-name uniqueness fixed, exporter-overwrite and option-order findings answered (tests guard regressions; one exact form on purpose).Declined review findings
test_dev_version_from_locked_build_requirements(quality, medium): kept, as in cloud-registry. The security property is enforced by the stricter, shlex-based credential-job test.sedregex exists in both the step and the test, and the test needs GNUsed(quality, medium): the test runs the step's ownsed, so the two copies can't drift unnoticed. CI runs on Linux.docs/development.mdis long (quality, low): kept, matching cloud-registry.🤖 Generated with Claude Code