Repository navigation
feat: share project signing keys across sources - #620
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
LGTM. Parsing the definitions once means the project's registries and other sources share one *signingKeyFile, so they share one cached key per SigningOperation. Always passing WithProjectConfig doesn't add any new CLI failure with DBC_BASE_URL, since decodeDriverList already validates the project config. The library behavior change is documented and only affects unreleased API. A few nits inline.
|
|
||
| // The project's signing key definitions also serve sources other than | ||
| // registries, so they are parsed even when the registries are replaced; | ||
| // its registry entries are only parsed when they are merged. Its |
There was a problem hiding this comment.
Nit: this is true within NewClient, but LoadProjectConfig, Validate and the CLI's decodeDriverList still validate the registry entries up front, so DBC_BASE_URL doesn't get around a broken [[registries]] entry. Maybe "its registry entries are only merged when no override is given"?
| func (c *Client) ProjectSigningPolicy(name string) (SigningPolicy, error) { | ||
| policy, ok := c.projectSigning[name] | ||
| if !ok { | ||
| return SigningPolicy{}, fmt.Errorf("signing_key %q is not defined in [signing_keys] of the project", name) |
There was a problem hiding this comment.
Nit: when no WithProjectConfig was passed at all, this says the name isn't defined "of the project", which could mislead a library caller who forgot the option. Could that case get its own message, e.g. "no project configuration"?
| // The project's registries that name the same definition share the policy, | ||
| // so within one SigningOperation the first key read from that definition | ||
| // serves both. | ||
| func (c *Client) ProjectSigningPolicy(name string) (SigningPolicy, error) { |
There was a problem hiding this comment.
Nothing calls this yet within this PR; I assume #621 is the consumer. Fine as part of the stack, just noting it's public API, so if the HTTP source design changes shape it's worth revisiting before 0.4.0.
fedb89c to
5d4b8f0
Compare
Client.ProjectSigningPolicy returns the policy of a [signing_keys] definition of the project by name, for sources of dbc.toml other than registries. It shares the policy with the project's registries that name the same definition, so one SigningOperation reads its key file once for both, and it never falls back to a definition of the global config. The definitions are parsed also when WithBaseURL or WithRegistries replaces the registries, and the CLI passes the project to the client under DBC_BASE_URL as well, which still replaces its registries.
With WithBaseURL or WithRegistries the project's registry entries are ignored, so an invalid one no longer stops NewClient; its signing key definitions are still checked, since ProjectSigningPolicy uses them.
Also describe ProjectSigningPolicy's lookup without reading key files, and drop the unused definitions from parseRegistryConfig.
…tion Also say that the project's registry entries are only merged when no override is given; they are still validated.
5d4b8f0 to
acfcd98
Compare
zeroshade
left a comment
There was a problem hiding this comment.
Re-reviewed after acfcd98; still LGTM.
- The comment in
NewClientnow says correctly when project registry entries are merged. - The separate error when no project configuration was given is clearer, and the new subtest covers it.
- Good that #621 is the caller of
ProjectSigningPolicy.
Optional nit: hasProject could be dropped. projectSigning is non-nil exactly when a project config was given, so c.projectSigning == nil would do the same check. Not blocking.
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.
Prepare for HTTP URL template sources by sharing signing key definitions across project sources.
Client.ProjectSigningPolicy(name)looks up a named definition in the project's[signing_keys]without reading the key file. A missing project definition returns an error, even if the user config defines the same name.SigningOperation.WithBaseURLandWithRegistries(andDBC_BASE_URLin the CLI) still skip project registry entries. Project key definitions remain available, and an invalid definition now causesNewClientto fail even with an override. WithDBC_BASE_URLset,dbc search,dbc info, anddbc docsstill skipdbc.toml.