Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions docs/integrations/engines/snowflake.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,42 @@ gateways:

### Snowflake Private Key Authorization

SQLMesh supports Snowflake private key authorization connections by providing the path to the private key file. `account` and `user` are required. For example:
SQLMesh supports Snowflake private key authorization connections by providing the private key bytes. Only config.py is supported when using private key authorization. `account` and `user` are required. For example:

```python
from sqlmesh.core.config import (
Config,
GatewayConfig,
ModelDefaultsConfig,
SnowflakeConnectionConfig,
)

```yaml
gateways:
snowflake:
connection:
type: snowflake
account: ************
user: ************
private_key: /path/to/private/key
warehouse: ************
database: ************
role: ************
from cryptography.hazmat.primitives import serialization

key = """-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----""".encode()

p_key= serialization.load_pem_private_key(key, password=None)

pkb = p_key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
)

config = Config(
model_defaults=ModelDefaultsConfig(dialect="snowflake"),
gateways={
"my_gateway": GatewayConfig(
connection=SnowflakeConnectionConfig(
user="user",
account="account",
private_key=pkb,
),
),
}
)
```

The authenticator method is assumed to be `snowflake_jwt` when `private_key` is provided, but it can also be explicitly provided in the connection configuration.
Expand All @@ -79,4 +102,4 @@ sqlmesh_airflow = SQLMeshAirflow(
"snowflake_conn_id": "<Connection ID>"
},
)
```
```
4 changes: 2 additions & 2 deletions sqlmesh/core/config/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SnowflakeConnectionConfig(ConnectionConfig):
concurrent_tasks: The maximum number of tasks that can use this connection concurrently.
authenticator: The optional authenticator name. Defaults to username/password authentication ("snowflake").
Options: https://github.com/snowflakedb/snowflake-connector-python/blob/e937591356c067a77f34a0a42328907fda792c23/src/snowflake/connector/network.py#L178-L183
private_key: The optional private key to use for authentication.
private_key: The optional private key to use for authentication. This is in the form of bytes and can only be created with the Python config. https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example#label-python-key-pair-authn-rotation
"""

account: str
Expand All @@ -125,7 +125,7 @@ class SnowflakeConnectionConfig(ConnectionConfig):
database: t.Optional[str] = None
role: t.Optional[str] = None
authenticator: t.Optional[str] = None
private_key: t.Optional[str] = None
private_key: t.Optional[bytes] = None

concurrent_tasks: int = 4

Expand Down