# 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](https://docs.arcwise.app/arcwise-setup/connect-data-warehouse/arcwise-fixed-ip-address "mention") page.

#### 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';

-- Define a password for the Arcwise user (ideally randomly generated). Remember it for later
SET user_password = '<your-password-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)
	password = $user_password
	first_name = 'Arcwise'
	last_name = 'User'
	default_warehouse = $warehouse_name
	default_role = $role_name;

-- 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 for each section below.

<figure><img src="https://803372693-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlIfwCAQgoIa97JJYtlXQ%2Fuploads%2FvV1jfohESNjwe88pgoKv%2FScreenshot%202023-07-19%20at%2010.27.14%20AM.png?alt=media&#x26;token=19f41d4e-89d1-4e16-8e40-22d0ff267fc3" alt="" width="563"><figcaption></figcaption></figure>

<details>

<summary>Name</summary>

A user-friendly name that describes the purpose of the connection. Will be shown to end-users in Arcwise.

</details>

<details>

<summary>Account</summary>

This is your [Snowflake account identifier](https://docs.snowflake.com/en/user-guide/admin-account-identifier.html#using-an-account-locator-as-an-identifier). It should be in the format:

`account_locator.cloud_region_id.cloud`

EG: `uc1234.us-west-1.aws`&#x20;

In Snowsight, you can hover over account menu in the bottom left and click **Copy account URL**; then remove the leading `https://` and trailing `.snowflakecomputing.com`

<img src="https://803372693-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlIfwCAQgoIa97JJYtlXQ%2Fuploads%2FZ73ivKjdOPZsHiZqU6ja%2FScreenshot%202023-06-06%20at%2012.23.57%20PM.png?alt=media&#x26;token=e4449978-cb5c-4b32-8ae6-743c4a1d9c28" alt="" data-size="original">

</details>

<details>

<summary>Warehouse</summary>

Use the `$warehouse_name` value from the SQL query (e.g. `ARCWISE_WAREHOUSE`)

</details>

<details>

<summary>Database</summary>

Use the `$database_name` value from the SQL query.

</details>

<details>

<summary>Snapshot Schema</summary>

Use the `$snapshot_schema_name` value from the SQL query.

</details>

<details>

<summary>Username/Password</summary>

`$user_name` and `$user_password` from the SQL query.

</details>

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 username/password didn’t work, please double check that the all queries in the “Create a new user/role” script ran successfully.
{% endhint %}
