Snowflake key-pair and token authentication¶
Snowflake is ending password-only sign-ins: users who sign in with a password need multi-factor authentication (MFA),
and service users (TYPE = SERVICE) can't have a password. The Replicator Service connects without any prompt, so it
can't answer an MFA challenge. This page explains the two sign-in methods that replace a password, a key pair and
an access token, for both the ODBC connection and the Apply extension that streams the changes. The steps are in
Set up a Snowflake destination.
When to use which¶
A Snowflake destination signs in twice, with separate settings:
- the Replicator Service's ODBC connection (snapshot replication, baselines, connection tests), set in the destination's connection string or DSN;
- the Stelo Capture Apply extension (
SnowFlakeApply), which streams incremental changes, set in the destination's Default Parameters and the group's copy of them.
| Login | How it works | Use it when |
|---|---|---|
| Key pair (recommended) | The user's public key is stored in Snowflake. The client signs in with the matching private key, a PKCS#8 file (.p8), usually protected by a passphrase. |
Long-running replication. The key doesn't expire, and one key file and passphrase serve both the ODBC connection and the Apply extension. |
| Programmatic access token (PAT) | A token generated in Snowflake for the user, sent instead of a password. | Short tests, or when you can't place a key file. Tokens expire (15 days by default, 365 at most), and by default Snowflake accepts a token only from a user with a network policy. |
| Password | User ID and password. | Only where your Snowflake account still allows password-only sign-in for that user. |
It's a key pair (an RSA key with the private key in PKCS#8 format), not an SSH key: Snowflake doesn't accept the
output of ssh-keygen.
How it works¶
- Choose the Connection String (driver-specific) authentication method for the destination. The Replicator
Service then adds no user ID, password or Windows login setting of its own: the connection string or DSN supplies
everything, including
UID. See Authentication. - The connection string names the Snowflake authenticator and the key or token. Keep the passphrase or token in a
secret and refer to it as
$$name$$; the Replicator Service puts the value in when it connects. Secrets aren't read from the Password field. - The Apply extension has its own parameters for the same login (see Apply extension parameters).
- Set the role in both places. Without it, Snowflake starts the session with the user's default role, which may have no access to the warehouse (see Role and warehouse).
Role and warehouse¶
Snowflake starts a session with the role named in the connection (ROLE, or the role parameter) or, without one, the
user's default role. If that role has no USAGE on the warehouse, the session has no warehouse: the sign-in and
statements that need no warehouse (such as TRUNCATE) work, but INSERT fails with "No active warehouse selected in
the current session". Setting the user's DEFAULT_WAREHOUSE doesn't help if the role can't use it.
Grant the role USAGE on the warehouse, with the other privileges replication needs (see
Grant the role its privileges), and make it the user's default role:
ALTER USER MY_USER SET DEFAULT_ROLE = MY_ROLE;
Token¶
To use a programmatic access token, for the ODBC connection or the Apply extension:
- By default Snowflake accepts a token only from a user with a network policy. If the user has none, create one with the addresses the Replicator Service and Stelo Capture connect from, and set it on the user (see Allow the network access). The policy then applies to all the user's sign-ins, key pair included.
-
Create the token, restricted to the replication role:
ALTER USER MY_USER ADD PROGRAMMATIC ACCESS TOKEN SQDR_REPLICATION ROLE_RESTRICTION = 'MY_ROLE' DAYS_TO_EXPIRY = 90;The token is shown once. Store it right away as a secret, for example
SNOWFLAKE_PAT. -
Use it for the destination: see With a token.
- Before it expires, create a new token and change the secret's value. Connections pick up the new value when they're opened again.
Related¶
- Set up a Snowflake destination
- Connection strings: Authentication and Secrets in connection strings
- Destination properties: Apply extensions
- Snowflake
- Troubleshooting › Snowflake sign-in
- Snowflake documentation: Key-pair authentication, Programmatic access tokens, ODBC connection parameters, JDBC connection parameters, Deprecation of single-factor password sign-ins