snowflakedb / snowflake-ml-python

Apache License 2.0
38 stars 8 forks source link

SNOW-888746: Private key authentication using named connection fails #40

Closed monai closed 11 months ago

monai commented 1 year ago

SnowflakeLoginOptions() expects password property in a named connection config despite private_key_path is being used.

Version: snowflake-snowpark-python 1.5.1 Python: 3.10.12 OS: macOS

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[7], line 4
      1 from snowflake.snowpark import Session
      2 from snowflake.ml.utils import connection_params
----> 4 params = connection_params.SnowflakeLoginOptions("a_connection")
      5 sp_session = Session.builder.configs(params).create()

File [/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/ml/utils/connection_params.py:143](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/ml/utils/connection_params.py:143), in SnowflakeLoginOptions(connection_name, login_file)
    141 else:
    142     data["user"] = conn_prop["user"]
--> 143     data["password"] = conn_prop["password"]
    145 if "ssl" in conn_prop and conn_prop["ssl"].lower() == "off":
    146     data["protocol"] = "http"

KeyError: 'password'
sfc-gh-sdas commented 1 year ago

SnowflakeLoginOptions() is a temporary solution while we build something more robust & concrete. We have added snowflake.connector.connect(connection_name = "a_connection") here. Could you please give it a try? We'll add support for snowpark soon.

Note: snowflake.ml is not part of package snowflake-snowpark-python.

monai commented 1 year ago

SnowflakeLoginOptions() is a temporary solution while we build something more robust & concrete. We have added snowflake.connector.connect(connection_name = "a_connection") here. Could you please give it a try? We'll add support for snowpark soon.

snowflake.connector.connect(connection_name = "a_connection") doesn't work either:

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/config_manager.py", line 171, in _get_config
    e = e[k]
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/tomlkit/container.py", line 613, in __getitem__
    raise NonExistentKey(key)
tomlkit.exceptions.NonExistentKey: 'Key "connections" does not exist.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/juozas/projects/lt/spml/transformations.py", line 37, in <module>
    snowflake.connector.connect(connection_name = "a_connection")
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/__init__.py", line 51, in Connect
    return SnowflakeConnection(**kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/connection.py", line 343, in __init__
    connections = CONFIG_PARSER["connections"]
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/config_manager.py", line 364, in __getitem__
    return self._options[name].value()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/config_manager.py", line 113, in value
    value = self._get_config()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/snowflake/connector/config_manager.py", line 173, in _get_config
    raise MissingConfigOptionError(  # TOOO: maybe a child Exception for missing option?
snowflake.connector.errors.MissingConfigOptionError: Configuration option 'connections' is not defined anywhere, have you forgotten to set it in a configuration file, or environmental variable?

My ~/.snowsql/config:

[connections]

[connections.a_connection]
accountname = xxx
region = xxx
username = xxx
private_key_path = xxx
dbname = xxx
schemaname = xxx
warehousename = xxx
rolename = xxx
sfc-gh-mkeller commented 1 year ago

@monai You'd want to move your config file from ~/.snowsql/config to ~/.snowflake/config.toml Hopefully that's the only reason why this isn't working for you!

sfc-gh-sdas commented 12 months ago

@monai could you please try with version 1.0.5?

sfc-gh-sdas commented 11 months ago

snowflake conda release happened. Closing the bug w/o confirmation. Please reopen if issue recur.