Skip to content

refactor: finish ClientBuilder adoption in NewRepository()/NewRegistry() #2316

Open

Description

@TerryHowe

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:

  1. Upstream it. Propose origin-scoped credential stripping in oras-go, so ClientBuilder does it for every consumer. Best outcome, slowest.
  2. Wrap BaseTransport. Keep registryCredentialTransport in the CLI and install it as the builder's base. Faster, but then ClientBuilder is 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. BaseTransport wrapper)
  • Both newConfiguredRepository and the default NewRepository/NewRegistry paths go through one client-construction path
  • No client certificate or --header value is sent to a cross-origin redirect target; covered by test
  • --resolve, --ca-file, --cert-file/--key-file, --insecure, --plain-http, --distribution-spec and the registries.conf token-flow override all still behave as they do today

Activity

  1. added this to the future milestone on Nov 4, 2026
  2. added
    enhancement
    go
    on Nov 4, 2026
  3. AuricX commented on Nov 14, 2026

    @AuricX

    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?

  4. TerryHowe commented on Nov 25, 2026

    @TerryHowe
    MemberAuthor

    Waiting on the next oras-go release. oras-project/oras-go#1786 (ClientBuilder from Configs) and oras-project/oras-go#1775 (extra sensitive headers for LoggingTransport) are merged on oras-go main but are not in v3.0.0, so this can't be picked up until oras-go v3.0.1/v3.1.0 is tagged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgo

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions