> For the complete documentation index, see [llms.txt](https://docs.arcwise.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arcwise.app/arcwise-setup/connect-data-warehouse/snowflake.md).

# Snowflake

## Step 1: Create a New User/Role for Arcwise

We recommend creating a separate Snowflake user & role for Arcwise access to have better visibility and granular access management. (It’s possible to skip to step 2 and provide an existing set of credentials instead).

### (Optional) Allow connection from Arcwise IP address

If you need to add a fixed IP address to your allowlist or network policy, please refer to our  [Arcwise Fixed IP Address](/arcwise-setup/connect-data-warehouse/arcwise-fixed-ip-address.md) page.

{% hint style="danger" %}
**IMPORTANT**

Snowflake is deprecating single-factor password authentication for service users. New Arcwise connections should use key-pair authentication. See [Snowflake’s migration timeline](https://docs.snowflake.com/en/user-guide/security-mfa-rollout).
{% endhint %}

### Generate a key-pair for service authentication

Currently we support Snowflake key-pair authentication, that requires an RSA key pair with the following properties:

* RSA key size of at least 2048 bits.
* Private key encoded as unencrypted PKCS#8 PEM.
* Public key encoded as PEM.
* The private key must remain secret. Only add the public key to Snowflake.

You may generate and manage the key pair using your organization’s preferred security tooling. The following OpenSSL commands are examples:

```bash
# Example: generate an unencrypted PKCS#8 private key
openssl genrsa 2048 |
  openssl pkcs8 -topk8 -nocrypt -out arcwise_private_key.p8

# Example: derive the corresponding public key
openssl pkey \
  -in arcwise_private_key.p8 \
  -pubout \
  -out arcwise_public_key.pem

# Example: copying the public key to be added on Snowflake
sed '/PUBLIC KEY/d' arcwise_public_key.pem | tr -d '\n'
```

### Creating a new user/role

We've provided a script here to help with role and user creation. You can paste this directly into Snowsight **if you have SYSADMIN or ACCOUNTADMIN privileges.**

{% hint style="danger" %}
**IMPORTANT**

* Take care to replace the **highlighted values** in the query below!
* Make sure to **execute all of the queries! S**elect the entire query text before running if using Snowsight, or check the “All Queries” checkbox if using the legacy console.
  {% endhint %}

By default, this will allow the Arcwise role to access all schemas in `$database_name`, but this can be restricted if preferred (see highlighted `GRANT USAGE ON SCHEMA` below). Be sure that each query runs successfully!

```sql
-- (Optional) Edit these if you prefer something else.
SET role_name = 'ARCWISE_ROLE';
SET user_name = 'ARCWISE_USER';
-- (Optional) You can also use an existing warehouse if desired.
SET warehouse_name = 'ARCWISE_WAREHOUSE';

-- Public key generated (see above).
-- Paste only the Base64 body, without the BEGIN/END lines or line breaks.
SET arcwise_public_key = '<your-public-key-here>';

-- Database you want to allow Arcwise to access and snapshot schema that
-- will be created in that database for data snapshot management
SET database_name = '<your-database-here>';
SET snapshot_schema_name = '_ARCWISE_SNAPSHOTS';

-- Database setup
CREATE DATABASE IF NOT EXISTS IDENTIFIER($database_name) COMMENT = 'Arcwise database';

-- Warehouse setup
CREATE WAREHOUSE IF NOT EXISTS IDENTIFIER($warehouse_name)
	warehouse_size = small
	warehouse_type = standard
	auto_suspend = 15
	auto_resume = true
	initially_suspended = true;

-- Role setup
CREATE ROLE IF NOT EXISTS IDENTIFIER($role_name) COMMENT = 'Arcwise default role';

-- User setup
CREATE USER IF NOT EXISTS IDENTIFIER($user_name)
	type = service
	default_warehouse = $warehouse_name
	default_role = $role_name;

-- Register the public key for Arcwise authentication
ALTER USER IDENTIFIER($user_name) ADD KEY PAIR ARCWISE_KEY
	PUBLIC_KEY = $arcwise_public_key
	COMMENT = 'Arcwise authentication key';

-- Assign user -> role
GRANT ROLE IDENTIFIER($role_name) TO USER IDENTIFIER($user_name);

-- Allow role -> warehouse & database
GRANT USAGE ON WAREHOUSE IDENTIFIER($warehouse_name) TO ROLE IDENTIFIER($role_name);
GRANT USAGE ON DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);

-- Allow role to access all schemas (and tables/views within the schema)
GRANT USAGE ON ALL SCHEMAS IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);
GRANT USAGE ON FUTURE SCHEMAS IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);
-- (Optional) To restrict access to certain schemas: comment out the two lines above and edit below
-- GRANT USAGE ON SCHEMA <your-database>.<your-schema> TO ROLE IDENTIFIER($role_name);

GRANT SELECT ON ALL TABLES IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);
GRANT SELECT ON FUTURE TABLES IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);

GRANT SELECT ON ALL VIEWS IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);
GRANT SELECT ON FUTURE VIEWS IN DATABASE IDENTIFIER($database_name) TO ROLE IDENTIFIER($role_name);

-- Create snapshot schema and grant role ownership over that schema
SET arcwise_snapshots_schema = $database_name || '.' || $snapshot_schema_name;
CREATE SCHEMA IF NOT EXISTS IDENTIFIER($arcwise_snapshots_schema) COMMENT = 'Arcwise-operated schema for managing data snapshots';
GRANT OWNERSHIP ON SCHEMA IDENTIFIER($arcwise_snapshots_schema) TO ROLE IDENTIFIER($role_name) REVOKE CURRENT GRANTS;

-- Allow Arcwise role to analyze query history & table usage activity
GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE IDENTIFIER($role_name);
```

By default the above commands will *not* give the `SYSADMIN` role access to data managed by Arcwise. To have the Arcwise role inherit from `SYSADMIN` and therefore grant that role full access run the following command:

```sql
GRANT ROLE IDENTIFIER($role_name) TO ROLE SYSADMIN;
```

## Step 2: Add Snowflake credentials in Arcwise

1. Go to the “Connections” tab in the Arcwise admin panel (<https://admin.arcwise.app/#/warehouse_connections>)
2. Click on the “Create” button to add the first connection.
3. Fill out the credentials based on the variables you filled in above. Additional instructions can be found on the form.

All credentials are stored securely using bank-level (256-bit) encryption. Once you hit Save and the connection has been added, you can switch over to the “Tables” tab to see all the tables that will be exposed in Arcwise.

{% hint style="warning" %}
If you get an error that the connection didn’t work, please double check that the all queries in the “Create a new user/role” script ran successfully.
{% endhint %}
