Skip to content

Commit d73afee

Browse files
authored
SNOW-1650124: Pass Azure SAS Token via params (#2060)
1 parent dbc9284 commit d73afee

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/snowflake/connector/azure_storage_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import xml.etree.ElementTree as ET
1010
from datetime import datetime, timezone
11-
from logging import getLogger
11+
from logging import Filter, getLogger
1212
from random import choice
1313
from string import hexdigits
1414
from typing import TYPE_CHECKING, Any, NamedTuple
@@ -39,6 +39,22 @@ class AzureLocation(NamedTuple):
3939
MATDESC = "x-ms-meta-matdesc"
4040

4141

42+
class AzureCredentialFilter(Filter):
43+
LEAKY_FMT = '%s://%s:%s "%s %s %s" %s %s'
44+
45+
def filter(self, record):
46+
if record.msg == AzureCredentialFilter.LEAKY_FMT and len(record.args) == 8:
47+
record.args = (
48+
record.args[:4] + (record.args[4].split("?")[0],) + record.args[5:]
49+
)
50+
return True
51+
52+
53+
getLogger("snowflake.connector.vendored.urllib3.connectionpool").addFilter(
54+
AzureCredentialFilter()
55+
)
56+
57+
4258
class SnowflakeAzureRestClient(SnowflakeStorageClient):
4359
def __init__(
4460
self,

test/integ/test_put_get_with_azure_token.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111
import sys
1212
import time
13-
from logging import getLogger
13+
from logging import DEBUG, getLogger
1414

1515
import pytest
1616

@@ -37,8 +37,9 @@
3737
@pytest.mark.parametrize(
3838
"from_path", [True, pytest.param(False, marks=pytest.mark.skipolddriver)]
3939
)
40-
def test_put_get_with_azure(tmpdir, conn_cnx, from_path):
40+
def test_put_get_with_azure(tmpdir, conn_cnx, from_path, caplog):
4141
"""[azure] Puts and Gets a small text using Azure."""
42+
caplog.set_level(DEBUG)
4243
# create a data file
4344
fname = str(tmpdir.join("test_put_get_with_azure_token.txt.gz"))
4445
original_contents = "123,test1\n456,test2\n"
@@ -85,6 +86,12 @@ def test_put_get_with_azure(tmpdir, conn_cnx, from_path):
8586
file_stream.close()
8687
csr.execute(f"drop table {table_name}")
8788

89+
for line in caplog.text.splitlines():
90+
if "blob.core.windows.net" in line:
91+
assert (
92+
"sig=" not in line
93+
), "connectionpool logger is leaking sensitive information"
94+
8895
files = glob.glob(os.path.join(tmp_dir, "data_*"))
8996
with gzip.open(files[0], "rb") as fd:
9097
contents = fd.read().decode(UTF8)

0 commit comments

Comments
 (0)