GENERATE_POSTGRES_ACCESS_TOKEN_FOR_USER

functionsupportedContainer services & dev tooling

docs.snowflake.com ↗

Generates a short-lived access token to use as a password when logging into a Snowflake Postgres instance that has the AUTHENTICATION_AUTHORITY attribute set to POSTGRES_OR_SNOWFLAKE. Short-lived access tokens generated with this function have a 15-minute lifetime. Once expired they can no longer be used to establish new connections to the Snowflake Postgres instance. Expiry doesn’t close established connections. A token is valid only for the instance it was generated for, including when connecting to a replica or fork. For mapping and token steps, see Configure authentication for Snowflake Postgres.

Syntax

GENERATE_POSTGRES_ACCESS_TOKEN_FOR_USER('<snowflake_postgres_instance_name>', '<postgres_username>')

Parameters

NameRequiredDescription
snowflake_postgres_instance_namerequiredSpecifies the Snowflake Postgres instance name to generate the short-lived access token for. If the given instance does not exist, or the caller doesn’t meet the access control requirements, the function fails. This argument is case-insensitive. Use double-quotes if case-sensitivity is needed.
postgres_usernamerequiredSpecifies the Postgres username to authenticate as. Snowflake resolves the corresponding access-role name case-insensitively. Individual user-token authentication compares the Postgres username case-sensitively. For access-role naming and incompatible mappings, see Access-role requirements and names.

Returns

Returns a short-lived access token that has a 15-minute lifetime.

Access control requirements

The function evaluates permissions from your primary role and active secondary roles, including their inherited roles. It returns the first applicable token in the following order: - Owner token: The active role hierarchy has OWNERSHIP on the instance. The token can authenticate as any Postgres login role, except superusers, replication users, and protected system users. See the owner-token login requirements. - Access role token: The caller holds the access role for postgres_username. The token can authenticate as the corresponding enrolled Postgres user. - User token: The token represents the calling Snowflake user’s identity. Attention If you have neither OWNERSHIP on the instance nor the access role for the requested Postgres user, the function returns a user token when your active role hierarchy has USAGE on the instance. Generating a token doesn’t validate the Postgres user’s existence or mapping. When you connect with a user token, Postgres checks that the requested Postgres login role is mapped to the Snowflake user who generated the token. An unexpired user token can authenticate after the required mapping is created. For mapping steps, see Map a Postgres user to a Snowflake user. If no token type applies, the function fails. You can’t call this function from an owner’s rights stored procedure unless the owner of the procedure has OWNERSHIP on the instance or holds the access role. The user-token fallback isn’t available in an owner’s rights stored procedure. MANAGE GRANTS authorizes access-role grants and revokes; it doesn’t by itself authorize an owner token. For the effect of revocation, Postgres role changes, and expiry on new and existing connections, see When revoked access takes effect.