Repository navigation
feat(lock)!: pin the signing key fingerprint in lockfile v2 - #576
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
The core change is solid. SigningKey takes its fingerprint and its verifier from the same parsed key, trustedSigner runs before any fetch, download or write and never falls back to another key, and an unknown type invalidates the lock instead of skipping verification. I tried it: dbc lock pins the Columnar fingerprint, and changing the fingerprint in the lock makes the next dbc lock fail with the "not trusted" error.
One design question to settle before v2 ships:
- Every driver gets Columnar's key pinned, whatever registry it comes from.
signerForignoresregistryIdentity, so a driver from a third-party registry locked with--no-verifystill getsfingerprint = <Columnar key>. The lock then records an expected signer that never signed the package. Once per-registry keys exist, which thesignerForcomment anticipates, those entries become "signer changed" or "untrusted" errors that users have to clear by hand. v2 is unreleased and a missingsignermakes the lock invalid, so now is the cheap time to decide how sources without a known key are recorded: an explicit "no signer" value, leaving the field out for those sources, or pinning Columnar's key only for registries known to be Columnar-signed. Requiring the field everywhere is fine; filling it with a key that doesn't apply is the problem.
Smaller points:
- The recovery advice in
trustedSignerandsignerChangedError("delete the driver's entry from the lock file") contradicts the lock file header, which says the file is not intended for manual editing. Pointing at a command instead would be better:rm dbc.lock && dbc lockfor now, ordbc lock --upgrade-driver <name>once that lands. - The changed-signer check in
plan(a re-resolution that switches signer has to fail) has no test for the failure. With only one trusted key it's hard to trigger, so a test double forsignerFormay be needed. - Nit:
--no-verifystill writes the pin, which is intended and documented indriver_list.md. One sentence onSigningKeyor thesignerdocs saying the pin is policy, not proof of verification, would stop library users from treating it as proof.
|
Thanks for the review.
|
zeroshade
left a comment
There was a problem hiding this comment.
Thanks, all addressed. The policy framing for (1) makes sense: without --no-verify, every registry is checked against the Columnar key today, so that's the right pin, and the planned signing_key = "<name>" | false plus an explicit unsigned signer type that still needs signing_key = false in dbc.toml to replay closes the gap without letting a lock file turn verification off. One request on ordering: let's land the per-registry signing_key PR before a release ships lock file v2, so third-party registry users don't get a Columnar pin they'd have to recreate later. The shared signerChangeHint, the changed-signer test that now tells the two errors apart, and the SigningKey doc note look good. LGTM.
A SigningKey is built from one parsed OpenPGP public key and provides both its primary key fingerprint and the detached signature verification, so the two cannot drift apart. SignedByColumnar and VerifyPackageSignature keep their behaviour and now delegate to the built-in Columnar key.
Every driver entry of a version 2 lock file now has a required signature table with the OpenPGP primary key fingerprint that its packages must verify with. It is an expected-signer policy, not evidence of a verification. dbc sync and dbc lock verify reused installations, new installations and hash-measuring downloads with the pinned key. A pin that is not trusted, or a re-resolution that would change it, fails before anything is downloaded or written and never falls back to another key, also with --no-verify.
git on Windows converted the line ending of the signed payload, which made its detached signature invalid.
The table pins who must have signed a driver, not a signature, and the name also fits sources that authenticate without an OpenPGP signature.
The signer errors told users to delete the driver's entry from the lock file, which the file header says is not meant for manual editing. Point to recreating the lock file with dbc lock instead. Check the changed-signer failure by its own message, state that a pinned fingerprint is not evidence of a verification, and leave a TODO for choosing the key per registry.
f42e905 to
84f4e51
Compare
|
#575 has been merged, so I've rebased and updated the PR body. |
zeroshade
left a comment
There was a problem hiding this comment.
Re-checked after the rebase onto main: the PR's commits are unchanged, and lint, build and tests are clean on the new base. Heads-up: this conflicts with #584 in sync_plan_test.go only (both add a test at the same spot); keep both. LGTM.
Follow-up to #576. Custom registries (#360) can name the key their packages are signed with, so drivers from them no longer need `--no-verify`. This also turns on the signer check of #601 for these keys. Closes #613. ```toml [signing_keys.acme] type = "openpgp" public_key_file = "keys/acme.asc" # or public_key = "-----BEGIN PGP PUBLIC KEY BLOCK-----..." [[registries]] url = "https://drivers.acme.example.com" signing_key = "acme" # omitted: built-in Columnar key; false: unsigned registry ``` - **Config:** in the user `config.toml` and in `dbc.toml`. A `signing_key` name is resolved only in the file that declares the registry, so adding a key to the user config never changes what a project trusts. A project cannot declare a registry from the user config or a default registry (compared without query, user information or default port) with a different signing policy; that is an error. An omitted `signing_key` always means the built-in Columnar key. `columnar` is reserved. Registry URLs in these files reject empty interior path segments, `.` or `..` segments even when escaped, and escaped slashes, so that another spelling of a trusted registry's path cannot get past this check. Registry identities, including lockfile sources, omit default ports and normalize path escapes by decoding unreserved characters and uppercasing the remaining hex digits, preserving the distinction between escaped and literal reserved characters. - **Keys:** exactly one public certificate, armored (or binary in a file). Private keys, several keys or armor blocks, unknown packets and trailing data are rejected instead of skipped. A relative `public_key_file` is relative to the file that defines it; in `dbc.toml` it must stay inside the project directory (no absolute or UNC paths or `..` that leaves it, read through `os.Root`). The file is read only when its key is needed, also for the signer check, and the certificate read is reused for the rest of the operation; a failure is an error, never a fallback to another key. - **Signer check:** when several registries list a driver, or an index is missing, their signers must match (#601). Keys match only when their certificates are identical, and every unsigned registry is a signer of its own, so a missing index of an unsigned registry, or of one with a key the others do not share, stops new resolution of drivers without a `source`. The signer check, the verification and the lock pin of one operation use the same certificate, even if a `public_key_file` changes meanwhile. - **Lockfile:** the selected key's fingerprint is pinned as in #576, or `type = 'none'` for `signing_key = false`. Replay requires the registry's current configuration to select the same signer, also with `--no-verify`, so a lock entry can neither switch keys nor turn verification off on its own. Each unsigned registry counts as a separate signer, so a driver locked from one is not resolved again from another unsigned registry, even with a changed `source`. - **Install:** `dbc install` and `Client.Install` select the key from the registry of the chosen package before downloading it, so a driver that a later registry with the same key serves (#584) is verified with that registry's key. `--no-verify` / `AllowUnsigned` skip the signature check, but not the signer check of an implicit selection; local archives keep using the Columnar key. The `install` and `sync` JSON report `signature_verified`, and `verify.start` / `verify.complete` are only emitted when a signature is checked. - **API:** `Registry.Signing` (`RegistrySigningPolicy`, zero value = Columnar key) with `SignWith` / `Unsigned`, plus `NewSigningKey` and `Registry.ResolveSigningKey`. `RegistrySigningOperation` keeps the keys of one operation; its `ResolvePackage` replaces the unreleased function of the same name (#584, #601). The unreleased `LoadProjectRegistries` / `WithProjectRegistries` become `LoadProjectConfig` / `WithProjectConfig`, so key definitions and their file path travel with the registries. Bindings take `signingKey` on explicit registries (`registry.<n>.signing_key` in the C API). The policy only covers detached OpenPGP signatures of registry packages; another source such as Packslip would get its own policy and lock signer type.
Follow-up to #575 (
dbc lock).Lockfile v2 pins sources and archive hashes, but not the key signatures are verified with. This PR adds that before v2 ships.
Lockfile: each driver requires a
signertable pinning the OpenPGP primary key its packages must verify with. This records the expected signer, not successful verification. A v2 lock without it is invalid; v2 is unreleased, so there is no migration. v1 upgrades are unchanged.Enforcement:
dbc syncanddbc lockverify reused installations, new installations and hash-measuring downloads with the pinned key. An untrusted pin, or a re-resolution that would change the pin, fails before anything is downloaded, installed or written. There is no fallback key.--no-verifyskips that run's signature check without changing or bypassing the pin.API:
dbc.SigningKeyexposes one key's fingerprint and verification;dbc.ColumnarSigningKey()returns the built-in key.SignedByColumnarandVerifyPackageSignatureare unchanged.Only Columnar's built-in key is trusted. Existing users see only the new lock field;
dbc install,Client.Installand install receipts are unchanged.Other sources and verification methods
The table identifies who must authenticate a release;
typespecifies how. It belongs to the driver release rather than its source: one registry can serve multiple publishers.openpgpwith another fingerprint, without format changes.typewould pin the verified identity (project, issuer and workflow identity for Sigstore keyless signing), so replaying the lock elsewhere does not trust a new identity on first use. Verified metadata hashes stay inevidence.This PR defines only
openpgp. An unknown type makes the lock invalid rather than skipping verification, so new types are additive.