Skip to content

feat(studio): role-aware access feedback for scoped access tokens - #48742

Closed
w3b6x9 wants to merge 1 commit into
w3b6x9/scoped-pat-ui-reworkfrom
w3b6x9/scoped-pat-access-feedback
Closed

w3b6x9 wants to merge 1 commit into
w3b6x9/scoped-pat-ui-reworkfrom
w3b6x9/scoped-pat-access-feedback

Conversation

@w3b6x9

@w3b6x9 w3b6x9 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Scoped PATs are enforced server-side as the intersection of the token's granted scopes and the owner's live role, re-checked on every request. The UI previously said nothing about this: any member could select any permission scope for any resource, get no warning at creation, and the token view kept rendering stored scopes as fact after the owner's access changed. This adds advisory (never blocking) feedback across the whole scoped-token flow so users learn at selection time -- not at their first 403 -- what a token can actually do.

Core (AccessToken.roles.ts):

  • FGA_SCOPE_MINIMUM_ROLE: all 83 permission scopes transcribed from the OpenFGA model's role unions, mapped to the lowest base role that holds them. A drift-guard test pins the key set to the scope ids published in @supabase/shared-types, so upstream additions fail CI here with re-transcription instructions.
  • estimateRoleLevel: derives the user's base role per org (or per project for project-invited members) from the ungated /platform/profile/ permissions rows via four discriminating ABAC probes, verified against the platform's default_permissions seeds. Works for every member type with no permission-gated endpoint.
  • computeTokenRoleContext + applySelectionToRoleContext: role resolution (expensive, memoized) is split from selection evaluation (cheap, re-run per permission toggle). Results carry per-resource failing roles, including per-project detail for members invited to projects rather than the org.

Creation form:

  • Orgs where the user only has project-level access are disabled in org-scope mode, with an inline explanation.
  • Permission rows and the review summary show a red "Exceeds your role" pill whose tooltip names the exact resources where requests would be denied, the required role, and the user's actual role there (spelling out per-project roles for project-invited members).
  • The review admonition breaks exceeded permissions down per resource, organizations first; the risk badge is computed on the role-capped effective scope set.
  • The immutability warning moved from a persistent admonition to micro-copy at the point of commitment; the permissions step links the access-control docs.

Token view sheet:

  • Lost access is distinguished from deletion (deleting a project/org erases the token's FGA bindings; removal does not): bindings that vanished render a "resources no longer exist" state, while bindings the user can no longer reach show an anonymous count with a "No longer accessible" badge and a "removed from" admonition.
  • Accessible resources list name plus ref/slug; capabilities carry the same exceeds-role pills; risk reflects what the owner's current role allows. Header now has separate Access control and API docs buttons (DocsButton gained a label prop).

All signals recompute from live org/project/permission queries, so the view tracks membership changes without stored state, and everything degrades to "no warnings" while data loads or on self-hosted.

@w3b6x9
w3b6x9 requested a review from a team as a code owner August 5, 2026 10:33
@vercel

vercel Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview Aug 5, 2026 11:38am
studio-staging Ready Ready Preview Aug 5, 2026 11:38am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 5, 2026 11:38am
design-system Skipped Skipped Aug 5, 2026 11:38am
docs Skipped Skipped Aug 5, 2026 11:38am
ui-library Skipped Skipped Aug 5, 2026 11:38am
zone-www-dot-com Skipped Skipped Aug 5, 2026 11:38am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c4d8954d-b97c-456f-b435-d24d7c39cc60

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Aug 5, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  3 minutes, 34 seconds
commit  a7d1d53

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  3 minutes, 20 seconds
commit  56ef87a

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Scoped PATs are enforced server-side as the intersection of the token's
granted scopes and the owner's live role, re-checked on every request. The
UI previously said nothing about this: any member could select any
permission scope for any resource, get no warning at creation, and the
token view kept rendering stored scopes as fact after the owner's access
changed. This adds advisory (never blocking) feedback across the whole
scoped-token flow so users learn at selection time -- not at their first
403 -- what a token can actually do.

Core (AccessToken.roles.ts, all pure and unit-tested):

- FGA_SCOPE_MINIMUM_ROLE: all 83 permission scopes transcribed from the
  OpenFGA model's role unions, mapped to the lowest base role that holds
  them. A drift-guard test pins the key set to the scope ids published in
  @supabase/shared-types, so upstream additions fail CI here with
  re-transcription instructions.
- estimateRoleLevel: derives the user's base role per org (or per project
  for project-invited members) from the ungated /platform/profile/
  permissions rows via four discriminating ABAC probes, verified against
  the platform's default_permissions seeds. Works for every member type
  with no permission-gated endpoint.
- computeTokenRoleContext + applySelectionToRoleContext: role resolution
  (expensive, memoized) is split from selection evaluation (cheap, re-run
  per permission toggle). Results carry per-resource failing roles,
  including per-project detail for members invited to projects rather
  than the org.

Creation form:

