Skip to content

Commit 68af7cd

Browse files
Merge pull request #6559 from segmentio/DOC-865
Snowflake key-pair authentication GA [DOC-865]
2 parents 7c0c845 + 18a8385 commit 68af7cd

File tree

2 files changed

+105
-11
lines changed

2 files changed

+105
-11
lines changed

src/connections/reverse-etl/reverse-etl-source-setup-guides/snowflake-setup.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ redirect_from:
77

88
Set up Snowflake as your Reverse ETL source.
99

10-
At a high level, when you set up Snowflake for Reverse ETL, the configured user/role needs read permissions for any resources (databases, schemas, tables) the query needs to access. Segment keeps track of changes to your query results with a managed schema (`__SEGMENT_REVERSE_ETL`), which requires the configured user to allow write permissions for that schema.
10+
At a high level, when you set up Snowflake for Reverse ETL, the configured user/role needs read permissions for any resources (databases, schemas, tables) the query needs to access. Segment keeps track of changes to your query results with a managed schema <br>(`__SEGMENT_REVERSE_ETL`), which requires the configured user to allow write permissions for that schema.
11+
12+
> success ""
13+
> Segment now supports key-pair authentication for Snowflake Reverse ETL sources. Key-pair authentication is available for Business Tier users only.
1114
1215
## Set up guide
13-
Follow the instructions below to set up the Segment Snowflake connector. Segment recommends you use the `ACCOUNTADMIN` role to execute all the commands below.
16+
Follow the instructions below to set up the Segment Snowflake connector. Segment recommends you use the `ACCOUNTADMIN` role to execute all the commands below, and that you create a user that authenticates with an encrypted key pair.
1417

1518
1. Log in to your Snowflake account.
1619
2. Navigate to *Worksheets*.
@@ -47,10 +50,22 @@ Follow the instructions below to set up the Segment Snowflake connector. Segment
4750
GRANT USAGE ON DATABASE segment_reverse_etl TO ROLE segment_reverse_etl;
4851
GRANT CREATE SCHEMA ON DATABASE segment_reverse_etl TO ROLE segment_reverse_etl;
4952
```
50-
6. Enter and run the code below to create the username and password combination that will be used to execute queries. Make sure to enter your password where it says `my_strong_password`.
53+
6. Enter and run one of the following code snippets below to create the user Segment uses to run queries. For added security, Segment recommends creating a user that authenticates using a key pair.
54+
55+
To create a user that authenticates with a key pair, [create a key pair](https://docs.snowflake.com/en/user-guide/key-pair-auth#configuring-key-pair-authentication){:target="_blank”} and then execute the following SQL commands:
56+
``` sql
57+
-- create user (key-pair authentication)
58+
CREATE USER segment_reverse_etl_user
59+
DEFAULT_ROLE = segment_reverse_etl
60+
RSA_PUBLIC_KEY = 'enter your public key';
61+
62+
-- role access
63+
GRANT ROLE segment_reverse_etl TO USER segment_reverse_etl_user;
64+
```
5165

66+
To create a user that authenticates with a password, execute the following SQL commands:
5267
```sql
53-
-- create user
68+
-- create user (password authentication)
5469
CREATE USER segment_reverse_etl_user
5570
MUST_CHANGE_PASSWORD = FALSE
5671
DEFAULT_ROLE = segment_reverse_etl

src/connections/storage/catalog/snowflake/index.md

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,48 @@ GRANT CREATE SCHEMA ON DATABASE "SEGMENT_EVENTS" TO ROLE "SEGMENT";
8686

8787
### Step 4: Create a user for Segment
8888

