Repository navigation
ci: install locked setuptools-scm in push job - #305
Conversation
The push job of ci.yml, which holds the Docker Hub credentials, installed setuptools-scm unpinned and without hash checks to derive the version of dev images. It now installs the build requirements from uv.lock (dependency group build-system) as the image build does: uv export, then pip install --require-hashes --only-binary :all: --no-deps into a virtual environment of their own. uv comes from astral-sh/setup-uv pinned by commit (v10.3.3, as in foca-plugins), at the version locked in uv.lock, without cache. New tests check that no job with an environment (publishing credentials) in any workflow installs Python packages without hash checks, and how the push job derives the version. release.yml installs no packages (its scripts use the standard library only). Closes #288 Co-Authored-By: Claude Opus 5.5 <[email protected]>
setup-uv verifies uv against its own checksum table only for versions it knows; after the next uv bump in uv.lock, it would fall back to a checksum from the host that serves the binary. The push job now runs the export with the uv image of the Dockerfile instead, pinned by digest (and bumped by Dependabot), without network, as the image build does. The tests also find versioned pip commands, pip wheel and download, and other installers, check options with shlex, find jobs that use Docker Hub secrets without an environment, and run the step's sed command against the Dockerfile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Find pip commands with global options, check each command of a chained line, flag builds that install build requirements (python -m build, uv build) and more installers, count jobs with write or signing permissions as credential jobs, and check that pip installs exactly the exported requirements. Note why the venv's pip is not hash-checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR hardens the credential-bearing push workflow by deriving dev-image versions with the same digest-pinned uv image and locked, hash-verified build requirements used by the Docker build, while adding tests and documentation to prevent regressions. Sequence diagram for locked dev-image version derivationsequenceDiagram
participant Push as CI push job
participant Docker as Docker uv container
participant Lock as pyproject.toml and uv.lock
participant Env as build-env virtualenv
participant SCM as setuptools_scm
participant Output as GITHUB_OUTPUT
Push->>Docker: docker run --network none
Docker->>Lock: uv export --frozen --only-group build-system --no-emit-project
Docker-->>Push: build-requirements.txt
Push->>Env: python -m venv
Push->>Env: pip install --require-hashes --only-binary :all: --no-deps -r requirements
Push->>SCM: python -m setuptools_scm
SCM-->>Push: version
Push->>Output: write version
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 #305 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2356 2356
=========================================
Hits 2356 2356 ☔ 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="tests/test_workflows.py" line_range="273-274" />
<code_context>
+ workflow = _load(path)
+ assert "secrets." not in yaml.safe_dump(workflow.get("env", {})), path
+ for job_id, job in workflow["jobs"].items():
+ permissions = job.get("permissions", {})
+ writes = isinstance(permissions, dict) and any(
+ permissions.get(scope) == "write"
+ for scope in ("id-token", "contents", "packages", "attestations")
</code_context>
<issue_to_address>
**Inherited credential installs escape checks**
When a workflow grants write permissions at workflow scope or a job uses `permissions: write-all`, without an environment or direct Docker Hub secret, `_credential_jobs` reads only job-level permission mappings, so it omits jobs inheriting workflow permissions or using the `write-all` shorthand; their package installs never reach the hash-check assertions, and an unchecked install passes the test.
Include inherited workflow permissions and the `write-all` shorthand when identifying credential jobs.
</issue_to_address>
### Comment 2
<location path="tests/test_workflows.py" line_range="310" />
<code_context>
+# pip (also `pip3`, `pip3.13`, `"<venv>/bin/pip"`, with global options)
+# commands that install or build packages; the latter runs their build
+# backends
+PIP = re.compile(r"\bpip[0-9.]*[\"']?(\s+-\S+)*\s+(install|wheel|download)\b")
+# Other installers, and builds that install build requirements
+INSTALLERS = re.compile(
</code_context>
<issue_to_address>
**Unverified pip installs pass the guard**
When a credential-job pip command uses a global option with a separate value before `install`, `PIP.search` does not match the command, so the credential-job loop skips its hash-check assertions and an unverified package install passes the test.
Update the pip command matcher to recognize value-taking global options and their separate arguments.
</issue_to_address>
### Comment 3
<location path="tests/test_workflows.py" line_range="313-314" />
<code_context>
+PIP = re.compile(r"\bpip[0-9.]*[\"']?(\s+-\S+)*\s+(install|wheel|download)\b")
+# Other installers, and builds that install build requirements
+INSTALLERS = re.compile(
+ r"\b(pipx|easy_install|uvx|pip-sync|poetry|pdm|hatch"
+ r"|uv\s+(pip|tool|sync|run|add|build|venv)|python[0-9.]*\s+-m\s+build)\b"
+)
+
</code_context>
<issue_to_address>
**Pipenv installs evade guard**
When a credential job uses `pipenv install`, `INSTALLERS` does not recognize `pipenv install`, and `PIP` does not match that command either. A credential job can therefore install packages without hash checks and still pass the new guard.
Include pipenv and other package-installing tools the guard is intended to prohibit in the installer detection, with tests for those commands.
</issue_to_address>
### Comment 4
<location path="tests/test_workflows.py" line_range="402-405" />
<code_context>
+ for option in (
+ "--require-hashes",
+ "--no-deps",
+ "-r",
+ "--only-binary",
+ ):
+ assert option in options, where
+ binary = options.index("--only-binary")
+ assert options[binary + 1] == ":all:", where
</code_context>
<issue_to_address>
**Untrusted requirements pass install checks**
When a pip install command supplies an extra requirements file alongside the locked requirements, when a credential job’s pip command includes an additional `-r untrusted.txt`, `test_credential_jobs_install_hash_checked` at lines 398-407 only checks that `-r` and the other option tokens occur; it never checks which requirements files pip receives. The job can install packages outside the exported lock and still pass.
Validate the requirements-file arguments and require them to be exactly the exported locked file.
</issue_to_address>Linked issues
#288 ci: hash-check setuptools-scm in the push job · 2 of 2 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | No job that holds publishing credentials installs Python packages without hash checks. | ✅ Met | The push job exports the locked build-system requirements and installs them with --require-hashes, --only-binary :all: and --no-deps; the new workflow test checks credential-holding jobs across workflows, including that no other installer or build command is used. |
| 2 | Dev image versions are derived as before. | ✅ Met | The push job still derives the version with python -m setuptools_scm before Docker Hub login, now using the locked build requirements; the PR reports matching versions from the old and new methods. |
Sourcery assessment
Needs a human reviewer. 4 findings to address first, and if the locked tools derive the wrong version, the push job could publish a dev image with an incorrect version tag or label. Reverting prevents future bad outputs, but an image already pushed would need to be retagged or cleaned up.
Blocking findings: tests/test_workflows.py:274, tests/test_workflows.py:310, tests/test_workflows.py:314, tests/test_workflows.py:405
Count jobs that inherit write permissions from the workflow or use write-all, find pip commands with option values before the subcommand and pipenv, and allow exactly one requirements file and the hash-check options in installs (review by Sourcery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The
pushjob ofci.ymlholds the Docker Hub credentials (environmentdev-images) and used topip install "setuptools-scm>=8"unpinned and without hash checks to derive the version of dev images. It now installs the build requirements as the image build does:uv export --frozen --only-group build-system --no-emit-project, run with the uv image of theDockerfile(ghcr.io/astral-sh/uv:<tag>@sha256:<digest>, read from theDockerfileby the step, so Dependabot'sdockerentry keeps both in step), in a container without network and withpyproject.tomlanduv.lockmounted read-only;pip install --require-hashes --only-binary :all: --no-deps -rinto a virtual environment of their own, andpython -m setuptools_scmfrom that environment.Why not
astral-sh/setup-uv(as proposed in the issue): the pinned action verifies the uv binary against its own checksum table only for uv versions it knows (up to 0.13.6 at v10.3.3). For newer versions, which Dependabot's lock updates would bring in, it falls back to a checksum taken from the same host that serves the binary. The image digest is an independent pin.release.ymlwas checked for the same pattern: its jobs install no Python packages (the release scripts use the standard library only), so nothing changes there.New tests (
tests/test_workflows.py):id-token/contents/packages/attestations: write) runs pip only aspip install --require-hashes --only-binary :all: --no-deps -r …, and uses no other installer or build (pipx,uv sync/run/pip/tool/build/venv,python -m build, …), with pip found also aspip3.13,"<venv>/bin/pip", with global options, and in chained commands;sedcommand, run against theDockerfile, finds the digest-pinned uv image.Docs:
docs/development.md(Dependencies) and theDockerfilecomment of the uv stage describe CI's use of the same locked tools and image.Closes #288
Verification
setuptools-scm>=8) and the new one (lockedbuild-systemgroup: setuptools-scm 10.3.4, vcs-versioning 2.6.0, setuptools 84.2.1, packaging 26.3) give identical versions:574d569→0.6.1.dev13+g574d569b1(both; also what the last dev CI run 41254921080 labelled the image with),dev~3→0.6.1.dev10+gc0e32774e,dev~10→0.6.1.dev3+g614195cbe.Derive versionscript, extracted fromci.ymland run locally withbash -e(Docker,RUNNER_TEMP,GITHUB_OUTPUTset): pulls the uv image by digest, installs the four wheels hash-checked, outputsversion=0.6.1.dev15+g9dbc220d4. The container export is identical to a hostuv export.devonly, so this PR's CI doesn't run it; the firstdevrun after the merge will be checked (version in the "Derive version" log and the image label).pre-commit run --all-files(incl. actionlint without ShellCheck locally) andgitleaks-all: passed.coverage run -m pyteston the locked dev dependencies (uv sync --frozen --extra dev): 1551 passed, 262 skipped (chart tests: no Helm locally), 100% coverage;tests/test_workflows.pyre-run after the review fixes: 34 passed. New tests fail againstdev'sci.yml.mkdocs build --strict(locked docs dependencies): passed.Push image/Publish imageskipped on pull requests, as intended).Declined review findings
test_dev_version_from_locked_build_requirements(quality, medium): kept textual; the security property is enforced by the stricter, shlex-based credential-job test, and the step'ssedruns for real intest_dev_version_uv_image.test_dev_version_uv_imageneeds GNUsed(quality, medium): as the existing chart-check test needsbashand GNUsha256sum; CI and the documented setup run on Linux.ensurepipof the runner's Python, not hash-checked (quality, low): it is the runner's own Python, nothing downloaded; noted in the step's comment.testjob with unpinned installs (adversarial, low, pre-existing): not a publishing credential; ci: run the tests on the locked dependencies #291 moves that job to the lock.🤖 Generated with Claude Code
Summary by Sourcery
Harden publishing workflows by deriving development image versions with the Dockerfile's digest-pinned uv image and hash-verified locked build requirements.
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: