feat(auth): add --read-only flag to auth login#1032
Open
RaeesBhatti wants to merge 2 commits into
Open
Conversation
Adds an opt-in flag on `sentry auth login` that requests only the `*:read` subset of OAUTH_SCOPES (project, org, event, member, team). Useful for handing tokens to AI agents or CI jobs that should not be able to mutate Sentry state. Refs getsentry#1031
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 09767b0. Configure here.
OAuth scope is fixed when the token is issued, so the CLI cannot narrow an existing API token's permissions. Silently dropping --read-only on the --token path would give a false sense of safety to AI-agent and CI use cases. Refuse the combination with a ValidationError that points at the two correct paths. Reported by Cursor Bugbot on getsentry#1032.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a
--read-onlyflag tosentry auth loginthat requests only the*:readsubset ofOAUTH_SCOPES(project, org, event, member, team)during the OAuth device flow.
Today the device flow always requests the full hardcoded scope set
(including
project:write,project:admin,event:write,team:write). The only way to obtain a read-only token is to create aUser Auth Token in the web UI and pass
--token, which bypasses thedevice flow entirely.
Refs #1031.
Motivation
Code, Cursor, etc.) read Sentry issues and events for debugging
context. These agents act autonomously and can misinterpret
instructions — handing them a token that can resolve issues, mutate
projects, or delete teams is a real footgun. A read-only OAuth path
lets "let the agent investigate" not also mean "let the agent
accidentally change production state."
that only read shouldn't hold tokens that can also write or delete.
Implementation
Minimal surface (+24/-5 across 4 files):
src/lib/oauth.ts— new localSCOPES_READ_ONLY(filtered subset ofOAUTH_SCOPES);requestDeviceCodeandperformDeviceFlowtake areadOnly = falseparameter that selects the scope string.src/lib/interactive-login.ts—InteractiveLoginOptions.readOnly?: boolean, threaded through toperformDeviceFlow.src/commands/auth/login.ts— new"read-only"boolean flag (kebabper Stricli convention), wired into
runInteractiveLogin.plugins/sentry-cli/skills/sentry-cli/references/auth.md—auto-regenerated by
generate:docs.Default behavior is unchanged: omitting
--read-onlyrequests the samefull scope set as today.
Usage
The resulting token carries only
project:read,org:read,event:read,member:read,team:read.Test plan
sentry auth login --helpshows--read-onlywith the brief.sentry auth login --read-onlyagainst SaaS — Sentry's OAuthconsent screen lists only the read scopes.
sentry project delete) with a scope error.sentry auth login(no flag) is unchanged — full scope set.