Skip to content

Commit 36e8752

Browse files
🔒️ Redact Postgres connection URL in logs (#8695)
1 parent 67770c8 commit 36e8752

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/common-library/tests/test_network.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_is_ip_address(host: str, expected: bool):
4949
),
5050
("amqp://admin:mysecret@rabbit:5672", "amqp://admin:***@rabbit:5672"),
5151
("redis://:adminadmin@redis:6379/3", "redis://:***@redis:6379/3"),
52+
(
53+
"postgresql+asyncpg://user:[email protected]:5432/database",
54+
"postgresql+asyncpg://user:***@db.example.com:5432/database",
55+
),
5256
# URLs with password and query/fragment
5357
(
5458
"https://user:[email protected]/path?query=value",

packages/service-library/src/servicelib/db_asyncpg_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections.abc import AsyncIterator
55
from datetime import timedelta
66

7+
from common_library.network import redact_url
78
from models_library.healthchecks import IsNonResponsive, IsResponsive, LivenessResult
89
from settings_library.postgres import PostgresSettings
910
from sqlalchemy.exc import SQLAlchemyError
@@ -80,7 +81,7 @@ async def with_async_pg_engine(
8081
with log_context(
8182
_logger,
8283
logging.DEBUG,
83-
f"connection to db {settings.dsn_with_async_sqlalchemy}",
84+
f"connection to db {redact_url(settings.dsn_with_async_sqlalchemy)}",
8485
):
8586
server_settings = {
8687
"application_name": settings.client_name(

0 commit comments

Comments
 (0)