snowflakedb / snowflake-connector-python

Snowflake Connector for Python
https://pypi.python.org/pypi/snowflake-connector-python/
Apache License 2.0
596 stars 473 forks source link

SNOW-1641112: Connector throws a user warning about connections.toml CHMOD, even when it will not use that file for connection details #2036

Open surpatean opened 2 months ago

surpatean commented 2 months ago

Python version

Python 3.9.18 (main, Sep 11 2023, 14:09:26) [MSC v.1916 64 bit (AMD64)]

Operating system and processor architecture

Windows-10-10.0.19045-SP0

Installed packages

snowflake-connector-python==3.12.1

What did you do?

I create a connection:

con = snowflake.connector.connect(
    account=...,
    user=...,
    private_key=...,
    role=...,
    database=...,
    schema=...,
    session_parameters={'QUERY_TAG': job_name})

A user warning is thrown lib\site-packages\snowflake\connector\config_manager.py:351: UserWarning: Bad owner or permissions on ~\.snowflake\connections.toml

My system does have a connections.toml file (used by the Snowflake VSCode extension)

["tl...1"]
name = "tl...1"
account = "tl...1"
user = "..."
authenticator = "externalbrowser"
password = ""

but no default connection, and this connection is not requested in connection_name=.

What did you expect to see?

If no TOML connection_name is provided, and connection details are provided in-line instead of via a TOML (default) connection, then the connector should not complain about the CHMOD of this file.

Can you set logging to DEBUG and collect the logs?

2024-08-27 12:33:23,534 - MainThread ssl_wrap_socket.py:44 - inject_into_urllib3() - DEBUG - Injecting ssl_wrap_socket_with_ocsp
2024-08-27 12:33:23,534 - MainThread _auth.py:91 - <module>() - DEBUG - cache directory: ~\AppData\Local\Snowflake\Caches
~\AppData\Local\miniconda3\envs\Glue_Python39_Analytics\lib\site-packages\snowflake\connector\config_manager.py:351: UserWarning: Bad owner or permissions on ~\.snowflake\connections.toml
  warn(f"Bad owner or permissions on {str(filep)}{chmod_message}")
2024-08-27 12:33:23,580 - MainThread config_manager.py:352 - read_config() - DEBUG - reading configuration file from ~\.snowflake\connections.toml
2024-08-27 12:33:23,592 - MainThread connection.py:413 - __init__() - INFO - Snowflake Connector for Python Version: 3.12.1, Python Version: 3.9.18, Platform: Windows-10-10.0.19045-SP0
2024-08-27 12:33:23,593 - MainThread connection.py:730 - connect() - DEBUG - connect
2024-08-27 12:33:23,593 - MainThread connection.py:1114 - __config() - DEBUG - __config
2024-08-27 12:33:23,593 - MainThread connection.py:1196 - __config() - INFO - Connecting to GLOBAL Snowflake domain
sfc-gh-dszmolka commented 2 months ago

hi - thank you for raising this issue with us and providing the details! we'll take a look

sfc-gh-dszmolka commented 2 months ago

hello and thank for reporting this issue ! to me, it looks like twofold:

  1. (a bug) permission checking on Windows for the connections.toml seems to be a bit broken. Tracking issue: https://github.com/snowflakedb/snowflake-connector-python/issues/1978 edit: there seems to be some quite useful comments on how to mitigate this bug and the output until it's fixed in the PythonConnector

  2. (an enhancement) if no default connection, nor explicitly pointed connection references this config file during connection, then we shouldn't read it at all

The second we can track on this issue, and I'll keep it updated if there's any progress with it.

surpatean commented 2 months ago

Silly of me to not notice that other bug report... I agree with your bug/enhancement split @sfc-gh-dszmolka

My concern is indeed more about not checking the file if not used in the connection. Thank you.