Commit 9deb0e3
authored
fix(scopes): Allow project:distribution scope to be granted to integration tokens (#102967)
## Summary
Fixes two related issues with the `project:distribution` scope for
Custom Integration tokens:
1. **Creation Error**: Users couldn't add the `project:distribution`
permission when creating Custom Integration tokens, getting the error:
*"Requested permission of project:distribution exceeds requester's
permission. Please contact an administrator to make the requested
change."*
<img width="1266" height="241" alt="Screenshot 2025-11-07 at 18 01 11"
src="https://github.com/user-attachments/assets/a7fdee78-182b-4f0c-a9da-be0b6d89d520"
/>
2. **Client Secret Masked**: Even if users bypassed the creation error,
the client secret was immediately masked as `****` instead of being
visible.
<img width="604" height="223" alt="Screenshot 2025-11-07 at 18 20 03"
src="https://github.com/user-attachments/assets/66f50d31-06bd-4454-9f7e-c280a9f6ab9e"
/>
## Root Cause
The `project:distribution` scope is a specialized token-only scope that
is intentionally not included in any user role (including owner). This
design allows distribution tokens to be used in apps that are
distributed without risking accidentally leaking a token with broader
permissions.
However, two pieces of validation logic were checking if the user
personally had these scopes:
1. **`SentryAppParser.validate_scopes()`** - Blocked creation if the
user didn't have the requested scopes
2. **`SentryApp.show_auth_info()`** - Hid the client secret if the user
didn't have all the integration's scopes
## Changes
- Added `SENTRY_TOKEN_ONLY_SCOPES` constant in `server.py` to define
scopes that can be granted to integration tokens even if the user
doesn't have them
- Updated `SentryAppParser.validate_scopes()` to skip permission checks
for token-only scopes
- Updated `SentryApp.show_auth_info()` to exclude token-only scopes when
determining if the client secret should be visible
- Added `project:distribution` to `SENTRY_SCOPE_SETS` for documentation
- Added test coverage for token-only scope validation and visibility1 parent 7616b7f commit 9deb0e3
File tree
4 files changed
+38
-1
lines changed- src/sentry
- conf
- sentry_apps
- api/parsers
- models
- tests/sentry/sentry_apps/api/endpoints
4 files changed
+38
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1789 | 1789 | | |
1790 | 1790 | | |
1791 | 1791 | | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
1792 | 1801 | | |
1793 | 1802 | | |
1794 | 1803 | | |
| |||
1818 | 1827 | | |
1819 | 1828 | | |
1820 | 1829 | | |
| 1830 | + | |
1821 | 1831 | | |
1822 | 1832 | | |
1823 | 1833 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
185 | 193 | | |
186 | 194 | | |
187 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
203 | 205 | | |
204 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
796 | 811 | | |
797 | 812 | | |
798 | 813 | | |
| |||
0 commit comments