Rotating Snowflake secrets with a managed identity¶
Verified 2026-11-11. Code: entra-snowflake-reference.
Automation usually reaches Snowflake through a service user with a password or private key in a vault. Someone has to rotate that secret, hand it to every consumer, and revoke it when people leave. If you're trying to follow best practices, that noramlly means a service account per applicaiton, per environment, and perhaps more depending on the granulaity of your security model. Manually rotating private keys doesn't scale well.
This guide aims to show two ways to make that process easier.
- A GitHub Actions job signs in to Snowflake as an Azure managed identity, through workload identity federation. No secret exists for that sign-in. If all service accounts can use workload identity, you may not have to rotate anything!
- A job rotates the key pairs of other service users (the ones whose tools only support key pairs) and stores each new private key in Key Vault, where consumers read it. No person handles the key.
| Who signs in | How | Credential stored for Snowflake |
|---|---|---|
| The automation job | Workload identity federation: a managed identity's Entra token signs in a Snowflake service user | No stored secret |
| A tool that only supports key pairs | Named key pairs rotated into Key Vault by the job above | a private key in Key Vault, rotated without a human handling it |
flowchart LR
GH["GitHub Actions job"] -->|OIDC token| MI["Managed identity"]
MI -->|"token for Snowflake's app"| SWI["Service principal for Snowflake's Entra app"]
MI -->|workload identity| SU["Snowflake service user WORKLOAD_IDENTITY = MI"]
SU -->|"ADD / REMOVE KEY PAIR"| TU["Other service users"]
MI -->|new private key| KV["Azure Key Vault"]
KV -->|reads key| C["Consumers"]
For people signing in to your applications, see the companion guide Snowflake sign-in for people with Entra ID.
What you need¶
- Azure: a subscription where you can create a user-assigned managed identity and its federated credentials, and Key Vault Secrets Officer (or Owner) on the vaults the rotation writes to.
- Entra: Application Administrator to create the service principal for Snowflake's application. Rotating Snowflake keys needs no Microsoft Graph permission. If you also rotate Entra app secrets, do it as a second managed identity (see part 2); granting that identity a Graph application permission needs Privileged Role Administrator or Global Administrator.
- Snowflake: USERADMIN and SECURITYADMIN for the service users and grants.
- GitHub: a repository where you can create environments and variables.
Nothing in this guide needs a warehouse. Every Snowflake statement is DDL,
SHOW/DESC, or a context function such as current_user(), and those run
without compute. You can follow it on a trial account without spending
credits.
Versions verified¶
Pin your own and expect details to move, particularly in the Snowflake connector, where workload identity support is recent.
| Component | Version | Used for |
|---|---|---|
| Python | 3.14.10 | kvrotate (needs 3.11+) |
| Azure CLI | 2.91.0 | az login in the workflow, Key Vault writes |
| Bicep / Microsoft Graph Bicep extension | 0.49.2 / v1.0 1.0.0 |
The service principal for Snowflake's app |
| OpenSSL | 3.0.13 | Key-pair generation |
| Snowflake CLI | 3.33.0 | Running the SQL as an administrator |
| snowflake-connector-python | 5.2.0 | Workload identity and key-pair sign-in |
| GitHub Actions runner | Ubuntu 24.04 | The rotation workflow |
Parts¶
Each part starts with the smallest version that works, then a short Hardening section with what to add before relying on it. The split is for clarity. Secure defaults are taken when able. You should coordinate and review with information security at your organizaiton and do your own research before you depend on this automation.
- Automation signs in as a managed identity. Workload identity federation, signing in from GitHub Actions, and network policies.
- Rotating service-user key pairs. Named key pairs, the privilege roles the rotation needs, and the order of operations that keeps consumers working.
- Troubleshooting. Every error we hit and what caused it.
What the reference repository contains¶
| Path | Contents |
|---|---|
examples/ |
The basic versions: a minimal workflow and script that sign in to Snowflake as a managed identity. Start here. |
kvrotate/ |
Rotates Snowflake key pairs, random values and Entra app secrets into Key Vault |
.github/workflows/kvrotate.yml |
The hardened version: runs kvrotate as one managed identity per lane, so the Snowflake rotation holds no Graph permission |
snowflake-oauth/sql/11_automation_user.sql |
The service user that trusts the managed identity |
snowflake-oauth/infra/main.bicep |
The service principal for Snowflake's app, behind a flag |