Skip to content

Commit 6f8c455

Browse files
authored
SNOW-1460707: Fix permission error when there is no permission on the parent directory of config file path (#1965)
1 parent 94c319d commit 6f8c455

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1515
- Added support for `disable_saml_url_check` connection parameter to disable SAML URL check in OKTA authentication.
1616
- Fixed a bug that OCSP certificate signed using SHA384 algorithm cannot be verified.
1717
- Fixed a bug that status code shown as uploaded when PUT command failed with 400 error.
18+
- Fixed a bug that a PermissionError was raised when the current user does not have the right permission on parent directory of config file path.
1819

1920
- v3.10.1(May 21, 2024)
2021

src/snowflake/connector/config_manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,15 @@ def read_config(
320320
):
321321
if sliceoptions.only_in_slice:
322322
del read_config_file[section]
323-
if not filep.exists():
323+
try:
324+
if not filep.exists():
325+
continue
326+
except PermissionError:
327+
LOGGER.debug(
328+
f"Fail to read configuration file from {str(filep)} due to no permission on its parent directory"
329+
)
324330
continue
331+
325332
if (
326333
sliceoptions.check_permissions # Skip checking if this file couldn't hold sensitive information
327334
# Same check as openssh does for permissions

test/unit/test_configmanager.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import logging
78
import os.path
89
import re
910
import shutil
@@ -598,6 +599,34 @@ def test_warn_config_file_permissions(tmp_path):
598599
)
599600

600601

602+
@pytest.mark.skipif(IS_WINDOWS, reason="chmod doesn't work on Windows")
603+
def test_log_debug_config_file_parent_dir_permissions(tmp_path, caplog):
604+
tmp_dir = tmp_path / "tmp_dir"
605+
tmp_dir.mkdir()
606+
c_file = tmp_dir / "config.toml"
607+
c1 = ConfigManager(file_path=c_file, name="root_parser")
608+
c1.add_option(name="b", parse_str=lambda e: e.lower() == "true")
609+
c_file.write_text(
610+
dedent(
611+
"""\
612+
b = true
613+
"""
614+
)
615+
)
616+
mod = tmp_dir.stat()
617+
tmp_dir.chmod(0)
618+
619+
caplog.clear()
620+
621+
with caplog.at_level(logging.DEBUG):
622+
c1.read_config()
623+
assert not c1.conf_file_cache
624+
assert "due to no permission on its parent directory" in caplog.text
625+
626+
tmp_dir.chmod(stat.S_IMODE(mod.st_mode))
627+
shutil.rmtree(tmp_dir)
628+
629+
601630
def test_configoption_missing_root_manager():
602631
with pytest.raises(
603632
TypeError,

0 commit comments

Comments
 (0)