# Getting Access
## Overview

Access to the Monta Data Warehouse uses **Key Pair Authentication** for enhanced security. This requires generating a public/private key pair and connecting via Snowflake-compatible tools.

:::info{title="Tool Compatibility"}
Not all BI or dashboard tools support key pair authentication. If your tool doesn't support private/public key setup, contact your Monta CSM to discuss alternatives.
:::

## Quick Start

1. Generate key pair → 2. Send public key to Monta CSM → 3. Receive connection details → 4. Connect using your preferred tool

***

## Prerequisites

Before accessing the Monta Data Warehouse:

* **Active partnership** with a mutual data sharing agreement in place
* **Snowflake-compatible tool** that supports key pair authentication (SnowSQL, Python Connector, DBeaver, JDBC, etc.)

***

## Setup: Generate Your Key Pair

### Mac OS / Linux (OpenSSL)

Generate a 2048-bit RSA key pair using these commands:

**1. Generate private key:**

```bash
(umask 077 && openssl genrsa 2048 \
  | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt)
```

`umask 077` makes the key file readable only by you.

**2. Generate public key:**

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

:::info{title="Windows Users"}
Follow [Snowflake's key pair authentication guide](https://docs.snowflake.com/en/user-guide/key-pair-auth#configuring-key-pair-authentication) for Windows-specific instructions.
:::

### Send Your Public Key

Share `rsa_key.pub` with your Monta CSM via email or Slack. **This file is safe to share** - it contains only the public key. Monta will respond with your Snowflake account identifier and connection details.

:::warning{title="Security Note"}
We only support **unencrypted private keys** at this time. Keep your `rsa_key.p8` file secure and never share it.
:::

***

## Connection Parameters

Once you receive your credentials, use these values when connecting:

| Parameter       | Value                                      |
| --------------- | ------------------------------------------ |
| **Account**     | `st17140.eu-west-1`                        |
| **Host**        | `st17140.eu-west-1.snowflakecomputing.com` |
| **Username**    | Your partner name (e.g., `examplepartner`) |
| **Warehouse**   | `PARTNER`                                  |
| **Database**    | `PARTNER`                                  |
| **Schema**      | `PRODUCTION_{partner_name}`                |
| **Private Key** | Path to your `rsa_key.p8` file             |

## Connecting to Snowflake

### Option 1: SnowSQL (CLI Tool)

**Install SnowSQL:**
Follow [Snowflake's installation guide](https://docs.snowflake.com/en/user-guide/snowsql-install-config) for your OS.

**Connect:**

```bash
snowsql -a st17140.eu-west-1 \
  -h st17140.eu-west-1.snowflakecomputing.com \
  -u {your_partner_name} \
  --private-key-path ~/rsa_key.p8 \
  -w PARTNER \
  -d PARTNER \
  -s PRODUCTION_{your_partner_name}
```

Replace `{your_partner_name}` with your actual partner name.

***

### Option 2: Code

**Install Snowflake's library for your language:** `pip install snowflake-connector-python` (Python), `npm install snowflake-sdk` (JavaScript), the `net.snowflake:snowflake-jdbc` driver from Maven Central (Java) or `go get github.com/snowflakedb/gosnowflake/v2` (Go).

**Connect with key pair authentication:** replace `your_partner_name` with your partner name. Each example reads `rsa_key.p8` from your home folder, counts the rows in [charges](/docs/charges) and prints the result.

<CodeTabs syncKey="language">

```python title="Python"
import os

import snowflake.connector

ACCOUNT = "st17140.eu-west-1"
PARTNER_NAME = "your_partner_name"
WAREHOUSE = "PARTNER"
DATABASE = "PARTNER"
SCHEMA = f"PRODUCTION_{PARTNER_NAME}"
PRIVATE_KEY_FILE = os.path.expanduser("~/rsa_key.p8")

with snowflake.connector.connect(
    account=ACCOUNT,
    user=PARTNER_NAME,
    authenticator="SNOWFLAKE_JWT",
    private_key_file=PRIVATE_KEY_FILE,
    warehouse=WAREHOUSE,
    database=DATABASE,
    schema=SCHEMA,
) as connection:
    cursor = connection.cursor()
    (count,) = cursor.execute("SELECT COUNT(*) FROM charges").fetchone()
    print(f"Charges: {count}")
```

```js title="JavaScript"
import { homedir } from "node:os";
import { join } from "node:path";
import snowflake from "snowflake-sdk";

const ACCOUNT = "st17140.eu-west-1";
const PARTNER_NAME = "your_partner_name";
const WAREHOUSE = "PARTNER";
const DATABASE = "PARTNER";
const SCHEMA = `PRODUCTION_${PARTNER_NAME}`;
const PRIVATE_KEY_PATH = join(homedir(), "rsa_key.p8");

const connection = snowflake.createConnection({
  account: ACCOUNT,
  username: PARTNER_NAME,
  authenticator: "SNOWFLAKE_JWT",
  privateKeyPath: PRIVATE_KEY_PATH,
  warehouse: WAREHOUSE,
  database: DATABASE,
  schema: SCHEMA,
});
await new Promise((resolve, reject) => {
  connection.connect((error) => (error ? reject(error) : resolve()));
});
const [row] = await new Promise((resolve, reject) => {
  connection.execute({
    sqlText: "SELECT COUNT(*) AS CHARGE_COUNT FROM charges",
    complete: (error, statement, rows) => (error ? reject(error) : resolve(rows)),
  });
});
console.log(`Charges: ${row.CHARGE_COUNT}`);
connection.destroy((error) => {
  if (error) {
    console.error(`Disconnect failed: ${error.message}`);
  }
});
```

```java title="Java"
import java.nio.file.Path;
import java.sql.DriverManager;
import java.util.Properties;

public class CountCharges {
    static final String ACCOUNT = "st17140.eu-west-1";
    static final String PARTNER_NAME = "your_partner_name";
    static final String WAREHOUSE = "PARTNER";
    static final String DATABASE = "PARTNER";
    static final String SCHEMA = "PRODUCTION_" + PARTNER_NAME;
    static final Path PRIVATE_KEY_FILE =
            Path.of(System.getProperty("user.home"), "rsa_key.p8");

    public static void main(String[] args) throws Exception {
        var properties = new Properties();
        properties.put("user", PARTNER_NAME);
        properties.put("private_key_file", PRIVATE_KEY_FILE.toString());
        properties.put("warehouse", WAREHOUSE);
        properties.put("db", DATABASE);
        properties.put("schema", SCHEMA);
        var url = "jdbc:snowflake://" + ACCOUNT + ".snowflakecomputing.com";
        try (var connection = DriverManager.getConnection(url, properties);
                var statement = connection.createStatement();
                var result = statement.executeQuery("SELECT COUNT(*) FROM charges")) {
            result.next();
            System.out.println("Charges: " + result.getLong(1));
        }
    }
}
```

```go title="Go"
package main

import (
	"crypto/rsa"
	"crypto/x509"
	"database/sql"
	"encoding/pem"
	"errors"
	"fmt"
	"log"
	"os"
	"path/filepath"

	sf "github.com/snowflakedb/gosnowflake/v2"
)

const (
	account     = "st17140.eu-west-1"
	partnerName = "your_partner_name"
	warehouse   = "PARTNER"
	database    = "PARTNER"
	schema      = "PRODUCTION_" + partnerName
	keyFileName = "rsa_key.p8"
)

func main() {
	home, err := os.UserHomeDir()
	if err != nil {
		log.Fatal(err)
	}
	privateKey, err := readPrivateKey(filepath.Join(home, keyFileName))
	if err != nil {
		log.Fatal(err)
	}
	config := sf.Config{
		Account:       account,
		User:          partnerName,
		Authenticator: sf.AuthTypeJwt,
		PrivateKey:    privateKey,
		Warehouse:     warehouse,
		Database:      database,
		Schema:        schema,
	}
	db := sql.OpenDB(sf.NewConnector(sf.SnowflakeDriver{}, config))
	defer db.Close()

	var count int64
	err = db.QueryRow("SELECT COUNT(*) FROM charges").Scan(&count)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Charges:", count)
}

func readPrivateKey(path string) (*rsa.PrivateKey, error) {
	keyFile, err := os.ReadFile(path)
	if err != nil {
		return nil, err
	}
	block, _ := pem.Decode(keyFile)
	if block == nil {
		return nil, errors.New("no PEM key found in " + path)
	}
	key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
	if err != nil {
		return nil, err
	}
	rsaKey, ok := key.(*rsa.PrivateKey)
	if !ok {
		return nil, errors.New("not an RSA key: " + path)
	}
	return rsaKey, nil
}
```

</CodeTabs>

See Snowflake's key pair authentication docs for [Python](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-connect#using-key-pair-authentication-and-key-pair-rotation), [Node.js](https://docs.snowflake.com/en/developer-guide/node-js/nodejs-driver-authenticate#use-key-pair-authentication-and-key-pair-rotation), [JDBC](https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-configure#using-key-pair-authentication-and-key-rotation) and [Go](https://docs.snowflake.com/en/developer-guide/golang/go-driver).

***

### Option 3: DBeaver (Visual Database Tool)

Download the free [community edition](https://dbeaver.io/download/) and follow these steps:

**1. Create new connection:** Database → New Database Connection

![DBeaver with the Database menu open on New Database Connection](/images/dbeaver-new-connection.webp)

**2. Select Snowflake:**

![DBeaver connection wizard with Snowflake selected](/images/dbeaver-select-snowflake.webp)

**3. Configure connection:**

* **Host:** `st17140.eu-west-1.snowflakecomputing.com:443`
* **Database:** `PARTNER`
* **Warehouse:** `PARTNER`
* **Schema:** `PRODUCTION_{your_partner_name}`
* **Username:** `{your_partner_name}`

![DBeaver Snowflake connection settings with host, database, warehouse, schema and username filled in](/images/dbeaver-configure-connection.webp)

**4. Add private key property:**

Go to **Driver properties** → Right-click → **Add new property** → Name it `private_key_file` → Click OK

![DBeaver Driver properties tab with the Add new property menu open](/images/dbeaver-add-driver-property.webp)

![DBeaver Property Name dialog with private_key_file entered](/images/dbeaver-name-private-key-property.webp)

**5. Set private key path:**

Click the value field next to `private_key_file` and enter the full path to your `rsa_key.p8` file.

![DBeaver Driver properties tab with the path to the private key file entered as the value of private_key_file](/images/dbeaver-set-private-key-path.webp)

**6. Finish:** Click Finish. You should see the PARTNER database in your Database Navigator.

***

## Need Help?

If you experience connection issues or have questions, contact your Monta CSM via your usual channel (email or Slack).
