# Connecting to Snowflake

Connect your Snowflake account to import tables and views into Galdera. Galdera gets read-only access to one database through a dedicated service user that signs in with a key pair. You never enter a Snowflake password in Galdera.

Setup has two parts:

* **Part 1: Connect your Snowflake account.** You enter a few details, your Snowflake administrator runs a setup script that Galdera generates, and you check that the connection works. You do this for each database connection.
* **Part 2: Import a table.** You choose a table or view, tell Galdera what each column means, and import the data. You repeat this for each table you want, using the same connection.

## Who does what

| Step | Who | Where |
|---|---|---|
| 1. Generate the setup script | A Galdera organization admin | Galdera |
| 2. Run the setup script | Your Snowflake administrator (or you, if you manage Snowflake) | Snowflake |
| 3. Test the connection | A Galdera organization admin | Galdera |
| 4–6. Choose, map, and import a table | Any Galdera member, once the connection test has succeeded | Galdera |

Organization admins connect, test, rotate, and remove connections. After an admin's connection test succeeds, any member can finish the setup: choose the table, map its columns, and import it. Members can also sync, re-map, and delete imported tables. Adding another table to a connection that already has one needs an admin.

## Before you start

### What you need

* **Your Snowflake account URL**, such as `ab12345.snowflakecomputing.com`. Ask your Snowflake administrator if you're not sure.
* **The name of the database** that holds your data.
* **An existing Snowflake user (optional).** If your IT team has already created a Snowflake user for Galdera, get its name. Otherwise, the script creates one called `GALDERA_SVC`.
* **A table or view with a date column** and the numbers you want to forecast.

### What your Snowflake administrator needs

