Skip to content

feat(cli): Treat SENTRY_AUTH_TOKEN as an account next to stored logins - #1558

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-env-token-account
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-env-token-account

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Closes #1553.

Until now, if you had both a stored login and SENTRY_AUTH_TOKEN/SENTRY_TOKEN, every command ignored one of them. With this change the env token acts as one more account: read-only, never stored, and only sent to its own server. That only happens when its server comes from a trusted source: the token's sntrys_ claim, SENTRY_HOST/SENTRY_URL from the boot env, or SaaS when neither is set. Everything else keeps today's behavior.

Behavior (follows the answers on the issue: env token wins, switching stays implicit, show the /auth/ user)

  • Org routing: when the org cache shows the env token can access the target org, the command uses the env token, even if the active stored account can access it too. Orgs it can't access stay with the stored accounts. Without a target org, the stored login still wins over the env token, as fixed in update_issue returns API errors but operations succeed #646.
  • Server selection: with SENTRY_HOST/SENTRY_URL set, the env token is used for that server when no stored account is on it.
  • sentry org list lists the env token first, as env:SENTRY_AUTH_TOKEN. An org it shares with a login is listed under it, which matches what routing will pick. The label includes the token's user from /auth/ when the server returns one (skipped for org auth tokens). --account env:SENTRY_AUTH_TOKEN lists only the env token's orgs. With only an env token, the output doesn't change.
  • sentry auth list / sentry auth status show the env token with its server and user. sentry auth switch can't select it.
  • SENTRY_FORCE_ENV_TOKEN=1 still means "use only the env token".

Trust model. The env-token host snapshot now records which token was present at boot. A token added later, like a .sentryclirc [auth] token copied in by the shim, isn't scoped by that snapshot, so it doesn't become an account and keeps its fallback-only role. withEnvAccount() (the counterpart of withStoredAccount()) runs work under an env copy with the token forced and SENTRY_URL pinned to its trusted host. That way a .sentryclirc or pasted URL can't move it to another server.

Tradeoff for review. Org routing only learns which orgs the env token can access from the org cache, mostly filled by sentry org list. Because the env token wins for those orgs, an org auth token (sntrys_) whose org is cached will also be used for that org's non-build commands, where its scopes may be too narrow. That follows from the "env token wins" decision. If it's a problem in practice, we can restrict the precedence to user tokens.

via byk.

--

View Junior Session in Sentry

Closes #1553.

An env token whose server is known from a trusted source (its sntrys_
claim, SENTRY_HOST/SENTRY_URL from the boot env, or SaaS) now acts as one
more, never stored, read-only account instead of being all-or-nothing:

- Org routing uses it for organizations it knows, ahead of stored
  accounts (the active one included), and server-based selection uses it
  when no stored account is on the configured server.
- `sentry org list` lists its orgs under `env:SENTRY_AUTH_TOKEN`, labeled
  with its `/auth/` user when available; `--account env:SENTRY_AUTH_TOKEN`
  selects it.
- `sentry auth list` and `sentry auth status` show it with its server and
  user. `sentry auth switch` can't select it.

Tokens set after boot (a `.sentryclirc` token) keep today's fallback-only
behavior, and SENTRY_FORCE_ENV_TOKEN still means "use only the env token".

Co-Authored-By: byk <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 20, 2026 4:14pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 20, 2026

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

Cursor Bugbot has reviewed your changes 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 1eaacd7. Configure here.

Comment thread packages/cli/src/lib/db/accounts.ts
The env token's credential fingerprint doesn't depend on its server, so
orgs it cached while scoped to another SENTRY_URL could select it for a
same-slug org on its current server. Match cached orgs against the
token's trusted host (SaaS regions count as SaaS).

This branch was previously deployed

1 inactive deployment
Preview — 2e2627b2 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: treat SENTRY_AUTH_TOKEN/SENTRY_TOKEN as another account alongside stored logins

0 participants