- Orgs where the user only has project-level access are disabled in
  org-scope mode, with an inline explanation.
- Permission rows and the review summary show a red "Exceeds your role"
  pill whose tooltip names the exact resources where requests would be
  denied, the required role, and the user's actual role there (spelling
  out per-project roles for project-invited members).
- The review admonition breaks exceeded permissions down per resource,
  organizations first; the risk badge is computed on the role-capped
  effective scope set.
- The immutability warning moved from a persistent admonition to
  micro-copy at the point of commitment; the permissions step links the
  access-control docs.

Token view sheet:

- Lost access is distinguished from deletion (deleting a project/org
  erases the token's FGA bindings; removal does not): bindings that
  vanished render a "resources no longer exist" state, while bindings the
  user can no longer reach show an anonymous count with a "No longer
  accessible" badge and a "removed from" admonition.
- Accessible resources list name plus ref/slug; capabilities carry the
  same exceeds-role pills; risk reflects what the owner's current role
  allows. Header now has separate Access control and API docs buttons
  (DocsButton gained a label prop).

All signals recompute from live org/project/permission queries, so the
view tracks membership changes without stored state, and everything
degrades to "no warnings" while data loads or on self-hosted.
@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-access-feedback branch from a7d1d53 to 56ef87a Compare August 5, 2026 11:34
kemaldotearth added a commit that referenced this pull request Aug 6, 2026
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Logic-only extraction from #48742. Scoped PATs are enforced server-side
as the intersection of the token's granted scopes and the owner's live
role, re-checked on every request. This lands the pure inference layer
that will power advisory (never blocking) UI feedback; no UI consumes it
yet.

- FGA_SCOPE_MINIMUM_ROLE: all 83 permission scopes transcribed from the
OpenFGA model's role unions, mapped to the lowest base role that holds
them. A drift-guard test pins the key set to the scope ids published in
@supabase/shared-types, so upstream additions fail CI here with
re-transcription instructions.
- estimateRoleLevel: derives the user's base role per org (or per
project for project-invited members) from the ungated /platform/profile/
permissions rows via four discriminating ABAC probes. Works for every
member type with no permission-gated endpoint.
- computeTokenRoleContext + applySelectionToRoleContext: role resolution
(expensive, memoized) is split from selection evaluation (cheap, re-run
per permission toggle).

AccessToken.permissions.ts gains only what the roles module needs: the
PermissionLevel type and the catalog's `level` field (decides whether an
org or project role governs a resource), plus getEntryScopes, which
selectionToScopes now reuses. The UI-only additions from #48742 (risk
badge/dot variants, mode labels, the OverallRisk.text -> description
rename) are deliberately left out so this PR touches no .tsx.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added role-aware evaluation for scoped access-token permissions.
* Added support for organization- and project-level permission scoping.
* Added guidance when selected permissions exceed the current role,
including read-only downgrades and inaccessible resources.
  * Added clearer grouping of permission access issues by resource.

* **Tests**
* Added comprehensive coverage for role mapping, permission evaluation,
scoping, and failure scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Wen Bo Xie <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
kemaldotearth added a commit that referenced this pull request Aug 7, 2026
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Extracts the token view sheet slice of #48742
(w3b6x9/scoped-pat-access-feedback, commit 56ef87a). The role-evaluation
logic (estimateRoleLevel, computeTokenRoleContext,
applySelectionToRoleContext, groupFailingResources) already landed on
master via #48805 and #48809 — this PR only wires the view sheet up to
it:

- Bindings whose project/org was deleted (FGA bindings erased) render a
"resources no longer exist" state; bindings the user can no longer reach
render an anonymous count with a "No longer accessible" badge and a
"removed from" admonition.
- Accessible resources list their name plus ref/slug; capabilities show
"Exceeds your role" pills and the risk badge reflects what the owner's
current role actually allows.
- Header split into separate "Access control" and "API docs" buttons.
- Everything recomputes from live org/project/permission queries (no
stored state) and degrades to no warnings while loading or on
self-hosted.

Also gives DocsButton an optional `label` prop (defaults preserve
existing behavior for every other consumer) so the two header buttons
can carry distinct text.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Enhanced access-token details with permission categories, risk
summaries, endpoint, and MCP information.
  * Added warnings for permissions exceeding the token’s role.
* Clearly identifies inaccessible, deleted, or unavailable organizations
and projects.
  * Added resource details and remediation guidance for unusable tokens.
  * Documentation links can now display custom labels.

* **Bug Fixes**
* Improved access evaluation when organization or project data is
incomplete or access has changed.
  * Deferred resource loading until token details are opened.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Sonnet 5 <[email protected]>
@kemaldotearth

Copy link
Copy Markdown
Contributor

Fully replaced by master-based PRs: #48803 (orphaned form cleanup), #48811 (expiry enforcement), #48844 (legacy token mode), #48849 (MCP warnings). The test-repair commit was superseded by the fix already on master via #48384.

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.

2 participants