Repository navigation
feat: verify registry-published archive hashes and record archive evidence - #567
Conversation
…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.
…ng Client.Install
|
CI failure should be fixed by #568 |
zeroshade
left a comment
There was a problem hiding this comment.
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.
f1a5fd3 to
d2aec3e
Compare
d2aec3e to
7fe261b
Compare
|
Both points are addressed in 7fe261b:
|
zeroshade
left a comment
There was a problem hiding this comment.
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.godefine the same truncated/HTML case table. One shared slice would do.
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.
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.
hash: sha256:<hex>intoPkgInfo.ArchiveSHA256. A malformed hash fails only when the affected package is resolved. Search and unrelated packages keep working.config.InstallPackagecomputes the archive SHA-256 while it extracts the archive, in one pass. If the newExpectedArchiveSHA256option is set and differs, it returns*config.ArchiveHashMismatchErrorbefore publishing anything, and any existing install stays in place.archive_sha256and asignature_verifiedflag. Only a successful call of the newSignatureVerifieroption sets the flag; the genericVerifierdoes not. The flag records only that this callback succeeded; the CLI andClient.InstallpassVerifyPackageSignature, which checks the Columnar library signature. The receipt schema is unreleased, so it stays at version 1.dbc install,dbc syncandClient.Installpass the published hash and verify signatures throughSignatureVerifier.--no-verifyandAllowUnsigned()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 ofClient.Installare unchanged.