feat(backend): add SASL/TLS support to the Kafka message queue backend - #167
Conversation
Signed-off-by: Harshit Gandhi <gandhiharshit716@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughKafka security configuration now selects plaintext, TLS, and SASL modes through ChangesKafka security support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant KafkaConfig
participant KafkaAdapter
participant kafkaSecurityOptions
participant Redpanda
KafkaConfig->>KafkaAdapter: configure securityProtocol and credentials
KafkaAdapter->>kafkaSecurityOptions: validate and build SASL/TLS options
kafkaSecurityOptions-->>KafkaAdapter: return client options
KafkaAdapter->>Redpanda: produce and consume secured message
Redpanda-->>KafkaAdapter: return record
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@matthyx PTAL |
Review — blocker: the new TLS integration tests fail CI deterministicallyNice, well-structured change: Blocker —
|
|
@matthyx Thanks for the review, this was a real blocker. I fixed it by updating the TLS test cert helper to generate RSA-2048 certs instead of ECDSA P-256 in I intentionally kept these tests in the default Verified locally with:
Also noted on the minor point: |
Re-check after
|
| # | test | CI |
|---|---|---|
| 1–5 | TestKafkaMessageProducer_*, TestKafkaMessageReader_* |
PASS |
| 6 | TestKafkaSecurity_SASLRoundTrip |
PASS |
| 7 | TestKafkaSecurity_TLSRoundTrip |
FAIL 139 |
| 8 | TestKafkaSecurity_SASLTLSRoundTrip |
FAIL 139 |
| 9 | TestKafkaSecurity_TLSRejectsUntrustedBroker |
FAIL 139 |
By test 7 there are six live brokers still squatting on the runner. The three TLS tests just happen to be numbers 7, 8 and 9, so they're the ones that hit the wall — a 4-core/16 GB GitHub runner runs out of headroom and seastar dies at boot. Nothing about the TLS path itself is faulty, which is also why swapping ECDSA→RSA changed nothing.
This also explains the note in the PR description: individually each test is container #1 and always passes; the whole suite in one process accumulates the leak and blows up. It's not flaky infra.
The fix
Terminate with a context that isn't tied to the test's lifetime:
// kafka_security_integration_test.go:47
t.Cleanup(func() { _ = container.Terminate(context.Background()) })
// kafka_integration_test.go:36
_ = container.Terminate(context.Background())Verified on this branch — leaked containers go from 9 to 0 and the suite stays green:
--- PASS: TestKafkaSecurity_SASLRoundTrip (1.94s)
--- PASS: TestKafkaSecurity_TLSRoundTrip (1.99s)
--- PASS: TestKafkaSecurity_SASLTLSRoundTrip (2.00s)
--- PASS: TestKafkaSecurity_TLSRejectsUntrustedBroker (1.52s)
LEAKED redpanda containers still running after the kafka suite: 0
ok github.com/kubescape/synchronizer/adapters/backend/v1 25.020s
Worth surfacing the teardown error instead of swallowing it (require.NoError in the cleanup, or at least t.Logf) so the next leak isn't silent.
One caveat, so you can weigh it: I could not reproduce the code-139 crash itself on my machine (24 cores / 30 GB simply absorbs nine stray brokers; I also tried pinning the container to 2 CPUs / 2 GB and it booted fine). The leak and the fix are directly measured; the leak → exhaustion → SIGSEGV link on the 4-core/16 GB runner is inference from the ordering above. CI is the confirmation — but the leak is a real defect regardless of whether it turns out to be the whole story.
Note the leak pattern predates this PR (kafka_integration_test.go came in with #166); this PR is just what pushes the container count past what the runner tolerates. Fixing both helpers is the right move.
Still unrelated
component-tests (TC01–TC13) continue to fail on fatal: Authentication failed for .../db-migrations.git — fork PRs don't get repo secrets. Not yours to fix.
Signed-off-by: Harshit Gandhi <gandhiharshit716@gmail.com>
31c076a to
102e0ca
Compare
Overview
Adds SASL and TLS support to the Kafka message queue backend.
Current behavior: the Kafka backend only supported
PLAINTEXT. The security config fields (securityProtocol,saslMechanism,saslUsername,saslPassword,tlsCaCertPath) were parsed but any non-plaintext value was explicitly rejected - SASL/TLS was deferred.Future behavior: SASL and TLS are now wired into both the producer and consumer (reader) franz-go clients:
PLAIN,SCRAM-SHA-256, andSCRAM-SHA-512mechanisms.tlsCaCertPath.securityProtocol(PLAINTEXT/SSL/SASL_PLAINTEXT/SASL_SSL) is the single authoritative selector; thePLAINTEXTpath is unchanged.Additional Information
Key design decisions:
securityProtocolis authoritative - theSASL_prefix enables SASL and the_SSLsuffix enables TLS. The redundanttlsEnabledflag was removed to avoid a config field that could only ever cause an error.PLAINis rejected without TLS -PLAINtransmits the password in cleartext, so it is only allowed over a TLS-encrypted channel (SASL_SSL).SCRAMnever exposes the password and is permitted over plaintext.kafkaSecurityOptions, so it applies regardless of which constructor is used.How to Test
Integration coverage added:
TestKafkaSecurity_SASLRoundTrip- SASL (SASL_PLAINTEXT+ SCRAM-SHA-256) produce/consume round-trip.TestKafkaSecurity_TLSRoundTrip- TLS (SSL) round-trip against a broker with a self-signed cert.TestKafkaSecurity_SASLTLSRoundTrip- the enterpriseSASL_SSLpath (SASL over TLS).TestKafkaSecurity_TLSRejectsUntrustedBroker- negative test proving TLS verification is enforced (untrusted CA ⇒ connection refused).Related issues/PRs:
Checklist before requesting a review
Please open the PR against the
devbranch (Unless the PR contains only documentation changes)Summary by CodeRabbit
tlsEnabledhas been removed;securityProtocolis the single source of truth for selecting plaintext/TLS/SASL behavior.