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

# Supported Databases

> Overview of database support levels in Atoti Market Risk DirectQuery, covering natively supported databases (Databricks, Microsoft SQL Server, and Snowflake), guidance on non-native database integration, and how to set up and rotate the Snowflake key pair used for key-pair authentication.

Atoti Market Risk offers two levels of DirectQuery database support. Native support provides a fully tested implementation with reference data, SQL scripts, and documentation. Non-native databases can connect through Atoti Server's DirectQuery framework but require self-managed configuration.

## Native support

These databases are natively supported by Atoti Market Risk. The Solution provides a fully tested standard implementation, with reference data and documentation for connecting to these databases.

With a natively supported database, Atoti Market Risk provides:

* Documentation on required configuration properties to connect to the remote database.
* Reference SQL queries to create the database tables (these are available in `mr-directquery/src/test/resources/databases`).
* Reference data in a format compatible with the specific database (for Databricks this is available in `mr-directquery/src/test/resources/databases/databricks/data`. For Microsoft SQL Server and Snowflake you can use the primary dataset in `mr-application/src/main/resources/data`).
* Databases tested for computational accuracy.

### Natively supported databases

Atoti Market Risk provides a fully tested standard implementation, with reference data and documentation for the following databases:

* [Databricks](https://www.databricks.com)
* [Microsoft SQL](https://www.microsoft.com/en-us/sql-server/)
* [Snowflake](https://www.snowflake.com/)

For detailed steps on how to connect to one of these databases, see [Getting started](.).

### Non-native support

Atoti Server supports connecting to other compatible databases, but Atoti Market Risk currently does not. You can manage these databases yourself, but we do not document the implementation steps required.

If your chosen Database isn't natively supported, you can contact us for implementation support or refer to the Atoti Server [DirectQuery documentation](https://docs.activeviam.com/engine/java-sdk/6.1/directquery/getting_started.md) to customize with a different database.

> [!NOTE]
>
> Your chosen database **must** be one [supported by Atoti Server DirectQuery](https://docs.activeviam.com/engine/java-sdk/6.1/directquery/compatibility.md)

## Snowflake key-pair authentication

Snowflake is deprecating single-factor password authentication. Atoti Market Risk therefore connects to Snowflake using [key-pair authentication](https://docs.snowflake.com/en/user-guide/key-pair-auth), available from Atoti Market Risk 6.0.9, instead of a password. The base64-encoded private key is supplied through the `directquery.database.snowflake.additional-options.private-key-base64` property. The profile sets no `password` property, and `SNOWFLAKE_PASSWORD` is unused and can be removed from the deployment environment:

```yaml theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
directquery:
  database:
    type: snowflake
    snowflake:
      connection-string: ${SNOWFLAKE_CONNECTION_STRING}
      username: ${SNOWFLAKE_USERNAME}
      # ...
      additional-options:
        private-key-base64: ${SNOWFLAKE_PRIVATE_KEY_BASE64}
```

### Prerequisites

* OpenSSL 1.1.1 or later, available on the command line.
* The Snowflake user that Atoti Market Risk connects with, the value of `SNOWFLAKE_USERNAME`.
* A Snowflake role that can run `ALTER USER` on that user, such as `SECURITYADMIN`.
* Write access to the environment of the Atoti Market Risk process, to set `SNOWFLAKE_PRIVATE_KEY_BASE64`.

### Set up the key pair

> [!WARNING]
>
> The private key grants full access to the Snowflake user. Supply it only through the `SNOWFLAKE_PRIVATE_KEY_BASE64` environment variable or a secret store. Never commit `rsa_key.p8` or its base64 encoding to source control.

1. Generate an unencrypted PKCS#8 RSA private key and its matching public key. The following commands create the `rsa_key.p8` private key and the `rsa_key.pub` public key in the current directory.

   ```bash theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
   openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
   ```

   To protect the key at rest instead, generate an encrypted PKCS#8 key with `openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -v2 aes-256-cbc -out rsa_key.p8`, and supply the passphrase through the `directquery.database.snowflake.additional-options.private-key-pwd` property.

2. Register the public key on the Snowflake user. The key value is the contents of `rsa_key.pub` without the PEM header, the PEM footer, and the line breaks, which the following command prints.

   ```bash theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   grep -v '^-----' rsa_key.pub | tr -d '\n'
   ```

   Run the following statement under a role that can alter the user, such as `SECURITYADMIN`.

   ```sql theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   ALTER USER <snowflake_user> SET RSA_PUBLIC_KEY='<stripped contents of rsa_key.pub>';
   ```

   Verify that Snowflake stored the key:

   ```sql theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   DESC USER <snowflake_user>;
   ```

   The `RSA_PUBLIC_KEY_FP` row holds a `SHA256:` fingerprint. An empty value means the key was not registered.

3. Base64-encode the private key and expose it to Atoti Market Risk. The following command encodes the entire `rsa_key.p8` file. The resulting value feeds the `directquery.database.snowflake.additional-options.private-key-base64` property.

   ```bash theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   export SNOWFLAKE_PRIVATE_KEY_BASE64=$(base64 < rsa_key.p8 | tr -d '\n')
   ```

### Verify the connection

Start Atoti Market Risk with the `snowflake` profile. That profile sets `directquery.schema.validation.fail-startup-on-bad-schema: true`, so a successful startup means the connection to Snowflake was established and the schema was validated. A failure to authenticate is reported in the startup logs.

### Rotate the key pair

`ALTER USER … SET RSA_PUBLIC_KEY` replaces the registered public key immediately, so rotating in place makes every query fail while the running application still signs with the old private key. Use Snowflake's second key slot to avoid that window.

1. Generate a new key pair, following the steps above.

2. Register the new public key as the user's second key:

   ```sql theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   ALTER USER <snowflake_user> SET RSA_PUBLIC_KEY_2='<stripped contents of the new rsa_key.pub>';
   ```

3. Update `SNOWFLAKE_PRIVATE_KEY_BASE64` with the new base64-encoded private key and restart Atoti Market Risk.

4. Confirm the connection succeeds, then retire the old key:

   ```sql theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
   ALTER USER <snowflake_user> UNSET RSA_PUBLIC_KEY;
   ```
