Skip to content

ci: install locked setuptools-scm in push job - #305

Merged
uniqueg merged 5 commits into
devfrom
ci/hash-check-scm
Nov 1, 2026
Merged

uniqueg merged 5 commits into
devfrom
ci/hash-check-scm

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

The push job of ci.yml holds the Docker Hub credentials (environment dev-images) and used to pip 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 the Dockerfile (ghcr.io/astral-sh/uv:<tag>@sha256:<digest>, read from the Dockerfile by the step, so Dependabot's docker entry keeps both in step), in a container without network and with pyproject.toml and uv.lock mounted read-only;
  • then pip install --require-hashes --only-binary :all: --no-deps -r into a virtual environment of their own, and python -m setuptools_scm from 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.yml was 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):

  • every job that holds publishing credentials (has an environment, uses a Docker Hub secret, or has id-token/contents/packages/attestations: write) runs pip only as pip 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 as pip3.13, "<venv>/bin/pip", with global options, and in chained commands;
  • the push job derives the version from the exported locked requirements, before logging in to Docker Hub;
  • the step's sed command, run against the Dockerfile, finds the digest-pinned uv image.

Docs: docs/development.md (Dependencies) and the Dockerfile comment of the uv stage describe CI's use of the same locked tools and image.

Closes #288

Verification

  • Dev image versions unchanged: on the same commits, the old method (unpinned setuptools-scm>=8) and the new one (locked build-system group: 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.
  • The exact Derive version script, extracted from ci.yml and run locally with bash -e (Docker, RUNNER_TEMP, GITHUB_OUTPUT set): pulls the uv image by digest, installs the four wheels hash-checked, outputs version=0.6.1.dev15+g9dbc220d4. The container export is identical to a host uv export.
  • The push job runs on pushes to dev only, so this PR's CI doesn't run it; the first dev run 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) and gitleaks-all: passed.
  • coverage run -m pytest on the locked dev dependencies (uv sync --frozen --extra dev): 1551 passed, 262 skipped (chart tests: no Helm locally), 100% coverage; tests/test_workflows.py re-run after the review fixes: 34 passed. New tests fail against dev's ci.yml.
  • mkdocs build --strict (locked docs dependencies): passed.
  • zizmor: not installed locally.
  • CI: all checks passed (run 41276587053; Push image/Publish image skipped on pull requests, as intended).

Declined review findings

  • Substring checks of the export command in 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's sed runs for real in test_dev_version_uv_image.
  • test_dev_version_uv_image needs GNU sed (quality, medium): as the existing chart-check test needs bash and GNU sha256sum; CI and the documented setup run on Linux.
  • The venv's pip comes from ensurepip of the runner's Python, not hash-checked (quality, low): it is the runner's own Python, nothing downloaded; noted in the step's comment.
  • Codecov token in the test job 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:

  • Ensure the CI push job derives development image versions using the locked build requirements instead of an unpinned setuptools-scm installation.

Enhancements:

  • Enforce hash-checked, wheel-only package installation in all jobs holding publishing credentials.
  • Reuse the Dockerfile's digest-pinned uv image to export locked build requirements without network access.
  • Add workflow tests that detect unsafe installers, validate locked version derivation, and verify the pinned uv image.
  • Document the shared locked build tooling and uv image used by image builds and CI.

CI:

  • Harden CI package installation and version derivation in publishing jobs.

Documentation:

  • Update development and Dockerfile documentation to describe CI's locked build requirements and shared uv image.

Tests:

  • Add workflow security tests covering credential-bearing jobs, hash-checked installations, version derivation ordering, and digest-pinned uv usage.

uniqueg and others added 4 commits November 1, 2026 03:49
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]>
@uniqueg uniqueg added this to the v1.0.0-rc1 milestone Nov 1, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 derivation

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Replace the push job’s unpinned setuptools-scm installation with an isolated, locked, hash-verified build-tool installation that mirrors the Docker image build.
  • Extract the digest-pinned uv image reference from the Dockerfile.
  • Run locked build-requirement export in a network-disabled container with read-only project and lockfile mounts.
  • Install the exported wheels into a dedicated virtual environment using pip hash checks, binary-only mode, and no dependency resolution.
  • Derive and publish the dev-image version from that environment before Docker Hub login.
.github/workflows/ci.yml
Add workflow-level regression tests that enforce secure package installation in jobs with publishing credentials and validate the version-derivation implementation.
  • Identify credential-bearing jobs from environments, Docker Hub secrets, and write permissions.
  • Parse chained shell commands and detect pip installers, alternative installers, and package builds.
  • Require credential-bearing jobs to use only hash-checked, wheel-only, no-dependency installs from requirement files.
  • Verify the push job derives its version before registry login and uses the locked build group and digest-pinned uv image.
tests/test_workflows.py
Document that CI and the Docker build share locked build requirements and the Dockerfile’s pinned uv image.
  • Update Dockerfile comments to identify CI’s reuse of the uv stage image.
  • Describe the locked, hash-checked CI installation and coordinated Dependabot updates.
  • Clarify that pyproject build requirements and the build-system dependency group remain synchronized.
Dockerfile
docs/development.md
pyproject.toml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c15a334) to head (0e34b83).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 1, 2026 05:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_workflows.py Resolved
Comment thread tests/test_workflows.py Resolved
Comment thread tests/test_workflows.py Resolved
Comment thread tests/test_workflows.py Resolved
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]>
@uniqueg
uniqueg merged commit 777a704 into dev Nov 1, 2026
19 checks passed
@uniqueg
uniqueg deleted the ci/hash-check-scm branch November 1, 2026 06:16
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.

ci: hash-check setuptools-scm in the push job

1 participant