Repository navigation
fix: share auth caches only between clients with the same credentials - #2288
Merged
TerryHowe merged 2 commits intoOct 24, 2026
Merged
Conversation
The first auth client became a package-level shared client, and every later client reused its auth.Cache. auth.Cache is keyed by registry and scope, not by credential, so in cp, backup and restore the --from and --to clients for the same registry could use each other's tokens. Key the shared caches by credential identity instead: username plus a hash of the secrets for static credentials, or the registry config paths for credential stores. Clients with the same credentials still share a cache across command executions, which keeps the behaviour added in oras-project#1923. Fixes oras-project#2276 Signed-off-by: sarankumar1325 <[email protected]>
sarankumar1325
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
October 24, 2026 05:40
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2288 +/- ##
==========================================
+ Coverage 60.78% 60.94% +0.15%
==========================================
Files 140 140
Lines 6092 6096 +4
==========================================
+ Hits 3703 3715 +12
+ Misses 2167 2161 -6
+ Partials 222 220 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
CodeQL flags SHA-256 over the password as weak password hashing. The key is only held in memory, so compare the credential directly and drop the hash. Signed-off-by: sarankumar1325 <[email protected]>
Member
|
Thanks! |
This was referenced Nov 1, 2026
vmvarela
added a commit
to vmvarela/oras
that referenced
this pull request
Nov 2, 2026
Replace the process-global auth cache map with a per-invocation store owned by option.Common. Clients with the same credentials still share a cache within one invocation, while different credentials and different invocations stay isolated. This is a follow-up to oras-project#2288, which stopped clients with different credentials from sharing tokens but kept the cache store global. Refs oras-project#2305 Signed-off-by: Victor M Varela <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
authClientused to make the first auth client a package-level shared client, and every later client reused itsauth.Cache.auth.Cacheis keyed by registry and scope, not by credential. So inoras cp,backupandrestore, when--fromand--topoint at the same registry with different credentials, each client could send the other's Basic or bearer token.This PR replaces
sharedClient(andSet/Get/ClearSharedClient) with shared caches keyed by credential identity:--registry-configpathsClients with the same identity still share a cache across command executions, which keeps the in-process re-auth saving from #1923. Clients with different identities get separate caches.
Tests:
TestRemote_authClient_SharedCachestill checks that same-credential clients share cached tokens. It now resets the caches withclearSharedCaches.TestRemote_authClient_SharedCacheByCredentialcovers a different username, password, identity token and credential store.TestRemote_authClient_SharedCacheByConfigcovers the same and different registry config paths.go test ./cmd/... ./internal/...andgolangci-lint run ./cmd/... ./internal/...pass. I did not run the e2e suite.The oras-go v3 branch (#2002) will need the same keying in its
CacheFactory. I left that out of this PR.AI assistance was used while preparing this change. I reviewed and tested it myself.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #2276
Please check the following list: