Snowflake Key-Pair Auth for Power BI, Python, and dbt

SQL Published 11 mins read By Leon Wei
Snowflake Key-Pair Auth for Power BI, Python, and dbt cover image

Quick summary

Summarize this blog with AI

Snowflake's final enforcement phase, rolled out account by account from August to October 2026, stops non-human users from signing in with a password and moves every LEGACY_SERVICE user to TYPE = SERVICE. If a scheduled Power BI refresh, a Python script, or a dbt job still logs in with a username and password, it will fail. The fix is to make that login a SERVICE user, register an RSA public key on it, and point each tool at the matching private key.

What was tested: the openssl commands ran with OpenSSL 4.1.0 on a throwaway key, since deleted. Parameter names and key loading were checked offline against snowflake-connector-python 5.2.0 and dbt-snowflake 1.12.5. No Snowflake account or Power BI tenant was available, so the SQL, Power BI steps, and server error codes are checked against current Snowflake and Microsoft Learn docs only.

What changed, and who is affected

Snowflake decides what a login is allowed to do from the user's TYPE property. The single-factor password deprecation page describes three phases:

  • Phase 1 (Sep 2025 to Jan 2026): MFA is required for password sign-ins to Snowsight. LEGACY_SERVICE users are not affected.
  • Phase 2 (May to Jul 2026, rolling): new human users need MFA everywhere, and you can no longer create a user as LEGACY_SERVICE or change an existing user to that type.
  • Phase 3 (Aug to Oct 2026, rolling): human users can't authenticate with a password alone. All non-human users are blocked from password authentication, and existing LEGACY_SERVICE users are migrated to SERVICE.

Dates vary by account and can be extended for complex workloads. The Strong Authentication Hub shows yours. Reader accounts, trial accounts, and Snowflake Postgres are excluded.

TYPETreated asPassword sign-in after Phase 3What to use for a scheduled job
PERSON (default) or unsetHumanOnly with a second factorDon't use a person's login for unattended jobs
SERVICENon-humanNever. These users also can't enroll in MFAKey pair, OAuth, workload identity, or programmatic access token
LEGACY_SERVICENon-human, transitionalBlocked; the user is migrated to SERVICENot an option any more

Step 1: Generate an encrypted key pair

These are the commands from Snowflake's key-pair authentication guide. The minimum is 2048-bit RSA, and Snowflake recommends AES-256-CBC over Triple DES.

# Private key, PKCS#8, encrypted with a passphrase you are prompted for
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 aes-256-cbc -inform PEM -out rsa_key.p8

# Public key derived from it (prompts for the same passphrase)
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub

# Lock down the private key file
chmod 600 rsa_key.p8

The files should start and end like this. Key bodies are truncated here, and writing RSA key is printed by the second command:

$ head -1 rsa_key.p8; tail -1 rsa_key.p8
-----BEGIN ENCRYPTED PRIVATE KEY-----
-----END ENCRYPTED PRIVATE KEY-----

$ cat rsa_key.pub
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqh...
-----END PUBLIC KEY-----

Check the first line of any key you are handed. BEGIN ENCRYPTED PRIVATE KEY and BEGIN PRIVATE KEY are PKCS#8. BEGIN RSA PRIVATE KEY is the older PKCS#1 format, which several clients reject. Convert it with openssl pkcs8 -topk8 -v2 aes-256-cbc -inform PEM -in old_key.pem -out rsa_key.p8.

For ALTER USER you need the public key body without the BEGIN and END lines, joined onto one line:

grep -v -- '-----' rsa_key.pub | tr -d '\n'; echo

Step 2: Make the login a SERVICE user and attach the key

Run this with a role that owns the user. To assign a key, Snowflake requires OWNERSHIP or the MODIFY PROGRAMMATIC AUTHENTICATION METHODS privilege on the user.

-- Existing login used by the refresh or job
ALTER USER svc_powerbi SET TYPE = SERVICE;

