Funções do Snowflake Postgres¶
O Postgres tem uma autenticação própria baseada em funções para gerenciar conexões com bancos de dados e usar bancos de dados em um servidor Postgres. Essas funções são separadas das funções do Snowflake. As funções do Postgres são usadas para acessar e gerenciar bancos de dados, tabelas e outros objetos dentro das instâncias do Snowflake Postgres.
Quando você cria uma instância do, o Snowflake gera automaticamente duas funções gerenciadas especiais para você usar, que estão descritas abaixo.
Para obter mais informações sobre o gerenciamento de funções do Postgres, consulte a documentação do Postgres.
Nota
Here and in many other places you will see the terms «role» and «user» used interchangeably in the context of Postgres user management. This is because a Postgres user is simply a role that has the Postgres role LOGIN attribute.
Funções gerenciadas pelo Snowflake Postgres¶
Snowflake Postgres automatically creates two managed roles at the same time that it creates your instance.
A função snowflake_admin¶
snowflake_admin é uma função de alto privilégio do Postgres usada para administrar sua instância do Snowflake Postgres. Ele não é um superusuário completo do Postgres; algumas operações permanecem restritas e são gerenciadas pelo Snowflake. No entanto, ele tem privilégios elevados que incluem:
Criar e gerenciar funções do Postgres.
Criar e gerenciar bancos de dados.
Gerenciar a replicação para sua instância do Snowflake Postgres.
Ignorar as políticas de segurança no nível da linha (Row-Level Security, RLS), quando aplicável.
Além disso, snowflake_admin é membro de várias funções integradas do Postgres que concedem funcionalidades operacionais e de monitoramento, incluindo:
pg_signal_backendpg_use_reserved_connectionspg_create_subscriptionpg_read_all_settingspg_read_all_statspg_stat_scan_tablespg_monitorsnowflake_admin_group
A função application¶
application é uma função não superusuário que, por padrão, tem permissões para criar objetos no banco de dados postgres. Novas permissões ou propriedades para essa função devem ser concedidas pela função snowflake_admin.
Segurança de senhas do Postgres¶
Nova geração de credenciais para funções gerenciadas pelo Snowflake Postgres¶
Credentials for the snowflake_admin and application roles are generated when you create the instance and are displayed only once.
You can regenerate these credentials at any time, invalidating the existing credentials.
No painel, você pode gerar novamente as credenciais para a função snowflake_admin da sua instância.
No menu de navegação, selecione Postgres.
Selecione a instância.
No menu Manage no canto superior direito, selecione Regenerate credentials.
Clique no botão Acknowledge & continue para confirmar a ação.
Para gerar novamente credenciais para a função
snowflake_adminouapplication, você pode usar um comando ALTER POSTGRES SERVICE com o parâmetro RESET ACCESS.ALTER POSTGRES SERVICE [IF EXISTS] <name> RESET ACCESS FOR { 'snowflake_admin' | 'application' }
Requer o privilégio OWNERSHIP ou OPERATE
That command returns one row with the following column:
password
Exemplo de rotação de credenciais
Redefinir o acesso para a função
snowflake_adminpara uma instância do Snowflake Postgres chamadamy_instance:ALTER POSTGRES SERVICE my_instance RESET ACCESS FOR 'snowflake_admin';
Definindo senhas para outras funções do Postgres¶
Snowflake Postgres instances are configured for scram-sha-256 password authentication. When new
passwords are set, a scram-sha-256 hash is generated and stored by the server, but when the Postgres
log_statement parameter
is set to any value other than none, then CREATE ROLE and ALTER ROLE DDL commands are fully
logged to the Postgres server log. Therefore, you should make sure that clear-text passwords are not
logged as part of those statements.
Desabilitando o registro de instruções para os comandos DDL CREATE ROLE e ALTER ROLE do Postgres¶
The simplest way to prevent clear-text passwords used in CREATE ROLE and ALTER ROLE DDL statements from appearing in the Postgres server
log is to disable the log_statement parameter for the transaction that you run them in. Do so by using SET LOCAL:
BEGIN;
SET LOCAL log_statement = 'none';
CREATE USER mynewrole PASSWORD 'mynewpassword';
COMMIT;
Usando o comando \password do cliente Postgres psql¶
The Postgres psql client program has a
password <https://www.postgresql.org/docs/current/app-psql.html>_ meta-command that can be used
to change the password for existing users. The \password meta-command precomputes the entered
password’s scram-sha-256 hash and uses that in the ALTER ROLE command that is sent to the server. To
use this method, first create new users without a password, and then set each user’s password with
the psql \password meta-command.
postgres=# CREATE ROLE mynewrole LOGIN;
CREATE ROLE
postgres=# \password mynewrole
Enter new password for user "mynewrole":
Enter it again:
If log_statement is set to a value other than 'none', then the log entry for ALTER ROLE
command sent by psql for the above \password command has the calculated scram-sha-256
hash instead of the actual clear-text password. You can combine this method with disabling
log_statement completely, as described above, to prevent even that hash from appearing in the
Postgres log:
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
Limitações da função¶
No Snowflake Postgres, certas operações são reservadas para o próprio serviço e não podem ser executadas por nenhuma função gerenciada pelo cliente, incluindo snowflake_admin. Alguns exemplos incluem:
Changing protected server-level configuration parameters that are managed by Snowflake.
Modifying or disabling core Snowflake-managed components or extensions.
Accessing or altering Snowflake-managed system databases or schemas used by the service.
Accessing or altering the Snowflake Postgres instance filesystem.
Direct modification of system catalog tables.
Creation of other superusers.
Creation of more than 64 roles in the instance.
Creation of more than 32 databases in the instance.
Execution of the ALTER SYSTEM command.
Acesso às funções genéricas de acesso a arquivos do Postgres que permitem o acesso ao sistema de arquivos
The Snowflake Postgres extension may introduce further restrictions on what both snowflake_admin
and application can do within an instance. These extension-specific limitations may evolve over
time and will be documented with the corresponding extension behavior. If an operation is blocked,
you receive an error indicating that it isn’t permitted in Snowflake Postgres.