How to set up key-pair authentication in Data Factory using a private key inside Key Vault

Strobel, Evan 0 Reputation points

I am trying to set up key-pair authentication between Data Factory and Snowflake. I want to store the private key inside of a secret in Key Vault. When testing the connection, I receive the following error:

Test connection operation failed. Failed to open the database connection. [Snowflake] Failed to parse PEM block containing the private key

I've seen that it may require inserting newline characters (\n) into the key but that hasn't worked for me. Does anyone have insight as to the correct format for the private key?

0 comments No comments

Sign in to comment

Answer recommended by moderator

kagiyama yutaka 3,685 Reputation points

I think the key is using a PKCS8 PEM and saving that same multiline PEM as a file in Key Vault so ADF can read it.

  1. Strobel, Evan 0 Reputation points

    How would I do this? I only see the ability to enter a single-line secret value.

  2. kagiyama yutaka 3,685 Reputation points

    The portal only shows a single‑line box, but Key Vault can store multiline secrets. Save the PEM as a secret using a method that keeps the original line breaks, not by pasting it into the UI. Once the multiline PEM is stored, ADF reads it without any issues.


Sign in to comment

2 additional answers

  1. Strobel, Evan 0 Reputation points

    I was able to get it working by using Powershell to save the multiline secret instead of converting it to a single line in bash. Thanks for your help!

    0 comments No comments

    Sign in to comment
  2. AI answer

    For Azure Data Factory’s Snowflake V2 linked service with key-pair authentication, the private key must be provided in a very specific format, and when using Azure Key Vault the multi-line PEM must be preserved exactly.

    Key points for the correct format:

    1. Use a PKCS#8 RSA private key in PEM format (.p8 file)
      • For mapping data flows, the recommendation is to generate a new RSA private key using the PKCS#8 standard in PEM format (.p8 file).
      • Example generation (from the referenced guidance) uses OpenSSL to produce rsa_key.p8.
    2. Preserve the exact PEM content when storing in Key Vault
      • The private key file includes newline characters (\n) and must remain a valid PEM when retrieved by Data Factory.
      • When storing the key as a secret, do not flatten or reformat the PEM; it must keep:
        • The -----BEGIN ... PRIVATE KEY----- header line
        • All internal lines with their original line breaks
        • The -----END ... PRIVATE KEY----- footer line
      • If the secret is created via a UI that converts line breaks to spaces, the PEM becomes malformed and Snowflake returns Failed to parse PEM block containing the private key.
    3. How to store the key correctly in Key Vault
      • Use CLI or another method that preserves multi-line content when creating the secret.
      • A similar pattern is documented for Purview + Snowflake, where the private key must be stored via Azure CLI or Cloud Shell because the Azure Portal text box corrupts the PEM by removing line breaks.
      • Example (from the Purview guidance, but the same principle applies to Data Factory):
        • View the private key file:
           cat rsa_key.p8
          
        • Store it as a secret using Azure CLI with --file to preserve multi-line format:
           az keyvault secret set \
           --vault-name <your-keyvault-name> \
           --name <your-secret-name> \
           --file rsa_key.p8
          
    4. Referencing the Key Vault secret in the linked service
      • In the Snowflake V2 linked service, the privateKey property is an Azure Key Vault secret reference (SecretBase) for key-pair auth.
      • Ensure the linked service’s privateKey property points to that Key Vault secret (not an inline string), so Data Factory retrieves the exact PEM content.
    5. When not using Key Vault (inline privateKey)
      • If the private key is embedded directly in the linked service JSON instead of Key Vault, the newline characters must be explicitly represented as \n in the string literal, as documented:
        • “Considering that the privateKey file includes newline characters (\n), it's essential to correctly format the privateKey content in its string literal form. This process involves adding \n explicitly to each newline.”
      • This requirement is for inline JSON only; when using Key Vault, store the real multi-line PEM and let ADF read it as-is.

    If the error persists, the most common causes are:

    • The key is not PKCS#8 PEM (for example, PKCS#1 or another format).
    • The secret was created via Azure Portal and line breaks were lost.
    • The header/footer lines were removed or altered.

    Ensuring a valid PKCS#8 PEM and storing it via CLI/Cloud Shell into Key Vault, then referencing that secret in the privateKey property, aligns with the documented pattern and avoids the Snowflake PEM parse error.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.
Sign in to answer

Your answer