Skip to content

Show native OAuth project limits in auth status - #325

Merged
masnwilliams merged 5 commits into
mainfrom
hypeship/auth-status-native-projects
Nov 23, 2026
Merged

masnwilliams merged 5 commits into
mainfrom
hypeship/auth-status-native-projects

Conversation

@masnwilliams

@masnwilliams masnwilliams commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

kernel auth status decides its "Access scope" line from the token response's access_scope and project_id. Tokens from the native authorization server limit a grant to chosen projects through its policy and list them in a separate projects field, with access_scope: organization and no project_id. The CLI ignored that field, so a sign-in limited to one project showed "organization-wide". Enforcement was already correct; only the display was wrong.

  • Store projects from the token response on login, and keep it across refreshes that omit it.
  • auth status shows project <id> for one project, projects <id>, <id> for several, and organization-wide only when the grant isn't limited.
  • Legacy project-scoped tokens (access_scope: project) display as before.

Testing

  • go test ./pkg/auth/ ./cmd/: new tests for storing projects on exchange and keeping them on refresh, and for the scope label.
  • Not run against a live sign-in.

Note

Medium Risk
Touches authentication storage, refresh, and multi-process locking; bugs could break login or cause race-related refresh failures, but behavior is heavily tested.

Overview
kernel auth status now derives Access scope from stored projects (native grants with access_scope: organization) via accessScopeLabel, with legacy project_id unchanged and an unknown hint for credentials saved before scope was recorded. Debug output uses tokens.Source instead of probing the keyring directly.

OAuth login and refresh persist Projects and ScopeRecorded from token responses, and refresh keeps project lists when the response omits them.

Credential I/O is serialized with a cross-process lock file (withCredentialsLock); refreshStoredTokens re-loads under that lock so parallel CLI processes refresh once and avoid reusing consumed refresh tokens. Save/load stamps SavedAt, prefers the newer keyring vs file copy, and cleans up stale keyring entries when falling back to disk.

New tests cover scope labels, project persistence, concurrent save/refresh, and lock behavior.

Reviewed by Cursor Bugbot for commit 17026d0. Bugbot is set up for automated code reviews on this repo. Configure here.

@yummybomb yummybomb 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.

two credential issues to address:

  • pkg/auth/storage.go:28 — projects can push credentials past the windows keyring's 2,560-byte limit. login reports success after saving to disk, but the next command still reads the old keyring entry. make the successful fallback authoritative.
  • cmd/auth.go:181 — project-limited native logins saved by older cli versions still show organization-wide until refresh. show the scope as unknown when it wasn't recorded, and point users to kernel login --force.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 26a80d1. Configure here.

Comment thread pkg/auth/oauth.go Resolved
@masnwilliams

Copy link
Copy Markdown
Contributor Author

@yummybomb thanks, both addressed (26a80d1, 08ad67f):

  • Stale keychain entry after a disk fallback (pkg/auth/storage.go): when the keychain refuses the credentials and the file write succeeds, SaveTokens now deletes the old keychain entry. A successful keychain save removes a leftover credentials file. LoadTokens reads both stores and returns the newer copy (a new saved_at stamp, falling back to expiry for credentials saved by older CLIs), so the right copy wins even if that delete fails. Tests: TestSaveTokensFallbackReplacesStaleKeyring (keychain fails the way Windows does above 2,560 bytes) and TestLoadTokensPrefersNewerCopy.
  • Older logins showing organization-wide (cmd/auth.go): credentials now record scope_recorded when a login or refresh response states the access scope. Without it, auth status shows "unknown (saved by an older CLI version; run 'kernel login --force' to record it)". The first refresh by this CLI records it. Tests: TestAccessScopeLabel, TestRefreshRecordsScopeForOlderCredentials, TestRefreshLegacyTokensRemainOrganizationWide.

go test ./... passes; CI and BugBot are green on 08ad67f.

@yummybomb yummybomb 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.

the two original cases are covered: a newly saved disk fallback wins over a stale keychain entry, and older credentials no longer claim organization-wide scope when it wasn’t recorded. make test and go test -race ./pkg/auth passed on linux with a temporary home.

three things to fix before merge: preserve the active account on upgrade, avoid losing both copies during overlapping saves, and isolate the credential files in tests.

Comment thread pkg/auth/storage.go Resolved
Comment thread pkg/auth/storage.go Resolved
Comment thread pkg/auth/storage.go Resolved
Comment thread pkg/auth/storage.go Resolved
yummybomb
yummybomb approved these changes Nov 23, 2026 •
…d keep the keychain when neither copy is stamped
…native-projects

# Conflicts:
#	pkg/auth/oauth_test.go
@masnwilliams
masnwilliams merged commit 4c54fe1 into main Nov 23, 2026
8 checks passed
@masnwilliams
masnwilliams deleted the hypeship/auth-status-native-projects branch November 23, 2026 19:12
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.

2 participants