-- Paste the one-line public key body, without BEGIN/END lines
ALTER USER svc_powerbi SET RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...';

-- Give it somewhere to land, so tools that don't send a role still work
ALTER USER svc_powerbi SET DEFAULT_ROLE = reporting_reader
                           DEFAULT_WAREHOUSE = reporting_wh;
GRANT ROLE reporting_reader TO USER svc_powerbi;

A SERVICE user can't sign in with a password, can't enroll in MFA, and can't hold properties such as PASSWORD. Per Snowflake's ALTER USER reference, those properties stay stored but hidden, and switching back to PERSON restores them. New users can be created the same way with CREATE USER ... TYPE = SERVICE RSA_PUBLIC_KEY = '...'.

Snowflake now recommends named key pairs (ALTER USER ... ADD KEY PAIR), which add role restriction and expiry. The RSA_PUBLIC_KEY property used here still works.

Step 3: Verify the fingerprint before touching any tool

Most key-pair failures come from the wrong public key on the user. Compare Snowflake's stored fingerprint with one you compute locally. Snowflake documents this query:

DESC USER svc_powerbi
  ->> SELECT SUBSTR(
     (SELECT "value" FROM $1
        WHERE "property" = 'RSA_PUBLIC_KEY_FP'),
     LEN('SHA256:') + 1) AS key;

Then run this locally on the public key file:

$ openssl rsa -pubin -in rsa_key.pub -outform DER | openssl dgst -sha256 -binary | openssl enc -base64
writing RSA key
1tWaUP...A7E=

The two values must match exactly. If you only have the private key on a job runner, regenerate the public key from it with openssl rsa -in rsa_key.p8 -pubout and fingerprint that.

Step 4: Python scripts (snowflake-connector-python)

Connector 5.0 renamed the passphrase parameter. It is now private_key_password. The old private_key_file_pwd still works but raises DeprecationWarning: 'private_key_file_pwd' is deprecated; use 'private_key_password' instead. That warning was reproduced on 5.2.0. On connector versions before 5.0, use private_key_file_pwd.

import os
import snowflake.connector

conn = snowflake.connector.connect(
    account=os.environ["SNOWFLAKE_ACCOUNT"],          # e.g. myorg-myaccount
    user=os.environ["SNOWFLAKE_USER"],                # must match LOGIN_NAME
    authenticator="SNOWFLAKE_JWT",
    private_key_file=os.environ["SNOWFLAKE_PRIVATE_KEY_PATH"],
    private_key_password=os.environ["SNOWFLAKE_PRIVATE_KEY_PASSPHRASE"],
    role="REPORTING_READER",
    warehouse="REPORTING_WH",
)
print(conn.cursor().execute("SELECT CURRENT_USER(), CURRENT_ROLE()").fetchone())

If your secrets manager gives you the key as text rather than a file, load it with cryptography and pass private_key= instead of private_key_file. The connector accepts PEM or base64 text, DER bytes, or a key object:

from cryptography.hazmat.primitives import serialization

pem_text = get_secret("snowflake/svc_reporting/private_key")   # your secrets client
key = serialization.load_pem_private_key(
    pem_text.encode(), password=get_secret("snowflake/svc_reporting/passphrase").encode())

conn = snowflake.connector.connect(account="myorg-myaccount", user="SVC_REPORTING",
                                   authenticator="SNOWFLAKE_JWT", private_key=key)

When you load the key with cryptography (dbt-snowflake does the same), these local errors were reproduced. Incorrect password, could not decrypt key means the wrong passphrase. Password was not given but private key is encrypted means the passphrase is missing. Unable to load PEM file means the input isn't PEM text.

Step 5: dbt (profiles.yml)

For dbt Core with dbt-snowflake, the profile fields are private_key_path or private_key, plus private_key_passphrase. They are defined in the dbt-snowflake adapter source in the dbt-labs/dbt-adapters GitHub repository. Use one key field, not both, or dbt raises a config error saying you can't specify both.

