Repository navigation
Description
Follow-on to #2008 (phase 3.1), the part that remains after #2002 merged.
Current state: a half-migration
cmd/oras/internal/option/containers_config.go:108 builds a ClientBuilder and calls builder.NewRepository(props) — then, 18 lines later, discards the client it just constructed:
builder := remote.NewClientBuilder()
builder.UserAgent = "oras/" + version.GetVersion()
builder.PolicyEvaluator = evaluator
...
repo, err := builder.NewRepository(props)
...
// line 126 — the builder's client is replaced wholesale
repo.Registry.Client, err = remo.authClientWithProperties(...)The in-tree comment is honest about why: the oras client carries --resolve, --header, client-certificate scoping, and the --debug trace. So ClientBuilder currently contributes only the user agent and policy evaluator, while authClientWithProperties (remote.go:383-507, ~125 lines of TLS/dialer/retry/auth assembly) still does the real work — and the default, non-containers path never touches ClientBuilder at all.
What blocks full adoption
ClientBuilder has a BaseTransport field, which can absorb the --resolve custom DialContext. What it has no hook for is registryCredentialTransport (remote.go:299-334): origin-scoped stripping of client certificates and --header values on cross-origin redirects, so a redirect to a third-party host does not receive the user's credentials. That is a deliberate security control, not incidental plumbing.
Two viable designs — pick one before writing code:
- Upstream it. Propose origin-scoped credential stripping in oras-go, so
ClientBuilderdoes it for every consumer. Best outcome, slowest. - Wrap
BaseTransport. KeepregistryCredentialTransportin the CLI and install it as the builder's base. Faster, but thenClientBuilderis not actually simplifying the hard part.
Note that the LOC reduction #2008 predicts (replacing "40+ lines of manual assembly") is unlikely to materialise under either design — the TLS/cert-scoping logic is the bulk of authClientWithProperties and it does not disappear.
Risk
This is the most security-sensitive code in the CLI. Reviewer feedback on #2002 found a Docker Hub credential-resolution regression that CI missed because e2e only exercises localhost registries — that blind spot is unchanged. Before refactoring here, consider adding e2e coverage against a non-localhost registry alias (the --resolve approach used to reproduce that bug).
Existing guard rails worth preserving: cmd/oras/internal/option/remote_test.go:1069 and :1140 assert on the transport scoping directly.
Acceptance
- Design decision recorded (upstream vs.
BaseTransportwrapper) - Both
newConfiguredRepositoryand the defaultNewRepository/NewRegistrypaths go through one client-construction path - No client certificate or
--headervalue is sent to a cross-origin redirect target; covered by test -
--resolve,--ca-file,--cert-file/--key-file,--insecure,--plain-http,--distribution-specand theregistries.conftoken-flow override all still behave as they do today
Activity
AuricX commentedon Nov 14, 2026
I want to work on this, I'd go with option 2 and install registryCredentialTransport as the builder's BaseTransport so both paths build the client through ClientBuilder. One catch is that buildTransport only applies the TLS config when the base is an *http.Transport, so the wrapper keeps building the registry and fallback transports with the client certs itself like it does today, and I'll add a test that a cross-origin redirect gets no client cert or --header values. Does that sound right or would you rather have the oras-go change first?
TerryHowe commentedon Nov 25, 2026
Waiting on the next oras-go release. oras-project/oras-go#1786 (
ClientBuilderfromConfigs) and oras-project/oras-go#1775 (extra sensitive headers forLoggingTransport) are merged on oras-gomainbut are not in v3.0.0, so this can't be picked up until oras-go v3.0.1/v3.1.0 is tagged.