Skip to content

Commit 00fa226

Browse files
authored
fix(ingest/snowflake): exclude private_key from config serialization (#16688)
1 parent 1f32684 commit 00fa226

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class SnowflakeConnectionConfig(ConfigModel):
8686
)
8787
private_key: Optional[TransparentSecretStr] = pydantic.Field(
8888
default=None,
89+
exclude=True,
8990
description="Private key in a form of '-----BEGIN PRIVATE KEY-----\\nprivate-key\\n-----END PRIVATE KEY-----\\n' if using key pair authentication. Encrypted version of private key will be in a form of '-----BEGIN ENCRYPTED PRIVATE KEY-----\\nencrypted-private-key\\n-----END ENCRYPTED PRIVATE KEY-----\\n' See: https://docs.snowflake.com/en/user-guide/key-pair-auth.html",
9091
)
9192

metadata-ingestion/tests/unit/snowflake/test_snowflake_source.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,31 @@ def test_private_key_set_but_auth_not_changed():
369369
)
370370

371371

372+
def test_snowflake_connection_config_excludes_secrets_from_serialization():
373+
"""Ensure secret fields are excluded from model_dump() to prevent leaking
374+
credentials in logs, reports, or the system info endpoint."""
375+
from datahub.ingestion.source.snowflake.snowflake_connection import (
376+
SnowflakeConnectionConfig,
377+
)
378+
379+
config = SnowflakeConnectionConfig.model_validate(
380+
{
381+
"account_id": "acctname",
382+
"username": "user",
383+
"password": "hunter2",
384+
"private_key": "-----BEGIN PRIVATE KEY-----\nfakekey\n-----END PRIVATE KEY-----\n",
385+
"private_key_password": "keypassword",
386+
"authentication_type": "KEY_PAIR_AUTHENTICATOR",
387+
}
388+
)
389+
390+
dumped = config.model_dump()
391+
assert "password" not in dumped
392+
assert "private_key" not in dumped
393+
assert "private_key_password" not in dumped
394+
assert dumped["username"] == "user" # non-secret field still present
395+
396+
372397
def test_snowflake_config_with_connect_args_overrides_base_connect_args():
373398
config_dict = default_config_dict.copy()
374399
config_dict["connect_args"] = {

0 commit comments

Comments
 (0)