Skip to content

feat(cli): Add token commands for org auth tokens - #1647

Open
sentry-junior[bot] wants to merge 4 commits into
mainfrom
feat/cli-org-auth-tokens
Open

sentry-junior[bot] wants to merge 4 commits into
mainfrom
feat/cli-org-auth-tokens

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Adds sentry token list, sentry token create, and sentry token delete for org auth tokens (the org:ci tokens used for source map, debug file, and release uploads). sentry tokens is an alias for token list. This is the CLI side of getsentry/sentry#128051, and replaces the archived getsentry/cli#1112.

sentry token list [<org>]
sentry token create [<org>/]<name>        # prints the token value once
sentry token delete [<org>/]<token-id>    # buildDeleteCommand: --yes/--force/--dry-run, type-to-confirm

Scopes

Sentry only lets OAuth application tokens that hold org:tokens manage org auth tokens. Personal tokens, org tokens, and SENTRY_AUTH_TOKEN get a 403. Here's what each endpoint requires, checked against the merged backend:

Command Needs
list org:tokens + org:read
create org:tokens + org:read + org:ci (an OAuth caller can only mint scopes it holds)
delete org:tokens + org:read + org:write (the delete is org:write, the confirm lookup is org:read)

org:tokens is now in SENTRY_SCOPES, so auth login --scope org:tokens validates. I kept it out of the default OAUTH_SCOPES on purpose. The device flow rejects the whole request when it sees a scope it doesn't know, so adding org:tokens to the defaults would break sentry auth login on older self-hosted servers.

Instead, each token command calls ensureScopesForAction, and it can now ask for scopes outside the defaults:

  • If required only names default scopes, nothing changes: the device flow requests the defaults.
  • Otherwise it requests three things: the defaults, the known opt-in scopes the grant already has (so elevating for one command doesn't remove what an earlier elevation added), and required.

When elevation is needed but this run can't do it (no TTY, --yes, or --json), a 403 gets a specific explanation: what to run once interactively, or that the command needs a CLI login plus an org role that allows it.

Notes for review

  • The endpoints are control-silo, so they're called through getControlSiloUrl(). They aren't in @sentry/api (checked 0.399.0), so OrgAuthTokenSchema is a Valibot schema that mirrors the backend serializer.
  • The full token value only appears in create output, including --json, because Sentry can't return it again. list shows only tokenLastCharacters.
  • delete reads the list to show the token name in the confirmation, since there's no single-token GET. The list is unpaginated server-side.
  • create splits org/name on the first /, but only when the prefix looks like an org slug. Names containing / work as long as the org is given explicitly.

Tests

  • New tests for the API module, the shared helpers, all three commands, and the opt-in scope elevation in scope-recovery.
  • typecheck, lint, check:docs-sections, check:destructive, check:fragments, and check:errors pass.
  • The full unit suite passes except 6 permission-based tests (chmod/EACCES) in completions, upgrade, telemetry, code-scanner, and file-changes. Those fail the same way on main in my sandbox, so they're environment issues unrelated to this change.
  • Not exercised against a live Sentry instance.

via BYK.

--

View Junior Session in Sentry

Add `sentry token list`, `sentry token create`, and `sentry token delete`
for managing org auth tokens (the org:ci tokens used for source map,
debug file, and release uploads). `sentry tokens` aliases `token list`.

Sentry only lets OAuth application tokens holding `org:tokens` manage org
auth tokens (getsentry/sentry#128051). `org:tokens` stays out of the
default login scopes so `sentry auth login` keeps working against older
self-hosted servers that don't know it. Instead, `ensureScopesForAction`
now requests scopes outside the defaults on demand: the device flow asks
for the defaults, the known opt-in scopes the grant already holds, and the
scopes the action needs.

Creating a token also needs `org:ci` (an OAuth caller can only mint scopes
it holds), and revoking one needs `org:write`.

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

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sentry-local Ready Ready Preview Oct 30, 2026 4:21pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 23, 2026
@BYK BYK self-assigned this Oct 23, 2026
@BYK
BYK requested a review from betegon October 23, 2026 22:36

@BYK BYK 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 but will wait on @betegon's review before merging

@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 a206a7f. Configure here.

--dry-run disables interactive prompts, so a dry run of token delete on a
login without org:tokens can't elevate and the token lookup fails with
403. Say that --dry-run is one of the flags that skips re-authorization.

betegon commented Oct 30, 2026

Copy link
Copy Markdown
Member

just seeing this now, i'll get to it today!

@betegon

betegon commented Oct 30, 2026

Copy link
Copy Markdown
Member

found two things while reviewing and fixed them in ac0edfd:

  • the table was splitting long tokens, breaking copy/paste. the token now prints intact on its own line.
  • token commands could use the wrong saved account. we now select the org's account before checking scopes.

added regression coverage for both; all 77 targeted tests pass.

This branch was successfully deployed

1 active deployment
Preview — cbb47a2d Deployed Oct 30, 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.

2 participants