Skip to content

Commit

Permalink
fix: Setup defaultl ssl context for kafka logger (#18640)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias authored Nov 15, 2023
1 parent f10da8b commit 89dd3da
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions posthog/temporal/workflows/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import json
import logging
import ssl

import aiokafka
import structlog
Expand All @@ -10,7 +11,6 @@
from structlog.processors import EventRenamer
from structlog.typing import FilteringBoundLogger

from posthog.kafka_client.client import _sasl_params
from posthog.kafka_client.topics import KAFKA_LOG_ENTRIES

BACKGROUND_LOGGER_TASKS = set()
Expand Down Expand Up @@ -255,7 +255,7 @@ def __init__(
security_protocol=settings.KAFKA_SECURITY_PROTOCOL or "PLAINTEXT",
acks="all",
api_version="2.5.0",
**_sasl_params(),
ssl_context=configure_default_ssl_context() if settings.KAFKA_SECURITY_PROTOCOL == "SSL" else None,
)
)
self.logger = structlog.get_logger()
Expand Down Expand Up @@ -299,3 +299,13 @@ async def flush(self):

def mark_queue_done(self, _=None):
self.queue.task_done()


def configure_default_ssl_context():
"""Setup a default SSL context for Kafka."""
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.options |= ssl.OP_NO_SSLv2
context.options |= ssl.OP_NO_SSLv3
context.verify_mode = ssl.CERT_OPTIONAL
context.load_default_certs()
return context

0 comments on commit 89dd3da

Please sign in to comment.