Skip to content

feat(auth): add --read-only flag to auth login#1032

Open
RaeesBhatti wants to merge 2 commits into
getsentry:mainfrom
RaeesBhatti:feat/auth-login-read-only
Open

feat(auth): add --read-only flag to auth login#1032
RaeesBhatti wants to merge 2 commits into
getsentry:mainfrom
RaeesBhatti:feat/auth-login-read-only

Conversation

@RaeesBhatti
Copy link
Copy Markdown

Summary

Adds a --read-only flag to sentry auth login that requests only the
*:read subset of OAUTH_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 a
User Auth Token in the web UI and pass --token, which bypasses the
device flow entirely.

Refs #1031.

Motivation

  • AI agents: a growing use case is letting an AI agent (Claude
    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."
  • Principle of least privilege: CI jobs and local dev sessions
    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 local SCOPES_READ_ONLY (filtered subset of
    OAUTH_SCOPES); requestDeviceCode and performDeviceFlow take a
    readOnly = false parameter that selects the scope string.
  • src/lib/interactive-login.tsInteractiveLoginOptions.readOnly?: boolean, threaded through to performDeviceFlow.
  • src/commands/auth/login.ts — new "read-only" boolean flag (kebab
    per 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-only requests the same
full scope set as today.

Usage

sentry auth login --read-only

The resulting token carries only project:read, org:read,
event:read, member:read, team:read.

Test plan

  • sentry auth login --help shows --read-only with the brief.
  • sentry auth login --read-only against SaaS — Sentry's OAuth
    consent screen lists only the read scopes.
  • The resulting token rejects write/admin endpoints (e.g.
    sentry project delete) with a scope error.
  • sentry auth login (no flag) is unchanged — full scope set.

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
Comment thread src/commands/auth/login.ts
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 09767b0. Configure here.

Comment thread src/commands/auth/login.ts
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.
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.

1 participant