Skip to content

fix(studio): model scoped PAT permissions as OR-of-AND alternatives - #48635

Closed
w3b6x9 wants to merge 28 commits into
masterfrom
w3b6x9/scoped-pat-permissions
Closed

w3b6x9 wants to merge 28 commits into
masterfrom
w3b6x9/scoped-pat-permissions

Conversation

@w3b6x9

@w3b6x9 w3b6x9 commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

The permission scope map previously flattened every x-fga-permissions annotation into a single conjunctive scope list, turning OR-alternatives (e.g. development vs production branching on GET /v1/.../branches) into impossible AND requirements. EndpointMap and McpMap now store ScopeGroupAlternatives (string[][]) verbatim, and an item is enabled when ALL scopes of at least ONE group are granted — matching how the mgmt-api FGA guard actually evaluates the annotation. Edge cases follow plain DNF semantics: [[]] (one empty group) is ungated and callable by any token, [] (no groups) is satisfied by nobody, and endpoints with unusable annotations are dropped rather than recorded as ungated.

The MCP tool map is rewritten as a direct audit of the Management API endpoint each tool's handler in @supabase/mcp-server-supabase actually calls, with the endpoint named above every entry for re-auditing. The old two-hop derivation (tool -> legacy OAuth scope bundle -> FGA permissions) expanded coarse bundles into conjunctions of permissions the tool never uses, hiding tools from tokens that could genuinely call them. The map now covers the full tool registry, including ungated tools (search_docs, get_project_url, get_cost, confirm_cost), and a new test diffs its keys against the installed package's tool schemas so a dependency bump that adds or drops a tool fails CI by name.

