# Snowflake with External OAuth Setup

## verview <a href="#overview" id="overview"></a>

This document provides an overview of how TrustLogix uses Snowflake External OAuth to secure access to our Snowflake data warehouse. It outlines the general process, supported Identity Providers (IdPs), and configuration guides.

### What is External OAuth <a href="#configuration-steps" id="configuration-steps"></a>

External OAuth allows Snowflake to leverage an external, trusted Identity Provider (IdP) for user authentication and authorization. This enables a seamless Single Sign-On (SSO) experience for programmatic clients (like Azure AD or Okta) and aligns Snowflake access with TrustLogix's central identity and access management policies.

### Supported **OAuth Provider** <a href="#configuration-steps" id="configuration-steps"></a>

TrustLogix supports external authorization servers, custom clients, and partner application integration, which are natively supported by Snowflake. Choose one of the supported providers:

<table><thead><tr><th width="362.60009765625">Snoflake Doc</th><th>Snowflake Community Doc Link</th></tr></thead><tbody><tr><td><a href="https://docs.snowflake.com/en/user-guide/oauth-okta">Okta</a></td><td><a href="https://community.snowflake.com/s/article/How-To-Create-External-Oauth-Token-Using-Okta-For-The-Client-Itself-Service-Flow">Okta</a></td></tr><tr><td><a href="https://docs.snowflake.com/en/user-guide/oauth-azure">Microsoft Entra ID</a></td><td><a href="https://community.snowflake.com/s/article/Create-External-OAuth-Token-Using-Azure-AD-For-The-OAuth-Client-Itself">Microsoft Entra ID</a></td></tr><tr><td><a href="https://docs.snowflake.com/en/user-guide/oauth-pingfed">Ping Identity PingFederate</a></td><td></td></tr><tr><td><a href="https://docs.snowflake.com/en/user-guide/oauth-ext-custom">External OAuth Custom Clients</a></td><td></td></tr><tr><td><a href="https://docs.snowflake.com/en/user-guide/oauth-powerbi">Microsoft Power BI</a></td><td></td></tr><tr><td><a href="https://help.sigmacomputing.com/docs/connect-to-snowflake-oauth">Sigma</a></td><td></td></tr></tbody></table>

**Note**: We recommend consulting the official Snowflake documentation for the latest configuration details and prerequisites.

### Configuration Overview <a href="#configuration-steps" id="configuration-steps"></a>

The external OAuth setup is a two-part process that establishes a trust relationship between your IdP provider and Snowflake.

1. Configure an App registration as OAuth client.
2. Request and decode the OAuth access token.
3. Create an External OAuth Security Integration in Snowflake
4. Verify the Access Token against the security integration. &#x20;
5. Alter TrustLogix user in Snowflake
6. Register Snowflake account using the access token.

#### Step 1: Configure an App registration as OAuth client. <a href="#step-3-request-and-decode-the-oauth-access-token" id="step-3-request-and-decode-the-oauth-access-token"></a>

* Refer to the Snowflake official document to register IdP provider applications.&#x20;
* Get the below value from IdP.
  * OAuth token endpoint.
  * Application scope
  * Client ID
  * Client secret
* Use the TrustLogix role in the application scope: Ex:- session:role:\<TLX\_ROLE>

#### Step 2: Request and decode the OAuth access token. <a href="#step-3-request-and-decode-the-oauth-access-token" id="step-3-request-and-decode-the-oauth-access-token"></a>

1. Refer to the Snowflake official document to prepare the CURL command to request the access token using the client\_credentials grant.
2. &#x20;**Decode the OAuth Access Token**
   1. Copy the value of the **access\_token** and decode it on an online decoder of your choice (e.g. [jwt.ms](https://jwt.ms/)), it will provide the details present in the token.
   2. Make sure the following attributes from the decoded token match the configuration in the external authorization server.
      * issuer
      * audience
      * roles

#### Step 3: Create an External OAuth Security Integration in Snowflake <a href="#step-4-create-an-external-oauth-security-integration-in-snowflake" id="step-4-create-an-external-oauth-security-integration-in-snowflake"></a>

Now configure the Snowflake account to trust and accept the access token generated in Step 2.&#x20;

* ISSUER&#x20;
* AUDIENCE &#x20;
* JWS\_KEY\_ENDPOINT&#x20;

> create security integration external\_oauth\_integration\
> &#x20;   type = external\_oauth\
> &#x20;   enabled = true\
> &#x20;   external\_oauth\_type = \<idp\_type>\
> &#x20;   external\_oauth\_issuer = '\<ISSUER>'\
> &#x20;   external\_oauth\_jws\_keys\_url = '\<JWS\_KEY\_ENDPOINT>'\
> &#x20;   external\_oauth\_audience\_list = ('\<AUDIENCE >')\
> &#x20;   external\_oauth\_token\_user\_mapping\_claim = 'sub'\
> &#x20;   external\_oauth\_snowflake\_user\_mapping\_attribute = 'login\_name';

#### Step 4: Verify the Access Token against the Security Integration  <a href="#step-5-verify-the-access-token-against-the-security-integration" id="step-5-verify-the-access-token-against-the-security-integration"></a>

Now that the security integration is created in Snowflake, it can accept or reject an access token issued from an OAuth provider client based on the configuration. Use the function [SYSTEM$VERIFY\_EXTERNAL\_OAUTH\_TOKEN](https://docs.snowflake.com/en/sql-reference/functions/system_verify_ext_oauth_token) to confirm whether your token will be accepted by the Snowflake account or not.

<details open>

<summary>Verify Token query</summary>

```
SELECT SYSTEM$VERIFY_EXTERNAL_OAUTH_TOKEN('eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSIsIm.......FTU5nctRpmaA');
```

</details>

A successful validation would look like the below:

> Token Validation finished. { "Validation Result":"Passed", "Issuer":"issuer endpoint/", "**Extracted User claim(s) from token**":"3d63xxxxxxxx0652895d" }

Please note down the value get from the token validation response `Extracted User claim(s) from token` . We will use it in the next step.&#x20;

#### Step 5: Alter TrustLogix user in Snowflake <a href="#step-6-alter-a-tlx-user-for-the-client-in-snowflake" id="step-6-alter-a-tlx-user-for-the-client-in-snowflake"></a>

Finally, alter the TrustLogix Snowflake user and use `Extracted User claim(s) from token` (the value from step 4 in LOGIN\_NAME).

Ex: `ALTER USER TLX_<id>_CP_USER SET LOGIN_NAME = "3d63xxxxxxxx0652895d" TYPE = 'SERVICE'`

#### Step 6: Register a Snowflake account using the access token. <a href="#step-7-register-snowflake-account-using-the-access-token-in-trustlogix" id="step-7-register-snowflake-account-using-the-access-token-in-trustlogix"></a>

* Once the token validation is successful, we can register the Snowflake account in TrustLogix.
* Enter all the details in the TrustLogix registration page, and click on save.<br>
*

```
<figure><img src="https://815455107-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0SWnT1NcjBiPxnUvPcqE%2Fuploads%2F1e6qNTzBlBt3xLBvTQPh%2Fimage.png?alt=media&#x26;token=16ae800e-1602-4eda-85ed-a60bf55e848b" alt=""><figcaption></figcaption></figure>
```

## External OAuth Authentication Setup For **Customer-hosted TrustLet**

Below are the additional steps required for Customer-hosted TrustLet or hybrid tenant.

1. Follow these steps mentioned above to create data plane user
   1. Configure an App registration as the OAuth Resource server
   2. Request and decode the OAuth access token.
   3. Alter the External OAuth Security Integration created for the DP user

      1. Run the describe command to check the audience list for the security integration created for the CP user.

         ```
         desc security integration EXTERNAL_OAUTH_AZURE;
         ```
      2. Alter Security Integration to add audience for DP user(include all audience from output of the above command)

      <pre><code><strong>ALTER SECURITY INTEGRATION EXTERNAL_OAUTH_INTEGRATION
      </strong><strong>SET EXTERNAL_OAUTH_AUDIENCE_LIST = ('&#x3C;audience_1>', '&#x3C;audience_2>', ...);
      </strong></code></pre>
   4. Verify the Access Token against the Security Integration &#x20;
   5. Alter TrustLogix user in Snowflake
2. Set following key and value&#x20;

* Trustlet is hosted on AWS ECS (Amazon Elastic Container Service)

```
tlx/<tenant-id>/<account-id>/role
tlx/<tenant-id>/<account-id>/username
tlx/<tenant-id>/<account-id>/jdbcurl
tlx/<tenant-id>/<account-id>/warehouse
tlx/<tenant-id>/<account-id>/clientSecret
tlx/<tenant-id>/<account-id>/clientId
tlx/<tenant-id>/<account-id>/scope
tlx/<tenant-id>/<account-id>/tokenUrl
```

* Trustlet is hosted on Azure Kubernetes Service (AKS)

```
tlx-<tenant-id>-<account-id>-role
tlx-<tenant-id>-<account-id>-username
tlx-<tenant-id>-<account-id>-jdbcurl
tlx-<tenant-id>-<account-id>-warehouse
tlx-<tenant-id>-<account-id>-clientSecret
tlx-<tenant-id>-<account-id>-clientId
tlx-<tenant-id>-<account-id>-scope
tlx-<tenant-id>-<account-id>-tokenUrl
```

> Please note that the value username (`tlx/<tenant-id>/<account-id>/username` or `tlx-<tenant-id>-<account-id>-username`) must match the `LOGIN_NAME` used in Step 5. For example:
>
> `tlx/<tenant-id>/<account-id>/username`  = `672a90b3-xxxx-xxxx-xxxx-xxxx2f7befef`&#x20;

***

## Final Steps to Confirm Setup <a href="#final-steps-to-confirm-setup" id="final-steps-to-confirm-setup"></a>

After completing the configuration:

* Create a **test policy** on a sample dataset.
* Deploy the policy.
* If the policy creation and deployment flow proceeds without errors (during database/schema selection and deployment), then the **External OAuth setup is successful**.