analytics:
  target: prod
  outputs:
    prod:
      type: snowflake
      account: myorg-myaccount
      user: SVC_DBT
      private_key_path: /run/secrets/snowflake_rsa_key.p8
      private_key_passphrase: "{{ env_var('SNOWFLAKE_PRIVATE_KEY_PASSPHRASE') }}"
      role: TRANSFORMER
      warehouse: TRANSFORM_WH
      database: ANALYTICS
      schema: DBT_PROD
      threads: 8

Two traps. First, delete the old password: line, and don't add authenticator: jwt. In dbt-snowflake, that setting means an externally issued token in the token field, not key pair. Key pair needs no authenticator. Second, dbt v2 rejects 3DES-encrypted and headerless keys. If you see Key is PKCS#1 (RSA private key). Snowflake requires PKCS#8, regenerate the key as in Step 1. Run dbt debug before the next scheduled run.

Step 6: Power BI Desktop, service, and gateway

The Power Query Snowflake connector page lists KeyPair as an authentication kind. It says the passphrase field appears only when the uploaded key is encrypted, and that both encrypted and unencrypted keys are supported. Key pair always uses the newer ADBC-based connector implementation, whatever the Implementation setting says.

  1. Desktop: update to a current 64-bit build. Go to Get Data > Database > Snowflake, and enter Server (myorg-myaccount.snowflakecomputing.com) and Warehouse. Under Advanced options, set Role name. Then choose KeyPair, enter the service user's login name, and supply the key. For an existing report, change the credential in File > Options and settings > Data source settings.
  2. Service: after publishing, open the semantic model's Settings and go to Data source credentials > Edit credentials. Microsoft's service article lists Basic, KeyPair, and OAuth2 (Microsoft Entra ID) for Snowflake.
  3. Gateway: Microsoft lists January 2025 as the minimum on-premises data gateway version for this connector and recommends the latest, so update it first. Microsoft publishes no separate key-pair procedure for gateways. If Snowflake is reachable from the internet, a cloud connection avoids the gateway.

Microsoft states that key pair isn't supported for Dataflows Gen1 or Power Apps (Dataflows). Those need a different method, such as Microsoft Entra ID. If a refresh still fails only in the service, work through why a refresh works in Desktop but fails in the service.

Troubleshooting table

Error textWhere it comes fromLikely cause and fix
Failed to parse PEM block containing the private keyPower BI, reported in Fabric Community threads. The same message is in the open-source ADBC Snowflake driver, which raises it when the input can't be decoded as PEM at all.A file path was pasted instead of the key, or the BEGIN/END lines are missing or mangled. Supply the full key text with both header lines, or upload the .p8 file where the dialog asks for one.
RSA PRIVATE KEY is not supportedADBC Snowflake driver sourceThe key is PKCS#1. Convert it with openssl pkcs8 -topk8 (Step 1).
Invalid authkind provided: KeyPairReported in a Fabric Community issue post. Microsoft doesn't document this message.Unconfirmed. Check that the item type supports KeyPair (Dataflows Gen1 and Power Apps don't), update Desktop and the gateway, and re-create the connection.
Key is PKCS#1 (RSA private key). Snowflake requires PKCS#8dbt docsRegenerate or convert to PKCS#8 with AES-256.
JWT token is invalid. [uuid], vendor code 390144Snowflake, any driverGive the UUID to an admin. They run SELECT JSON_EXTRACT_PATH_TEXT(SYSTEM$GET_LOGIN_FAILURE_DETAILS('uuid'), 'errorCode'); and read the specific code from the rows below.
394304 JWT_TOKEN_INVALID_PUBLIC_KEY_FINGERPRINT_MISMATCHSnowflakeThe private key doesn't match the user's public key. Redo Step 3.
394302 JWT_TOKEN_INVALID_ISSUE_TIMESnowflakeThe token arrived more than 60 seconds after it was issued, usually because of clock skew. Sync the host to NTP. A January 2026 snowflake-connector-net issue traced 390144 to a clock that was a minute off.
394300 JWT_TOKEN_INVALID_USER_IN_ISSUERSnowflakeThe client sent the user's NAME instead of its LOGIN_NAME. Check DESC USER.
Authentication works only after a role is entered / Object does not exist, or operation cannot be performedFabric Community thread; Microsoft LearnNo usable role, or an invalid default database. Set Role name in Advanced options, or set DEFAULT_ROLE with GRANT ROLE and fix DEFAULT_NAMESPACE.

