Skip to content

Add SSL, mTLS and SASL support to KafkaCancellationNotifier (4.5.0) - #237

Merged
boma96 merged 2 commits into
masterfrom
feature/kafka-security
Nov 25, 2026
Merged

boma96 merged 2 commits into
masterfrom
feature/kafka-security

Conversation

@boma96

@boma96 boma96 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds support for secured Kafka connections to ConductorSharp.KafkaCancellationNotifier: SSL, mTLS (PEM files or PKCS#12 keystore), SASL_SSL and SASL_PLAINTEXT (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512).

What changed

  • New overload AddKafkaCancellationNotifier(IConfiguration section) binds the Conductor:KafkaCancellationNotifier section, including the new security settings, into the internal KafkaOptions. Works with appsettings, environment variables, user secrets and vault-backed configuration.
  • KafkaOptions (still internal) gains optional SecurityProtocol, SaslMechanism, SaslUsername, SaslPassword, SslCaLocation, SslCertificateLocation, SslKeyLocation, SslKeyPassword, SslKeystoreLocation, SslKeystorePassword, EnableSslCertificateVerification and SslEndpointIdentificationAlgorithm.
  • KafkaClientConfigFactory builds both the consumer config and the admin client config (used for CreateTopicOnStartup), so topic creation also works against secured brokers. Optional settings are only passed to librdkafka when configured.
  • KafkaOptionsValidator runs on startup (ValidateOnStart) for the new overload only and reports all problems at once:
    • BootstrapServers, TopicName, GroupId are required
    • SASL protocols require a supported SaslMechanism, SaslUsername and SaslPassword
    • SslCertificateLocation and SslKeyLocation must be configured together
    • SslKeystoreLocation cannot be combined with certificate/key
    • configured certificate/key/keystore files must exist
  • A warning is logged when Ssl* settings are configured but the protocol is not Ssl/SaslSsl.
  • README documents both registration methods, the full settings reference (required/optional/default) and an example per security mode. SKILL.md's Kafka section documents the new overload and security settings. The NoApi example uses the new overload.
  • All packages (Client, Engine, Patterns, KafkaCancellationNotifier, Toolkit) bumped from 4.4.1 to 4.5.0 to keep them on the same version. Only KafkaCancellationNotifier has code changes.
  • New dependency for KafkaCancellationNotifier: Microsoft.Extensions.Options.ConfigurationExtensions 8.0.0 (matches the 8.0 Microsoft.Extensions.* packages Engine already uses).

Backward compatibility

Drop-in upgrade from 4.4.1:

  • The existing AddKafkaCancellationNotifier(bootstrapServers, topicName, groupId, createTopicOnStartup) is unchanged and not deprecated. It keeps its null-only argument checks and does not run the new startup validation.
  • Without security settings, the generated consumer and admin client configs are identical to before (covered by a test asserting the exact key set).
  • KafkaOptions stays internal, so no new public types; enums come from Confluent.Kafka. Confluent.Kafka stays at 2.8.0.

Notes for reviewers

  • Ssl* validation (file existence, cert/key pairing, keystore exclusivity) only applies when the protocol is Ssl or SaslSsl; otherwise those settings are ignored with a warning instead of failing startup.
  • GSSAPI and OAUTHBEARER are intentionally not supported and are rejected by validation.
  • Inline PEM strings are intentionally not supported; only file paths.
  • Out of scope: the existing consumer loop stops consuming after the first exception (5s delay, then exits). Worth a separate fix.

Testing

37 new unit tests in ConductorSharp.Engine.Tests (110 total, all passing):

  • config mapping for each mode, and that unset optional settings are not emitted
  • every validation rule, including missing files
  • IConfiguration binding, defaults, and startup validation via IStartupValidator
  • existing method registers the same options without validation
  • librdkafka accepts the generated config for all four protocols (builds real consumer/admin clients, no broker needed)

Not tested against a live secured broker.

🤖 Generated with Claude Code

boma96 and others added 2 commits November 23, 2026 15:29
Add a new AddKafkaCancellationNotifier(IConfiguration) overload that binds
the Conductor:KafkaCancellationNotifier section, including security
settings for SSL, mTLS (PEM files or PKCS#12 keystore), SASL_SSL and
SASL_PLAINTEXT (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512). Settings are
validated on startup.

Security settings are optional and only passed to librdkafka when
configured, so existing setups produce the same client config as before.
The existing AddKafkaCancellationNotifier method is unchanged and does not
run the new validation. The admin client used for topic creation now
shares the consumer's connection settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…SKILL.md

Keep all packages on the same version as KafkaCancellationNotifier, and
describe the new IConfiguration overload and security settings in the
SKILL.md Kafka section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@boma96
boma96 merged commit d66065f into master Nov 25, 2026
1 check passed
@boma96
boma96 deleted the feature/kafka-security branch November 25, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant