> For the complete documentation index, see [llms.txt](https://docs.carto.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carto.com/carto-user-manual/connections/snowflake.md). Agents can also search and read this documentation through its [MCP server](https://docs.carto.com/~gitbook/mcp).

# Snowflake

CARTO can connect to your Snowflake Data Warehouse, allowing you to use your data for building Maps and Workflows. There are three methods available for connecting to Snowflake:

* [**OAuth**](#connecting-to-snowflake-via-oauth)**:** Users authenticate into Snowflake using their individual Snowflake credentials, generating an access token for each user. This is the recommended setup, but it needs to be configured by an Admin first.
* [**Key-pair**](#connecting-to-snowflake-using-key-pair-authentication): This method requires generating an RSA key pair, where the public key is registered with your Snowflake user account (or service account) and the private key is securely stored in CARTO. Both keys are then used to establish a secure connection to Snowflake. This method is ideal for developing custom applications and using service accounts.

{% hint style="success" %}
CARTO is a fully cloud-native platform that runs queries on your behalf to power maps, workflows, etc. We never create or maintain any copies of your data.

[What it means to be fully cloud native.](https://carto.com/blog/what-being-cloud-native-should-really-mean-spatial-data)
{% endhint %}

***

## Connecting to Snowflake via OAuth

CARTO supports connecting to Snowflake with OAuth using one of the following options:

* [**Snowflake OAuth**](https://docs.snowflake.com/en/user-guide/oauth-snowflake-overview)**:** Snowflake acts as the authorization server, allowing users to authenticate using their Snowflake credentials
* [**External OAuth**](https://docs.snowflake.com/en/user-guide/oauth-ext-overview)**:** A separate Identity Provider such as Okta or Microsoft Entra handles authentication and Snowflake validates the issued tokens to grant access.

{% hint style="warning" %}
**Initial setup required**

To connect to Snowflake using OAuth, an organization Admin must first set up a Snowflake OAuth integration in CARTO. Once this is done, OAuth for Snowflake will be available to all users within the organization. [Read more about setting up a Snowflake OAuth integration](https://docs.carto.com/carto-user-manual/settings/advanced-settings/configuring-oauth-connections-to-snowflake.md).
{% endhint %}

To connect to Snowflake using OAuth, go to the *Connections* section, select *Snowflake*, and click *Setup connection with OAuth*.

First, you'll be asked which role CARTO should use with this connection. The role is optional for both Snowflake OAuth and External OAuth: if you leave it empty, queries use your default role in Snowflake. When the connection is shared, each user is asked for a role when they add their credentials, and can also leave it empty to use their own default role.

{% hint style="info" %}
**Setting a role with External OAuth**

When a role is set, CARTO requests a role-specific scope from your identity provider instead of the "any role" scope: `<Application ID URI>/session:scope:<ROLE>` for Microsoft Entra ID, or `session:role:<ROLE>` for Okta and custom providers. That scope must be exposed in your identity provider and consented for the CARTO OAuth client, otherwise the authorization fails (in Microsoft Entra ID, with error `AADSTS650053`).

The role can't be edited once the connection is created. To use a different role, complete the OAuth flow again.
{% endhint %}

Next, provide your credentials. Once authenticated, you'll be asked to grant CARTO permission to access your Snowflake data on your behalf.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-138401771536e4d80d5cfad39d0576dd8984b987%2FScreenshot%202023-11-21%20at%2015.19.38.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-d962d19e99ba083d332917baae46af44e7e2495c%2FScreenshot%202023-11-21%20at%2016.00.31.png?alt=media" alt=""><figcaption><p>Requesting consent when setting up a Snowflake OAuth connection. This consent would be done via Azure AD, Okta or any other identity provider if External OAuth was configured instead.</p></figcaption></figure>

If the OAuth connection is successful, you'll be taken to a form where the Snowflake user and account name are pre-filled. To complete the connection setup, provide the following details:

* **Connection name**: To identify the connection in CARTO.
* **Database**: The Snowflake database your connection will use when running queries.
* **Warehouse (optional)**: The Snowflake warehouse your connection will use when running queries. If you leave it empty, Snowflake uses the default warehouse of the user running the query.

Once you provide these details, click *Connect* to validate your setup and create the connection. The connection will be added to the workspace and you can start using it right away.

{% hint style="info" %}
OAuth connections are tied to an individual's personal credentials. They can be shared, but other users must authenticate using their own credentials to gain access. For more information, see [Sharing a connection](https://docs.carto.com/carto-user-manual/connections/sharing-a-connection.md#require-viewers-credentials).
{% endhint %}

### Sharing an OAuth connection

OAuth connections never share the owner's credentials. Each user you share the connection with signs in with their own Snowflake account and chooses a role, and their queries run with their own permissions.

The **database** and **warehouse** are the ones set in the connection, so each user's role needs `USAGE` on them, for example:

```sql
GRANT USAGE ON WAREHOUSE <warehouse> TO ROLE <role>;
GRANT USAGE ON DATABASE <database> TO ROLE <role>;
```

If the role can't use the warehouse, queries fail with `No active warehouse selected in the current session`.

Users who only view maps don't need access to the connection. See [What map viewers use](https://docs.carto.com/carto-user-manual/connections/sharing-a-connection.md#what-map-viewers-use).

For more information, see [Sharing a connection](https://docs.carto.com/carto-user-manual/connections/sharing-a-connection.md#require-viewers-credentials).

### When the connection owner leaves the organization

When a user is deleted, their connections are transferred to the user who inherits their assets, but CARTO stops using the previous owner's credentials on OAuth connections. To keep maps, workflows and tokens working, create a new connection with your own credentials, then delete the old one and choose **Update to use another connection**. See [Deleting connections](https://docs.carto.com/carto-user-manual/connections/deleting-a-connection.md). A shared connection must be made private before it can be deleted.

***

## Connecting to Snowflake using Key-pair authentication

CARTO supports key-pair authentication and key rotation for Snowflake connections. Follow the steps below to create your first key-pair connection, or see Snowflake's official documentation for more details:

{% embed url="<https://docs.snowflake.com/en/user-guide/key-pair-auth>" %}

1. **Generate a private key**

The first step is to generate a private RSA key. CARTO supports both unencrypted and encrypted private keys, although the latter is recommended.

Encrypted private keys are protected with a passphrase, which is used for protecting the private key and will never be sent to Snowflake. Use this command in your terminal to generate a private key:

```bash
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out rsa_key.p8
```

After pressing enter, a new key will be created in the directory where you ran the command. You will also need to establish a passphrase for the key, since this is an encrypted key. Store it as you will need it later. The resulting key will look something like this:

```
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIE6T...
-----END ENCRYPTED PRIVATE KEY-----
```

2. **Generate a public key**

Next, you need to generate a public key. You can do so from your terminal by referencing your private key. The following command assumes the private key is encrypted and contained in the file named `rsa_key.p8` created in the step before:

```bash
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
```

The resulting key will look like this:

```
-----BEGIN PUBLIC KEY-----
MIIBIj...
-----END PUBLIC KEY-----
```

3. **Assign the public key to a Snowflake user**

Once you have created the key pair, the public key needs to be associated with your Snowflake user (or the service account). Copy the public key created in the step above and use it in the following command in your Snowflake terminal:

```
ALTER USER snowflake_user SET RSA_PUBLIC_KEY='MIIBIjANBgkqh...';
```

{% hint style="warning" %}
Make sure to exclude the public key delimiters (-----BEGIN PUBLIC KEY-----) in the command above. Only owners of a user, or users with the SECURITYADMIN role or higher can alter a user.
{% endhint %}

3. **Create the key-pair connection in CARTO**

Lastly, create the connection in CARTO from the connection settings, selecting key-pair as an option under the Snowflake card.

Make sure to paste the entire private key (including its delimiters) in the box. If you're using an encrypted key, you'll also need to enter the passphrase. For the account name, you can either enter your Snowflake account identifier or your complete Account URL (e.g., `https://test.west-us-2.azure.snowflakecomputing.com`).

Click connect to validate the setup and create the connection.

### Key-pair rotation

CARTO users with a Snowflake key-pair connection can choose to rotate keys periodically for additional security. To do so, simply click the ***Change private key*** button in the connection settings to replace the private key (and passphrase, if used). Please note that the new key must be associated with the existing public key that you have established in Snowflake.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-b733dd92ae4c02ede69385aa03dcadc36ee41c9c%2FScreenshot%202025-01-21%20at%2014.56.45.png?alt=media" alt=""><figcaption><p>Connection settings of a Snowflake key-pair connection.</p></figcaption></figure>

***

## Advanced options

* **Analytics Toolbox location:** This setting controls the location of the Analytics Toolbox used in SQL queries generated by Workflows components, Builder SQL Analyses, 'Create Tileset', 'Geocode Table' and 'Enrich Data' functionalities.\
  By default, `CARTO.CARTO` will be used.
* **Data Observatory location:** This settings controls the location of the Data Observatory subscriptions. This setting will be observed by Data Explorer, Workflows and Enrichment to access your data subscriptions.\
  By default, `CARTO-DATA.CARTO`will be used.
* **CARTO temp location**

  Location to store **temporary tables** used during workflow execution. These include intermediate tables with hashed names created by nodes in a workflow.\
  By default, CARTO uses a `CARTO_TEMP` schema per database. For connections shared requiring Viewer Credentials, a `CARTO_TEMP_<USER>` schema is created per user.\
  **Example:** `MY_DB.CARTO_TEMP`
* **CARTO Workspace location**

  Location to store **persistent objects** related to workflows, such as API stored procedures and imported files.\
  By default, CARTO uses a `CARTO_WORKSPACE` schema per database. For connections shared requiring Viewer Credentials, a `CARTO_WORKSPACE_<USER>` schema is created per user.\
  **Example:** `MY_DB.CARTO_WORKSPACE`
* **CARTO Extensions location**

  Location to store **Extension Package resources**, including shared stored procedures and metadata.\
  By default, CARTO uses a `CARTO_EXTENSIONS` schema in the connection's database.\
  Important notes:

  * This schema is shared across all users of the connection, even for connections shared requiring Viewer Credentials.
  * User-specific schemas like `CARTO_EXTENSIONS_<USER>` are **not** created, to ensure a single source of extensions per connection.\
    **Example:** `MY_DB.CARTO_EXTENSIONS`
* **Max number of concurrent queries:** This setting controls the maximum number of simultaneous queries that CARTO will send to Snowflake using this connection.
* **Max query timeout:** This setting controls the maximum allowed duration of queries that CARTO runs in Snowflake using this connection.
* **Restrict this connection to only use Named Sources:** When this setting is enabled, this connection will only work within apps that use [Named Sources](https://docs.carto.com/carto-user-manual/developers/named-sources.md), and it will NOT work in Data Explorer, Builder and Workflows. This prevents the usage of arbitrary SQL in applications for this connection.

### Workflows locations and permissions

If a temp, workspace or extensions schema doesn't exist, CARTO tries to create it when a workflow is opened. If the role used by the connection can't create schemas, create them in advance, grant the role privileges on them, and set them in the advanced options. Otherwise, Workflows shows *Workflows temporal storage does not exist, is not authorized, or can not be created*.

{% hint style="warning" %}
**Locations on shared OAuth connections**

The **CARTO temp location** and **CARTO Workspace location** set in the advanced options are used only by the connection owner. Every other user the connection is shared with gets their own `CARTO_TEMP_<USER>` and `CARTO_WORKSPACE_<USER>` schemas in the connection's database, even if the owner set custom locations. CARTO assigns these names when the user first adds their credentials or creates a workflow, and creates the schemas when they open a workflow, so each user's role needs `CREATE SCHEMA` on the connection's database. `<USER>` combines the user's email and a short hash of their CARTO user ID, so it can't be worked out from the email alone.

The **CARTO Extensions location** is shared by all users. CARTO doesn't drop per-user schemas when a user is removed.
{% endhint %}

## IP Whitelisting <a href="#ip-whitelisting" id="ip-whitelisting"></a>

If you're using CARTO Cloud, CARTO will connect to Snowflake using a set of static IPs for each region. [Check this guide to find the IPs you need to allow](https://docs.carto.com/carto-user-manual/connections/ip-whitelisting.md) for your specific region.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.carto.com/carto-user-manual/connections/snowflake.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