Snowflake's key-pair troubleshooting page lists the remaining 3943xx codes.

Rotate keys without downtime

A user can hold two public keys, RSA_PUBLIC_KEY and RSA_PUBLIC_KEY_2, and Snowflake accepts whichever one matches the private key that is presented.

-- 1. Add the new public key in the empty slot
ALTER USER svc_powerbi SET RSA_PUBLIC_KEY_2 = 'MIIBIjANBgkqh...new...';

-- 2. Switch every client to the new private key and confirm a refresh succeeds
--    (DESC USER shows RSA_PUBLIC_KEY_2_FP for the new key)

-- 3. Remove the old key
ALTER USER svc_powerbi UNSET RSA_PUBLIC_KEY;

Next time, generate a key for the now-empty RSA_PUBLIC_KEY slot and remove RSA_PUBLIC_KEY_2. With named key pairs, ALTER USER ... ROTATE KEY PAIR keeps the old key valid for 24 hours by default.

Keep the private key private

  • Store the key and the passphrase as separate entries in a secrets manager or your CI secret store, and inject them at run time.
  • Never commit keys. Add *.p8, *.pem, and profiles.yml to .gitignore.
  • Use one service user and key per tool, so revoking one doesn't break the others.
  • Limit where each user can connect from. Create a network policy with your runners' or gateway's egress IPs, then run ALTER USER svc_dbt SET NETWORK_POLICY = dbt_runners_policy;.
  • Grant each service role only what its job needs.

Migration checklist

  1. List the logins that still use passwords from jobs, and check each user's TYPE with DESC USER.
  2. Generate an AES-256 encrypted PKCS#8 key per service user.
  3. Set TYPE = SERVICE, RSA_PUBLIC_KEY, DEFAULT_ROLE, and DEFAULT_WAREHOUSE, then grant the role.
  4. Match the DESC USER fingerprint against your local openssl fingerprint.
  5. Update Python (private_key_password), dbt (private_key_path), and Power BI (KeyPair plus Role name). Update the gateway first.
  6. Trigger one manual run of each job, and confirm with SELECT CURRENT_ROLE() or dbt debug.
  7. Move keys into a secrets manager, attach a network policy, and put the next rotation date on the calendar.

Once the job is authenticating again, harden its output too. See turning a one-off SQL query into a reliable weekly report.

FAQ

Can I keep my service account on LEGACY_SERVICE a little longer?

Not by choice. Since Phase 2 you can't set TYPE = LEGACY_SERVICE on any user. Phase 3 then migrates existing legacy service users to SERVICE, which blocks their passwords. Snowflake says it may extend an account's enforcement date for complex workloads, and the Strong Authentication Hub shows yours. Plan as if the date has already passed.

Should the key be encrypted if Power BI stores it anyway?

Yes. The Python connector, dbt, and Power BI all accept encrypted PKCS#8 keys. An encrypted file that leaks from a laptop or a build log is useless without the passphrase.

Is key pair the only option for scheduled jobs?

No. Snowflake also documents OAuth, workload identity federation, and programmatic access tokens, and Power BI supports Microsoft Entra ID sign-in. Key pair is simply the one method that works the same way in all three tools with no identity-provider setup.

Interview Prep

Begin Your SQL, Python, and R Journey

Master 230 interview-style coding questions and build the data skills needed for analyst, scientist, and engineering roles.

Related Articles

All Articles