Area: Ingestion Issues
Sub-Area: Snowflake Connector, Key Pair Authentication
Applies to: OSS + Cloud
Issue
You use key pair authentication for Snowflake ingestion and keep the private key in a DataHub secret. The run fails before it reads any metadata, with an error that starts like this:
Failed to configure the source (snowflake): Failed to connect to snowflake instance: ...
The rest of the message comes from the library that parses the key.
The executor log can also show one of these lines before the failure:
Secret '<your-secret-name>' not found in secret stores or environment, using empty stringCaught exception while attempting to fetch secrets from DataHub. Secret names: ['<your-secret-name>']
You Might Be Asking
- Does the key need real line breaks, or does the single line
\nform work? - Do I need to delete and recreate the secret instead of editing it?
- Which key formats does the connector accept?
- Why does the log say my secret was not found?
Cause
The Snowflake connector reads private_key as a PEM key. Before it parses the key, it replaces every literal \n (a backslash followed by the letter n) with a real line break. After it loads the key, it converts it to PKCS#8 itself before it connects. So both of these values work:
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7...
...rest of key...
-----END PRIVATE KEY-----
-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg...\n-----END PRIVATE KEY-----
The key fails to load when the value the connector receives is not a valid PEM key. These are the common reasons:
- The secret resolved to an empty string. When the executor can't find the secret in any secret store or environment variable, it logs the "not found" line above and puts an empty value in the recipe. An empty key can't load. If the log also shows "Caught exception while attempting to fetch secrets from DataHub", the executor could not read secrets from DataHub at all.
- The value is escaped twice, so it contains
\\n(two backslashes before the n). The connector turns\ninto a line break and leaves a stray backslash at the end of each line, which breaks the PEM. - The line breaks are gone. The Snowflake source docs require the key to keep its PEM line breaks at the beginning, at the end, and about every 64 characters in the key body. A key flattened to one line with spaces instead of
\nis not valid PEM. - The key is encrypted (
-----BEGIN ENCRYPTED PRIVATE KEY-----) and the recipe has noprivate_key_password. The connector requires the password for an encrypted key.
Editing a secret does not corrupt it. The Secrets tab sends the new value to the server exactly as you type it, and the server encrypts it unchanged, the same way it does when you create a secret.
Solution
-
Check the secret name. The
${NAME}reference in the recipe must match the secret name exactly, including case. Secret names can contain only letters, numbers and underscores, and must start with a letter or underscore. See Secret Resolution in Recipes. If the log shows "Caught exception while attempting to fetch secrets from DataHub" and you run a Remote Executor, check that the executor can reach your DataHub instance. See Configuring Remote Executor. -
Paste the key again. Go to Ingestion, open the Secrets tab, and click the edit (pencil) button on the secret, or create a new secret. The Secrets tab never shows a stored value, and the edit form opens with an empty Value field, so paste the whole key again. Copy it straight from the key file, from the
-----BEGINline through the-----ENDline. The Value field accepts multiple lines, so the real line breaks are kept. You don't need to delete the secret first. See Managing Sensitive Information with Secrets. -
Check the key format. The connector documents two forms: an unencrypted PKCS#8 key (
-----BEGIN PRIVATE KEY-----) and an encrypted PKCS#8 key (-----BEGIN ENCRYPTED PRIVATE KEY-----) withprivate_key_password. If your key file starts with-----BEGIN RSA PRIVATE KEY-----(PKCS#1), convert it to the documented unencrypted PKCS#8 form:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt \
-in rsa_key_pkcs1.pem \
-out rsa_key_pkcs8.pem
- Check the recipe. Set
authentication_type: KEY_PAIR_AUTHENTICATOR. Key pair authentication replaces the password, so leavepasswordout. See Key Pair Authentication in the Snowflake source docs.
source:
type: snowflake
config:
account_id: <your-snowflake-account>
authentication_type: KEY_PAIR_AUTHENTICATOR
username: <your-snowflake-username>
role: <your-role>
warehouse: <your-warehouse>
private_key: ${SNOWFLAKE_PRIVATE_KEY}
# Only for an encrypted key:
# private_key_password: ${SNOWFLAKE_PRIVATE_KEY_PASSWORD}
If you set private_key without authentication_type, the recipe fails validation with a message that ends in Should be set to 'KEY_PAIR_AUTHENTICATOR' when using key pair authentication.
- Run the ingestion again.
If you run a Remote Executor, you can keep the key out of DataHub. Store it as a file in the executor's secrets directory (/mnt/secrets by default) and reference it by file name, as described in Secret Resolution in Recipes.