buildAPIPermissionScopeMap now fetches the v1/v2 specs in parallel and indexes them in one pass (their path prefixes can't collide), replacing the lodash mergeWith custom-merger, and deep-clones the module-level tool mapping so callers can't mutate state that outlives the request.

djhi and others added 24 commits July 28, 2026 11:19
First stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Next stacked PR is #47979

This PR:
- merge the two existing token lists (classic and scoped) into one
- add an admonition about the scoped PAT migration (missing the docs
URL)

## Notes

It's not possible to create classic tokens anymore with the `scopedPAT`
flag enabled.

## How to test

### With the `scopedPAT` enabled (default on staging)

Go to
https://studio-staging-git-scopedpat-merge-token-lists-supabase.vercel.app/dashboard/account/tokens.
- You shouldn't see two tabs anymore
- If you had classic tokens, they should have the _classic_ badge
- You can create scoped tokens
- You have a way to copy newly created tokens above the list upon form
submission

### With the `scopedPAT` disabled (use the devtool to override)
- You shouldn't see two tabs anymore
- If you had classic tokens, they should **not** have the _classic_
badge
- You can create classic tokens
- You have a way to copy newly created tokens above the list upon form
submission

## Screenshots

Before:
<img width="775" height="515" alt="image"
src="https://github.com/user-attachments/assets/35733e7f-6e3e-40f9-ac5b-cfd7caf5d830"
/>

After:
<img width="767" height="671" alt="image"
src="https://github.com/user-attachments/assets/2fd86e6e-6dc6-46c8-9c89-cbfc553e4eb9"
/>
Second stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47886
Next stacked PR is #48003

This PR:
- refactor the scoped token creation form in a multi-step fashion

## How to test

Go to
https://studio-staging-git-scopedpat-scoped-token-creat-80c55b-supabase.vercel.app/dashboard/account/tokens

- Click the _Generate new token_ button
- Try submitting immediately. It should display errors correctly
- Configure everything except permissions and try submitting. It should
display a warning about missing permissions
- Configure the permissions and submit. It should display the review
step
- Try going back, modify anything and submit

- Create the token. It should display the token value with a button to
copy it and a checkbox to confirm the copy. You cannot close the sheet
at this step until you check the box and click _Done_.
Third stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47979
Next stacked PR is #47999

This PR add a way to view the tokens permissions

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

## Summary by CodeRabbit

* **New Features**
  * Added a “View permissions” option for scoped access tokens.
  * Scoped token permissions now open in a dedicated viewing panel.
  * Scoped token support is enabled by default.

* **Bug Fixes**
* Improved token deletion confirmation to clearly identify the selected
token.
  * Deletion dialogs now close correctly after successful removal.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fourth stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #48003
Next stacked PR is #48002

This PR:
- fix some accessibility issues
- add unit tests

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

## Summary by CodeRabbit

* **Tests**
* Added coverage for creating scoped access tokens at the project,
organization, and account levels.
* Verified validation for required fields, successful token creation,
clipboard copying, and completion flow.

* **Chores**
* Added temporary browser console logging when viewing a scoped access
token.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
…n API specs (#48182)

Fifth stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47999
Next stacked PR is #48359

This PR refactor how we get the map of which scopes enable which
endpoint or mcp tool. Previously it was an hardcoded file. We now
compute it from the OpenAPI specs of our API. This ensure the map stays
up to date when the API changes.

However, we don't have an always up-to-date equivalent for mcp tools so
we duplicated code from platform that map the OAuth scopes they check
with the FGA permissions.

## Notes

The react-hook-form usage is not great. A follow up PR will fix it

## How to test

- On
https://studio-staging-git-scopedpat-scope-permissions-api-supabase.vercel.app/dashboard/account/tokens
- Create a new token with a few permissions (their risk marker should be
displayed: (_High risk_, _Medium risk_ or _Low risk_)
- You should see the available endpoints and mcp tools in the review
step

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

## Summary by CodeRabbit

* **New Features**
* Added dynamic permission mapping for scoped access tokens, covering
Management API endpoints and MCP tools.
* Added a permissions endpoint with hosted-platform support and caching.
* Updated scoped token creation and review screens to show capabilities
based on granted permissions.
  * Added permission-aware risk indicators and tool visibility.

* **Bug Fixes**
* Improved authorization checks so endpoints and tools require all
necessary scopes.

* **Tests**
  * Added coverage for endpoint, scope, and MCP tool mapping behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
We don't follow good practices using react-hook-form for the scoped PAT.
This PR aims to fix that:

- pass `control` and `setValue` instead of `form`
- call `useWatch` instead of `form.watch`

No functional nor visual changes

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

## Summary by CodeRabbit

* **Bug Fixes**
* Improved the scoped access token creation flow so permission
selections and configured counts update reliably.
* Ensured the review step and final token creation use the validated
settings entered in the form.
* Reset dependent resource selections when changing access modes to
prevent conflicting configurations.
* Improved handling of account-level confirmation and token expiration
settings.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fixes UX/UI issues:
- when organization scope is selected: org selector should take the full
width
- Use org name and project name as the selected values label instead of
their ids
- There's a wrapping issue in multi-selector when more than one value is
selected
- There's an hover effect on disabled selects (when account scope
selected)
- On the review step: use the project/org names instead of their ids
@vercel

vercel Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

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

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

Request Review

@supabase

supabase Bot commented Aug 3, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented Aug 3, 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: c92a7cbe-fb0a-4088-9767-1e94b55fece5

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.

@w3b6x9
w3b6x9 requested a review from djhi August 3, 2026 05:43
@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  241 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  3 minutes, 46 seconds
commit  0a73f22

Flaky tests

Features › rls-policies.spec.ts › RLS Policies › Create RLS Policy › should create an UPDATE policy with custom condition
Features › table-editor.spec.ts › table editor › importing, pagination and large data actions works as expected

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

## 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?

@w3b6x9 initial pass at the announcement banner here. Please have a read
of the copy and feel free to improve where you see fit. I also corrected
how the actions are passed to our `<Admonition />` component. There's
also an inline comment to remind us to update the `Learn more` link when
we go live.

| Before | After |
|--------|--------|
| <img width="755" height="264" alt="Screenshot 2026-08-03 at 14 03 34"
src="https://github.com/user-attachments/assets/05b9e577-4d56-4c42-961a-37ac1e753141"
/> | <img width="769" height="300" alt="Screenshot 2026-08-03 at 14 03
46"
src="https://github.com/user-attachments/assets/11b7bdef-f7a3-47e5-a8b5-a021aafb0bca"
/> |
@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-permissions branch from 31e158d to d190858 Compare August 4, 2026 09:39
@w3b6x9 w3b6x9 changed the title fix(studio): preserve FGA OR-groups and correct MCP tool map for scoped tokens Scoped PAT: model FGA permission groups as OR-of-AND alternatives Aug 4, 2026
@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-permissions branch from d190858 to fde0554 Compare August 4, 2026 09:48
## 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?

This touches a few things, brushing them up in anticipation of release.

**Fixes and updates:**
- Fixed sheet width resizing on content changing within sheet.
- Tidied up labelling styles on Permissions row.
- Show expand icon on multi select input.
- Permissions list got a small tidy up.
- Vertical padding on footer to match rest of the sheet.
- Risk badge updated.
- Risk badge tooltip tidied up.
- View permissions sheet tidied up and updated to include MCP and API
endpoints.
- Second step/token summary tidied up.
@kemaldotearth

Copy link
Copy Markdown
Contributor

@w3b6x9 might want to pull latest from the parent branch, I styled some bits, though I don't think it'll effect your changes too much.

@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-permissions branch from fde0554 to 0897dad Compare August 4, 2026 16:55
The permission scope map previously flattened every `x-fga-permissions`
annotation into a single conjunctive scope list, turning OR-alternatives
(e.g. development vs production branching on `GET /v1/.../branches`)
into impossible AND requirements. EndpointMap and McpMap now store
ScopeGroupAlternatives (string[][]) verbatim, and an item is enabled
when ALL scopes of at least ONE group are granted — matching how the
mgmt-api FGA guard actually evaluates the annotation. Edge cases follow
plain DNF semantics: `[[]]` (one empty group) is ungated and callable by
any token, `[]` (no groups) is satisfied by nobody, and endpoints with
unusable annotations are dropped rather than recorded as ungated.

The MCP tool map is rewritten as a direct audit of the Management API
endpoint each tool's handler in @supabase/mcp-server-supabase actually
calls, with the endpoint named above every entry for re-auditing. The
old two-hop derivation (tool -> legacy OAuth scope bundle -> FGA
permissions) expanded coarse bundles into conjunctions of permissions
the tool never uses, hiding tools from tokens that could genuinely call
them. The map now covers the full tool registry, including ungated
tools (search_docs, get_project_url, get_cost, confirm_cost), and a new
test diffs its keys against the installed package's tool schemas so a
dependency bump that adds or drops a tool fails CI by name.

buildAPIPermissionScopeMap now fetches the v1/v2 specs in parallel and
indexes them in one pass (their path prefixes can't collide), replacing
the lodash mergeWith custom-merger, and deep-clones the module-level
tool mapping so callers can't mutate state that outlives the request.
@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-permissions branch from 0897dad to 0eff5a0 Compare August 4, 2026 18:58
@w3b6x9 w3b6x9 changed the title Scoped PAT: model FGA permission groups as OR-of-AND alternatives fix(studio): model scoped PAT permissions as OR-of-AND alternatives Aug 4, 2026
@w3b6x9
w3b6x9 marked this pull request as ready for review August 5, 2026 10:36
@w3b6x9
w3b6x9 requested a review from a team as a code owner August 5, 2026 10:36
Two small copy fixes to keep PAT descriptions accurate:

- temporary-access: drop the "(PAT or Scoped PAT)" parenthetical — the
token used as the Postgres role password is simply the user's Personal
Access Token, and calling out scoped variants here was confusing
- api/introduction: describe PATs as tokens with a custom expiry rather
than "long-lived", since expiry is now user-configurable
@w3b6x9
w3b6x9 requested a review from a team as a code owner August 5, 2026 10:40
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 5, 2026
Base automatically changed from scopedpat/root-branch to master August 6, 2026 13:40
@awaseem
awaseem requested review from a team as code owners August 6, 2026 13:41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if we considered the effect of rewording this on the data cleanness?

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?

First step in breaking down #48635


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

## Summary by CodeRabbit

* **Refactor**
* Removed the scoped access-token form, including token details,
expiration settings, resource access, and permission configuration.
* Removed resource and permission selection controls from the
access-token workflow.

* **Tests**
* Removed automated coverage for access-token validation, permission
handling, expiration logic, and resource selection.

<!-- 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]>
w3b6x9 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?

First step in breaking down #48635


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

## Summary by CodeRabbit

* **Refactor**
* Removed the scoped access-token form, including token details,
expiration settings, resource access, and permission configuration.
* Removed resource and permission selection controls from the
access-token workflow.

* **Tests**
* Removed automated coverage for access-token validation, permission
handling, expiration logic, and resource selection.

<!-- 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
… smaller version (#48809)

## 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?

Breaking down #48635


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

- **New Features**
- Scoped access tokens now support alternative permission requirements,
enabling more precise access for APIs and tools.
- Added clearer role and resource access evaluation, including
project-specific permissions and partial read access.
- Access reviews now identify unavailable or excessive permissions and
group inaccessible resources for easier resolution.
- **Bug Fixes**
- Improved handling of legacy, incomplete, or invalid permission data
with safer fallback behavior.
  - Corrected access filtering for MCP tools and API capabilities.
- **Documentation**
- Updated access-review wording to clarify the relationship between
scopes and related MCP tools.
<!-- 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

Copy link
Copy Markdown
Contributor

Closing this as #48809 took care of it and is now in master.

cc @w3b6x9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants