Repository navigation
feat: migrate from oras-go v2 to v3 - #2002
Conversation
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
The remaining work beyond this PR's mechanical API renames is tracked in #2008 (phases 2–4). SummaryRemaining deprecation fixes (bugs / code duplication):
New v3 features to implement:
Steps 3 and 4 require a small slog→logrus bridge ( Steps 5+6 are the most impactful: adopting The full implementation order is in #2008. |
dd31789 to
850e58f
Compare
850e58f to
737eafc
Compare
41fe6f6 to
981dda2
Compare
94798d1 to
dc774e0
Compare
sajayantony
left a comment
There was a problem hiding this comment.
pending resolving conflicts.
dc774e0 to
bc28827
Compare
bc28827 to
8893aff
Compare
Rohilalala
left a comment
There was a problem hiding this comment.
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.
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. |
6cca507 to
0b0dac7
Compare
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]>
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]>
Signed-off-by: Terry Howe <[email protected]>
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]>
Signed-off-by: Terry Howe <[email protected]>
Signed-off-by: Terry Howe <[email protected]>
Signed-off-by: Terry Howe <[email protected]>
Signed-off-by: Terry Howe <[email protected]>
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]>
Signed-off-by: Terry Howe <[email protected]>
Signed-off-by: Terry Howe <[email protected]>
e921bee to
9e50b97
Compare
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]>
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]>
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]>
Summary
oras.land/oras-go/v2imports withgithub.com/oras-project/oras-go/v3, targetingv3.0.0(also bumped intest/e2e/go.mod)auth.NewCompositeTokenFetcheroras copy(oras copycan not handle separate authentication for same registry #1892): v3 keys the auth cache and scope hints by repository instead of registry hostRefs #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-prefixescerts.d: per-registry CA and client certificatesauth.json: credentials, consulted after the oras credential store (skipped when--registry-configis given)policy.json+registries.d: pull policy withsignedByverification--plain-http,--insecure,--ca-file,--cert-file/--key-file,--distribution-spec,-u/-p)ClientBuilder(for mirrors and policy), but the primary registry keeps the oras auth client, so--resolve,--header, client-certificate scoping and--debugbehave as beforeoras login/oras repo lsapply the host'sregistries.confentry (blocked, insecure, token-flow) andcerts.d, without a location rewrite, so credentials are stored under the name typedKey API Changes
auth.Credential{}credentials.Credential{}auth.EmptyCredentialcredentials.EmptyCredentialclient.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 byproperties.Resource)registry.ParseReference(s)properties.NewReference(s)repo.Client/PlainHTTP/HandleWarningrepo.Registry.Client/PlainHTTP/HandleWarningrepo.Reference.Registryrepo.Registry.Reference.Registryrepo.Reference.Repositoryrepo.RepositoryNamerepo.Reference(field)repo.Reference()(method, returnsproperties.Reference)ref.Reference(field)ref.GetReference()ref.ValidateReferenceAsTag()ref.ValidateTag()(properties.Reference.Tag)SetReferrersCapability()returns errorproperties.NewReferencerejects an empty tag (repo:), sooras backupstrips a trailing:before parsing to keep accepting that form.Test plan
go build ./...succeedsgo test ./...all passgo vet ./...cleangolangci-lint runcleanFixes #1892
Fixes #2260
Refs #2118 (
certs.dsupport is available behindORAS_EXPERIMENTAL_CONTAINERS_CONFIG)