* **Someone to run the setup script.** This is usually your IT or data team. If you are a Snowflake administrator yourself, you can run it.
* **The `SYSADMIN` and `SECURITYADMIN` roles** in Snowflake. The section [For your Snowflake administrator](#for-your-snowflake-administrator) at the end of this page explains what the script does, so they can review it before running it.

## Part 1: Connect your Snowflake account

### Step 1: Generate the setup script

1. Open **Connectors**.
2. Find **Snowflake** under **Additional connectors** and click **Connect**.
3. Enter the **Account URL** and **Database**. If your team already created a Snowflake user for Galdera, enter it under **Snowflake user (optional)**.
4. Click **Generate setup script**.
5. Click **Copy script**.

Use the generated script: it contains the public key for this connection. Your administrator can review and adapt its grants before running it.

### Step 2: Have the script run in Snowflake

**If someone else manages Snowflake**, send them the script by email, chat, or ticket, and ask them to run it. The script is safe to share: it contains no passwords or secret keys. You can also send them this page: [For your Snowflake administrator](#for-your-snowflake-administrator) explains what the script does.

**If you manage Snowflake yourself**, open a SQL worksheet in Snowsight (Snowflake's web interface), paste the script, and run all of it. [For your Snowflake administrator](#for-your-snowflake-administrator) lists the roles it needs.

You can close Galdera while you wait. The script is saved with the connection: to get it again, open **Connectors** and click **Continue setup** next to Snowflake.

### Step 3: Test the connection

When the script has run, return to the Snowflake setup in Galdera and click **Test connection**. If the test fails, the message explains what to fix. For common errors, see [Snowflake Syncs and Troubleshooting](/sources/manage-snowflake).

When the test succeeds, your Snowflake account is connected. Galdera can read the database, but no data has been imported yet.

## Part 2: Import a table

### Step 4: Choose the table

1. On the connection page, click **Add table** to begin table setup at **Choose data**.
2. Select a **Schema** and a **Table**. The list shows the tables and views Galdera can read.
3. Select a **Start date**: **Last 1 year**, **Last 2 years**, **Last 3 years**, or **Custom date**. The import runs up to today's date.
4. Check the sample preview to confirm you chose the right data.

### Step 5: Map the columns

In **Review columns**, tell Galdera what each column means:

* The **date column** that orders the data in time.
* At least one **measure**: a numeric column to forecast, such as revenue or units.
* Any **dimensions**: columns to break the forecast down by, such as region or product.
* The **frequency** of the data, such as daily or monthly.

Galdera suggests a role for each column. Check the suggestions, and answer any questions about the table's layout.

### Step 6: Import

In **Import**, review your choices and click **Start import**.

If the date range contains no rows, Galdera shows the dates it checked. Choose an earlier start date and import again.

Galdera saves your progress as you go. If you leave, setup reopens at the first step you haven't finished.

When the import is done, the table appears under **Tables** on the **Connectors** page. To refresh its data later, open the table and use the circular-arrow button in the top toolbar (tooltip **Sync**). A refresh button beside the status is labeled **Import again** in **Connectors**, or **Sync now** on other source pages.

### Import another table

Importing another table through a connection that already has one needs an organization admin.

For another table in the same database, open **Connectors**, click **Add table**, and select your Snowflake connection under **Use a saved connection**. Galdera reuses that connection's database and opens **Choose data**. Choose the schema, table, and history window as in Step 4, then continue with Step 5. You can also click **Add table** on the connection page.

For a different database, find **Snowflake** under **Additional connectors** and click **Add another connection**. Enter the same **Account URL** and the new **Database**, then click **Generate setup script**. Have the script run as in Step 2, test the connection as in Step 3, then add a table as in Part 2.

## For your Snowflake administrator

This section is for the person who runs the setup script. It explains what each part of the script does and why, so you can review it before running it.

### Summary

* **Roles needed:** `SYSADMIN` and `SECURITYADMIN`. The script switches between them itself.
* **Access granted:** read-only (`SELECT`) on one database. No write, delete, or administrative privileges.
* **Objects created:** a service user (unless you supply one), the `GALDERA_READER` role, and an X-Small warehouse. The default user is `GALDERA_SVC`.
* **Sign-in:** Galdera uses a key pair. A newly created service user has no password and cannot sign in to the Snowflake web interface; a supplied user's existing type and sign-in methods are preserved, unless it is named `GALDERA_SVC`, which the script always sets to a service user.
* **Re-running:** objects are created only if missing, but `ALTER USER` sets the default role, warehouse, and primary public key. Check an existing user's key before running it.

### What the script does, step by step

Your generated script contains these steps in this order. Its comments repeat the key points.

| Step | Runs as | Statement | What it does and why |
|---|---|---|---|
| 1 | `SYSADMIN` | `CREATE WAREHOUSE IF NOT EXISTS GALDERA_XS_WH` | Creates a dedicated X-Small warehouse that starts on demand and suspends after 60 seconds idle. Galdera's queries never compete with your workloads, and its cost shows separately on your bill. |
| 2 | `SECURITYADMIN` | `CREATE ROLE IF NOT EXISTS GALDERA_READER` | Creates the role that holds all of Galdera's privileges. |
| 3 | `SECURITYADMIN` | `GRANT ROLE GALDERA_READER TO ROLE SYSADMIN` | Places the role under `SYSADMIN`, as Snowflake recommends for custom roles, so your administrators can see and manage it. |
| 4 | `SECURITYADMIN` | `CREATE USER IF NOT EXISTS GALDERA_SVC TYPE = SERVICE` | Creates a service user. `TYPE = SERVICE` users cannot have a password or sign in to the web interface. |
| 5 | `SECURITYADMIN` | `ALTER USER GALDERA_SVC SET … RSA_PUBLIC_KEY = '…'` | Installs Galdera's public key and sets the user's default role and warehouse. This is a separate statement so it also applies when the user already exists, for example when you re-run the script. |
| 6 | `SECURITYADMIN` | `GRANT ROLE GALDERA_READER TO USER GALDERA_SVC` and `GRANT USAGE ON WAREHOUSE GALDERA_XS_WH` | Lets the user act as the role, and lets the role run queries on the warehouse. |
| 7 | `SECURITYADMIN` | `GRANT USAGE ON DATABASE …`, `GRANT USAGE ON ALL / FUTURE SCHEMAS …`, `GRANT SELECT ON ALL / FUTURE TABLES …`, `GRANT SELECT ON ALL / FUTURE VIEWS …` | Gives read access to the database. `ALL` covers what exists today. `FUTURE` covers tables and views created later, except in schemas that have their own future grants (see [Schemas with their own future grants](#schemas-with-their-own-future-grants)). |
| 8 | — | `DESC USER GALDERA_SVC` | Shows the user so you can confirm the key landed: `RSA_PUBLIC_KEY_FP` should show a fingerprint. |

`SECURITYADMIN` runs everything after step 1: by default it can create users and roles, and it holds the `MANAGE GRANTS` privilege that the grants, including `FUTURE` grants, require.

### Schemas with their own future grants

Snowflake applies future grants at one level only. If a schema already has future grants for tables (or views), for any role, those schema-level grants take precedence, and the script's database-level future grants are ignored for that object type in that schema. Tables and views that already exist are unaffected, because the `ALL` grants cover them. But `GALDERA_READER` won't be able to read new ones created in that schema.

To check a schema:

```sql
SHOW FUTURE GRANTS IN SCHEMA <DATABASE>.<SCHEMA>;
```

If it lists grants for `TABLE` or `VIEW`, add schema-level future grants for Galdera for the same object type:

```sql
USE ROLE SECURITYADMIN;
GRANT SELECT ON FUTURE TABLES IN SCHEMA <DATABASE>.<SCHEMA> TO ROLE GALDERA_READER;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA <DATABASE>.<SCHEMA> TO ROLE GALDERA_READER;
```

See Snowflake's [rules for future grants on database or schema objects](https://docs.snowflake.com/en/sql-reference/sql/grant-privilege#future-grants-on-database-or-schema-objects).

### Using a user your team already created

If your organization provisions its own service users, for example `SVC_GALDERA`, give that name to the Galdera user connecting Snowflake so they can enter it under **Snowflake user (optional)**. The generated script then uses your user instead of `GALDERA_SVC`:

* `CREATE USER IF NOT EXISTS` does nothing, because the user already exists.
* `ALTER USER` installs Galdera's public key and sets the default role and warehouse. It does not change the user's type, so an existing password or sign-in method stays as it is.
* The role, warehouse, and grants are the same as for `GALDERA_SVC`. Galdera always connects with the `GALDERA_READER` role.

Before running the script, check that the user's key slot is free: `DESC USER <your user>` should show no `RSA_PUBLIC_KEY_FP`. If another tool already uses that key, the script would replace it, so contact Galdera support instead. The user's ownership matters too: the role that runs `ALTER USER` must own it, or be above the role that does.

### Limiting access to one schema

By default the script grants read access to every schema in the database. To limit Galdera to one schema, edit step 7 before running the script: keep `GRANT USAGE ON DATABASE`, and replace the other six grants with the schema-scoped versions listed in the script's comments. Then choose a table from that schema in Galdera.

### Network policies

Galdera always connects from one fixed IP address, shown at the top of the script. If a network policy applies to `GALDERA_SVC`, add that address to the policy's allowed list, keeping its existing entries. If the script shows no address, contact Galdera support for it before testing.

### How the key is handled

Galdera generates the key pair when someone clicks **Generate setup script**. The script contains only the public half. The private half is stored securely by Galdera, is used only by Galdera's connector, and is never displayed or sent to anyone. To replace the key, use key rotation: see [Snowflake Syncs and Troubleshooting](/sources/manage-snowflake).

### Check what Galdera can access

After running the script, you can confirm exactly what the role holds:

```sql
USE ROLE SECURITYADMIN;
SHOW GRANTS TO ROLE GALDERA_READER;
SHOW GRANTS TO USER GALDERA_SVC;
```

### Other scripts Galdera may give you

* **Adding a second database:** a short script with only step 7 for the new database. Run it as `SECURITYADMIN`.
* **Key rotation:** an `ALTER USER GALDERA_SVC SET RSA_PUBLIC_KEY_2 = '…'` statement that installs the replacement key in the second slot. Run it as `SECURITYADMIN` after checking that the slot is not in use; it replaces any key already there.

### Removing access

See **Disconnect and revoke access** in [Snowflake Syncs and Troubleshooting](/sources/manage-snowflake).

### Snowflake documentation

* [Access control best practices](https://docs.snowflake.com/en/user-guide/security-access-control-considerations): why custom roles sit under `SYSADMIN`, and what `SECURITYADMIN` is for.
* [Key-pair authentication and key-pair rotation](https://docs.snowflake.com/en/user-guide/key-pair-auth): how Galdera signs in, and how the two key slots allow rotation without downtime.
* [Controlling network traffic with network policies](https://docs.snowflake.com/en/user-guide/network-policies): allowing Galdera's IP address.
* [GRANT privileges TO ROLE](https://docs.snowflake.com/en/sql-reference/sql/grant-privilege): the grants in step 7, including future grants.
