Skip to content

feat: send registry requests to a mirror with URL replacement rules - #577

Merged
zeroshade merged 10 commits into
columnar-tech:mainfrom
eitsupi:feat/url-replacements
Nov 18, 2026
Merged

zeroshade merged 10 commits into
columnar-tech:mainfrom
eitsupi:feat/url-replacements

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Motivation

In #394, @tokoko pointed out that absolute artifact URLs are a problem behind a corporate firewall, where the ideal setup is a plain Artifactory-style proxy in front of the real host. My reply suggested keeping canonical upstream URLs in the lock file and rewriting them locally when fetching, as mise's URL replacements do. This PR implements that for registries.

It matters now because lock file v2 records the registry URL. Today a mirror has to be configured as a different registry, so a dbc.lock created on the internet cannot be replayed behind the mirror, and the other way round. With this PR the user's own config says where requests go, and project and lock files keep the original URLs.

# user config.toml
[[network.url_replacements]]
prefix = "https://dbc-cdn.columnar.tech"
replacement = "https://artifactory.example.com/dbc-cdn"
  • Rules: an ordered list; the first match wins and results do not chain. A rule matches on origin plus a path prefix at a segment boundary, not on a substring. Invalid rules are an error: the CLI fails registry operations instead of warning, because continuing would contact the upstream the user meant to avoid.
  • Replaced requests are anonymous: no credentials for the original site, no mid/uid, and a URL with a query is refused. There is no fallback to the original URL, and any redirect to a replaced URL is refused, whether it comes from the mirror or from a site no rule replaces. A 401 or 403 from the mirror is reported as such rather than suggesting dbc auth login.
  • Unchanged: registry identities, lock files, archive hash and signature checks, and requests that match no rule. DBC_BASE_URL, WithBaseURL and WithRegistries still choose registries; replacements apply on top.
  • Behavior change: the CLI now refuses registry operations, instead of falling back to the default registries, when the user config.toml cannot be read, is not valid TOML, or has an invalid [[registries]] entry or URL replacement rule. The warning is still printed. This applies even without URL replacements. A missing config file works as before.
  • User config only: a dbc.toml with a network table is rejected, so a repository cannot redirect a user's requests.
  • API: GlobalConfig.Network, WithURLReplacements, ErrURLReplacementUnauthorized, and SetDefaultURLReplacements for the deprecated package-level functions.

Not included: mirrors that need authentication, regex rules, and an environment variable. The Node and other bindings pick the rules up when they load the default registry config; with an explicit registry list they do not. In the Wasm build redirects are followed by fetch, so the redirect refusal does not apply there.

A client can be given ordered prefix rules that send requests for a URL
prefix to another URL. The user's config.toml carries them in
network.url_replacements, and WithURLReplacements sets them explicitly.

A replaced request is anonymous: no credentials for the original site,
no telemetry identifiers, no query, and no fallback to the original URL.
Registry identities and package URLs stay canonical, so lock files do
not change. A project's dbc.toml cannot set network settings.
Registry clients and the package download path use the rules of the
user's config.toml, also when DBC_BASE_URL is set. Invalid rules make
registry operations fail instead of only warning, because continuing
would contact the upstream the user meant to avoid. A dbc.toml with a
network table is rejected.
A mirror could answer with a redirect to the registry it stands in for,
and the HTTP client followed it, contacting the upstream despite the
rule.
A sync that replays a lock entry can download an archive without building
a registry client, so it would have contacted the upstream despite the
invalid rules.
@eitsupi
eitsupi marked this pull request as draft November 11, 2026 14:04
@eitsupi
eitsupi marked this pull request as ready for review November 11, 2026 14:25
@eitsupi
eitsupi requested review from amoeba and zeroshade November 17, 2026 02:12

@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, this is carefully done. Matching on origin plus a segment-boundary path prefix with unreserved-escape normalization, first match without chaining, anonymous replaced requests with no fallback, and rejecting [network] in dbc.toml all look right, and the tests cover the edges well. I merged it with current main (including #583's lint config): build, vet, go test ./... and golangci-lint v2.15.0 are clean.

Two things I'd like addressed before approving:

  1. Redirects into a replaced origin from an unmatched request. The redirect guard only wraps replaced requests. If a request that matches no rule gets a redirect to a URL a rule covers, the client's normal checkRedirect follows it straight to the upstream. I checked with a quick test: WithBaseURL(other) where other 302s to upstream/pkg.tar.gz, with a rule for upstream, succeeds with one upstream hit and no mirror hits. Since the point of failing closed is not to contact the upstream the user replaced, could the router also refuse redirects to replaced URLs for unreplaced requests, with a test?
  2. 401/403 from a mirror. anonymousGet wraps ErrUnauthorized, so the CLI adds "Did you run dbc auth login?", but replaced requests never send credentials, so logging in can't help. A separate error or message, e.g. that the mirror requires authentication, which isn't supported yet, would avoid sending users the wrong way.

Also: 2ee202f makes every user-config load failure (bad TOML, invalid [[registries]] entry) a hard error for registry commands, where it used to be a warning that fell back to the default registries. That makes sense with mirrors, but it's a behaviour change for all users, so please mention it in the PR description so it shows up in the release notes.

Requests that match no URL replacement rule could be redirected to a URL
that a rule replaces and reach the upstream the user replaced. Guard the
redirects of unreplaced requests too, keeping the client's own redirect
policy.

A 401 or 403 from a URL replacement target no longer wraps
ErrUnauthorized, so the CLI does not suggest `dbc auth login`, which
cannot help because replaced requests carry no credentials. It wraps the
new ErrURLReplacementUnauthorized instead.
@eitsupi
eitsupi marked this pull request as draft November 18, 2026 10:42
A custom CheckRedirect can rewrite the redirect URL. The guard already
checked the rewritten URL against the replacement rules; check it for an
HTTPS to HTTP downgrade as well.
@eitsupi

eitsupi commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Both points are addressed in 1539401:

  1. Redirects into a replaced origin: requests that match no rule now refuse a redirect to any URL a rule replaces, at every hop, keeping the client's own CheckRedirect (or the default limit of 10 redirects). Tests cover your case, an intermediate hop, a target with a query, a CheckRedirect that rewrites the URL, and the deprecated package-level functions. 4ef85cc also checks for an HTTPS-to-HTTP downgrade again after a custom CheckRedirect, since it can rewrite the URL.
  2. 401/403 from a mirror: this now wraps a new ErrURLReplacementUnauthorized instead of ErrUnauthorized, so the CLI no longer suggests dbc auth login. The error includes the status.

I also merged current main and added the config-loading behaviour change to the description.

@eitsupi
eitsupi marked this pull request as ready for review November 18, 2026 11:10

@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 addressed. guardRedirects now covers unreplaced requests on both the client and package-level paths, so a site the user didn't replace can no longer bounce a request to the upstream they did. I re-ran my repro and it's refused with no upstream hit. Keeping the caller's CheckRedirect semantics (the 10-hop default, ErrUseLastResponse passed through unwrapped) and re-checking after the callback rewrites the URL, including the HTTPS→HTTP check, is careful, and the tests cover each case. ErrURLReplacementUnauthorized with its own formatErr hint fixes the misleading dbc auth login suggestion, and the behavior-change note in the description is clear. Build, tests and golangci-lint v2.15.0 are clean on 4ef85cc. LGTM.

@zeroshade
zeroshade merged commit 3f0fba9 into columnar-tech:main Nov 18, 2026
20 checks passed
@eitsupi
eitsupi deleted the feat/url-replacements branch November 18, 2026 23:10
zeroshade pushed a commit that referenced this pull request Nov 23, 2026
…uiltin_registries` (#598)

Follow-up to #360. `replace_defaults` is named for replacing the
built-in registries, which is no longer needed: with #595 a third-party
registry can name its signing key and works like the built-in ones, and
with #577 the built-in registries can be reached through a mirror. What
the setting does is remove the built-in registries (the public and the
private Columnar registry) while keeping the `[[registries]]` entries,
so this renames it to `exclude_builtin_registries`. The user config now
wins when it excludes them.

```toml
exclude_builtin_registries = true

[[registries]]
url = "https://drivers.example.com"
name = "example"
```

- **Semantics:** the built-in registries are excluded when either the
user `config.toml` or the project's `dbc.toml` sets
`exclude_builtin_registries = true`, and a project's `false` no longer
adds them back. The CLI warns when a `dbc.toml` sets `false` that the
user config overrides, and keeps that `false` when it writes the file
back. The setting only stops dbc from adding the built-in registries to
the list; it is not an access control, so a `[[registries]]` entry with
a built-in registry's URL is still used. Omitting the key and `false`
now mean the same thing in both files.
- **Migration:** `replace_defaults` has not been released, so there is
no alias. The old key is ignored like any other unknown key, so a
`replace_defaults = true` written for a development build has to be
renamed or the built-in registries are used again.
- **Go API:** `GlobalConfig.ReplaceDefaults` becomes
`ExcludeBuiltinRegistries`. `LoadProjectRegistries` returns a `bool`
instead of a `*bool`, and `WithProjectRegistries` takes a `bool`, since
there is no longer an "inherit" state.
- **Docs:** adds a "Configuring registries" section to the driver
registry concepts page and a "Registries" section to the driver list
reference with the same content as #393, updated for the new key and
semantics, so this supersedes #393. For drivers that several registries
publish, they describe the behavior since #584 (the highest-priority
registry that has a matching version).
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