LeveredDocs

Snowflake

Connect a Snowflake database to Levered.

What you need

ItemDescription
Account identifierThe Snowflake account, for example xy12345.us-east-1.
WarehouseThe compute warehouse that runs the queries, for example LEVERED_WH.
DatabaseThe database that contains the event tables.
SchemaThe schema within the database, for example PUBLIC.
AuthenticationPassword or RSA key pair. The key pair is recommended for service accounts.

Option A: Password authentication

CREATE ROLE levered_reader;
GRANT USAGE ON WAREHOUSE LEVERED_WH TO ROLE levered_reader;
GRANT USAGE ON DATABASE analytics_db TO ROLE levered_reader;
GRANT USAGE ON SCHEMA analytics_db.public TO ROLE levered_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA analytics_db.public TO ROLE levered_reader;
GRANT SELECT ON FUTURE TABLES IN SCHEMA analytics_db.public TO ROLE levered_reader;

CREATE USER levered_svc
  PASSWORD = 'a-strong-password'
  DEFAULT_ROLE = levered_reader
  DEFAULT_WAREHOUSE = LEVERED_WH;

GRANT ROLE levered_reader TO USER levered_svc;

Option B: Key pair authentication

Key pair authentication uses an RSA private key instead of a password. Snowflake recommends it for service accounts.

  1. Generate an RSA key pair:
# Generate a 2048-bit private key in PKCS#8 PEM format (unencrypted)
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -nocrypt -out levered_rsa_key.pem

# Extract the public key
openssl rsa -in levered_rsa_key.pem -pubout -out levered_rsa_key.pub

Note: Snowflake recommends encrypted private keys (generated with -v2 des3 instead of -nocrypt). Levered currently supports unencrypted private keys only. If your security policy requires encrypted keys, generate an encrypted key and decrypt it before pasting it into the dashboard:

# Generate encrypted key (you'll be prompted for a passphrase)
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -out rsa_key_encrypted.p8
# Decrypt it for use with Levered
openssl pkcs8 -in rsa_key_encrypted.p8 -nocrypt -out levered_rsa_key.pem
  1. Create the user and assign the public key in Snowflake:
CREATE ROLE levered_reader;
GRANT USAGE ON WAREHOUSE LEVERED_WH TO ROLE levered_reader;
GRANT USAGE ON DATABASE analytics_db TO ROLE levered_reader;
GRANT USAGE ON SCHEMA analytics_db.public TO ROLE levered_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA analytics_db.public TO ROLE levered_reader;
GRANT SELECT ON FUTURE TABLES IN SCHEMA analytics_db.public TO ROLE levered_reader;

CREATE USER levered_svc
  DEFAULT_ROLE = levered_reader
  DEFAULT_WAREHOUSE = LEVERED_WH;

GRANT ROLE levered_reader TO USER levered_svc;

-- Set the public key (paste the key content without the BEGIN/END lines)
ALTER USER levered_svc SET RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...your-public-key...';
  1. Paste the contents of the private key into the dashboard. Paste the full PEM, including the -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- lines.

Connect via the dashboard

The dashboard requires an existing exposures table and rewards table before it saves the connection. Create the tables first (Create the table).

  1. Click Warehouse in the Levered dashboard sidebar.
  2. Click Snowflake.
  3. Enter Account Identifier, Database and the Username of the read-only user.
  4. Under Authentication, choose Password or Key Pair (RSA).
    • With Password, enter the password.
    • With Key Pair (RSA), paste the full PEM private key.
  5. Optionally set Schema (default PUBLIC), Warehouse and Role, then click Next.
  6. Select the Exposures table and the Rewards table.
  7. Click Save Connection.
  8. Click Test connection on the connection card to verify the connection.

Troubleshooting

Connection test fails

Check that the account identifier includes the region, for example xy12345.us-east-1. Check that the user has USAGE on the warehouse, the database and the schema.

Permission errors at training time

Levered runs SQL queries during model training. If training fails with a permission error, check that the Snowflake user has SELECT access to the tables that the metric queries reference.

Next step

Set up the data pipeline to log exposures and rewards into the tables that Levered reads during training.