Skip to content

Separate hash generation policy from verification policy - #21247

Merged
zanieb merged 2 commits into
mainfrom
zb/source-hash-verification-policy
Aug 24, 2026
Merged

zanieb merged 2 commits into
mainfrom
zb/source-hash-verification-policy

Conversation

@zanieb

@zanieb zanieb commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

HashStrategy currently represents hash generation and verification as mutually exclusive choices. A resolution may need both: verify artifacts whose hashes have been supplied, while generating hashes for new artifacts.

Store generation separately from HashVerification in HashStrategy. Each distribution still receives a HashPolicy specifying whether to generate or check hashes. Update existing call sites to use the separate settings while preserving their hash inputs and which hashes uv treats as trusted. Generation remains available for artifacts without supplied hashes, unless the caller requires a hash for every artifact. This does not read hashes from uv.lock or add new archive comparisons.

Based on #21246. #21248 checks caller-supplied hashes before source archives enter the cache. #21223 reads hashes from an existing uv.lock and supplies them for verification.

@zanieb
zanieb force-pushed the zb/source-hash-verification-policy branch from c73a17d to a084d2c Compare August 20, 2026 21:46
@zanieb
zanieb force-pushed the zb/source-hash-verification-policy branch from a084d2c to 9a42c8d Compare August 21, 2026 00:08
@zanieb zanieb changed the title Separate hash generation from verification Separate hash generation policy from verification policy Aug 21, 2026
@zanieb
zanieb requested a review from charliermarsh August 21, 2026 00:49
@zanieb
zanieb marked this pull request as ready for review August 21, 2026 00:50
@zanieb
zanieb force-pushed the zb/source-hash-verification-policy branch from 9a42c8d to f533ba4 Compare August 21, 2026 18:44
Base automatically changed from zb/validated-source-archive-refactor to main August 24, 2026 16:47
@zanieb
zanieb force-pushed the zb/source-hash-verification-policy branch from f533ba4 to fda53d3 Compare August 24, 2026 16:47
astral-automations-bot Bot pushed a commit to astral-sh/uv-dev that referenced this pull request Aug 24, 2026
Source archive helpers currently extract an archive and save it to the
cache in the same call. Separate those steps so the type system records
that extraction and its existing checks have completed before
persistence.

Introduce a private `ValidatedSourceArchive` that owns the temporary
directory. Its HTTP and local constructors retain their transport setup,
diagnostics, and cleanup behavior, while a private reader helper
performs the shared extraction and hash collection. The consuming
`persist` method saves the source tree and returns the collected hashes
and byte count. This preserves existing behavior; it does not add
trusted-hash comparisons or change cache repair.

astral-sh#21247 separates hash generation from verification, and astral-sh#21248 checks
caller-supplied hashes before persistence.
@zanieb
zanieb merged commit 60a38ed into main Aug 24, 2026
81 of 83 checks passed
@zanieb
zanieb deleted the zb/source-hash-verification-policy branch August 24, 2026 17:08
zanieb added a commit that referenced this pull request Aug 27, 2026
Source archives can be saved to the cache before their caller-supplied
hashes are checked. Cache repair can also save replacement contents
before detecting a mismatch with the previous revision.

Check supplied hashes alongside the existing download-size check in
`ValidatedSourceArchive::extract`, before it returns the value consumed
by `persist`. Check every digest from a previous revision there too,
before a repaired source tree is saved. Extraction still streams into a
private temporary directory and returns parser errors immediately.

This also removes the split in persistence behavior captured by
`ArchiveOrigin`. HTTP and local archives now accept `AlreadyExists` or
`DirectoryNotEmpty` only when the destination is a directory, and both
retain temporary-directory ownership through persistence. The HTTP path
no longer calls `TempDir::keep` for archives with multiple top-level
entries, so failed persistence attempts clean up those staged files too.

HTTP response handling and local file opening remain separate, and cache
locations and `rename_with_retry` are unchanged. The caller still
supplies the hashes and any download size to check; this PR does not
read trusted hashes from `uv.lock`. #21223 supplies the hashes recorded
in an existing `uv.lock`.

Based on #21247.
zanieb added a commit that referenced this pull request Sep 8, 2026
`uv.lock` records archive digests, but checking an existing lockfile or
resolving with `--locked` can obtain source metadata without comparing
those digests. A replaced source archive can therefore run its build
backend before a later hash or lockfile check rejects it.

Construct a `HashStrategy` from the existing lockfile's hashes for
registry packages, direct URLs, and local archives. Enforce the recorded
hashes when reusing cached source metadata, resolving with `--locked`,
and installing build dependencies recorded in the lockfile into isolated
build environments. Normalize equivalent archive subdirectories so they
find the same recorded hashes. Keep recorded hashes while checking
whether an existing lockfile is still usable, but allow unlocked fresh
resolution to replace them. Build dependencies without recorded hashes
remain allowed.

Based on #21248, which checks source archives before saving them to the
cache. #21246 contains the structural refactor, and #21247 separates
hash generation from verification.

---------

Co-authored-by: Zanie Blue <[email protected]>
Co-authored-by: Tomasz Kramkowski <[email protected]>
Co-authored-by: Charlie Marsh <[email protected]>

This branch was previously deployed

1 inactive deployment
automations — fda53d33 Deployed Aug 24, 2026 by zanieb via review / security review #45209
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.

2 participants