Skip to content

fix(auth): add alerts:read and alerts:write to default OAuth scopes#1137

Merged
MathurAditya724 merged 1 commit into
mainfrom
fix/add-alerts-scopes-to-oauth
Jun 24, 2026
Merged

fix(auth): add alerts:read and alerts:write to default OAuth scopes#1137
MathurAditya724 merged 1 commit into
mainfrom
fix/add-alerts-scopes-to-oauth

Conversation

@sergical

Copy link
Copy Markdown
Member

What

Add alerts:read and alerts:write to the default OAuth scope set requested during sentry auth login.

Why

sentry alert metrics create was returning "You may not have access to this resource" (403) even after a successful sentry auth login. Dashboard creation worked fine, so something was inconsistent.

Root cause: the metric alert POST /organizations/{org}/alert-rules/ endpoint has two permission layers:

  1. Scope map check — allows org:read, which the CLI already requests. This passes. ✓
  2. Secondary check_can_create_alert() in src/sentry/incidents/endpoints/bases.py — requires one of alerts:write, org:write, or org:admin (or team-admin project access). This fails. ✗

Dashboard creation only has the scope map check (accepts org:read), so it worked. Alert creation silently had a harder gate that the CLI's scope set never satisfied.

The fix is adding alerts:write (and its paired read scope) to OAUTH_SCOPES in src/lib/oauth.ts.

Impact

Existing users will need to re-authenticate to pick up the new scopes:

sentry auth logout
sentry auth login

The generated doc sections in DEVELOPMENT.md and docs/src/content/docs/self-hosted.md are updated to match (these are normally regenerated by pnpm run generate:docs-sections).


View Session in Sentry

sentry alert metrics create was blocked with 403 even after sentry auth
login because the metric alert POST endpoint has a secondary permission
check (check_can_create_alert) that requires alerts:write, org:write, or
org:admin — none of which were in the CLI's default OAuth scope set.

Dashboard creation works fine because its POST only gates on org:read,
which is already in scope. The inconsistency was the missing alerts:write.

Add alerts:read and alerts:write to OAUTH_SCOPES. Users with existing
tokens will need to re-authenticate to pick up the new scopes:

  sentry auth logout && sentry auth login

Update generated doc sections in DEVELOPMENT.md and self-hosted.md
(script/generate-docs-sections.ts regenerates these from OAUTH_SCOPES).

Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1137/

Built to branch gh-pages at 2026-06-24 01:08 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@sergical sergical marked this pull request as ready for review June 24, 2026 01:08
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5050 uncovered lines.
✅ Project coverage is 81.34%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.34%    81.34%        —%
==========================================
  Files          392       392         —
  Lines        27070     27070         —
  Branches     17566     17566         —
==========================================
+ Hits         22019     22020        +1
- Misses        5051      5050        -1
- Partials      1832      1832         —

Generated by Codecov Action

@MathurAditya724 MathurAditya724 merged commit 39bdc65 into main Jun 24, 2026
29 checks passed
@MathurAditya724 MathurAditya724 deleted the fix/add-alerts-scopes-to-oauth branch June 24, 2026 05:23
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