Skip to content

feat(studio): add legacy token mode to scoped PAT creation flow - #48714

Closed
w3b6x9 wants to merge 9 commits into
w3b6x9/scoped-pat-permissionsfrom
w3b6x9/scoped-pat-ui-rework
Closed

w3b6x9 wants to merge 9 commits into
w3b6x9/scoped-pat-permissionsfrom
w3b6x9/scoped-pat-ui-rework

Conversation

@w3b6x9

@w3b6x9 w3b6x9 commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Replaces the scoped form's inline account-level access mode (blur overlay + confirmation checkbox) with a proper legacy-token escape hatch, tightens expiry handling across both token forms, and models permission requirements the way the platform actually enforces them.

Legacy token escape hatch

  • "Create legacy token" switches the sheet to the classic form (name + expiry only, with the classic account-wide warning) and creates the token through the legacy endpoint; the two-step review is skipped. The review step's MCP notice links back into legacy mode too.
  • Restore the "Generate token for experimental API" split-button dropdown on the scoped flow, extracted into a shared ExperimentalTokenDropdown used by both the classic button and the scoped sheet.
  • The mode-switch links mirror each other: "Need a token with full access to your account or one for the Supabase MCP server? Create legacy token" ↔ "Only need a token for specific projects or organizations? Create scoped token".

Tokens always expire

  • Removed the "Never" expiry option from every creation path (classic dialog and experimental V0 dialog) — new tokens must have an expiry. Existing non-expiring tokens are unaffected and still display normally.
  • Custom expiry dates are capped at one year from today: a single shared getMaxCustomExpiryDate() drives the scoped calendar bounds, zod validation, and the classic dialog's maxDate.
  • Calendars no longer page past the selectable range (scoped Calendar via startMonth/endMonth; the shared DatePicker derives them from minDate/maxDate). The shared DatePicker's only other consumer is the JIT database-access expiry picker, which picks up the same month bounds; reports/logs use the separate LogsDatePicker and are unaffected.

Permission groups modeled as OR-of-AND alternatives

  • Endpoint and MCP tool requirements are recorded as alternative permission groups (a token needs ALL scopes of at least ONE group), mirroring the mgmt-api x-fga-permissions semantics — development-vs-production branching alternatives no longer collapse into impossible conjunctions.
  • MCPToolScopeMappings is rewritten per endpoint from what each tool's handler actually calls (instead of expanding coarse OAuth scope bundles), with each entry annotated with its endpoint and the tool list pinned to the installed @supabase/mcp-server-supabase by test.

MCP-unsupported warnings

  • Add an MCP-unsupported warning to the review step (with a link back into legacy mode) and the view-token sheet, sharing one set of copy constants.

Cleanup and fixes

  • Deleted the orphaned first-iteration scoped form (Scoped/Form/Permissions/, Scoped/Form/ResourceAccess/, BasicInfo.tsx, AccessToken.schemas.ts + test) — no live importers.
  • Repaired the sheet component tests broken by the styling cleanup (chore(studio): scoped pat styling clean up #48689): permission categories now start collapsed and the risk summary renders as badge + description. Stacked PRs don't trigger the unit-test workflow, so this only surfaces locally until the stack targets master.
  • Switching into legacy mode clears stale organizationSlugs/projectRefs validation errors; covered by a round-trip regression test, plus a test for the review-step legacy link.
  • Copy: resource access card descriptions, "can't be updated after creation" admonition, correct "Search projects" placeholder, mode-agnostic sheet description, and inline links use InlineLinkClassName.

@coderabbitai

coderabbitai Bot commented Aug 4, 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: e0a113b4-01d9-4315-965e-1d09c0a5a504

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 4, 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 ↗︎.

@vercel

vercel Bot commented Aug 4, 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 7:10am
studio-staging Ready Ready Preview Aug 5, 2026 7:10am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 5, 2026 7:10am
design-system Skipped Skipped Aug 5, 2026 7:10am
docs Skipped Skipped Aug 5, 2026 7:10am
ui-library Skipped Skipped Aug 5, 2026 7:10am
zone-www-dot-com Skipped Skipped Aug 5, 2026 7:10am

Request Review

@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-permissions branch from 0897dad to 0eff5a0 Compare August 4, 2026 18:58
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  3 minutes, 56 seconds
commit  84c2e74

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

@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-ui-rework branch 3 times, most recently from a212038 to 308688c Compare August 5, 2026 07:00
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 5, 2026
w3b6x9 added 9 commits August 5, 2026 14:03
Replaces the scoped form's inline account-level access mode (blur overlay +
confirmation checkbox) with a proper legacy-token escape hatch, and tightens
expiry handling across both token forms.

- "Create legacy token" now switches the sheet to the classic form (name +
  expiry only, with the classic account-wide warning) and creates the token
  through the legacy endpoint; the two-step review is skipped. The link also
  mentions the Supabase MCP server as a reason to need one.
- Restore the "Generate token for experimental API" split-button dropdown on
  the scoped flow, extracted into a shared ExperimentalTokenDropdown used by
  both the classic button and the scoped sheet.
- Cap custom expiry dates at one year from today: single shared
  getMaxCustomExpiryDate() drives the scoped calendar bounds, zod validation,
  and the classic dialog's maxDate. Calendars no longer page past the last
  selectable month (scoped Calendar via startMonth/endMonth; shared DatePicker
  derives them from minDate/maxDate).
- Add an MCP-unsupported warning to the review step (with a link back into
  legacy mode) and the view-token sheet, sharing one set of copy constants.
- Copy: resource access card descriptions, "can't be updated after creation"
  admonition, and inline links now use InlineLinkClassName.
Tokens must always have an expiry: drop the "Never" preset from
EXPIRES_AT_OPTIONS so both classic entry points (flag-off dialog and the
experimental V0 dialog) can no longer create non-expiring tokens, matching
the scoped/legacy sheet which never offered one. Existing non-expiring
tokens are unaffected; the list still displays them.

Also deletes the orphaned BasicInfo.tsx (superseded by TokenDetails), the
dead 'never' branch in getExpirationDate, and re-baselines the dialog's
close reset to the full defaults.
Scoped/Form/Permissions/, Scoped/Form/ResourceAccess/, and
AccessToken.schemas.ts (+ test) belonged to the superseded scoped-form
design and had no live importers; the schemas file also still encoded the
removed non-expiring token semantics. PERMISSION_LIST /
ACCESS_TOKEN_RESOURCES stay: AccessTokenNewBanner still consumes them via
useGroupedPermissions.
The two create-token tests broke in the styling cleanup (#48689): permission
categories now start collapsed and the review step splits the risk summary
into a badge plus description. This never surfaced because stacked PRs don't
trigger the unit-test workflow. Expand the Project category before selecting
a permission and assert the new risk structure.

Also mirror the mode-switch links: "Switch back" becomes "Create scoped
token" so both directions read "…need a token…? Create <type> token".
The projects MultiSelector's search input said "Search organizations",
copied from the organization selector above it.
The sr-only description said the sheet is a two-step scoped token flow,
which is wrong once the legacy link switches it to the one-step classic
form. Use mode-agnostic copy.
setValue alone leaves a lingering organizationSlugs/projectRefs error in
formState after a failed scoped submit; the fields unmount in legacy mode
so the error was invisible but survived until the next full validation.
Buttons are keyboard-focusable by default; the explicit tabIndex={0} on
the three mode-switch links was a no-op.
The MCP-unsupported notice on the review step links back into legacy mode;
it was the only untested mode-switch entry point.
@w3b6x9
w3b6x9 force-pushed the w3b6x9/scoped-pat-ui-rework branch from 308688c to 84c2e74 Compare August 5, 2026 07:04
@w3b6x9 w3b6x9 removed the documentation Improvements or additions to documentation label Aug 5, 2026
@w3b6x9
w3b6x9 marked this pull request as ready for review August 5, 2026 10:39
@w3b6x9
w3b6x9 requested a review from a team as a code owner August 5, 2026 10:39
@kemaldotearth

Copy link
Copy Markdown
Contributor

Closing in favour of #48858

kemaldotearth added a commit that referenced this pull request Aug 8, 2026
…8858)

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

Remaining bits of #48714


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

## Summary by CodeRabbit

* **New Features**
  * Added role-aware access checks throughout scoped token creation.
* Organization selectors now disable project-only organizations and
recommend project-scoped tokens when appropriate.
* Review screens highlight missing capabilities and permissions
exceeding your current role.
  * Permission rows display indicators when access exceeds your role.
* Added resource keys, labels, and summaries to improve token review
clarity.

* **Documentation**
* Updated permission guidance with links to access-control
documentation.

* **Bug Fixes**
* Corrected project selector behavior when no organization is selected.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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