移除 Studio 的超级用户权限
Learn how to switch from the supabase_admin to postgres role in self-hosted Supabase.
概览 #
🌐 Overview
在2022年底,Supabase 在托管项目中引入了一项安全变更,从仪表板 SQL 编辑器中移除了超级用户访问权限,并将用户创建的数据库对象的所有权从 supabase_admin 转移到了 postgres 角色。你可以在官方公告中了解更多信息。
🌐 In late 2022, Supabase introduced a security change in hosted projects that removed superuser access from the dashboard SQL editor and shifted ownership of user-created database objects away from supabase_admin toward the postgres role.
You can read more about it in the official announcement.
不过,这次迁移从未自动应用到自托管的 Supabase 实例上。
🌐 However, this migration was never automatically applied to self-hosted Supabase instances.
结果是:
🌐 As a result:
- 通过仪表板创建的对象可能仍然归
supabase_admin所有 - 行为与 Supabase 平台不同
- 有些迁移在以
postgres身份运行时可能会失败
本指南解释了如何将你自托管的 Supabase 实例与 Supabase 平台上使用的安全增强和所有权模型对齐。
🌐 This guide explains how to align your self-hosted Supabase instance with the security enhancements and ownership model used on the Supabase platform.
更改配置 #
🌐 Changing the configuration
第1步:更新数据库对象所有权 #
🌐 Step 1: Update database object ownership
使用提供的脚本将 public 模式中的数据库对象所有权从 supabase_admin 转移到 postgres。在包含 docker-compose.yml 的项目目录下运行:
🌐 Use the provided script to reassign ownership of database objects in the public schema from supabase_admin to postgres. From the project directory containing docker-compose.yml, run:
1sh utils/reassign-owner.sh这个脚本只会更新 public 模式下数据库对象的所有权。Supabase 管理的和自定义的模式不会受到影响。
🌐 This script only updates ownership for database objects in the public schema. Supabase-managed and custom schemas are not affected.
步骤 2:在 docker-compose.yml 中更新环境变量 #
🌐 Step 2: Update environment variables in docker-compose.yml
-
在你的
docker-compose.yml配置中,取消注释以下行,以便studio服务使用postgres角色进行读/写操作:docker-compose.yml1studio:2environment:3POSTGRES_USER_READ_WRITE: postgres -
找到
meta服务的环境变量,然后把PG_META_DB_USER环境变量从supabase_admin改成postgres:docker-compose.yml1meta:2environment:3PG_META_DB_USER: postgres
Studio 使用自己的凭据通过 postgres-meta 访问 Postgres,所以这个更改只为向后兼容和保持一致性而需要。
🌐 Studio uses its own credentials to access Postgres via postgres-meta, so this change is only needed for backward compatibility and consistency.
步骤 3:重启 Supabase #
🌐 Step 3: Restart Supabase
1sh run.sh recreate验证角色 #
🌐 Verify roles
重新启动你的服务后,确认 Supabase Studio 现在使用的是 postgres 角色。在 Supabase Studio 的 SQL 编辑器中运行以下查询:
🌐 After restarting your services, verify that Supabase Studio is now using the postgres role. Run the following query in the Supabase Studio SQL Editor:
1select current_user;2-- expected result: postgres