Skip to content
Self-Hosting

移除 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:

1
sh utils/reassign-owner.sh

步骤 2:在 docker-compose.yml 中更新环境变量 #

🌐 Step 2: Update environment variables in docker-compose.yml

  • 在你的 docker-compose.yml 配置中,取消注释以下行,以便 studio 服务使用 postgres 角色进行读/写操作:

    docker-compose.yml
    1
    studio:
    2
    environment:
    3
    POSTGRES_USER_READ_WRITE: postgres
  • 找到 meta 服务的环境变量,然后把 PG_META_DB_USER 环境变量从 supabase_admin 改成 postgres

    docker-compose.yml
    1
    meta:
    2
    environment:
    3
    PG_META_DB_USER: postgres

步骤 3:重启 Supabase #

🌐 Step 3: Restart Supabase

1
sh 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:

1
select current_user;
2
-- expected result: postgres