Skip to content

refactor: let dbc lock pin measured archives without checking them - #623

Merged
eitsupi merged 6 commits into
feat/project-signing-keysfrom
feat/lock-measure-hash-only
Dec 1, 2026
Merged

eitsupi merged 6 commits into
feat/project-signing-keysfrom
feat/lock-measure-hash-only

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Align measured hashes with the published-hash path ahead of HTTP URL template sources (#621).

  • Background: feat: add dbc lock to update the lock file without installing #575 checked signatures before pinning measured archives, to catch invalid signatures before saving the lockfile; --no-verify skipped that check. After review, it also extracted those archives even with the flag, so that locking would catch malformed tarballs.
  • Why change: A lockfile pins archive bytes and the required signer; it does not prove that every platform's package installs. Installation always verifies the signature with the pinned key, so checking at lock time only reports a bad archive earlier, and a published hash was already pinned without these checks. The checks also cost an extraction for every newly measured platform, which an HTTP source without checksum_url needs for every archive.
  • Archive hashes: dbc lock and dbc sync use the published hash when available and otherwise record the downloaded archive's SHA-256, without extracting it or verifying its signature. An applicable v1 library checksum still requires extracting the current platform's archive.
  • Installation: dbc sync checks the archive during extraction and uses the pinned key to verify the driver library's signature when required. The signature covers the library alone. A malformed archive or one with an invalid signature can now be pinned and fail at installation.
  • Lock options: Remove dbc lock --no-verify now that signature checks happen at installation or reuse. Both commands still reject a signer that differs from the registry configuration before downloading any archives, even with dbc sync --no-verify.

@eitsupi
eitsupi added this pull request to stack #624 November 26, 2026 05:45
@eitsupi eitsupi changed the title feat: let dbc lock pin measured archives without checking them refactor: let dbc lock pin measured archives without checking them Nov 26, 2026
@eitsupi
eitsupi marked this pull request as ready for review November 26, 2026 05:53
@eitsupi
eitsupi marked this pull request as draft November 26, 2026 05:54
@eitsupi
eitsupi marked this pull request as ready for review November 26, 2026 05:59
@eitsupi
eitsupi requested review from amoeba and zeroshade November 26, 2026 06:44

@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.

LGTM. Pinning a measured hash without checking the archive matches what the published-hash path already does: installation still verifies the library with the pinned key, reuse re-verifies, and the signer mismatch is still rejected before any download. Removing dbc lock --no-verify breaks nobody, since dbc lock hasn't been released yet. A few non-blocking comments are inline.

Comment thread cmd/dbc/sync.go
@@ -608,16 +593,11 @@ func (e *signatureVerificationError) Error() string { return e.err.Error() }
func (e *signatureVerificationError) Unwrap() error { return e.err }

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.

nit: the comment on signatureVerificationError just above (it exists "so that it is not reported as a failure to inspect the archive") is stale now that the AsType branch in checkDownloadedArchive is gone. The type now only separates "failed to verify signature" from "failed to install driver package" at install.

Comment thread config/package_archive.go Outdated
// with the same safety checks as InstallPackage, hashes the archive and the
// driver library, optionally verifies the staged package, removes the staging
// directory and returns the result. It does not close f and does not touch any
// driver library, removes the staging directory and returns the result. It does not close f and does not touch any

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.

nit: this line runs to about 120 columns after the edit; the comment needs rewrapping.

Comment thread cmd/dbc/lock_test.go Outdated
func (suite *SubcommandTestSuite) TestLockVerifiesWithThePlannedKey() {
// TestLockKeepsThePlannedKey pins that dbc lock records the planned key without
// verifying anything with it.
func (suite *SubcommandTestSuite) TestLockKeepsThePlannedKey() {

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.

This now only checks that fetch passes pd.Signer through to item, which it copies directly. TestLockPinsArchiveWithoutVerifyingSignature already covers "doesn't verify". Either drop this test, or use a key that does not sign the archive, so it actually tests "records the key without verifying anything with it".

Comment thread cmd/dbc/lock_test.go Outdated
@@ -314,19 +330,15 @@ func (suite *SubcommandTestSuite) TestLockRecordsSigner() {
suite.runCmd(LockCmd{Path: listPath}.GetModelCustom(testBaseModel()))
suite.Equal(testSigner, suite.lockedDriverEntry("test-driver-1").Signer)

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.

nit: there's a blank line left before the closing brace.

Comment thread docs/guides/driver_list.md Outdated
The lockfile can also carry an artifact size, source evidence, and host requirements supplied by a resolver. When an archive needs to be downloaded, `dbc sync` also checks its size if recorded. A matching installed archive can be reused without downloading, even when a size is recorded. Registry-generated locks currently omit size, evidence, and host requirements. Host requirements and evidence are receiver-side metadata only; their presence does not mean `dbc sync` enforces them.

When a lockfile exists, `dbc sync` uses the archive recorded for the current platform without consulting the registry index. A driver that is already installed is reused only when the installed package evidence matches that archive; signature verification is repeated against the installed library and signature before reuse unless `--no-verify` is set. If a lock file cannot be opened because of permissions or a read-only filesystem, dbc checks an optimistic read-only snapshot; observed changes prevent reuse. For a v1 lockfile, dbc checks the applicable library proof against the installed library or downloaded archive. If reuse checks fail, the recorded archive is downloaded, its hash is checked, and the driver is reinstalled. dbc downloads and checks every archive it needs before it writes the lockfile or changes any installed driver. A project lock serializes concurrent syncs through installation; acquiring it waits at most 10 seconds before returning an error. The new lockfile is written before installation starts, so if an installation then fails (for example on signature verification), the lockfile is kept and running `dbc sync` again retries with the same archives. `--no-verify` skips signature verification but never the archive hash check, and a driver installed with `--no-verify` is reinstalled with signature verification by a later `dbc sync` without that flag.
When a lockfile exists, `dbc sync` uses the archive recorded for the current platform without consulting the registry index. A driver that is already installed is reused only when the installed package evidence matches that archive; signature verification is repeated against the installed library and signature before reuse unless `--no-verify` is set. If a lock file cannot be opened because of permissions or a read-only filesystem, dbc checks an optimistic read-only snapshot; observed changes prevent reuse. For a v1 lockfile, dbc checks the applicable library proof against the installed library or downloaded archive. If reuse checks fail, the recorded archive is downloaded, its hash is checked, and the driver is reinstalled. dbc checks or measures the hashes of the archives it downloads before it writes the lockfile or changes any installed driver. A project lock serializes concurrent syncs through installation; acquiring it waits at most 10 seconds before returning an error. dbc writes the lockfile before installation. If installation fails, for example on signature verification, the next `dbc sync` still uses the recorded hashes. To pick up a corrected archive at the same location, delete `dbc.lock` and run `dbc lock` again after the registry updates any published hash for that archive. `--no-verify` skips signature verification but never the archive hash check, and a driver installed with `--no-verify` is reinstalled with signature verification by a later `dbc sync` without that flag.

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 advice to delete dbc.lock and run dbc lock again should carry the same warning as the key-rotation paragraph above: it resolves every driver again and may select newer versions of the others.

Optional: since a bad archive can now be pinned, dbc sync could point to re-locking in its error when the failing artifact's hash was measured rather than published.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd keep the existing sync error for now.

  • If the bytes match the pin but the archive fails to install, re-locking the same bytes won't help.
  • If the bytes changed, re-locking could accept an unexpected replacement.

I'd expect an upgrade to a corrected release to cover the usual recovery once #196 lands.
Was there a particular failure where you'd want sync to suggest accepting new bytes for the same version?

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.

No particular failure in mind. Your reasoning holds: re-locking the same bytes doesn't help, and pointing users at accepting new bytes defeats the pin. Keeping the current error and leaving recovery to upgrades (#196) is fine.

dbc lock pins the archive bytes and the signing key, and leaves the
signature, the extraction checks and the package version to the
installation, which checks them with the pinned key anyway. A measured
archive is now only hashed, like an archive with a published hash is
recorded as is. Only a v1 library proof still extracts the host archive,
without its signature.

With nothing left to verify, dbc lock no longer accepts --no-verify.
Nothing verifies a signature while inspecting an archive any more, and
the option was never released.
Say what signatureVerificationError separates now, rewrap the comment of
InspectPackageArchive, and drop a test that only checked that fetch passes
the planned signer through.
@eitsupi
eitsupi force-pushed the feat/lock-measure-hash-only branch from ad7a6fe to 087fe02 Compare November 30, 2026 13:44
@eitsupi

eitsupi commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

f433a29 updates the comments and removes the signer pass-through test.
087fe02 warns that deleting the lockfile can also update other drivers.

@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.

Re-reviewed after f433a29 and 087fe02; still LGTM. All comments are addressed. The stale signatureVerificationError comment is updated, the comment is rewrapped, the pass-through test is gone, and the lockfile-deletion advice now warns about other drivers. No remaining references to dbc lock --no-verify in the docs or completions.

@eitsupi
eitsupi merged commit 20b7973 into main Dec 1, 2026
30 checks passed
@eitsupi
eitsupi deleted the feat/lock-measure-hash-only branch December 1, 2026 00:30
eitsupi added a commit that referenced this pull request Dec 1, 2026
Let projects install off-registry dbc packages using HTTP URL templates
in `dbc.toml` (see #394).

```toml
[drivers.example]
version = "1.2.0"

[drivers.example.source]
type = "http"
url = "https://example.com/releases/download/v{version}/example_{os}_{arch}_v{version}.tar.gz"
checksum_url = "https://example.com/releases/download/v{version}/SHA256SUMS"
signing_key = false
```

- **Configuration:** Requires a dbc package archive. URL templates
support `{version}`, `{os}`, and `{arch}` in the path. dbc does not
discover available versions, so `version` must be a full version
(`"1.2.0"` or `"=1.2.0"`); `{version}` expands to it, including any
prerelease or build metadata. Unknown HTTP source keys are errors. An
HTTP source can name a key from the project's `[signing_keys]` (#620),
use the built-in key by default, or opt out with `signing_key = false`.
Registry sources reject `signing_key` and `checksum_url`.
- **Targets:** Locks archives for the declared platforms, or the current
platform by default. **Limitation:** musl and architecture variant
drivers (such as `linux_amd64_musl` or `linux_amd64_v3`) cannot be
installed from an HTTP source yet. A template cannot tell those targets
from the plain target, so HTTP sources reject them, including artifacts
already recorded for them.
- **Hashes:** dbc reads new hashes from `checksum_url` when set, as GNU
`sha256sum` lines or as a single hash for a file that serves one
archive. Otherwise, it records the first download's SHA-256 and size. As
in #623, locking extracts an archive only to check an applicable v1
library checksum. At installation, `dbc sync` checks the archive, its
`MANIFEST` version, and any required library signature. dbc warns when a
new hash comes from a declared plain HTTP URL.
- **Downloads:** Archive and checksum requests carry no registry
credentials or telemetry IDs. URL replacements apply. The CLI rejects
HTTPS-to-HTTP replacements and redirects. `DBC_BASE_URL` does not affect
HTTP sources.
- **Lock replay:** Records the template digest and absolute archive
URLs. `dbc sync` rejects a changed source or a recorded URL that no
longer matches the template. `dbc lock` can relock an explicitly changed
source subject to signer continuity. Each unsigned source is a signer of
its own, so changing an unsigned source's template needs its lock entry
removed first; the error says so. Removing the HTTP declaration stops
both commands without a registry search.
- **`dbc sync --locked`:** Installs from the recorded artifacts without
updating the lockfile or fetching a checksum file or registry index. The
HTTP declaration, URL template, exact version, and pinned signer must
still match.
- **Future work:** mise's HTTP backend reads versions from a
`version_list_url`, extracting them with a regex, JSON path or
expression, so that `latest` and version prefixes work. A similar source
key would let an HTTP source take a version range; this version of dbc
rejects such a key with a hint that a newer dbc may be required.
eitsupi added a commit that referenced this pull request Dec 4, 2026
dbc could save an arbitrarily large archive to disk, and `dbc lock` can
pin a downloaded archive without extracting it (#623).

Registry and HTTP archive downloads are now capped at 512 MiB. dbc
rejects a Content-Length above the cap before reading the body, enforces
the cap as it reads, and removes partial downloads. The largest archive
measured in the central registry was about 174 MiB (182,358,568 bytes).
mise also caps its self-update downloads at 512 MiB.

The cap also applies to the released Go APIs `PkgInfo.DownloadPackage`
(deprecated) and `Client.Install`. Transfer errors from
`PkgInfo.DownloadPackage` now start with "failed to download driver",
just like request errors. The unreleased Go API `Client.OpenAnonymous`
now returns the declared response length when known. `Client.Download`
remains an uncapped stream.

This branch was previously deployed

1 inactive deployment
snapshot — 087fe022 Deployed Nov 30, 2026 by eitsupi via snapshot #1409
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