Repository navigation
build: hash-check the build backend in the image - #289
Conversation
Lock the build requirements of the app (`build-system.requires`) in `uv.lock` as the dependency group `build-system`, and build the app's wheel in a build stage: the requirements are installed from the lock with `--require-hashes` into a virtual environment, and the wheel is built with them, without build isolation, index or network. The image installs only the wheel, without index or network, so the image build downloads nothing without a hash check. Dependabot's `uv` entry keeps updating the build requirements with the rest of the lock. Tests check that the group matches `build-system.requires`, that the locked build requirements are hashed, and that every pip command of the `Dockerfile` checks hashes or has no index (and no network). Closes #282 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Recognize `pip3` and `pip3.X` too, reject heredocs in `RUN` (they would hide their commands from the checks), and drop exact counts of build steps. Reword the docs on the `build-system` group. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Find pip the same way in both image build checks (also `pip3` steps must have no network), reject heredocs after line continuations too, and rewrap the Dependabot paragraph of the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR makes image builds fully hash-checked and network-isolated by locking the app’s build requirements in uv, building the application wheel in a dedicated offline stage, and installing only that wheel in the final image; accompanying tests enforce dependency parity, hash coverage, uv mounting, and Dockerfile download safeguards. Sequence diagram for the offline wheel buildsequenceDiagram
participant U as uv
participant B as build stage
participant E as build venv
participant W as wheel
participant I as final image
B->>U: export --frozen --only-group build-system
U-->>B: hashed build requirements
B->>E: pip install --require-hashes --only-binary :all: --no-deps
B->>W: pip wheel --no-index --no-build-isolation --check-build-dependencies
Note over B,W: RUN --network=none
W->>I: pip install --no-index --no-deps
Note over I,W: RUN --network=none
File-Level Changes
Assessment against linked issues
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 #289 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2321 2321
=========================================
Hits 2321 2321 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pyproject.toml" line_range="158" />
<code_context>
+# image build installs them hash-checked instead of downloading them into an
+# isolated build environment (`Dockerfile`); Dependabot updates them with the
+# other locked packages
+build-system = ["setuptools>=77", "setuptools-scm>=8"]
+
[project.readme]
</code_context>
<issue_to_address>
**Build backend updates can be missed**
When dependabot's `uv` resolver does not recognize PEP 735 dependency groups for updates, dependabot's `uv` resolver does not treat PEP 735 dependency groups as updateable dependencies, so its configured updates leave the build-only requirements unchanged and the promised lock updates do not arrive.
Verify that Dependabot updates this group in practice, and add a supported update mechanism if it does not.
Also at `.github/dependabot.yml:8`.
</issue_to_address>
### Comment 2
<location path="tests/test_image_build.py" line_range="93" />
<code_context>
+ assert match, run
+ options, commands = match.groups()
+ runs.append(
+ (options.split(), [command.strip() for command in commands.split("&&")])
+ )
+ return runs
</code_context>
<issue_to_address>
**Unchecked pip download passes test**
When a Dockerfile RUN command chains an unchecked pip invocation after `;` or a pipe, `test_downloads_hash_checked` validates only the first pip invocation in each parsed command: `_runs` splits on `&&`, and `_pip_args` returns the first match. A later unchecked pip invocation after `;` or a pipe therefore goes unchecked, and the test passes.
Parse shell commands so every pip invocation is checked, including those separated by other shell operators.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: pyproject.toml:158, tests/test_image_build.py:93
Split the commands of `RUN` instructions on `||`, `;` and `|` too, not only on `&&`, so that a chained pip command can't pass unchecked (Sourcery review). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #282.
The image build no longer downloads anything without a hash check:
build-system.requires:setuptools,setuptools-scm) are now also a PEP 735 dependency group,build-system, souv.locklocks them (and their dependenciesvcs-versioning,packaging) with hashes. A test keeps the group andbuild-system.requiresidentical.buildstage (from the same pinned base image) exports that group with uv (mounted, as before), installs it withpip install --require-hashes --only-binary :all: --no-depsinto a venv (pip fromensurepip, no download), and builds the wheel withpip wheel --no-index --no-build-isolation --check-build-dependenciesunderRUN --network=none.--no-index --no-deps,--network=none, mounted from the build stage). The runtime dependency step is unchanged;scripts/image_requirements.pyis untouched.SETUPTOOLS_SCM_PRETEND_VERSIONstays a build argument, now of the build stage; uv is still never in the image.Why a dependency group (Dependabot): Dependabot's
uventry already maintainsuv.lock; with the group in the lock, the build requirements are updated by the same entry and group (python-dependencies), with hashes, and no second ecosystem is needed. A hashedrequirements.txtunder Dependabot'spipecosystem would add a second lock format, and apipentry for/would also pick uppyproject.toml. uv'sbuild-constraint-dependenciesaren't hash-locked inuv.lock, so that wouldn't do.Image contents: compared file by file (md5) with an image built from
dev: identical, exceptcloud_registry-*.dist-info/direct_url.jsonandRECORD(installed from a wheel file now, not a source dir), and a few stray stdlib.pycfiles that the old in-image build left behind (image about 0.6 MB smaller). Config, labels, user, command and health check are the same.How it was verified
pytestwith coverage (as in CI, mongomock): 1519 passed, 262 skipped (Helm/MongoDB-dependent), coverage 100%. New tests intests/test_image_build.pyfail ondevand pass here.pre-commit run --all-files: all hooks pass.docker build --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0+cr282: builds; build log shows only hash-checked downloads; app reports0.0.0+cr282; nosetuptools,setuptools-scmoruvin the image;/tmpempty.setuptools-scmremoved from the group (and relocked), the build fails at the wheel step (Some build dependencies for file:///tmp/src are missing: 'setuptools-scm>=8'), so the build doesn't fall back to downloads.0.0.0+compose, Swagger UI 200; removed afterwards.not found, while Smoke test pulled the same digest); a re-run passed.Declined review findings
_pinned,_runs,_pip_args); they're exercised by the tests that use them, and the tightened checks were probed with modified Dockerfiles (e.g.pip3 installwithout--network=nonefails the tests).Dockerfilecomments; kept, as the repo documents the build steps in place.pushjob installssetuptools-scmunhashed to derive the dev version, in a job with Docker Hub credentials. Out of scope for the image build; follow-up ci: hash-check setuptools-scm in the push job #288.Unverified
uvsupport picks up packages that only a PEP 735 dependency group requires. They are inuv.lock, which Dependabot updates; the first monthly run will show it.🤖 Generated with Claude Code
Summary by Sourcery
Build and install the application wheel entirely from hash-locked dependencies without allowing unchecked network downloads.
New Features:
Bug Fixes:
Enhancements:
build-system.requiresand that Dockerfile package operations remain hash-checked and network-isolated.Documentation:
Tests:
Chores: