个人访问令牌
个人访问令牌(PATs)用于验证你对管理 API以及基于它构建的工具的访问,比如 Supabase CLI 和 MCP 服务器。它们有两种类型:
🌐 Personal access tokens (PATs) authenticate you to the Management API and the tools built on it, like the Supabase CLI and the MCP server. They come in two flavors:
- 经典令牌,在仪表板中带有 Legacy(遗留) 徽章,拥有你账户的全部访问权限。这意味着你今天所属的每个组织和每个项目的所有权限,以及你未来创建或加入的每个项目的权限。一年前创建的经典令牌,也可以访问你今天创建的项目。
- 作用域令牌 仅包含你选择的组织、项目和权限。例如:你可以读取某个项目的数据库并查看其日志,但无法访问计费或组织设置。
我们建议给所有东西都使用范围限定的令牌,特别是 AI 代理、自动化脚本和持续集成环境。如果令牌泄露,影响范围也会很小。
🌐 We recommend scoped tokens for everything, especially AI agents, automation scripts, and CI environments. If a token leaks, the blast radius stays small.
要使用带作用域的个人访问令牌,你需要一个 Supabase 账号,并且在你希望令牌访问的组织或项目中有相应角色。带作用域的个人访问令牌的权限只能限制你账号已经有的操作,绝不会增加权限。如果你的角色没有某项权限(参见 访问控制),即使给令牌授予该权限也没用:令牌仍然无法执行该操作。
🌐 To use scoped personal access tokens you need a Supabase account with a role on the organization or project you want the token to reach. A scoped personal access token's permissions only ever narrow what your account can already do. They never grant more. If your role doesn't include a permission (see Access Control), granting that permission to a token has no effect: the token still can't do it.
你创建作用域令牌的方式与经典令牌相同,都是在你的访问令牌设置中完成。在创建时选择要授予的权限,而不是默认让令牌拥有全部访问权限。
🌐 You create scoped tokens the same way as classic tokens, from your access tokens settings. Choose which permissions to grant during creation instead of leaving the token with full access.
创建并使用有范围的个人访问令牌 #
🌐 Create and use a scoped personal access token
这个例子创建了一个只能读取一个项目设置的令牌,然后调用了该范围之外的端点。两个调用都是每个组织角色都可以读取的,包括只读,所以任何人都可以运行它。
🌐 This example creates a token that can only read one project's settings, then calls an endpoint outside that scope. Both calls are reads available to every organization role, including Read-Only, so anyone can run it.
- 去你的 访问令牌 设置里生成一个新的令牌。
- 在创建它时,将令牌限定在一个项目中,并只授予项目设置的读取权限。
- 复制令牌(作用域个人访问令牌以
sbp_fc开头)并在管理 API 中使用它,将your-project-ref替换为项目的引用:
export SUPABASE_ACCESS_TOKEN="sbp_fc..."# Allowed: Project Settings Read unlocks this endpointcurl "https://api.supabase.com/v1/projects/your-project-ref" \ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"# Returns the project's details# Denied: this endpoint needs the Database permission, which the token lackscurl -i "https://api.supabase.com/v1/projects/your-project-ref/types/typescript" \ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"# Returns HTTP 403要准确授予工作流所需的权限,请参阅 权限范围 了解每个端点所需的权限,以及 MCP 工具 了解每个 MCP 工具所需的权限。
🌐 To grant exactly what a workflow needs, see Permission scopes for the permission each endpoint requires and MCP tools for the permission each MCP tool requires.
在 Supabase CLI 中使用带作用域的个人访问令牌 #
🌐 Use a scoped personal access token with the Supabase CLI
supabase login 的浏览器流程会创建一个经典令牌。如果你想用范围令牌运行 CLI,可以把它设置在 SUPABASE_ACCESS_TOKEN 环境变量中,或者用 supabase login --token 保存它。环境变量会优先于任何已保存的令牌,所以它也是在 CI 中的正确选择。
🌐 The browser flow of supabase login creates a classic token. To run the CLI with a scoped token instead, set it in the SUPABASE_ACCESS_TOKEN environment variable, or save it with supabase login --token. The environment variable takes precedence over any saved token, which also makes it the right choice for CI.
例如,使用一个被授予 项目(全账户) 且拥有 读取 权限的令牌,supabase projects list 列出该令牌可以访问的项目:
🌐 For example, with a token granted Projects (account-wide) with Read access, supabase projects list lists the projects the token can reach:
export SUPABASE_ACCESS_TOKEN="sbp_fc..."supabase projects list当令牌缺少所需权限时,调用管理 API 的命令会因权限错误而失败。例如,supabase link 需要 项目设置、API 密钥 和 API 密钥秘密,所有这些都需要 读取 权限。
🌐 Commands that call the Management API fail with a permission error when the token lacks the required permission. supabase link, for instance, needs Project Settings, API Keys, and API Key Secrets, all with Read access.
连接你数据库密码的数据库命令,比如设置了 SUPABASE_DB_PASSWORD 的 supabase db push,不受令牌权限的限制。一个在执行 supabase db push 之前运行 supabase link 的工作流仍然需要 supabase link 所需的权限。
🌐 Database commands that connect with your database password, such as supabase db push with SUPABASE_DB_PASSWORD set, aren't limited by the token's permissions. A workflow that runs supabase link before supabase db push still needs the permissions supabase link requires.
权限范围 #
🌐 Permission scopes
每个权限控制对某个资源的只读或读写访问,例如 数据库、Edge 函数 或 生产分支。下面列出的权限和名称与创建作用域个人访问令牌时显示的内容相匹配。目前未解锁任何公共管理 API 端点或 MCP 工具的权限已省略。有些端点需要不止一个权限。脚注会标明这些情况。
🌐 Each permission controls read or read-write access to one resource, for example Database, Edge Functions, or Production Branches. The permissions and names below match those shown when creating a scoped personal access token. Permissions that currently unlock neither a public Management API endpoint nor an MCP tool are omitted. A few endpoints need more than one permission. The footnotes call these out.
MCP 工具 #
🌐 MCP tools
用于验证 MCP 服务器 的 scoped 个人访问令牌只能调用其授予权限解锁的工具。有关每个工具的功能,请参见 可用工具。
🌐 A scoped personal access token used to authenticate the MCP server can only call the tools its granted permissions unlock. See Available tools for what each tool does.
| MCP 工具 | 所需权限 |
|---|---|
apply_migration | 迁移(可读写) |
confirm_cost | 无(始终可用) |
create_branch | 开发分支(可读写)或 生产分支(可读写) |
create_edge_function_secret | 边缘函数密钥(读写)和 边缘函数密钥(只读) |
create_project | 组织项目(可读写) |
delete_branch | 生产分支(可读写)或 开发分支(可读写) |
deploy_edge_function | 边缘函数(可读写) |
execute_sql | 数据库(只读) |
generate_typescript_types | 数据库(只读) |
get_advisors | 顾问(只读) |
get_cost | 组织设置(只读)和 项目(全账户)(只读) |
get_edge_function | 边缘功能(只读) |
get_logs | 日志(只读) |
get_organization | 组织设置(只读) |
get_project | 项目设置(只读) |
get_project_url | 项目设置(只读) |
get_publishable_keys | API 密钥(只读) |
get_storage_config | 存储配置(只读) |
list_branches | 开发分支(只读)或 生产分支(只读) |
list_edge_functions | 边缘功能(只读) |
list_extensions | 数据库(只读) |
list_migrations | 迁移(只读) |
list_organizations | 组织(只读) |
list_projects | 项目(全账户)(只读) |
list_storage_buckets | 存储(只读) |
list_tables | 数据库(只读) |
merge_branch | 生产分支(可读写)或 开发分支(可读写) |
pause_project | 项目设置(可读写) |
query_logs | 日志(只读) |
rebase_branch | 生产分支(可读写)或 开发分支(可读写) |
reset_branch | 生产分支(可读写)或 开发分支(可读写) |
restore_project | 项目设置(可读写) |
search_docs | 无(始终可用) |
update_storage_config | 存储配置(可读写) |
Footnotes#
-
Requires Project Settings (Read) and Database (Read). ↩ ↩2 ↩3 ↩4
-
Requires Organization Settings (Read-write) and Project Settings (Read-write). ↩ ↩2
-
Requires Auth Config (Read-write) and Project Settings (Read-write). ↩ ↩2
-
Requires Project Settings (Read-write) and Database (Read-write). ↩ ↩2
-
Requires Database Config (Read), Database (Read), SSL Enforcement (Read), Network Restrictions (Read), Auth Config (Read), Data API Config (Read), Realtime Config (Read), and Storage Config (Read). ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
-
Requires Data API Config (Read) and Data API JWT Secret (Read). ↩