Skip to content

feat: migrate from oras-go v2 to v3 - #2002

Merged
TerryHowe merged 14 commits into
oras-project:mainfrom
TerryHowe:feat/migrate-to-oras-go-v3
Nov 2, 2026
Merged

TerryHowe merged 14 commits into
oras-project:mainfrom
TerryHowe:feat/migrate-to-oras-go-v3

Conversation

@TerryHowe

@TerryHowe TerryHowe commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replace all oras.land/oras-go/v2 imports with github.com/oras-project/oras-go/v3, targeting v3.0.0 (also bumped in test/e2e/go.mod)
  • Update API call sites for breaking changes in v3 (credential types and credential functions, repository struct fields, reference parsing and access, login/logout, scope hints)
  • Keep the v2 distribution-spec token flow for username/password credentials via auth.NewCompositeTokenFetcher
  • Add tests covering the migrated code paths (login, repo tags, tag, target/remote/cache options, registry auth scopes)
  • Follow-up work (remaining v3 deprecation fixes and new feature adoption) remains tracked in feat: migrate ORAS CLI from oras-go v2 to v3 #2008 (phases 2–4)
  • Fixes separate source/destination credentials on the same registry in oras copy (oras copy can not handle separate authentication for same registry #1892): v3 keys the auth cache and scope hints by repository instead of registry host
  • Fixes login to registries whose token realm is on a different private-network host, such as self-hosted GitLab (Gitlab registry login fails with 1.3.5 #2260): v3 blocks only loopback, link-local, unspecified and cloud-metadata realm addresses by default

Refs #2008 (phase 1 only; the issue stays open for the follow-up phases)

Experimental: containers configuration (ORAS_EXPERIMENTAL_CONTAINERS_CONFIG)

Setting ORAS_EXPERIMENTAL_CONTAINERS_CONFIG=1 (any true value) configures registry access from the container ecosystem files in their default locations, as podman and buildah do. Off by default: without the variable nothing new is read and behavior is unchanged.

  • registries.conf: aliases, blocked registries, location rewrites, mirrors, insecure, token-flow, referrers-api, blocked-realm-prefixes
  • certs.d: per-registry CA and client certificates
  • auth.json: credentials, consulted after the oras credential store (skipped when --registry-config is given)
  • policy.json + registries.d: pull policy with signedBy verification
  • Command line flags win over the files (--plain-http, --insecure, --ca-file, --cert-file/--key-file, --distribution-spec, -u/-p)
  • Repositories are assembled with oras-go's ClientBuilder (for mirrors and policy), but the primary registry keeps the oras auth client, so --resolve, --header, client-certificate scoping and --debug behave as before
  • oras login / oras repo ls apply the host's registries.conf entry (blocked, insecure, token-flow) and certs.d, without a location rewrite, so credentials are stored under the name typed
  • A config file that exists but cannot be parsed fails registry commands only when the variable is set

Key API Changes

v2 v3
auth.Credential{} credentials.Credential{}
auth.EmptyCredential credentials.EmptyCredential
client.Credential = func(ctx, hostport string) client.CredentialFunc = func(ctx, properties.Resource)
credentials.Credential(store) remote.NewCredentialFunc(store)
credentials.Login(ctx, store, reg, cred) remote.Login(ctx, store, reg, cred)
credentials.Logout(ctx, store, hostname) remote.Logout(ctx, store, properties.Resource{Registry: hostname})
auth.AppendRepositoryScope(ctx, registry.Reference, ...) auth.AppendRepositoryScope(ctx, properties.Reference, ...) (scope hints keyed by properties.Resource)
registry.ParseReference(s) properties.NewReference(s)
repo.Client/PlainHTTP/HandleWarning repo.Registry.Client/PlainHTTP/HandleWarning
repo.Reference.Registry repo.Registry.Reference.Registry
repo.Reference.Repository repo.RepositoryName
repo.Reference (field) repo.Reference() (method, returns properties.Reference)
ref.Reference (field) ref.GetReference()
ref.ValidateReferenceAsTag() ref.ValidateTag() (properties.Reference.Tag)
SetReferrersCapability() returns error no return value

properties.NewReference rejects an empty tag (repo:), so oras backup strips a trailing : before parsing to keep accepting that form.

Test plan

  • go build ./... succeeds
  • go test ./... all pass
  • go vet ./... clean
  • golangci-lint run clean

Fixes #1892
Fixes #2260

Refs #2118 (certs.d support is available behind ORAS_EXPERIMENTAL_CONTAINERS_CONFIG)

@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.80203% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.36%. Comparing base (986ac88) to head (9e50b97).

Files with missing lines Patch % Lines
cmd/oras/internal/option/containers_config.go 76.59% 14 Missing and 8 partials ⚠️
cmd/oras/root/logout.go 50.00% 1 Missing and 1 partial ⚠️
cmd/oras/internal/option/remote.go 98.00% 0 Missing and 1 partial ⚠️
cmd/oras/root/login.go 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2002      +/-   ##
==========================================
+ Coverage   70.59%   73.36%   +2.77%     
==========================================
  Files         154      155       +1     
  Lines        6342     6485     +143     
==========================================
+ Hits         4477     4758     +281     
+ Misses       1601     1444     -157     
- Partials      264      283      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe

TerryHowe commented Mar 11, 2026 •

Copy link
Copy Markdown
Member Author

The remaining work beyond this PR's mechanical API renames is tracked in #2008 (phases 2–4).

Summary

Remaining deprecation fixes (bugs / code duplication):

# Task Files Impact
1 oci.New() → oci.NewStorage() in cache — fixes process-safety bug for shared ORAS_CACHE option/cache.go bug fix
2 Delete internal/cache/ — use oras-go/content/cache (already ships this logic) internal/cache/, option/cache.go −100 lines
3 Replace custom handleWarning() sync.Map logic with remote.NewWarningLogger() option/remote.go −25 lines
4 Replace internal/trace/transport.go with remote.NewLoggingTransport() via ClientBuilder.Logger internal/trace/, option/remote.go −160 lines

New v3 features to implement:

# Task Benefit
5 ClientBuilder + properties.Registry in NewRepository()/NewRegistry() Consolidates 40+ lines of manual TLS/retry/auth plumbing
6 config.LoadConfigs() full ecosystem config stack Automatic Podman auth.json, per-registry TLS from certs.d, registry mirrors from registries.conf
7 oras.CopyError structured error handling in cp/push/pull/attach Distinguishes source vs destination failures in error messages

Steps 3 and 4 require a small slog→logrus bridge (internal/logutil/bridge.go, ~15 lines) since v3's warning/logging APIs use *slog.Logger and ORAS currently uses logrus.

Steps 5+6 are the most impactful: adopting config.LoadConfigs() unlocks mirrors and Podman credentials for users with no CLI changes needed.

The full implementation order is in #2008.

@TerryHowe
TerryHowe marked this pull request as draft March 18, 2026 00:24
@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from dd31789 to 850e58f Compare March 18, 2026 00:28
@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from 850e58f to 737eafc Compare April 18, 2026 15:33
@TerryHowe TerryHowe added this to the v1.4.0 milestone May 24, 2026
@TerryHowe TerryHowe mentioned this pull request Jul 21, 2026
1 task
@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from 41fe6f6 to 981dda2 Compare September 1, 2026 17:17
@TerryHowe
TerryHowe marked this pull request as ready for review September 1, 2026 20:26
@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from 94798d1 to dc774e0 Compare September 6, 2026 18:02

@sajayantony sajayantony left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending resolving conflicts.

@Rohilalala Rohilalala left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this through, it's a big one. I built it against rc.1 and against current oras-go main, and ran into a few things worth fixing before it goes in.

The main one: Docker Hub credentials stop being found. v2's credentials.Credential(store) mapped registry-1.docker.io to the https://index.docker.io/v1/ key, which is where docker login and oras login docker.io save them. remo.store.Get skips that mapping, so docker.io requests go out anonymously. I checked it with a fake registry behind --resolve: main sends the Basic auth header, this branch sends nothing and fails with "basic credential not found". CI doesn't catch it because e2e only uses localhost registries. remote.NewCredentialFunc(remo.store) fixes it on rc.1, and it's what main will need anyway.

Second, properties.NewReference strips http://, https:// and oci://, so oras manifest fetch http://host/repo:tag now quietly goes over HTTPS. It used to fail with an error. Not sure which way we want it, but it probably deserves a test.

Also, I don't see anything reading certs.d here, so Closes #2118 would close that issue unfixed. The description also mentions a remote/config blank import that isn't in the diff.

Heads-up for the rebase on oras-go main: AppendScopesForHost is gone (#1485), CredentialFunc and Logout now take properties.Resource (#1423, #1448), #1404 rejects a trailing :, so the reference_with_empty_tag backup test fails, and the new option/extra_tags.go from #2237 still imports v2. With those patched, the merged tree builds and passes for me.

Comment thread cmd/oras/internal/option/remote.go Resolved
Comment thread cmd/oras/internal/option/target.go Resolved
Comment thread internal/registryutil/auth.go Resolved
Comment thread cmd/oras/root/logout.go Resolved
Comment thread docs/proposals/oras-go-v3-migration.md Resolved
@TerryHowe

TerryHowe commented Oct 23, 2026 •

Copy link
Copy Markdown
Member Author

Also, I don't see anything reading certs.d here, so Closes #2118 would close that issue unfixed. The description also mentions a remote/config blank import that isn't in the diff.

Updated the comment to Refs that issue although even that is probably overstated. There will be a fast follow-up to this with a feature flag to enable all the new configuration

Thanks for the review btw.

@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from 6cca507 to 0b0dac7 Compare November 1, 2026 15:20
TerryHowe and others added 14 commits November 2, 2026 04:25
Replace all oras.land/oras-go/v2 imports with
github.com/oras-project/oras-go/v3 (v3.0.0-rc.1) across the CLI and the
e2e module, and update the call sites for the v3 breaking changes:

- auth.Credential -> credentials.Credential (moved package)
- auth.EmptyCredential -> credentials.EmptyCredential
- client.Credential -> client.CredentialFunc
- credentials.Credential(store) -> store.Get
- credentials.Login/Logout -> remote.Login/Logout
- repo.Client/PlainHTTP/HandleWarning -> repo.Registry.*
- repo.Reference.Registry -> repo.Registry.Reference.Registry
- repo.Reference.Repository -> repo.RepositoryName
- repo.Reference (field) -> repo.Reference().GetReference()
- ref.Reference (field) -> ref.GetReference()
- SetReferrersCapability no longer returns an error
- registry.ParseReference/registry.Reference -> properties.NewReference
- ValidateReferenceAsTag -> ValidateTag
- auth.AppendRepositoryScope -> auth.ScopeRepository +
  auth.AppendScopesForHost

Preserve the v2 runtime behavior where v3 changed a default, so this
migration is not user-visible:

- Set StoreOptions.IgnoreDefaultNativeStore. v3 replaced
  DetectDefaultNativeStore with its inverse and enabled detection by
  default, which would silently change where 'oras login' writes
  credentials (osxkeychain, wincred, or pass/secretservice instead of
  the plain-text config file). Adopting the new default is a separate
  decision.
- Pin the auth client to legacy token mode. v2's ForceAttemptOAuth2
  defaulted to false, so bearer tokens were fetched with GET <realm>
  using basic auth. v3's default composite TokenFetcher sends POST
  <realm> with grant_type=password and has no fallback, which would
  break registries that implement only the distribution-spec token
  endpoint. Set after SetUserAgent, since headers.Clone() returns nil
  when no custom headers are set.
- Key scope hints by request host. AppendScopesForHost with
  repo.Registry.Reference.Registry filed the Docker Hub hint under a key
  the auth client never reads (it looks up by request host, where
  docker.io maps to registry-1.docker.io), costing extra token
  round-trips and, for 'oras cp', the combined-scope token that
  cross-repo blob mount depends on. Adds a regression test; WithScopeHint
  had no coverage.

Also use remote.NewRepository with a tag- and digest-free reference
(v3.0.0-rc.1 rejects one carrying either, see oras-project/oras-go#1368),
initialize Repository with a non-nil Registry in the mount test, and
gofmt the touched files.

The docs/proposals entry records the remaining deprecation fixes and the
v3 features to adopt beyond this rename-level migration.

Closes: oras-project#2118

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Terry Howe <[email protected]>
Claude-Session: https://claude.ai/code/session_01MpTKRChww8pvfSPgN7cp33
Signed-off-by: Terry Howe <[email protected]>
Adapt to the API changes between rc.1 and rc.3:
- credentials.CredentialFunc takes a properties.Resource; resolve stored
  credentials through remote.NewCredentialFunc
- remote.Logout takes a properties.Resource
- scope hints are keyed by resource; use auth.AppendRepositoryScope
- strip a trailing ':' before parsing backup references, since
  properties.NewReference now rejects an empty tag

Signed-off-by: Terry Howe <[email protected]>
Reject URL schemes in references instead of letting oras-go v3 strip
them, parse the logout hostname with properties.ParseResource, and cover
docker.io credential lookup through the legacy index key.

Signed-off-by: Terry Howe <[email protected]>
…RS_CONFIG

When ORAS_EXPERIMENTAL_CONTAINERS_CONFIG is set to a true value, remote
repositories and registries are configured from registries.conf
(aliases, blocked registries, location rewrites, mirrors, insecure,
token-flow, referrers-api, blocked-realm-prefixes), certs.d, auth.json
(after the oras credential store, unless --registry-config is given),
and policy.json with registries.d signedBy verification. Command line
flags take precedence over the files.

Repositories are assembled by the oras-go ClientBuilder for mirrors and
policy, with the oras auth client kept for the primary registry so that
--resolve, --header, client certificate scoping and --debug behave as
before. Without the variable nothing new is read.

Signed-off-by: Terry Howe <[email protected]>
@TerryHowe
TerryHowe force-pushed the feat/migrate-to-oras-go-v3 branch from e921bee to 9e50b97 Compare November 2, 2026 11:26
@TerryHowe
TerryHowe merged commit 19a99d1 into oras-project:main Nov 2, 2026
10 checks passed
@TerryHowe
TerryHowe deleted the feat/migrate-to-oras-go-v3 branch November 2, 2026 11:36
NopeCharon added a commit to NopeCharon/oras-www that referenced this pull request Nov 19, 2026
ORAS CLI v1.4.0 can read the registry configuration files that Podman,
Buildah and Skopeo use when ORAS_EXPERIMENTAL_CONTAINERS_CONFIG is set
(oras-project/oras#2002). The site didn't document it.

Add a 1.4 how-to guide that covers:

- turning the experimental support on and the files it reads
  (registries.conf with its drop-ins, certs.d, auth.json, policy.json
  and registries.d), with their default locations and merge order
- pulling through a mirror, including pull-from-mirror, which commands
  use mirrors, and that mirrors don't use certs.d
- trusting a private CA and using a client certificate with certs.d,
  and that `insecure` skips certificate verification but doesn't enable
  plain HTTP
- location rewrites, wildcard and longest prefix matching, and blocked
  registries
- credentials from auth.json and when they are used
- restricting access with policy.json
- the ORAS-specific token-flow, referrers-api and
  blocked-realm-prefixes keys
- how command line flags combine with the files
- logging in when a registry is redirected, and troubleshooting
  configuration files that can't be parsed

Every behavior and error message in the guide was checked against the
v1.4.0 release binary with local registries.

Also link the guide from the v1.4.0 blog post, and add Podman, Buildah,
Skopeo and loopback to the Vale vocabulary.

Fixes oras-project#700

Signed-off-by: NopeCharon <[email protected]>
NopeCharon added a commit to NopeCharon/oras-www that referenced this pull request Nov 20, 2026
ORAS CLI v1.4.0 can read the registry configuration files that Podman,
Buildah and Skopeo use when ORAS_EXPERIMENTAL_CONTAINERS_CONFIG is set
(oras-project/oras#2002). The site didn't document it.

Add a 1.4 how-to guide that covers:

- turning the experimental support on and the files it reads
  (registries.conf with its drop-ins, certs.d, auth.json, policy.json
  and registries.d), with their default locations and merge order
- pulling through a mirror, including pull-from-mirror, which commands
  use mirrors, and that mirrors don't use certs.d
- trusting a private CA and using a client certificate with certs.d,
  and that `insecure` skips certificate verification but doesn't enable
  plain HTTP
- location rewrites, wildcard and longest prefix matching, and blocked
  registries
- credentials from auth.json and when they are used
- restricting access with policy.json
- the ORAS-specific token-flow, referrers-api and
  blocked-realm-prefixes keys
- how command line flags combine with the files
- logging in when a registry is redirected, and troubleshooting
  configuration files that can't be parsed

Every behavior and error message in the guide was checked against the
v1.4.0 release binary with local registries.

Also link the guide from the v1.4.0 blog post, and add Podman, Buildah,
Skopeo and loopback to the Vale vocabulary.

Fixes oras-project#700

Signed-off-by: NopeCharon <[email protected]>
TerryHowe pushed a commit to oras-project/oras-www that referenced this pull request Nov 20, 2026
Fixes #700 (part of #697)

**Depends on #705.** The guide goes in `versioned_docs/version-1.4/`,
which #705 adds, so this branch is based on it. Only the last commit,
2302395, belongs to this PR. Once #705 is merged I'll rebase, and the
diff will only show the guide.

## Summary

ORAS CLI v1.4.0 can read the registry configuration files that Podman,
Buildah and Skopeo use when `ORAS_EXPERIMENTAL_CONTAINERS_CONFIG` is set
(oras-project/oras#2002). This PR adds
`how_to_guides/containers_config.mdx` to the 1.4 docs. It covers the
items listed in the issue:

- **What it does and its status:** an "experimental, off by default"
warning at the top, how to turn it on, and that ORAS ignores the files
without the variable
- **Supported files:** a table of `registries.conf` (and its drop-ins),
`certs.d`, `auth.json`, `policy.json` and `registries.d`, with their
default locations, what ORAS uses from each, the merge order, and links
to the containers man pages
- **Worked examples:** a mirror (including `pull-from-mirror`), a
private CA and a client certificate in `certs.d`, a location rewrite, a
blocked registry, and a `policy.json` that allows only one registry
- **ORAS-specific keys:** `token-flow`, `referrers-api` and
`blocked-realm-prefixes`
- **Precedence:** how each flag combines with the files
- **`oras login` and `oras repo ls`:** which settings they use, and
which host to log in to when a registry is redirected
- **Errors:** the error you get when a file can't be parsed, and how to
rule out the files

It also links the guide from the v1.4.0 blog post, which said it would
add the link once this guide existed. It also adds `Podman`, `Buildah`,
`Skopeo` and `loopback` to the Vale vocabulary.

## Behavior worth knowing

I ran each scenario against the v1.4.0 binary, and some of the results
are worth documenting:

- for the registry, `insecure = true` only skips certificate
verification. Unlike Podman, ORAS doesn't fall back to plain HTTP, so
`--plain-http` is still needed
- mirrors are only used for resolving and fetching. They are reached
over TLS, verified against the system trust store or skipped with
`insecure`. `certs.d` doesn't apply to them (see
`buildMirrorRepositories` in oras-go v3)
- short-name `[aliases]` can't be used from the CLI, because ORAS
rejects a reference without a registry before it reads the files. The
guide says so rather than listing aliases as supported
- `policy.json` is also checked for `oras push` and `oras repo tags`
- a malformed `$HOME/.config/containers/registries.conf` is skipped
without an error, while a malformed drop-in, `auth.json`, `policy.json`
or `~/.docker/config.json` fails the command. This comes from
`LoadSystemRegistriesConfig` in oras-go v3. The guide mentions it in the
troubleshooting section

## Validation

- ran local `registry:3` instances (plain HTTP, TLS with a private CA,
htpasswd auth, and mutual TLS) and checked every behavior and error
message in the guide with the v1.4.0 binary: mirror fallback and
`Pulled` output, `certs.d` CA and client certificates (also for `oras
repo ls`), path rewrites for pull and push, wildcard and blocked
prefixes, `auth.json` from `$XDG_RUNTIME_DIR` and `~/.config/containers`
(including a namespace entry, and skipped with `--registry-config`),
`policy.json` reject and allow, login against a rewritten registry,
flags overriding the files, and parse errors
- `vale` on the new page: 0 errors, 0 warnings
- `npm test` (32 passed), `npm run check-links`, `docusaurus build`. The
page shows up in the 1.4 sidebar only

Signed-off-by: NopeCharon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gitlab registry login fails with 1.3.5 oras copy can not handle separate authentication for same registry

4 participants