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
- Key pairs: 2048 bit RSA minimum;
RSA_PUBLIC_KEYandRSA_PUBLIC_KEY_2allow rotation without downtime. ROTATE KEY PAIRkeeps the previous key valid for 24 hours by default.- PAT: default expiry 15 days, maximum 365; secret shown once;
ROLE_RESTRICTIONset 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.
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:
| Way | Notes |
|---|---|
ALTER USER ... ADD KEY PAIR | Recommended; 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.
- Named key pairs (recommended):
ALTER USER ... ROTATE KEY PAIR. The previous key stays valid for 24 hours by default;EXPIRE_ROTATED_KEY_PAIR_AFTER_HOURSchanges it and0expires it immediately. Update the client in that window. - Property method: put the new key in whichever of
RSA_PUBLIC_KEYandRSA_PUBLIC_KEY_2is free, move the client to the new private key, thenALTER USER ... UNSET RSA_PUBLIC_KEYfor 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;
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
ADDorROTATE(and in Snowsight at creation). Afterward only metadata is visible. - Expiry: default 15 days, maximum 365, set in the
PAT_POLICYclause of an authentication policy (DEFAULT_EXPIRY_IN_DAYS,MAX_EXPIRY_IN_DAYS). Tokens that exceed a newly lowered maximum stop working. - Rotation:
ROTATEissues a new secret;EXPIRE_ROTATED_TOKEN_AFTER_HOURSsets how long the old one lives and0expires 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 setsREQUIRE_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_EVALUATIONinPAT_POLICYisENFORCED_REQUIRED(default),ENFORCED_NOT_REQUIREDorNOT_ENFORCED. - Allowed methods: if an authentication policy lists
AUTHENTICATION_METHODS, it must include'PROGRAMMATIC_ACCESS_TOKEN'. - User types: tokens exist for
PERSONandSERVICEusers (and service agent users).
Choosing between them
| Need | Choice |
|---|---|
| Long lived automation with a private key under your control | Key pair |
| Simple token for a REST or driver client, short life, easy revoke | PAT |
| A human at a terminal | Neither; use SSO or password with MFA |
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_KEYandRSA_PUBLIC_KEY_2allow rotation without downtime. ROTATE KEY PAIRkeeps the previous key valid for 24 hours by default.- PAT: default expiry 15 days, maximum 365; secret shown once;
ROLE_RESTRICTIONset at creation. - Service users need a network policy to use PATs.
- Setting keys needs
MODIFY PROGRAMMATIC AUTHENTICATION METHODSor 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_RESTRICTIONdo?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.