Skip to content

refactor: scope auth cache to command invocation - #2306

Merged
TerryHowe merged 2 commits into
oras-project:mainfrom
vmvarela:issue-2305/remove-global-auth-cache
Nov 2, 2026
Merged

TerryHowe merged 2 commits into
oras-project:mainfrom
vmvarela:issue-2305/remove-global-auth-cache

Conversation

@vmvarela

@vmvarela vmvarela commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

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 #2288, which stopped clients with different credentials from sharing tokens but kept the cache store global. Removing the global also removes the test order dependence (resetting the shared store) and stops cached tokens from outliving a command in the same process.

Which issue(s) this PR fixes:
Fixes #2305

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update? (not applicable)
  • Does this introduce breaking changes that would require an announcement or bumping the major version? (no; internal API only)
  • Do all new files have an appropriate license header?

Comment thread cmd/oras/internal/option/common.go Resolved
Comment thread cmd/oras/internal/option/remote.go Resolved
Comment thread cmd/oras/internal/option/remote.go Resolved
vmvarela added a commit to vmvarela/oras that referenced this pull request Nov 1, 2026
Address review feedback on oras-project#2306 by rebinding remotes on repeated command execution and allowing embedders to opt into cache reuse through a shared context.

Refs oras-project#2305
@vmvarela

vmvarela commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks Terry, fixed in 668b989.

ensureAuthCaches now rebinds on re-execution, and I’ve corrected the comment.

For #1923, embedders can opt into cross-execution token reuse via root.WithSharedAuthCache(ctx), without process-global state.

Added regression tests.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! The code looks good; the only blocker is the DCO check, because this commit is missing a Signed-off-by trailer:

  • 668b989 fix: preserve optional in-process auth cache reuse

https://github.com/oras-project/oras/runs/124987019290

To fix it, sign off the commits and force-push the branch:

git checkout issue-2305/remove-global-auth-cache
git rebase --signoff HEAD~2
git push --force-with-lease origin issue-2305/remove-global-auth-cache

For future commits, use git commit -s.

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]>
Address review feedback on oras-project#2306 by rebinding remotes on repeated command execution and allowing embedders to opt into cache reuse through a shared context.

Refs oras-project#2305

Signed-off-by: Victor M Varela <[email protected]>
@vmvarela
vmvarela force-pushed the issue-2305/remove-global-auth-cache branch from 668b989 to 4ca7d72 Compare November 2, 2026 07:51
@vmvarela
vmvarela requested a review from TerryHowe November 2, 2026 07:54
@TerryHowe
TerryHowe dismissed their stale review November 2, 2026 10:29

DCO is passing now, thanks!

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.59%. Comparing base (b50ff65) to head (4ca7d72).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/cmd.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2306      +/-   ##
==========================================
+ Coverage   61.90%   70.59%   +8.69%     
==========================================
  Files         140      154      +14     
  Lines        6100     6342     +242     
==========================================
+ Hits         3776     4477     +701     
+ Misses       2101     1601     -500     
- Partials      223      264      +41     

☔ 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 merged commit 986ac88 into oras-project:main Nov 2, 2026
10 checks passed
@TerryHowe TerryHowe mentioned this pull request Nov 17, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: remove process-global auth cache store

2 participants