Skip to content

feat: verify registry-published archive hashes and record archive evidence - #567

Merged
zeroshade merged 6 commits into
columnar-tech:mainfrom
eitsupi:feat/archive-hash-evidence
Nov 9, 2026
Merged

zeroshade merged 6 commits into
columnar-tech:mainfrom
eitsupi:feat/archive-hash-evidence

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

This PR verifies downloaded archives against the hash the registry publishes and records archive and signature evidence in the install receipt. A follow-up PR for lockfile v2 builds on it.

  • dbc reads the optional per-package hash: sha256:<hex> into PkgInfo.ArchiveSHA256. A malformed hash fails only when the affected package is resolved. Search and unrelated packages keep working.
  • config.InstallPackage computes the archive SHA-256 while it extracts the archive, in one pass. If the new ExpectedArchiveSHA256 option is set and differs, it returns *config.ArchiveHashMismatchError before publishing anything, and any existing install stays in place.
  • Receipts record the measured archive_sha256 and a signature_verified flag. Only a successful call of the new SignatureVerifier option sets the flag; the generic Verifier does not. The flag records only that this callback succeeded; the CLI and Client.Install pass VerifyPackageSignature, which checks the Columnar library signature. The receipt schema is unreleased, so it stays at version 1.
  • dbc install, dbc sync and Client.Install pass the published hash and verify signatures through SignatureVerifier. --no-verify and AllowUnsigned() skip only signature verification, not the archive hash check.

Same-version direct installs still skip the download, including drivers installed with --no-verify. The lockfile format, resolution, the sync skip policy and the existing signature and version requirements of Client.Install are unchanged.

…dence

Parse the optional per-package `hash` (sha256:<hex>) from registry indexes
and expose it as PkgInfo.ArchiveSHA256. A malformed hash only invalidates
the affected package when it is resolved; the rest of the index still works.

InstallPackage now hashes the archive bytes it actually extracts in a single
pass, rejects a mismatch with InstallPackageOptions.ExpectedArchiveSHA256
before anything is published, and records the measured digest in the install
receipt. A new SignatureVerifier option marks the receipt as
signature-verified only when it succeeds.

`dbc install`, `dbc sync`, and Client.Install pass the registry hash when one
is published. --no-verify and AllowUnsigned skip only signature checks, not
the archive hash check.
…idence

ArchiveHashMismatchError and ExpectedArchiveSHA256 now describe the digest
the caller requires rather than assuming the registry, so InstallPackage
stays usable for other artifact sources. Document that signature_verified
only records that the caller-supplied verifier succeeded, and note at each
caller that VerifyPackageSignature checks the Columnar library signature.

Add tests that read the receipts written by `dbc install`, `dbc sync` and
Client.Install, and check that a failed hash or signature check on upgrade
leaves the existing receipt, registration and library untouched.
@eitsupi

eitsupi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

CI failure should be fixed by #568

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The design works: when a hash mismatches, nothing is published, the staging directory and lock are cleaned up, and the existing install stays as it was. It also handles the live indexes. On the public (655 packages, 133 with hashes) and private indexes, every package resolves with no errors. A real Client.Install of firebolt recorded archive_sha256 equal to the registry hash and signature_verified: true. Rejecting only the affected package when its hash is malformed is a nice touch.

Should fix: config/install_package.go:151-170, a mismatch shows up as an extraction error when the archive doesn't extract. The hash is compared only after extractPackageArchiveWithDigest succeeds. With ExpectedArchiveSHA256 set:

Input Error errors.As(*ArchiveHashMismatchError)
Truncated download failed to extract package: could not read MANIFEST: unexpected EOF false
HTML error page served as the archive could not create gzip reader: gzip: invalid header false
Intact archive, wrong hash mismatch error true

The first two are the most common real-world mismatches. They get misleading messages, and a caller that classifies errors with errors.As (the lockfile v2 follow-up, for example) won't see them as mismatches. It also means untrusted bytes get parsed before they are verified. When an expected hash is set, I'd hash the file before extracting it. That costs one extra read of a local file. A smaller fix is to hash the file on the extraction-error path and return errors.Join(&ArchiveHashMismatchError{...}, extractErr). Either way, please add a truncated-archive case to TestInstallPackageArchiveHash.

Nit: the comment at config/package_archive.go:147-148 describes a case that never occurs. It says "bytes left after the gzip stream are drained into it", but gzip.Reader reads multi-member streams. Any non-gzip trailing byte fails the drain with gzip: invalid header, so the final io.Copy(archiveHash, f) always copies 0 bytes. The digest still covers the whole file. Please reword the comment, or drop the copy.

CI: the ubuntu-latest failure is the sudo -E issue that #568 fixes, as you said. Both failing tests pass on this branch when not run as root.

@zeroshade
zeroshade force-pushed the feat/archive-hash-evidence branch from f1a5fd3 to d2aec3e Compare November 6, 2026 19:24
@eitsupi
eitsupi force-pushed the feat/archive-hash-evidence branch from d2aec3e to 7fe261b Compare November 6, 2026 23:06
@eitsupi

eitsupi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Both points are addressed in 7fe261b:

  • When an expected hash is set, InstallPackage now hashes the archive before extracting it. A truncated download or an HTML error page is reported as *ArchiveHashMismatchError, and the untrusted bytes are never parsed. The digest measured during extraction is still compared, in case the file changes in between. TestInstallPackageArchiveHash now covers truncated, HTML and wrong-hash archives. It also covers a corrupt archive whose hash does match, which still fails as an extraction error.
  • I dropped the final io.Copy and fixed the comment. The gzip drain still reads the whole multi-member stream.

@eitsupi
eitsupi requested a review from zeroshade November 7, 2026 13:45

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, both points are addressed in 7fe261b. With an expected hash set, truncated and HTML archives now surface as *ArchiveHashMismatchError before any parsing. The extraction digest is still compared afterwards in case the file changes, and the reverse case (corrupt archive with a matching hash → extraction error) is covered too. I re-ran go test ./... and the config tests under -race on the branch; all pass, and CI is green.

Two optional nits, neither blocking:

  • The pre-extraction hash runs after acquireDriverInstallLockWith. It doesn't need the lock, so hashing first would reject mismatches without taking it.
  • The two new subtests in install_package_archive_hash_test.go define the same truncated/HTML case table. One shared slice would do.

@zeroshade
zeroshade merged commit da3192f into columnar-tech:main Nov 9, 2026
20 checks passed
zeroshade pushed a commit that referenced this pull request Nov 10, 2026
Closes #400

Builds on the archive hash verification from #567. This PR adds lockfile
v2 and archive-based reuse to `dbc sync`.

- **Lockfile v2:** records each driver’s registry, per-target archive
SHA-256, structured target, format, and typed location. Optional size is
checked on downloads. Evidence and host requirements can be read, but
registry resolution does not produce them and sync does not enforce
them. Invalid or ambiguous secondary targets are omitted; current-target
failures remain errors. v1 locks upgrade automatically, retaining
compatible pins and checking applicable library proofs. dbc 0.3.1
rejects v2; 0.3.0 and earlier ignore v2 metadata, install pinned names
and versions without archive hash checks, and rewrite the lock as v1.
All collaborators must upgrade to a v2-supporting release before sharing
an upgraded lock.
- **Replay and registry binding:** a compatible lock entry for the
current target avoids registry index lookup. Its credential-free
registry identity must match exactly one configured registry; configured
registries differing only by userinfo or query are ambiguous. Missing
targets cannot be added when the matching registry URL has a query
string. HTTPS registries cannot use HTTP artifact URLs.
- **Reuse and install:** the `config.CheckInstalledPackage` API checks
installed registration, receipt, library, and archive digest before
reuse, and re-verifies signatures unless `--no-verify` is set. If a lock
file cannot be opened because of permissions or a read-only filesystem,
it checks an optimistic read-only snapshot; observed changes prevent
reuse. The `config.InspectPackageArchive` API checks v1 library proofs.
Otherwise sync downloads and checks required archives before saving the
lock and installing. Installation failures retain the lock and prior
successful installs so a later sync retries with the same archives.
Concurrent syncs wait up to 10 seconds for the project lock, which
remains held through installation.

Normal sync reinstalls drivers previously installed with `--no-verify`
using signature verification; direct `dbc install` retains its
already-installed behavior. Default HTTP clients strip Authorization and
Referer across origins and reject HTTPS-to-HTTP redirects. Download
filenames omit URL queries.

Network cancellation and local path sources remain deferred; quitting is
immediate, and an in-flight download may leave a temporary file.
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