> ## Documentation Index
> Fetch the complete documentation index at: https://klef.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Snowflake User Provisioning & Deprovisioning

> Automate Snowflake user provisioning and deprovisioning from your HRIS. Klef creates, updates, and deactivates accounts when HR makes a change.

![](https://mintcdn.com/klef/_LgTg4RHjin1TYFy/images/connectors/snowflake.svg?fit=max\&auto=format\&n=_LgTg4RHjin1TYFy\&q=85\&s=c969e7313610e2500117ae3331b4b86f)

# Snowflake

## Connection

### Setup

Klef creates users in one Snowflake account, grants and revokes their account roles, and disables them. It signs in as a service user with a key pair, through Snowflake's SQL API.

**Step 1**

Make an RSA key pair of at least 2048 bits, as Snowflake's [key-pair authentication](https://docs.snowflake.com/en/user-guide/key-pair-auth) guide shows: `openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt`, then `openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub`.

**Step 2**

As an administrator, create the service user and give it the public key, without the PEM header and footer:

```sql theme={null}
CREATE USER KLEF_SERVICE TYPE = SERVICE DEFAULT_ROLE = SECURITYADMIN RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...';
GRANT ROLE SECURITYADMIN TO USER KLEF_SERVICE;
```

Klef needs MANAGE GRANTS to see every user and grant any role, and CREATE USER to create users. SECURITYADMIN holds both. A custom role works too, if it holds both privileges itself and is the role Klef runs as: Snowflake shows user details only for privileges of that role.

**Step 3**

If the account has a network policy, allow Klef's outbound addresses for the service user.

**Step 4**

Copy the account identifier from Snowsight, under your name, then **Connect a tool to Snowflake**. Use the organization-account form, such as `myorg-my_account`, keeping any underscores.

**Step 5**

In Klef, enter the account identifier, the service user's name and the private key, and the passphrase if the key has one. Leave **Role** blank to use the service user's default role, and click the **Connect** button.

> [!NOTE]
>
> Klef can change only users its role owns, which includes every user it creates. To manage a user another role created, grant Klef's role MODIFY on that user, with `GRANT MODIFY ON USER <name> TO ROLE SECURITYADMIN`, or transfer its ownership.

> [!NOTE]
>
> Klef matches Snowflake's users to your people by login name, so login names should be work email addresses, as single sign-on usually needs.

### Settings

| Setting | Required | Description |
| - | - | - |
| Account identifier | Yes | The account in organization-account form, such as myorg-my\_account, as Snowsight shows it under Connect a tool to Snowflake, with any underscores kept. |
| Service user | Yes | Name of the Snowflake user the connector signs in as, which holds the public key. |
| Private key (PEM) | Yes | The RSA private key whose public key is set on the service user, in PEM. |
| Private key passphrase | | The passphrase of an encrypted private key. Leave it blank for a key that has none. |
| Role | | The role the connector runs as, such as SECURITYADMIN, written as SHOW ROLES shows it. Left blank, the connector runs as the service user's default role. |

## snowflake.user

### Fields

| Field | Type | Required | Description |
| - | - | - | - |
| `loginName` | string, up to 255 | Yes | The name the user signs in with, which single sign-on matches. Snowflake treats it without case. |
| `name` | string, up to 255 | | The user's identifier in Snowflake. Left out, the connector uses the login name. Never changed once the account exists. |
| `displayName` | string | | The name Snowsight shows. Snowflake uses the user name when none is set. |
| `email` | string | | Email address. |
| `firstName` | string | | First name. |
| `lastName` | string | | Last name. |
| `defaultRole` | string | | The role a session starts in. It grants nothing, so grant the role in Roles too. |
| `roles` | entitlements | | Account roles granted to the user directly. A role holds every role granted to it. PUBLIC is held by everyone and is not listed. One row grants one role. |
| `roles[]` | string | | Role name. |
| `disabled` | bool | | Whether the user is locked out. Disabling aborts their running queries and keeps the user. Shows the account's status: a policy reads it and sets `status` instead. |
| `status` | enum | | Whether the person can sign in, the account is kept switched off, or the account is gone. Values: `enabled` (Enabled), `disabled` (Disabled). |

### Default Account Matching Rules

When Klef [adopts](https://klef.ai/docs/adoption.md) an account that already exists in Snowflake, it works out whose it is by trying these in order. A connection can override them.

| Account field | Worker field |
| - | - |
| `loginName` | `worker.business_email` |

## Examples

### Snowflake users

A Snowflake user for every engineer, signing in through single sign-on in the role that carries their data access, disabled and cleared when they leave.

```hcl theme={null}
stage active {
  target snowflake.user {
    loginName   = worker.business_email
    email       = worker.business_email
    firstName   = worker.legal_name.given
    lastName    = worker.legal_name.family
    defaultRole = "ENGINEERING"
    roles       = ["ENGINEERING"]
    status      = enabled
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.