89-
Create the user that Segment uses to connect to your warehouse. Be sure to use a strong, unique password.
89+
Create the user that Segment uses to connect to your warehouse. You can create a user that authenticates with a key pair, or you can create a user that authenticates using a password. For enhanced security, Segment recommends creating a user that authenticates with an encrypted key pair.
90+
91+
> info "Key-pair authentication restricted to Business Tier users only"
92+
> Users on other plans can authenticate with Snowflake using a [username and password](#create-a-user-that-authenticates-with-a-username-and-password).
93+
94+
#### Create a user that authenticates with a key pair
95+
If you are creating a user that will use a key pair to authenticate, you first must create a public key and then can create a new user.
96+
97+
##### Generate keys
98+
99+
To start, open a terminal window and generate a private key by running the following command, replacing `key_name` with the name you'd like to give the key. The command generates a private key in PEM format, and will prompt you to enter a passphrase. Write down or remember this passphrase, as you will need it when creating your Segment user and configuring your destination in the Segment app.
100+
101+
> success ""
102+
> If you want to generate an unencrypted private key, append `-nocrypt` to the end of the command.
103+
104+
```
105+
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out key_name.p8
106+
```
107+
108+
After you've created the private key, save the file to a local directory. You'll need to upload the .p8 file to the Segment app when you create your Snowflake destination.
109+
110+
Next, generate your public key by running the following command, replacing `key_name.p8` with the name of the private key that you previously created and `public_key_name` with the name of your new public key.
111+
112+
```
113+
openssl rsa -in key_name.p8 -pubout -out public_key_name.pub
114+
```
115+
116+
After you've created the public key, save the file to a local directory.
117+
118+
##### Generate a new user and assign the key to them
119+
120+
Now, create a new user by executing the following SQL command, replacing the public key value with the key you previously generated.
121+
122+
``` sql
123+
CREATE USER SEGMENT_USER
124+
DEFAULT_ROLE = SEGMENT
125+
RSA_PUBLIC_KEY = 'enter your public key';
126+
GRANT ROLE "SEGMENT" TO USER "SEGMENT_USER";
127+
```
128+
129+
#### Create a user that authenticates with a username and password
130+
If you are creating a user that will use a username and password to authenticate, execute the following SQL command. Be sure to set a strong, unique password.
90131

91132
```sql
92133
CREATE USER "SEGMENT_USER"
@@ -98,13 +139,30 @@ GRANT ROLE "SEGMENT" TO USER "SEGMENT_USER";
98139

99140
### Step 5: Test the user and credentials
100141

101-
Before you continue, test and validate the new user and credentials. When you can run the following commands successfully, you can connect Snowflake to Segment.
142+
Before you continue, test and validate the new user and credentials. After you verify the new credentials, you can connect Snowflake to Segment.
102143

144+
#### Test a key pair
103145
Segment uses [SnowSQL](https://docs.snowflake.com/en/user-guide/snowsql){:target="_blank"} to run these verification steps.
104146
To install SnowSQL and verify your accounts:
105147

106148
1. Download [SnowSQL](https://docs.snowflake.com/en/user-guide/snowsql){:target="_blank"}
107-
2. Open the Installer and follow instructions
149+
2. Open the Installer and follow instructions.
150+
3. When the installation is complete, run the following command, replacing "account", "username", and "path_to_the_rsa_key_encrypted.p8" with your Snowflake Account ID, username, and path to your private RSA key:
151+
152+
```
153+
snowsql -a segment -u <username> -d <Database> -w <warehouse> --private-key-path <path_to_the_rsa_key_encrypted.p8>
154+
```
155+
156+
For accounts outside the US, the account ID includes the region. You can find your account name from the browser address string.
157+
158+
For example, if your web address is `https://myaccountname.snowflakecomputing.com/console#/internal/worksheet`, your account name would be `myaccountname`.
159+
160+
#### Test a username and password
161+
Segment uses [SnowSQL](https://docs.snowflake.com/en/user-guide/snowsql){:target="_blank"} to run these verification steps.
162+
To install SnowSQL and verify your accounts:
163+
164+
1. Download [SnowSQL](https://docs.snowflake.com/en/user-guide/snowsql){:target="_blank"}
165+
2. Open the Installer and follow instructions.
108166
3. When the installation is complete, run the following command, replacing "account" and "user" with your Snowflake Account ID and username:
109167

110168
```
@@ -167,12 +225,23 @@ After configuring your Snowflake resources, connect them to Segment.
167225

168226
1. In the Segment App, select Add Destination.
169227
2. Search for and select "Snowflake".
170-
3. Add your credentials as follows:
171-
- **User**: The user name that you created in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
172-
- **Password**: The password that you set in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
228+
3. Enter a name for your destination.
229+
4. Enter your Snowflake credentials as follows:
173230
- **Account**: The account id of your cluster, not the url (for example, url: `my-business.snowflakecomputing.com`, account-id: `my-business`. **Note:** If you are using Snowflake on AWS, the account id includes the region. For example, your url might be: `my-business.us-east-1.snowflakecomputing.com/` and your account-id would be: `my-business.us-east-1`)
174-
- **Database**: The database name that you created in [Step 2: Create database](#step-2-create-database)
175231
- **Warehouse**: The name of the warehouse that you created in [Step 1: Create a virtual warehouse](#step-1-create-a-virtual-warehouse)
232+
- **Database**: The database name that you created in [Step 2: Create database](#step-2-create-database)
233+
- **Username**: The username that you created in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
234+
- **Authentication method**: Select the authentication method that you used when creating a user in [Step 4: Create a user for Segment](#step-4-create-user-for-segment). You can select either Key pair or Password.
235+
236+
If you selected Key pair as your authentication method:
237+
- **Private key**: Upload your private key (stored in .p8 format) that you created in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
238+
- **Passphrase** _(Optional)_ : If you created an encrypted key, enter the passphrase you created in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
239+
240+
> info "Segment supports uploading one key at a time"
241+
> Although you can create up to two keys in Snowflake, Segment only supports authenticating with one key at a time. To change the key that is in Segment, return to your Snowflake destination's settings and upload a new key in the **Private Key** field.
242+
243+
If you selected Password as your authentication method:
244+
- **Password**: The password that you set in [Step 4: Create a user for Segment](#step-4-create-user-for-segment)
176245

177246
## Security
178247

@@ -188,6 +257,12 @@ At this time, the Segment Snowflake destination is not compatible with Snowflake
188257

189258
## Best Practices
190259

260+
### Key pair authentication
261+
262+
Segment recommends that you authenticate with your Snowflake warehouse using an encrypted key pair. Key-pair authentication uses PKCS#8 private keys, which are typically exchanged in the PEM base64-encoded format.
263+
264+
Although you can create up to two keys in Snowflake, Segment only supports authenticating with one key at a time. To change the key that is in Segment, return to your Snowflake destination's settings and upload a new key in the **Private Key** field.
265+
191266
### Auto Suspend and Auto Resume
192267

193268
Set `AUTO_SUSPEND` to ~10 minutes in the UI (or 600 if using SQL) to minimize the credit consumption of Segment's syncing process.
@@ -249,3 +324,7 @@ Queuing - you can use a different Warehouse for Segment, or use the recommendati
249324
{% include content/warehouse-sync-sched.md %}
250325

251326
![sync schedule image](/docs/connections/destinations/catalog/images/syncsched.png)
327+
328+
### I'm encountering a "JWT token is invalid" error. What do I do?
329+
330+
For more information about troubleshooting a `JWT token is invalid` error, see Snowflake's [Key Pair Authentication: Troubleshooting](https://docs.snowflake.com/user-guide/key-pair-auth-troubleshooting){:target="_blank”} documentation.

0 commit comments

Comments
 (0)