Snowflake network policy, key options and privileges¶
More about preparing the Snowflake user that SQDR signs in as (see Prepare Snowflake).
Allow the network access¶
A network policy on the user limits the addresses it can sign in from. By default Snowflake accepts a programmatic access token only from a user with a network policy, so a token needs one; with a key pair it's optional but good practice. Allow the public IP addresses that the Stelo VM (and Stelo Capture, if it runs on another computer) connects from.
That's the address Snowflake sees, not the server's own: behind NAT, a firewall or a cloud gateway (for example an
Azure or AWS NAT gateway), it's the gateway's public egress IP. To find it, ask your network team, or open a site that
shows your public IP from the server. A wrong or missing address blocks every sign-in for the user once the policy is
set, so check it before you attach the policy. After SQDR's first sign-in attempt (for example Verify when the
destination is created), Snowflake's LOGIN_HISTORY shows the address it saw (CLIENT_IP); see
Troubleshooting.
-- Or a role with CREATE NETWORK RULE on the schema and CREATE NETWORK POLICY on the account.
USE ROLE ACCOUNTADMIN;
-- A network rule is a schema object: create it in a schema of your choice.
CREATE NETWORK RULE MY_DB.MY_SCHEMA.SQDR_IP_RULE
TYPE = IPV4
MODE = INGRESS
VALUE_LIST = ('203.0.113.10');
CREATE NETWORK POLICY SQDR_POLICY
ALLOWED_NETWORK_RULE_LIST = ('MY_DB.MY_SCHEMA.SQDR_IP_RULE')
COMMENT = 'Sign-ins of the SQDR replication user';
ALTER USER MY_USER SET NETWORK_POLICY = SQDR_POLICY;
Replace 203.0.113.10 with your addresses (a list, or ranges such as 203.0.113.0/24). The policy applies to all of
the user's sign-ins, from the ODBC connection and the Apply extension.
More key-pair options¶
- Encryption of the key. Snowflake's own example uses
-v2 des3; the ODBC and JDBC drivers read such a key, but Snowpipe Streaming, which the Apply extension uses, may not. Use AES-256 (-v2 aes256). - A key without a passphrase. Use
openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocryptin the first command. An encrypted key is safer (a copy of the file alone isn't enough to sign in); a key without a passphrase is acceptable if only the service's account and administrators can read its folder on the Stelo VM (see Copy the private key file). - A passphrase from a file. If a script passes the passphrase from a file (
-passout file:pp.txt), the file must not end with a line break: OpenSSL keeps everything on the first line except the final\n, so a Windows\rbecomes part of the passphrase and the secret you store later won't match. Check withopenssl pkcs8 -in rsa_key.p8 -out NUL(/dev/nullon Linux) and enter the passphrase you'll put in the secret; a wrong one givesbad decrypt. -
Check the fingerprint. To check that Snowflake has the key that matches your file, compare
RSA_PUBLIC_KEY_FPfromDESC USER MY_USER(without theSHA256:prefix) with:openssl rsa -pubin -in rsa_key.pub -outform DER | openssl dgst -sha256 -binary | openssl enc -base64 -
Replace the key. To replace a key without a break, set the new one as
RSA_PUBLIC_KEY_2, switch the destination to the new private key, thenALTER USER MY_USER UNSET RSA_PUBLIC_KEY;.
Privileges¶
| Privilege | Why it's needed |
|---|---|
USAGE on the warehouse |
To run INSERT, MERGE and queries. Without it the sign-in works but the session has no warehouse, and statements fail with "No active warehouse selected in the current session" (see Role and warehouse). |
USAGE on the database and the schema |
To use any object in them. Snowpipe Streaming requires both. |
CREATE TABLE on the schema |
The Replicator Service creates the destination tables, and the Apply extension creates a Z__ work table for each table. |
The role owns the tables it creates, which gives it everything else it needs on them: INSERT for streaming,
UPDATE and DELETE for the MERGE, TRUNCATE, ALTER and DROP, and the right to evolve the work table's schema.
GRANT ALL ON SCHEMA MY_DB.MY_SCHEMA TO ROLE MY_ROLE is a simpler alternative to the last grant.
Tables you created yourself. If subscriptions write to existing tables that another role owns, also grant the replication role the table privileges:
GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA MY_DB.MY_SCHEMA TO ROLE MY_ROLE;
When a source table changes, the Replicator Service changes the destination table with ALTER TABLE, which only the
table's owner can do. Let SQDR create the tables where you can.