Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48214: Unset ssl.VERIFY_X509_STRICT flag on Kafka SSl contexts #361

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Unset the `ssl.VERIFY_X509_STRICT` flag in SSL contexts used for Kafka connections. Python 3.13 enables this flag by default, and the current certs that Strimzi generates for these Kafka endpoints are missing an Authority Key Identifier, which prevents connections when the flag is set.
22 changes: 20 additions & 2 deletions safir/src/safir/kafka/_kafka_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,21 @@ class SslSettings(BaseModel):

def to_ssl_context(self) -> ssl.SSLContext:
"""Create an SSL context for connecting to Kafka."""
return helpers.create_ssl_context(
context = helpers.create_ssl_context(
cafile=str(self.cluster_ca_path),
certfile=str(self.client_cert_path),
keyfile=str(self.client_key_path),
)

# Starting with Python 3.13, the VERIFY_X509_STRICT flag is set in
# contexts created with ssl.create_default_context(), which this
# context is. The certs generated by Strimzi on the Kafka bootstrap
# endpoints do not have an Authority Key Identifier set, which makes
# connections fail. Until these get fixed and regenerated in Strimzi,
# unset VERIFY_X590_STRICT.
context.verify_flags &= ~ssl.VERIFY_X509_STRICT
return context

def to_faststream_params(self) -> FastStreamBrokerParams:
return {
"bootstrap_servers": self.bootstrap_servers,
Expand Down Expand Up @@ -189,10 +198,19 @@ def to_ssl_context(self) -> ssl.SSLContext:

if self.cluster_ca_path:
cafile = str(self.cluster_ca_path)
return helpers.create_ssl_context(
context = helpers.create_ssl_context(
cafile=cafile,
)

# Starting with Python 3.13, the VERIFY_X509_STRICT flag is set in
# contexts created with ssl.create_default_context(), which this
# context is. The certs generated by Strimzi on the Kafka bootstrap
# endpoints do not have an Authority Key Identifier set, which makes
# connections fail. Until these get fixed and regenerated in Strimzi,
# unset VERIFY_X590_STRICT.
context.verify_flags &= ~ssl.VERIFY_X509_STRICT
return context

def to_faststream_params(self) -> FastStreamBrokerParams:
cls: type[SASLScram512 | SASLScram256 | SASLPlaintext]
match self.sasl_mechanism:
Expand Down
Loading