Skip to content

fix(security): build images from hashed lock files (Fixes #121) - #215

Merged
OkiriGabriel merged 1 commit into
mainfrom
fix/hashed-lockfile-121
Nov 26, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
fix/hashed-lockfile-121

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Fixes #121.

Problem

Every image build installed requirements.txt's open >= ranges, so it pulled whatever was newest on PyPI that day, unpinned and unhashed. A malicious release live for even two hours (the LiteLLM 1.107.0 incident) would have gone straight into our images, and two builds of the same commit could differ.

Change

Item
requirements.lock, middleware/requirements.lock Every package, including transitive ones (103 for the agent), pinned with sha256 hashes. Universal across Linux/macOS and amd64/arm64: the agent for Python 3.10+ (CI matrix and image), the middleware for 3.12+ (its image; FastAPI there needs 3.11+).
scripts/lock.sh uv pip compile --universal --generate-hashes. A plain run keeps existing pins and is stable (checked: same output twice). --upgrade moves to the newest allowed versions.
docker/Dockerfile, middleware/Dockerfile pip install --require-hashes --no-deps -r requirements.lock: nothing outside the lock, and every file must match its hash.
CI job Dependency Lock Fails if a lock doesn't match requirements.txt; installs with hashes enforced plus pip check; runs the full test suite on the locked versions; runs pip-audit --strict on both locks (blocking).
.github/workflows/lock-refresh.yml Weekly and on demand: scripts/lock.sh --upgrade, then opens or updates a deps/lock-refresh PR, so upgrades are reviewed.
dependabot.yml The pip entries are removed (Dependabot can't regenerate this lock, and its range bumps would fail the lock check). It still manages GitHub Actions and base images, and Dependabot security alerts are unaffected.
CONTRIBUTING.md New "Dependencies (hashed lock files)" section.

Verified locally

  • A fresh Python 3.12 venv installs --require-hashes --no-deps -r requirements.lock, and pip check is clean. 1429 passed, 4 skipped against the locked versions.
  • Tamper test: with structlog's hashes replaced, pip refuses with THESE PACKAGES DO NOT MATCH THE HASHES and installs nothing.
  • pip-audit -r … --require-hashes --strict: no known vulnerabilities in either lock.

Notes

- requirements.lock and middleware/requirements.lock pin every package
  (transitive included) with sha256 hashes, generated by scripts/lock.sh
  (uv pip compile --universal --generate-hashes; agent for Python 3.10+,
  middleware 3.12+). Re-running keeps existing pins, so output is stable.
- Both Dockerfiles install with pip --require-hashes --no-deps from the lock:
  a tampered or re-published package fails the build.
- CI "Dependency Lock" job: lock must match requirements.txt, hash-enforced
  install + pip check, full test suite on the locked versions, and blocking
  pip-audit on both locks.
- Weekly lock-refresh workflow runs scripts/lock.sh --upgrade and opens a PR;
  Dependabot keeps actions and base images (pip entries removed).
- CONTRIBUTING: how to change dependencies and regenerate the lock.

Fixes #121
@OkiriGabriel
OkiriGabriel merged commit 0d3ab6c into main Nov 26, 2026
17 checks passed
@OkiriGabriel
OkiriGabriel deleted the fix/hashed-lockfile-121 branch November 26, 2026 10:13
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.

[SECURITY] Supply chain: build images from a hashed lock file instead of open >= ranges

1 participant