CertSafari
    DBT Architect· Lessons

    Domain 3 · Lesson 10/39

    Rotating Snowflake key pairs and API tokens in dbt

    Rotating key pair authentication via the API

    14 min read
    2.56% of exam
    6 sources
    Published 12 Oct 2026
    Docs as of 12 Oct 2026

    What you will be able to do

    • Locate where a Snowflake key pair credential lives in dbt for development and deployment environments
    • Generate a replacement key in a format dbt v2 accepts and register its public half on the Snowflake user
    • Choose the right API token to update credentials programmatically
    • Rotate a credential or token in the create-swap-delete order without breaking running jobs
    • Diagnose the errors that appear when a rotated key is pasted or registered incorrectly

    Key concept

    Overlap rotation — Rotating a secret means bringing the replacement into service before the old one is retired. You create the new key or token with the same access, swap it into every system that uses it, and delete the old one only after that.

    1.What a key pair credential is and where it lives

    On dbt platform, a key pair is the credential you will most often rotate, because it is the default for Snowflake. You can no longer create Snowflake credentials with a username and password. New development and deployment credentials default to key pair authentication. Snowflake OAuth is also available for user credentials on Enterprise-tier plans when it is configured on the connection. A key pair has two halves. The public key is attached to the Snowflake user. The private key, plus an optional passphrase, is stored in dbt. Rotating the pair means replacing both halves, and the private half sits in a different place depending on the environment type.

    Deployment credentials for Production, Staging and General environments are shared and are set up centrally in the Connections area of Account settings. Development credentials belong to individual people, and each user stores theirs in the Credentials area of their own profile. dbt also wraps each deployment environment's connection, credentials and extended attributes in a project-level profile. You can manage profiles through the API, but they don't apply to development environments, where every user's credentials are their own. The [split between development and deployment access](lesson:3.1) therefore decides whose key you are rotating and where the new private key goes.

    Where each kind of Snowflake key pair credential is configured
    CredentialConfigured inOwned by
    Deployment (Production, Staging, General)Connections area of Account settingsThe account, shared by jobs
    DevelopmentCredentials area of the user profileThe individual user

    Checkpoint 1 of 8· Check yourself

    A security team asks you to rotate the key that the nightly Production jobs use to connect to Snowflake. Where does the new private key go?

    Sources12

    2.Generating the new key and registering its public half

    Start with the key format, because a key that dbt v2 can't read fails even when every other step is right. Here dbt v2 means the dbt v2 Snowflake adapter, which applies both to the dbt platform Snowflake connection marked "dbt v2 compatible" and to a local profiles.yml; it is unrelated to the Administrative API's v2 routes. dbt recommends PKCS#8 with AES-256 encryption. Legacy 3DES encryption and headerless key formats are not supported. If dbt reports Key is PKCS#1 (RSA private key). Snowflake requires PKCS#8, the fix is to re-export the key, not to keep retrying the connection.

    Generating an AES-256-encrypted private key in PKCS#8 formatbash
    openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 aes-256-cbc -inform PEM -out rsa_key.p8

    Next, attach the public half to the Snowflake user that dbt connects as, with an alter user statement. Snowflake checks dbt's signature against this key, so until it is set, the new private key will not authenticate. For development credentials that user is the developer's own; for deployment credentials it is the Snowflake user or service account the connection uses.

    Checkpoint 2 of 8· Fill the gap

    Which property completes the statement that registers the new public key on the Snowflake user?

    alter user jsmith set  ? ='MIIBIjANBgkqh...';

    Finally, dbt needs the private half. Put it in the Private Key field, and in the Private Key Passphrase field if the key is encrypted. Unencrypted keys are allowed, so add a passphrase only if you need one. The key is entered as a string, either Base64-encoded DER or plain-text PEM, and the PEM form must keep its -----BEGIN ENCRYPTED PRIVATE KEY----- and -----END ENCRYPTED PRIVATE KEY----- lines. Rotation can't be shortcut through an environment variable: the private key field does not support an env_var() reference. The new key has to be written into the credential itself. That is why rotating a key ends with updating a dbt credential, by hand or through the API.

    Sources1

    3.Choosing the token that updates credentials through the API

    Doing the swap through the dbt Administrative API turns rotation into a repeatable script rather than a list of manual clicks. The API manages the account as well as running jobs. dbt recommends v3 in general, though some routes still exist only in v2, and many endpoints can also be called through the dbt Terraform provider.

    What decides whether the call succeeds is the token that authenticates it. Endpoints that create and update user credentials, which means a developer's own credentials, need user context, and only a personal access token (PAT) carries it. A [service account token](lesson:3.2) belongs to the account rather than to a person, so it fits system-level integrations that do not act on behalf of any one user, such as an orchestrator that triggers jobs. Production automation that acts as a service account, Terraform included, uses a service token, while PATs suit developmental workflows. A script that writes a new private key into a developer's credential therefore runs with a PAT.

    Checkpoint 3 of 8· Check yourself

    An automation script calls the API endpoint that updates a user's Snowflake credential to install a newly rotated private key. Which token should authenticate it?

    Checkpoint 4 of 8· Exam question

    A platform team maintains a service token used by an in-house orchestration tool to trigger production dbt Cloud jobs through the Administrative API. Compliance now requires the token to be rotated on a fixed schedule. Which sequence describes the correct way to rotate this token without interrupting the orchestration tool's job runs?

    Sources345

    4.Rotating in order: create, swap, then delete

    Every rotation follows the same order, whatever the secret. Create the replacement with the same access, put it into every system that uses it, and only then remove the old one. If you delete first, every job, integration or script still holding the old secret fails until the new one arrives. If you create the new one with fewer permissions, the swap looks successful until the first call that needed the permission you dropped.

    API tokens are secrets too, and they follow this order. For a PAT, dbt's guidance is to rotate regularly by creating a new token and deleting the old one once the new one is in place. Service tokens have their own procedure, in Account settings under Service tokens. The rotation steps name the button + New Token, while the page for creating a service token calls it + Create service token. A service token is shown only once, at creation, so copy it into the consuming system before you close that screen.

    A swapped token can still fail for a reason unrelated to the swap. All service token traffic is subject to IP restrictions, so a request from an address that is not on the allowlist comes back as a 403 with the message Forbidden: Access denied. The fix is to add the integration's CIDRs (network addresses) to the allowlist, not to rotate the token again.

    Checkpoint 5 of 8· Put it in order

    Put the steps for rotating a service token in order

    1. 1.Copy the new token and replace the old one in your systems
    2. 2.Delete the old token with the trash can icon
    3. 3.Open Account settings and select Service tokens
    4. 4.Click + New Token and give it the same permissions as the old token

    Checkpoint 6 of 8· Exam question

    Your dbt Cloud account has IP restrictions enabled with an allowlist that includes only the CIDR ranges of your CI runners. After rotating a service token used by a third-party BI tool that calls the Administrative API from a different network range, the BI tool's calls start failing with a 403 'Forbidden: Access denied' response. What is the most likely cause?

    Sources46

    5.Errors that follow a bad swap

    Key errors after a rotation trace back to how the key was pasted or registered. Could not deserialize key data usually means the private key was damaged on the way into dbt: part of it wasn't copied, dashes are missing, or the commented BEGIN and END lines were dropped. Paste the key into a text editor and check it before putting it into dbt.

    A JWT token is invalid error has two possible causes. When dbt connects, it gets a JWT that is valid for only 60 seconds, so a slow response from Snowflake can cause a transient failure that a retry fixes. The other cause is that the public key was not entered correctly on the Snowflake user, so check the rsa_public_key you registered as well as the connection.

    Checkpoint 7 of 8· Match them up

    Match each error after a key rotation to its likely cause

    Tap a term, then the definition that fits it.

    Token errors on the API side differ from key errors, and the token type matters. A PAT inherits the permissions of the user who created it, so a Project Admin's PAT carries Project Admin access to the same projects. It is also account-specific, so a user in several dbt accounts needs a separate PAT for each. A service token is different: it belongs to the account, and its permission sets are assigned when it is created. A PAT cannot create a service token. That request returns a 400 error, and an existing service token has to create the new one.

    Checkpoint 8 of 8· Exam question

    Which statement accurately distinguishes a dbt Cloud service token from a personal access token (PAT)?

    Sources164

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.To rotate a token safely, delete the compromised or old token first and then create a new one.Why is that wrong?

      Create the new token with the same permissions, swap it into every system, and delete the old one only afterwards. Otherwise integrations fail in the gap.

      Covered in Rotating in order: create, swap, then delete

    2. 2.Storing the Snowflake private key in an env_var lets you rotate it by changing the variable's value alone.Why is that wrong?

      dbt does not support reading a private key from an environment variable. The new key has to be written into the credential's Private Key field.

      Covered in Generating the new key and registering its public half

    3. 3.A service account token with enough permissions can call any API endpoint, including the ones that update user credentials.Why is that wrong?

      Endpoints that create or update user credentials require user context, so they are called with a personal access token.

      Covered in Choosing the token that updates credentials through the API

    4. 4.Any RSA key that worked before, including a legacy 3DES-encrypted PKCS#1 key, will keep working with dbt v2.Why is that wrong?

      dbt v2 needs PKCS#8, ideally with AES-256 encryption. Legacy 3DES and headerless formats cause authentication failures.

      Covered in Generating the new key and registering its public half

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “New development and deployment credentials default to key pair authentication.”
      ↩︎ What a key pair credential is and where it lives
      “For user credentials on Enterprise-tier plans, Snowflake OAuth is also available when configured on the connection.”
      ↩︎ What a key pair credential is and where it lives
      “Individual users configure their user credentials in the Credentials area of their user profile.”
      ↩︎ What a key pair credential is and where it lives
      “We recommend using PKCS#8 format with AES-256 encryption for key pair authentication with dbt v2.”
      ↩︎ Generating the new key and registering its public half
      “be sure to set the rsa_public_key for the Snowflake user to authenticate in dbt”
      ↩︎ Generating the new key and registering its public half
      “This private_key string can be in either Base64-encoded DER format, representing the key bytes, or in plain-text PEM format.”
      ↩︎ Generating the new key and registering its public half
      “To successfully fill in the Private Key field, you must include commented lines.”
      ↩︎ Generating the new key and registering its public half
      “The Snowflake user or service account that dbt v2 connects as must be able to run dbt workloads”
      ↩︎ Generating the new key and registering its public half
      “dbt gets a JWT token valid for only 60 seconds.”
      ↩︎ Errors that follow a bad swap
      “The public key was not entered correctly in Snowflake.”
      ↩︎ Errors that follow a bad swap
      “Specifying a private key using an environment variable (for example, {{ env_var('DBT_PRIVATE_KEY') }}) is not supported.”
      ↩︎ Exam trap 2
      “dbt v2 doesn't support legacy 3DES encryption or headerless key formats.”
      ↩︎ Exam trap 4
      “Configure deployment environment (Production, Staging, General) credentials globally in the Connections area of Account settings.”
      ↩︎ Checkpoint
      “Specifying a private key using an environment variable (for example, {{ env_var('DBT_PRIVATE_KEY') }}) is not supported.”
      ↩︎ Prediction
      “This could be because of mistakes like not copying correctly, missing dashes, or leaving out commented lines.”
      ↩︎ Checkpoint
    2. 2.
      “Profiles don't apply to development environments because of the unique configurations and individual credentials applied.”
      ↩︎ What a key pair credential is and where it lives
      “You can manage profiles programmatically using our API documentation.”
      ↩︎ What a key pair credential is and where it lives
    3. 3.
      “Use PATs to authenticate to any API endpoint that requires user context (for example, endpoints to create and update user credentials).”
      ↩︎ Choosing the token that updates credentials through the API
      “You should use service tokens broadly for any production workflow where you need a service account.”
      ↩︎ Choosing the token that updates credentials through the API
      “Use PATs to authenticate to any API endpoint that requires user context (for example, endpoints to create and update user credentials).”
      ↩︎ Exam trap 3
    4. 4.
      “You can use service account tokens for system-level integrations that do not run on behalf of any one user.”
      ↩︎ Choosing the token that updates credentials through the API
      “Ensure the new token has the same permissions as the old one.”
      ↩︎ Rotating in order: create, swap, then delete
      “Copy the new token and replace the old one in your systems.”
      ↩︎ Rotating in order: create, swap, then delete
      “Click the + Create service token button to generate a new token.”
      ↩︎ Rotating in order: create, swap, then delete
      “All service token traffic is subject to IP restrictions.”
      ↩︎ Rotating in order: create, swap, then delete
      “you should add your third-party integration CIDRs (network addresses) to your allowlist.”
      ↩︎ Rotating in order: create, swap, then delete
      “Service account tokens enable you to securely authenticate with the dbt API by assigning each token a narrow set of permissions”
      ↩︎ Errors that follow a bad swap
      “Only take this action after the new token is in place to avoid service disruptions.”
      ↩︎ Key concept
      “Only take this action after the new token is in place to avoid service disruptions.”
      ↩︎ Exam trap 1
      “Only take this action after the new token is in place to avoid service disruptions.”
      ↩︎ Checkpoint
    5. 5.
      “Many endpoints of the Administrative API can also be called through the dbt Terraform provider.”
      ↩︎ Choosing the token that updates credentials through the API
      “In general, v3 is the recommended version to use”
      ↩︎ Choosing the token that updates credentials through the API
    6. 6.
      “To do so, create a new token and delete the old one once it's in place.”
      ↩︎ Rotating in order: create, swap, then delete
      “PATs inherit the permissions of the user that created them.”
      ↩︎ Errors that follow a bad swap
      “You can't use a PAT to create a service token.”
      ↩︎ Errors that follow a bad swap

    Ready to test yourself?

    Practise the 9 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.