Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1526475: str typing for private_key is misleading and causes errors if used #1995

Closed
sfc-gh-turbaszek opened this issue Jul 9, 2024 · 1 comment
Assignees
Labels
status-triage_done Initial triage done, will be further handled by the driver team

Comments

@sfc-gh-turbaszek
Copy link

Python version

3.10

Operating system and processor architecture

macOS-14.5-arm64-arm-64bit

Installed packages

annotated-types==0.6.0
anyio==4.3.0
asn1crypto==1.5.1
atpublic==4.1.0
beautifulsoup4==4.12.3
certifi==2024.2.2
cffi==1.16.0
cfgv==3.4.0
charset-normalizer==3.3.2
click==8.1.7
cloudpickle==2.2.1
coverage==7.5.4
cryptography==42.0.5
DatastreamPy==2.0.21
distlib==0.3.8
execnet==2.1.1
filelock==3.13.1
gitdb==4.0.11
GitPython==3.1.43
h11==0.14.0
hatch==1.10.0
hatchling==1.24.2
httpcore==1.0.5
httpx==0.27.0
hyperlink==21.0.0
identify==2.5.35
idna==3.6
importlib-metadata==7.0.1
iniconfig==2.0.0
jaraco.classes==3.3.1
Jinja2==3.1.4
keyring==24.3.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
more-itertools==10.2.0
nodeenv==1.8.0
numpy==1.26.4
packaging==23.2
pandas==2.2.1
pathspec==0.12.1
pexpect==4.9.0
pkginfo==1.10.0
platformdirs==3.11.0
pluggy==1.5.0
pre-commit==3.6.2
ptyprocess==0.7.0
pycparser==2.21
pydantic==2.7.4
pydantic_core==2.18.4
Pygments==2.17.2
PyJWT==2.8.0
pyOpenSSL==24.0.0
pytest==8.2.2
pytest-randomly==3.15.0
python-dateutil==2.8.2
pytz==2024.1
PyYAML==6.0.1
requests==2.32.3
requirements-parser==0.9.0
rich==13.7.1
shellingham==1.5.4
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
snowflake-connector-python==3.11.0
snowflake-snowpark-python==1.15.0
snowflake.core==0.8.0
sortedcontainers==2.4.0
soupsieve==2.5
strictyaml==1.7.3
sybil==6.0.2
syrupy==4.6.1
tomli_w==1.0.0
tomlkit==0.12.5
trove-classifiers==2024.3.3
typer==0.12.3
types-setuptools==69.1.0.20240229
typing_extensions==4.10.0
tzdata==2024.1
urllib3==2.2.1
userpath==1.9.2
uv==0.1.42
virtualenv==20.26.1
zipp==3.17.0
zstandard==0.22.0

What did you do?

The connector has the following code
https://github.com/snowflakedb/snowflake-connector-python/blob/b3e816be80545e34d28d60bcec18460b8ff81e67/src/snowflake/connector/connection.py#L1040-L1053
where

"private_key": (None, (type(None), str, RSAPrivateKey)),

unfortunately passing private_key as str will cause an error because `AuthByKeyPair` which we use expects
```py
 private_key: bytes | RSAPrivateKey

and raises

            raise TypeError(
                f"Expected bytes or RSAPrivateKey, got {type(self._private_key)}"
            )


### What did you expect to see?

It would make sens to handle string on connector side allowing users to pass the key as env variable.

### Can you set logging to DEBUG and collect the logs?

_No response_
@github-actions github-actions bot changed the title str typing for private_key is misleading and causes errors if used SNOW-1526475: str typing for private_key is misleading and causes errors if used Jul 9, 2024
@sfc-gh-sghosh sfc-gh-sghosh self-assigned this Jul 10, 2024
@sfc-gh-sghosh sfc-gh-sghosh added the status-triage Issue is under initial triage label Jul 10, 2024
@sfc-gh-sghosh
Copy link

Hello @sfc-gh-turbaszek ,

When using key-pair authentication, you need to pass PrivateKey object and not String. For the Snowflake Python driver, authentication using a private key involves using PrivateKey object.

String is not the expected type, read the private key from the PEM file, Convert the PEM formatted string to a PrivateKey object.

Regards,
Sujan

@sfc-gh-sghosh sfc-gh-sghosh added status-triage_done Initial triage done, will be further handled by the driver team and removed bug status-triage Issue is under initial triage labels Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

3 participants