admin管理员组

文章数量:1303412

I meet an issue when trying to use snowflake.connector with an RSA pkcs8 key with passphrase.

When I try this code, with this kind of RSA Key: openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8

import snowflake.connector as sc

private_key_file = 'config/rsa_key.p8'
private_key_file_pwd = input(f"Give to me the passphrase of the key {private_key_file}: ")

conn_params = {
    'account': 'SFK_ORG-SRF_ISTANCE',
    'user': 'TEST_RSA',
    'private_key_file': private_key_file,
    'private_key_file_pwd': private_key_file_pwd,
    'warehouse': 'MY_WH',
    'database': 'MY_DB',
    'schema': 'MY_SCHEMA',
    'role': 'USER_ROLE'
}

conn = sc.connect(**conn_params)

I get this error:

TypeError: Password was given but private key is not encrypted.

Why?

I meet an issue when trying to use snowflake.connector with an RSA pkcs8 key with passphrase.

When I try this code, with this kind of RSA Key: openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8

import snowflake.connector as sc

private_key_file = 'config/rsa_key.p8'
private_key_file_pwd = input(f"Give to me the passphrase of the key {private_key_file}: ")

conn_params = {
    'account': 'SFK_ORG-SRF_ISTANCE',
    'user': 'TEST_RSA',
    'private_key_file': private_key_file,
    'private_key_file_pwd': private_key_file_pwd,
    'warehouse': 'MY_WH',
    'database': 'MY_DB',
    'schema': 'MY_SCHEMA',
    'role': 'USER_ROLE'
}

conn = sc.connect(**conn_params)

I get this error:

TypeError: Password was given but private key is not encrypted.

Why?

Share Improve this question edited Feb 4 at 17:25 Yunnosch 26.8k9 gold badges44 silver badges62 bronze badges asked Feb 4 at 16:16 Stefano G.Stefano G. 3095 silver badges15 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default -1

The problem is how snowflake.connector uses the key.
If the key is created with the option -v2 des3, es:
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out rsa_key_des3.p8

then snowflake.connector uses the key.

So, using this key the previous code works.

But if I use the key shown above (openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8), the snowflake.connector doesn't require the private_key_file_pwd and the most important thing, DOESN'T WANT the private_key_file_pwd.

So with this key, the code must be in this way:

import snowflake.connector as sc

private_key_file = 'config/rsa_key.p8'

conn_params = {
 'account': 'SFK_ORG-SRF_ISTANCE',
 'user': 'TEST_RSA',
 'private_key_file': private_key_file,
 'warehouse': 'MY_WH',
 'database': 'MY_DB',
 'schema': 'MY_SCHEMA',
 'role': 'USER_ROLE'
}

conn = sc.connect(**conn_params)

本文标签: python snowflakeconnector amp rsa privatekeyfile issueStack Overflow