Snowflake Security, RBAC, and User Administration · Topic 11 of 16

Key-Pair Authentication, Programmatic Access Tokens and Rotation

Manage Snowflake key-pair authentication and rotation and programmatic access tokens with role restriction, expiry and network policy requirements.

  • 5 min
In a nutshell
  • Key pairs: 2048 bit RSA minimum; RSA_PUBLIC_KEY and RSA_PUBLIC_KEY_2 allow rotation without downtime.
  • ROTATE KEY PAIR keeps the previous key valid for 24 hours by default.
  • PAT: default expiry 15 days, maximum 365; secret shown once; ROLE_RESTRICTION set at creation.

What it is

Scripts, pipelines and applications cannot answer an MFA prompt. Snowflake gives them two non interactive credentials. Key-pair authentication uses an RSA key pair: Snowflake stores the public key on the user, the client keeps the private key and signs a token. A programmatic access token (PAT) is a secret generated for a user that the client sends in place of a password.

Both must be rotated. The exam tests the rotation steps, the privileges needed, and the safeguards that PATs bring: role restriction, expiry and network policies.

Clientprivate keysigns tokenSnowflakepublic key on userverifiesSessionClientPAT secretpresentedSnowflaketoken on userchecks policySession

How it works

Key-pair authentication

Requirements from the docs: an RSA key pair of at least 2048 bits in PEM format, generated with OpenSSL. Encrypted private keys are safer, using AES-256-CBC rather than Triple DES, but some clients (for example the Spark and Kafka connectors and the Go driver) do not support encrypted keys.

To set a key you need the MODIFY PROGRAMMATIC AUTHENTICATION METHODS privilege on the user or OWNERSHIP of the user.

Two ways to assign keys:

WayNotes
ALTER USER ... ADD KEY PAIRRecommended; supports role restriction and key expiration, and named key pairs
ALTER USER ... SET RSA_PUBLIC_KEY = '...'Older property; no role restriction or expiry; leave out the BEGIN and END lines

Verify with DESC USER: the RSA_PUBLIC_KEY_FP property holds the fingerprint, which you compare with the OpenSSL fingerprint of your key. The user view HAS_RSA_PUBLIC_KEY in ACCOUNT_USAGE.USERS shows whether a key is set.

Rotating key pairs

Rotation replaces a key without an outage, using a second slot.

Add new public keyunused slotthenSwitch clientnew private keythenRemove old keyUNSET
  • Named key pairs (recommended): ALTER USER ... ROTATE KEY PAIR. The previous key stays valid for 24 hours by default; EXPIRE_ROTATED_KEY_PAIR_AFTER_HOURS changes it and 0 expires it immediately. Update the client in that window.
  • Property method: put the new key in whichever of RSA_PUBLIC_KEY and RSA_PUBLIC_KEY_2 is free, move the client to the new private key, then ALTER USER ... UNSET RSA_PUBLIC_KEY for the old one.
ALTER USER etl_svc SET RSA_PUBLIC_KEY_2 = 'MIIBIjANBgkq...';
-- client now signs with the new private key
ALTER USER etl_svc UNSET RSA_PUBLIC_KEY;
Exam tip

Two key slots exist so that rotation needs no downtime. A rotation that "causes failed logins" removed the old key before the client moved.

Programmatic access tokens (PATs)

ALTER USER etl_svc ADD PROGRAMMATIC ACCESS TOKEN etl_token
  ROLE_RESTRICTION = 'ETL_ROLE' DAYS_TO_EXPIRY = 30 COMMENT = 'nightly load';
ALTER USER etl_svc ROTATE PROGRAMMATIC ACCESS TOKEN etl_token;
ALTER USER etl_svc REMOVE PROGRAMMATIC ACCESS TOKEN etl_token;

Key facts:

  • The secret is shown once, in the output of ADD or ROTATE (and in Snowsight at creation). Afterward only metadata is visible.
  • Expiry: default 15 days, maximum 365, set in the PAT_POLICY clause of an authentication policy (DEFAULT_EXPIRY_IN_DAYS, MAX_EXPIRY_IN_DAYS). Tokens that exceed a newly lowered maximum stop working.
  • Rotation: ROTATE issues a new secret; EXPIRE_ROTATED_TOKEN_AFTER_HOURS sets how long the old one lives and 0 expires it at once.
  • ROLE_RESTRICTION: limits privilege evaluation and object ownership to one role granted to the user, and can only be set at creation. It is required for service users unless the policy sets REQUIRE_ROLE_RESTRICTION_FOR_SERVICE_USERS = FALSE.
  • Network policy: service users must be under a network policy to generate or use tokens. Person users can generate without one but need one to authenticate. NETWORK_POLICY_EVALUATION in PAT_POLICY is ENFORCED_REQUIRED (default), ENFORCED_NOT_REQUIRED or NOT_ENFORCED.
  • Allowed methods: if an authentication policy lists AUTHENTICATION_METHODS, it must include 'PROGRAMMATIC_ACCESS_TOKEN'.
  • User types: tokens exist for PERSON and SERVICE users (and service agent users).
Adminadds PAT with role restrictionthenSecret shown oncestored in secret managerthenClient uses tokennetwork policy checkedthenRotate before expiry

Choosing between them

NeedChoice
Long lived automation with a private key under your controlKey pair
Simple token for a REST or driver client, short life, easy revokePAT
A human at a terminalNeither; use SSO or password with MFA
Watch out

A PAT without a network policy fails for service users. If a token "worked in a test and failed in production", check the network policy on the user.

Common mistakes

Rotating by deleting first. Add the new key, move the client, then remove the old one.

Losing the PAT secret. It cannot be viewed again; rotate to get a new one.

Forgetting the authentication policy. If it restricts methods, PATs or key pairs may be blocked.

Giving a token broad roles. Use ROLE_RESTRICTION to least privilege.

What to remember for the exam

  • Key pairs: 2048 bit RSA minimum; RSA_PUBLIC_KEY and RSA_PUBLIC_KEY_2 allow rotation without downtime.
  • ROTATE KEY PAIR keeps the previous key valid for 24 hours by default.
  • PAT: default expiry 15 days, maximum 365; secret shown once; ROLE_RESTRICTION set at creation.
  • Service users need a network policy to use PATs.
  • Setting keys needs MODIFY PROGRAMMATIC AUTHENTICATION METHODS or OWNERSHIP of the user.

Check yourself

  • How do you rotate a key pair with no downtime?

    Add the new public key in the unused slot, move the client to the new private key, then unset the old key.

  • Can you view a PAT secret after creation?

    No, it is shown only once; rotate the token to get a new secret.

  • What does ROLE_RESTRICTION do?

    It limits a token to one role granted to the user for privileges and ownership, and is set only at creation.

Topic 11 of 16 in Snowflake Security, RBAC, and User Administration

Test yourself on Snowflake Security, RBAC, and User Administration

The full Snowflake ADA-C02 question bank has 814 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.