Skip to content

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

Merged
BYK merged 11 commits into
mainfrom
feat/cli-org-auth-tokens
Nov 4, 2026
Merged

BYK merged 11 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.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 4, 2026 4:37pm 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.

Stale Bugbot comment from a previous run.

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

token delete revokes by the numeric ID from 'sentry token list'. Make
the argument help and examples say so, and reject sntrys_/sntryu_
values without echoing the secret back into the terminal or errors.

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

Stale Bugbot comment from a previous run.

Stricli's 'Failed to parse "<input>"' message quotes the raw argument,
so a pasted sntrys_/sntryu_ token still reached the terminal even after
token delete refused it. Redact the formatted message like other CLI
error output.

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

You should realize that this PR has merge conflicts?

Resolve conflicts with main's command manifest (#1918), build-only output
schemas (#1923) and toolkit-core Markdown builders (#1805):

- Register token/tokens in app.ts, command-manifest.ts, app-root.ts
  plurals and top-level-briefs.ts
- Re-export OrgAuthTokenSchema from output-schemas/token.ts (it also
  validates API responses) and read token list's fields from generated data
- Use text/inlineCode/tableCell from @sentry/toolkit-core/markdown
- Move the argument-error credential redaction to lib/application.ts
In a TTY the rendered code span wraps the token in color codes and a
space on each side, so copying the line could pick up an invalid
credential, and Sentry can't show the token again. Print the value as a
plain line after the rendered summary.

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

We should also accept the token name for token delete etc.

A token can now be revoked by the name shown in 'sentry token list', as
well as by its numeric ID. A name that several tokens share is refused
with their IDs, so a destructive action never picks one of them.

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

The ID grammar read 'my-org/ci/2024' as a project and ID, so a token
named 'ci/2024', which token create accepts, couldn't be revoked by
name. Tokens have no project, so split at the first slash like create.
Older Sentry orgs can have underscores in their slug, so 'my_org/ci'
named a token 'my_org/ci' in the default org instead of 'ci' in my_org.
@BYK
BYK merged commit 5a3f0a9 into main Nov 4, 2026
27 checks passed
@BYK
BYK deleted the feat/cli-org-auth-tokens branch November 4, 2026 21:09
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

Bumps `@sentry/api` from 0.256.0 to 0.337.0. getsentry#1559 needs the
issue-linking operations and the `expectedExternalIssueUrl` guard that
ship in the newer schema; landing the bump on its own keeps that PR
focused on the feature.

No source changes were needed. The only regenerated file is the `event`
skill reference, which now lists the `formatted` field the schema
documents for `event view`.

## Validation

- `tsc --noEmit` and lint pass.
- Unit suite: 473 files, 10,092 passed / 17 skipped (`TZ=UTC`).

Split out of getsentry#1559.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch was previously deployed

1 inactive deployment
Preview — cc253b55 Deployed Nov 4, 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