Give the scheduled load its own identity
Ravi’s nightly orders job must keep running when he is on leave or changes teams. Give it a dedicated TYPE = SERVICE user and an account role scoped to the load. Give development a separate identity. Choose a method based on the runtime’s supported connector, identity provider and Snowflake authentication policy.
With key-pair authentication, Snowflake stores a public key. The client proves it has the corresponding private key by signing. Keep the private key in an approved secret store and restrict access to the job runtime. Snowflake supports overlapping public keys for rotation. Verify the new key through an approved test connection before retiring the old public key.
OAuth uses a scoped access token. With Snowflake OAuth, Snowflake is the authorization server. With External OAuth, a trusted external issuer supplies the token and a security integration defines validation and mapping. Check client and flow support, identity mapping, audience, role restrictions and expiry. Never put access or refresh tokens in SQL examples, logs or commits.
Workload identity federation, or WIF, lets a supported connector use a cloud or OpenID Connect identity to prove which workload is connecting. A managed runtime can obtain short-lived proof instead of storing a long-lived Snowflake password or private key. Configure the expected provider and exact workload identity, use supported connector versions and verify the account policy permits the method.
| Method | What Snowflake trusts | What to operate |
|---|---|---|
| Key pair | Signature verified with a registered public key | Private-key protection, rotation and revocation |
| OAuth | Token from Snowflake or a configured external issuer | Token issuer, audience, expiry and role mapping |
| WIF | Short-lived proof for an approved runtime identity | Provider and workload mapping, connector compatibility and role assignment |
Keep the grant and credential lifecycles visible
For External OAuth, SAML and SCIM, a security integration stores the trust or provisioning configuration on the Snowflake side. Have a named owner for changes and a review date. WIF uses workload identity information on the service user. Verify expected configuration, run a test from the real approved runtime and inspect the resulting user and role.
After retiring the job, remove its role memberships and retire its credential or workload mapping through the owning team. A valid signature or token proves identity. It still needs the role and object privileges granted to that identity.
Keep the workload’s permissions fixed while changing its sign-in
Use an approved sandbox account, the service administrator who can create users, and an integration administrator with CREATE INTEGRATION for the OAuth option. Use a warehouse supplied by the platform owner. Each method gets a dedicated test user. Replace the placeholders with approved values. Keep the same INSERT-only role so the sign-in comparison does not change permissions.
The job should append one unique test order per path and be unable to select raw rows. Use a fresh table. The administrator verifies the inserts. Keep private keys, passphrases and client secrets in the approved runtime secret store. The SQL below uses only public key material and sample object names.
Create the role and test target once
SYSADMIN creates the two-column inbox and owns it. SECURITYADMIN creates the job role and gives it compute, path and INSERT permissions. Replace M17_LAB_WH everywhere if your approved warehouse uses another name.
USE ROLE SYSADMIN;
CREATE DATABASE M17D_SERVICE;
CREATE SCHEMA M17D_SERVICE.RAW;
CREATE TABLE M17D_SERVICE.RAW.ORDERS (order_id NUMBER, amount NUMBER);
USE ROLE SECURITYADMIN;
CREATE ROLE M17D_WRITER;
GRANT USAGE ON WAREHOUSE M17_LAB_WH TO ROLE M17D_WRITER;
GRANT USAGE ON DATABASE M17D_SERVICE TO ROLE M17D_WRITER;
GRANT USAGE ON SCHEMA M17D_SERVICE.RAW TO ROLE M17D_WRITER;
GRANT INSERT ON TABLE M17D_SERVICE.RAW.ORDERS TO ROLE M17D_WRITER;
SHOW GRANTS TO ROLE M17D_WRITER;Save the shared connection test as m17_probe.py
Place this file next to the connector example. It checks the user and role, inserts one test order and attempts a separate read. Inspect the reported error code to confirm a permission failure. The platform owner independently verifies the rows at the end. Run each method once to keep the fixture free of duplicates.
from snowflake.connector.errors import ProgrammingError
def verify_writer(connection, expected_user, order_id):
with connection.cursor() as cursor:
user, role = cursor.execute("SELECT CURRENT_USER(), CURRENT_ROLE()").fetchone()
if (user, role) != (expected_user, "M17D_WRITER"):
raise RuntimeError("Unexpected Snowflake session context")
cursor.execute(
"INSERT INTO M17D_SERVICE.RAW.ORDERS VALUES (%s, %s)",
(order_id, 40),
)
print(user, role, cursor.rowcount)
try:
cursor.execute("SELECT order_id FROM M17D_SERVICE.RAW.ORDERS")
except ProgrammingError as error:
print("Review the expected SELECT denial code:", error.errno)
else:
raise RuntimeError("The writer can unexpectedly read the raw table")Set up key-pair authentication and rotate it without downtime
The client signs a short-lived JSON Web Token (JWT) with an RSA private key. Snowflake checks its signature using the registered public key and checks the identity and token validity. The public key can be registered by an approved identity administrator. Keep the private key and passphrase outside the warehouse and code repository.
Use OpenSSL in the controlled runtime. Restrict file access, enter the passphrase interactively and keep the private key on the approved filesystem or in the vault. Copy only the base64 body of the public PEM file into the Snowflake user.
Generate an encrypted private key and its public key
genpkey creates the private key. rsa_keygen_bits 2048 sets its size and aes-256-cbc encrypts the file. pkey -pubout derives the matching public key. Expect a protected private PEM file and a separate public PEM file.
umask 077
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 \
-aes-256-cbc -out m17d_key.p8
openssl pkey -in m17d_key.p8 -pubout -out m17d_key.pubRegister the public key and grant the job role
SECURITYADMIN creates the pilot service user and grants the role. RSA_PUBLIC_KEY takes the body without PEM header, footer or line breaks. DESCRIBE USER shows a public key fingerprint. DEFAULT_ROLE is the preference at sign-in. GRANT ROLE is the assignment.
USE ROLE SECURITYADMIN;
CREATE USER M17D_KEY_SVC TYPE = SERVICE
RSA_PUBLIC_KEY = '<approved_public_key_body>'
DEFAULT_ROLE = M17D_WRITER DEFAULT_SECONDARY_ROLES = ();
GRANT ROLE M17D_WRITER TO USER M17D_KEY_SVC;
DESCRIBE USER M17D_KEY_SVC;Connect and prove the key before rotating
Use Snowflake Connector for Python 5.x and the runtime’s secret injection for the file passphrase. SNOWFLAKE_JWT selects key-pair sign-in. Run the shared verification below with order 201. If signing fails, check that the expected public key is registered, the client can decrypt its file, the account and login name match, and the runtime clock is accurate.
Generate a second pair separately, then run ALTER USER M17D_KEY_SVC SET RSA_PUBLIC_KEY_2 = followed by the new public key body as a SQL string. Test a fresh client with the second private key and the same small verification. After every runtime has switched and the next scheduled run succeeds, run ALTER USER M17D_KEY_SVC UNSET RSA_PUBLIC_KEY to retire the first key. Verify fingerprints and revoke runtime access to retired private material.
import os
import snowflake.connector
from m17_probe import verify_writer
with snowflake.connector.connect(
account=os.environ["M17_SNOWFLAKE_ACCOUNT"],
user="M17D_KEY_SVC",
authenticator="SNOWFLAKE_JWT",
private_key_file=os.environ["M17_KEY_FILE"],
private_key_password=os.environ["M17_KEY_PASSPHRASE"],
warehouse="M17_LAB_WH",
) as connection:
verify_writer(connection, "M17D_KEY_SVC", 201)Issue and validate an External OAuth token
OAuth gives the client an access token with limited lifetime and scope. In this setup the external authorization server issues the token. Snowflake verifies the signature, issuer, audience, expiry and identity mapping. The named role in the scope must also be granted to the mapped user. A token does not create a role grant.
Choose External OAuth when your identity platform should issue and govern the tokens. With Snowflake OAuth, Snowflake issues the tokens and the client uses the approved Snowflake OAuth integration, typically a user authorization flow. Use that separate integration type for a supported interactive client. For this service lab, use an external server with the client credentials grant and a signed JWT access token.
Register the issuer, audience and service subject
In the external server, register a confidential sandbox client for client credentials. Grant only session:role:M17D_WRITER. Configure the server to issue a short-lived signed JWT with the approved issuer, Snowflake audience and a string sub claim that exactly matches M17D_OAUTH_SVC. Use a supported scope claim such as scp as documented for the custom issuer. Obtain the HTTPS signing-key URL and token endpoint. Store the client credential in the runtime vault.
As the integration administrator, configure the same issuer and audience in Snowflake. JWS_KEYS_URL is the issuer’s public verification key set. The mapping uses sub and LOGIN_NAME. ANY_ROLE_MODE DISABLE keeps the session on the scoped role. Coordinate one integration per applicable issuer configuration with the platform owner and use a separate sandbox issuer where required.
USE ROLE SECURITYADMIN;
CREATE USER M17D_OAUTH_SVC TYPE = SERVICE
LOGIN_NAME = 'M17D_OAUTH_SVC' DEFAULT_ROLE = M17D_WRITER DEFAULT_SECONDARY_ROLES = ();
GRANT ROLE M17D_WRITER TO USER M17D_OAUTH_SVC;
USE ROLE <APPROVED_INTEGRATION_ADMIN>;
CREATE SECURITY INTEGRATION M17D_OAUTH
TYPE = EXTERNAL_OAUTH ENABLED = TRUE
EXTERNAL_OAUTH_TYPE = CUSTOM
EXTERNAL_OAUTH_ISSUER = '<issuer>'
EXTERNAL_OAUTH_JWS_KEYS_URL = '<https_jwks_url>'
EXTERNAL_OAUTH_AUDIENCE_LIST = ('<snowflake_audience>')
EXTERNAL_OAUTH_TOKEN_USER_MAPPING_CLAIM = 'sub'
EXTERNAL_OAUTH_SNOWFLAKE_USER_MAPPING_ATTRIBUTE = 'LOGIN_NAME'
EXTERNAL_OAUTH_ANY_ROLE_MODE = 'DISABLE';
DESCRIBE SECURITY INTEGRATION M17D_OAUTH;Request a scoped token and open a session
This example assumes the issuer supports HTTP Basic client authentication at its HTTPS token endpoint and puts the requested scope and mapped subject in its signed access token. Review the provider’s configuration for the audience it issues. Configure each environment value through your approved secret injection. Keep the token in memory. On a successful run expect M17D_OAUTH_SVC and M17D_WRITER. For the shared INSERT and denial check, use order 202.
If the issuer rejects the request, check the app’s client grant and scope. If Snowflake rejects the token, compare issuer, audience, key identifier, expiry, sub mapping and permitted role. Test a rejection using a sandbox client without the approved scope. Ask the issuer owner to rotate or retire the pilot client credential. Disable or drop the pilot integration only after the test is done.
import os
import requests
import snowflake.connector
from m17_probe import verify_writer
response = requests.post(
os.environ["M17_OAUTH_TOKEN_ENDPOINT"],
auth=(os.environ["M17_OAUTH_CLIENT_ID"], os.environ["M17_OAUTH_CLIENT_SECRET"]),
data={"grant_type": "client_credentials", "scope": "session:role:M17D_WRITER"},
timeout=15,
)
response.raise_for_status()
with snowflake.connector.connect(
account=os.environ["M17_SNOWFLAKE_ACCOUNT"],
user="M17D_OAUTH_SVC",
authenticator="oauth",
token=response.json()["access_token"],
warehouse="M17_LAB_WH",
) as connection:
verify_writer(connection, "M17D_OAUTH_SVC", 202)Configure Snowflake OAuth for an interactive reporting client
Use this separate option when an approved user-facing app needs Snowflake to issue the token. Use a sandbox PERSON user already granted a custom read-only role and an approved OAuth-capable app with a real HTTPS callback. The integration administrator needs CREATE INTEGRATION. The app needs support for the authorization code flow with Proof Key for Code Exchange (PKCE).
Configure the app with the client ID and allowed authorization and token endpoints shown by DESCRIBE. Open the authorization endpoint in the user’s browser. The app requests response_type=code, the exact callback URI and the approved session:role scope. It sends a random state and an S256 code challenge for its one-time verifier. After the approved user signs in and consents, the callback verifies state.
The client exchanges the returned code at the Snowflake token endpoint with grant_type=authorization_code, the client ID, the same callback URI and its original code verifier. The verifier binds the exchange to the app that started it. Keep tokens in memory or approved secure storage. Open a supported connection with authenticator oauth, run the session context check and verify one approved read and one denied write. A redirect mismatch or incorrect verifier should fail before SQL. Remove the pilot app registration and have the integration owner drop the pilot integration after the test.
Register the callback and require PKCE
PUBLIC here means an OAuth client that cannot keep a client secret. It does not refer to the Snowflake PUBLIC role. OAUTH_REDIRECT_URI names the exact approved HTTPS callback. OAUTH_ENFORCE_PKCE requires the per-request verifier. Allow only the approved report role and leave secondary roles disabled for the pilot. Disabling refresh tokens keeps this pilot to a single short-lived access token per authorization.
CREATE SECURITY INTEGRATION M17D_SNOWFLAKE_OAUTH
TYPE = OAUTH
ENABLED = TRUE
OAUTH_CLIENT = CUSTOM
OAUTH_CLIENT_TYPE = 'PUBLIC'
OAUTH_REDIRECT_URI = 'https://<approved_app>/oauth/callback'
OAUTH_ENFORCE_PKCE = TRUE
OAUTH_USE_SECONDARY_ROLES = NONE
ALLOWED_ROLES_LIST = ('<approved_read_role>')
OAUTH_ISSUE_REFRESH_TOKENS = FALSE;
DESCRIBE SECURITY INTEGRATION M17D_SNOWFLAKE_OAUTH;
-- After the pilot, run separately as the integration owner.
-- DROP SECURITY INTEGRATION M17D_SNOWFLAKE_OAUTH;Let an AWS runtime prove its own workload identity
Workload identity federation (WIF) lets Snowflake verify short-lived identity proof from a cloud or OpenID Connect provider. The association is on the Snowflake service user. Use it when a managed workload already has an approved provider identity and the connector supports the provider. No Snowflake password or client-managed signing key is needed.
The AWS example uses an existing non-production EC2 instance with an approved AWS Identity and Access Management (IAM) role attached through its instance profile. In AWS IAM, open that role and copy its Amazon Resource Name (ARN) including any path. Check the runtime identity with aws sts get-caller-identity from the instance and confirm the assumed role corresponds to the approved IAM role. The Python version below uses the documented default AWS proof path.
Bind the AWS role to a service user
Use SECURITYADMIN to create the service identity, then grant the same writer role. WORKLOAD_IDENTITY specifies the provider and exact ARN Snowflake should accept. Check that the effective authentication policy permits WORKLOAD_IDENTITY.
USE ROLE SECURITYADMIN;
CREATE USER M17D_WIF_SVC
WORKLOAD_IDENTITY = (TYPE = AWS ARN = '<approved_aws_iam_role_arn>')
TYPE = SERVICE DEFAULT_ROLE = M17D_WRITER DEFAULT_SECONDARY_ROLES = ();
GRANT ROLE M17D_WRITER TO USER M17D_WIF_SVC;
DESCRIBE USER M17D_WIF_SVC;Connect from the mapped runtime
Run Snowflake Connector for Python 5.x on the instance. With WORKLOAD_IDENTITY and provider AWS, the connector uses the runtime’s AWS identity proof. Expect M17D_WIF_SVC and M17D_WRITER. Use order 203 in the shared verification.
If Snowflake cannot map the workload, verify the role and account seen by the actual process, the configured ARN, connector compatibility and the effective policy. If your organization uses AWS outbound federation, Snowflake documents a separate JWT setup with the AWS issuer and a driver setting. Configure both sides before switching the client.
import os
import snowflake.connector
from m17_probe import verify_writer
with snowflake.connector.connect(
account=os.environ["M17_SNOWFLAKE_ACCOUNT"],
authenticator="WORKLOAD_IDENTITY",
workload_identity_provider="AWS",
warehouse="M17_LAB_WH",
) as connection:
verify_writer(connection, "M17D_WIF_SVC", 203)Prove the job can insert and cannot read
The shared Python function runs the INSERT and SELECT in the connected session. The SQL below shows what it runs so you can repeat either check separately in an approved client. Using autocommit, expect one row inserted. The following SELECT should fail for the writer. Do not print tokens, credentials or a full driver error with connection details.
For the key-pair test use order 201, for External OAuth use 202, and for WIF use 203. Run each insert once. An authorized admin with SELECT on the fixture verifies the rows in order. Expect only those methods you tested to appear, each with amount 40. Connection success alone does not prove the write permission.
Check the positive and negative workload cases
Copy each statement to cursor.execute in the authenticated test process. Substitute only the stated fixture order ID. Try the forbidden SELECT separately. If it succeeds, look at inherited and PUBLIC access before using the role outside the pilot.
INSERT INTO M17D_SERVICE.RAW.ORDERS VALUES (201, 40);
-- Run separately. Expect denial for M17D_WRITER.
SELECT order_id FROM M17D_SERVICE.RAW.ORDERS;Verify the inserts and retire pilot access
SYSADMIN checks the expected rows and drops only the disposable database once testing ends. SECURITYADMIN disables and drops the pilot users you created, then drops the writer role. The OAuth integration owner removes the pilot integration separately. Revoke the unused issuer credential, remove temporary access to key material and remove the temporary workload binding in the cloud if one was created for this lab.
USE ROLE SYSADMIN;
USE WAREHOUSE M17_LAB_WH;
SELECT order_id, amount FROM M17D_SERVICE.RAW.ORDERS ORDER BY order_id;
DROP DATABASE M17D_SERVICE;
USE ROLE SECURITYADMIN;
-- Run only for the users you created in this exercise.
ALTER USER M17D_KEY_SVC SET DISABLED = TRUE;
ALTER USER M17D_OAUTH_SVC SET DISABLED = TRUE;
ALTER USER M17D_WIF_SVC SET DISABLED = TRUE;
DROP USER M17D_KEY_SVC;
DROP USER M17D_OAUTH_SVC;
DROP USER M17D_WIF_SVC;
DROP ROLE M17D_WRITER;
USE ROLE <APPROVED_INTEGRATION_ADMIN>;
DROP SECURITY INTEGRATION M17D_OAUTH;Explain the design in an interview
Name the rule, then explain how you would prove it.
How can you rotate a signing key while the job is running?
I register the new public key in the second slot, validate a fresh session with the new private key, then switch the runtime and retire the old public key after a successful run.
The token is valid. Why can the job still be denied?
I check which user and role the token supplies and verify the warehouse, parent objects and INSERT. An issuer can identify the job without granting SQL permissions.
When would you prefer WIF?
If my cloud runtime already has a well-scoped identity and the driver supports it, I would use WIF to avoid a client-managed long-lived secret. I would test the exact runtime and its configured identity.
Words used in this lesson
- Key pair
- A private signing key and its matching public verification key.
- OAuth
- Token-based delegated access, with privileges governed by role mapping and grants.
- WIF
- Trust an approved workload identity to obtain short-lived sign-in proof.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Snowflake Key-Pair Authentication, OAuth and Workload Identity Federation
Match the runtime to a method
Choose approved WIF, OAuth or key-pair support for the particular client and account.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Match the runtime to a method
Choose approved WIF, OAuth or key-pair support for the particular client and account.
Runtime identity → Supported method → Authentication policy
- Verify the resulting session
Check the service user, active role and one authorized workload operation.
Service user → Workload role → Scoped operation
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Identify the service user and writer role
SELECT CURRENT_USER() AS connected_user,
CURRENT_ROLE() AS active_role,
CURRENT_WAREHOUSE() AS warehouse;What to expect and why
Run this in one of the approved pilot connections. Expect the mapped key-pair, OAuth or federated service user and M17D_WRITER. The shared verification in the article tests INSERT and the denied read as separate outcomes.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
A supported cloud job can supply WIF. Name the first checks before switching a production job.
Compare your reasoning
Confirm provider and connector compatibility, identity mapping, policy and the dedicated workload role. Test from a scoped job and use the approved migration and recovery plan.
Official sources and curriculum
Module 17 · See module scope
- Key-pair authentication and rotation
- OAuth approaches
- External OAuth mapping and scopes
- Workload identity federation and supported setups
- CREATE USER and user types
- Configure an External OAuth issuer
- External OAuth security integration parameters
- Snowflake OAuth custom integrations
- Snowflake OAuth client and token exchange
- Connect with the Snowflake Python connector
By Rohit Ray · Independent educational lesson · Explore this visual lab