Snowflake Postgres 角色

Postgres 拥有基于角色的身份验证机制,用于管理数据库连接及 Postgres 服务器上的数据库操作。这些角色与 Snowflake 角色相互独立。Postgres 角色用于访问和管理 Snowflake Postgres 实例内的数据库、表及其他对象。

创建实例时,Snowflake 会自动为您创建两个特殊管理角色,具体说明如下。

有关管理 Postgres 角色的更多信息,请参阅 Postgres 文档 (https://www.postgresql.org/docs/current/user-manag.html)。

备注

在这里和许多其他地方,您会看到术语“角色”和“用户”在 Postgres 用户管理上下文中交替使用。这是因为 Postgres 用户本质上就是具有 Postgres 角色 LOGIN 属性的角色。

Snowflake Postgres 托管角色

Snowflake Postgres 在创建实例的同时会自动创建两个托管角色。

snowflake_admin 角色

snowflake_admin 角色是用于管理 Snowflake Postgres 实例的高权限 Postgres 角色。它 不是 完整的 Postgres 超级用户,部分操作仍受限制并由 Snowflake 管理。但是,它具有提升的权限,包括:

  • 创建和管理 Postgres 角色。

  • 创建和管理数据库。

  • 管理 Snowflake Postgres 实例的复制。

  • 绕过行级安全性 (RLS) 策略(如适用)。

此外,snowflake_admin 同时隶属于多个 Postgres 内置角色,这些角色赋予其监控和运维能力,包括:

  • pg_signal_backend

  • pg_use_reserved_connections

  • pg_create_subscription

  • pg_read_all_settings

  • pg_read_all_stats

  • pg_stat_scan_tables

  • pg_monitor

  • snowflake_admin_group

application 角色

application 角色是一个非超级用户角色,默认具有在 postgres 数据库中创建对象的权限。该角色的新权限或所有权应由 snowflake_admin 角色授予。

Postgres 密码安全

为 Snowflake Postgres 托管角色重新生成凭据

snowflake_adminapplication 角色的凭据在创建实例时生成,且仅显示一次。您可随时重新生成这些凭据,届时现有凭据将失效。

从仪表板中,您可以为实例的 snowflake_admin 角色重新生成凭据。

  1. 在导航菜单中,选择 Postgres

  2. 选择您的实例。

  3. 在右上角的 Manage 菜单中选择 Regenerate credentials

  4. 点击 Acknowledge & continue 按钮确认操作。

为其他 Postgres 角色设置密码

Snowflake Postgres 实例默认配置为 scram-sha-256 密码身份验证。设置新密码时,服务器会生成并存储 scram-sha-256 哈希值。但若 Postgres 的 log_statement (https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-STATEMENT) 参数设置为除 none 以外的任何值,则 CREATE ROLE 和 ALTER ROLE DDL 命令将完整记录至 Postgres 服务器日志。因此,应确保明文密码不会作为这些语句的一部分记录。

禁用 CREATEROLE 和 ALTERROLE Postgres DDL 命令的语句日志记录

防止 CREATE ROLE 和 ALTER ROLE DDL 语句中使用的明文密码出现在 Postgres 服务器日志中的最简便方法,是在执行这些语句的事务中禁用 log_statement 参数。可通过使用 SET LOCAL 实现这一操作:

BEGIN;
SET LOCAL log_statement = 'none';
CREATE USER mynewrole PASSWORD 'mynewpassword';
COMMIT;
Copy

使用 psql Postgres 客户端的 \password 命令

Postgres psql (https://www.postgresql.org/docs/current/app-psql.html) 客户端程序拥有可用于更改现有用户密码的 password <https://www.postgresql.org/docs/current/app-psql.html>_ 元命令。\password 元命令会预先计算所输入密码的 scram-sha-256 哈希值,并在发送给服务器的 ALTER ROLE 命令中使用该哈希值。要使用此方法,先创建无密码的新用户,再通过 psql \password 元命令为每个用户设置密码。

postgres=# CREATE ROLE mynewrole LOGIN;
CREATE ROLE

postgres=# \password mynewrole
Enter new password for user "mynewrole":
Enter it again:
Copy

如果将 log_statement 设置为除 'none' 以外的值,则 psql 为上述 \password 命令发送的 ALTER ROLE 命令的日志条目会包含计算得到的 scram-sha-256 哈希值,而非实际明文密码。您可以将此方法与完全禁用 ``log_statement``(如上所述)结合使用,以防止该哈希值出现在 Postgres 日志中:

postgres=# CREATE ROLE mynewrole LOGIN;
CREATE ROLE

postgres=# BEGIN;
BEGIN

postgres=# SET LOCAL log_statement = 'none';
SET

postgres=# \password mynewrole
Enter new password for user "mynewrole":
Enter it again:

postgres=# COMMIT;
COMMIT
Copy

泄露密码保护

Leaked password protection is provided for roles on Snowflake Postgres instances. Discovery and notification work as described in our main 泄露密码保护. When Snowflake discovers a leaked password for one of your Snowflake Postgres roles:

  • 该角色已添加到特殊 snowflake_nologin Postgres 组角色中,以防止将来使用它登录。

  • 该角色的所有现有连接都将终止。

  • 您收到的电子邮件通知的主题为“紧急 – Snowflake Postgres 角色密码重置以防止未经授权的访问”。

Should you receive this email you should immediately securely update the role's password as described above. When regenerating credentials for managed roles they are automatically removed from the snowflake_nologin Postgres role group. For non-managed roles, after updating the role's password they can be removed from the snowflake_nologin group role by running this Postgres with the snowflake_admin role:

REVOKE snowflake_nologin FROM {rolename};
Copy

角色限制

在 Snowflake Postgres 中,某些操作是为服务本身保留的,任何客户管理角色(包括 snowflake_admin)均无法执行。示例包括:

  • 更改由 Snowflake 管理的受保护服务器级配置参数。

  • 修改或禁用 Snowflake 管理的核心组件或扩展。

  • 访问或更改服务使用的 Snowflake 管理的系统数据库或架构。

  • 访问或更改 Snowflake Postgres 实例文件系统。

  • 直接修改系统目录表。

  • 创建其他超级用户。

  • 在实例中创建超过 64 个角色。

  • 在实例中创建超过 32 个数据库。

  • 执行 ALTER SYSTEM 命令。

  • 访问 Postgres 通用文件访问函数 (https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-GENFILE) 以获取文件系统访问权限。

Snowflake Postgres 扩展可能对 snowflake_adminapplication 在实例内的操作施加额外限制。这些扩展特有的限制可能随时间演变,并将随扩展行为文档同步更新。如果某个操作被阻止,您会收到一条错误,指示 Snowflake Postgres 中不允许进行该操作。