KAFKA-20419 : Add SASL_PLAINTEXT docker compose examples and sanity test - #22023
Conversation
| - `KAFKA_OPTS` is set to point to the JAAS config file. | ||
| - Similar to the plaintext example, two listeners are configured: one for inter-broker communication and one for client-to-broker communication. Both use the `SASL_PLAINTEXT` security protocol. | ||
| - Two users are configured in the JAAS file: `admin` (for inter-broker) and `alice` (for clients). | ||
| - Note: SASL is currently not supported with the GraalVM based native image (`apache/kafka-native`) due to missing reflection configuration for `java.security.AccessController`. See [KAFKA-19584](https://issues.apache.org/jira/browse/KAFKA-19584) for details. |
There was a problem hiding this comment.
This is an open issue.
| print(constants.FILE_INPUT_ERROR_PREFIX, str(e)) | ||
| total_errors.append(str(e)) | ||
| # SASL is not supported on native image due to missing reflection config (KAFKA-19584) | ||
| if self.MODE == "jvm": |
There was a problem hiding this comment.
since this sasl config doesn't work on native image, adding this condition to run only on jvm based image
|
@chia7712 updated the pr with test instructions. Pls take a look. Thank you. |
There was a problem hiding this comment.
Pull request overview
Adds SASL/PLAIN (SASL_PLAINTEXT) Docker Compose examples and extends the Docker sanity test suite to validate SASL client connectivity against the Docker image, complementing the existing plaintext/SSL examples and flows.
Changes:
- Added new SASL_PLAINTEXT Docker Compose examples (single-node and multi-node: combined + isolated) plus supporting JAAS/client config fixtures.
- Updated Docker examples README with SASL mode guidance and run instructions.
- Extended docker sanity tests and fixture compose files to exercise a SASL client flow (JVM image only).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docker/test/fixtures/sasl/client-sasl.properties | Adds SASL client properties fixture for docker sanity tests. |
| docker/test/fixtures/sasl/broker_jaas.conf | Adds broker JAAS fixture for SASL/PLAIN in docker sanity tests. |
| docker/test/fixtures/mode/isolated/docker-compose.yml | Exposes a SASL_PLAINTEXT listener (9095) for isolated-mode docker sanity tests. |
| docker/test/fixtures/mode/combined/docker-compose.yml | Exposes a SASL_PLAINTEXT listener (9095) for combined-mode docker sanity tests. |
| docker/test/docker_sanity_test.py | Adds a SASL flow test and gates it to JVM image mode. |
| docker/test/constants.py | Introduces constants for SASL flow naming/config paths/topic/error prefix. |
| docker/examples/README.md | Documents SASL mode and adds SASL_PLAINTEXT run instructions for examples. |
| docker/examples/fixtures/sasl/broker_jaas.conf | Adds example JAAS config for SASL/PLAIN brokers. |
| docker/examples/fixtures/client-secrets/client-sasl.properties | Adds example client SASL properties. |
| docker/examples/docker-compose-files/single-node/sasl_plaintext/docker-compose.yml | Adds single-node SASL_PLAINTEXT compose example. |
| docker/examples/docker-compose-files/cluster/isolated/sasl_plaintext/docker-compose.yml | Adds isolated multi-node SASL_PLAINTEXT compose example. |
| docker/examples/docker-compose-files/cluster/combined/sasl_plaintext/docker-compose.yml | Adds combined multi-node SASL_PLAINTEXT compose example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Set `KAFKA_OPTS` to `-Djava.security.auth.login.config=/etc/kafka/secrets/<jaas_config_filename>`. | ||
| - Set `KAFKA_SASL_ENABLED_MECHANISMS` to the desired SASL mechanism (e.g. `GSSAPI` , `PLAIN`, `SCRAM-SHA-256`, `SCRAM-SHA-512`). | ||
| - Ensure `KAFKA_ADVERTISED_LISTENERS` contains a `SASL_PLAINTEXT://` or `SASL_SSL://` listener. | ||
| - For inter-broker SASL communication, set `KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL` to the desired mechanism (SASL_PLAINTEXT (or SASL_SSL)). |
| - Set `KAFKA_SASL_ENABLED_MECHANISMS` to the desired SASL mechanism (e.g. `GSSAPI` , `PLAIN`, `SCRAM-SHA-256`, `SCRAM-SHA-512`). | ||
| - Ensure `KAFKA_ADVERTISED_LISTENERS` contains a `SASL_PLAINTEXT://` or `SASL_SSL://` listener. | ||
| - For inter-broker SASL communication, set `KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL` to the desired mechanism (SASL_PLAINTEXT (or SASL_SSL)). | ||
| - The Docker image `configure` script will validate that `KAFKA_OPTS` contains the `java.security.auth.login.config` property when SASL listeners are detected. |
There was a problem hiding this comment.
@muralibasani as I see the configure script will only warn if KAFKA_OPTS doesn't contain -Djava.security.auth.login.config=..., so we should correct the readme here.
There was a problem hiding this comment.
@viktorsomogyi good point, indeed. Updated.
| def sasl_flow(self, sasl_broker_port, test_name, test_error_prefix, topic): | ||
| print(f"Running {test_name}") | ||
| errors = [] | ||
| try: | ||
| self.assertTrue(self.create_topic(topic, ["--bootstrap-server", sasl_broker_port, "--command-config", f"{self.FIXTURES_DIR}/{constants.SASL_CLIENT_CONFIG}"])) | ||
| except AssertionError as e: | ||
| errors.append(test_error_prefix + str(e)) | ||
| return errors | ||
|
|
||
| producer_config = ["--bootstrap-server", sasl_broker_port, | ||
| "--command-config", f"{self.FIXTURES_DIR}/{constants.SASL_CLIENT_CONFIG}"] | ||
| self.produce_message(topic, producer_config, "key", "message") | ||
|
|
||
| consumer_config = [ | ||
| "--bootstrap-server", sasl_broker_port, | ||
| "--command-property", "auto.offset.reset=earliest", | ||
| "--command-config", f"{self.FIXTURES_DIR}/{constants.SASL_CLIENT_CONFIG}", | ||
| ] | ||
| message = self.consume_message(topic, consumer_config) |
There was a problem hiding this comment.
Updated to remove the duplicate blocks.
There was a problem hiding this comment.
@muralibasani would you please address the copilot reviews? I see that there are some valid comments from it. Also, would you please create a ticket and reformat your PR title to fit the conventions?
@viktorsomogyi thanks for the review. Updated PR based on the suggestions. |
|
@muralibasani merged it, thanks for your contribution! |
…est (apache#22023) Note : these examples work only with jvm image and not with native image. (Open issue https://issues.apache.org/jira/browse/KAFKA-19584) Changes : - Adding sasl_plain docker compose examples - Updated readme - Added sasl_flow tests (only combined and isolated modes) Reviewers: Viktor Somogyi-Vass <viktorsomogyi@gmail.com>
| KAFKA_NODE_ID: 4 | ||
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,PLAINTEXT_HOST:PLAINTEXT' | ||
| KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT_HOST://localhost:9092,SSL://localhost:19093,PLAINTEXT://broker1:29092' | ||
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,PLAINTEXT_HOST:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT' |
There was a problem hiding this comment.
It seems we only set the SASL_PLAINTEXT listener for broker1, but the partition created by the test could be hosted by broker2 or broker3, so the client wouldn't be able to connect to the leader.
Am I missing something?
There was a problem hiding this comment.
opened https://issues.apache.org/jira/browse/KAFKA-20982 as blocker
Ref : https://issues.apache.org/jira/browse/KAFKA-20419
Note : these examples work only with jvm image and not with native
image. (Open issue https://issues.apache.org/jira/browse/KAFKA-19584)
Changes :
Testing the changes locally :
Start single node cluster :
IMAGE=apache/kafka:latest docker compose -f docker/examples/docker-compose-files/single-node/sasl_plaintext/docker-compose.yml up -dCreate a topic :
./bin/kafka-topics.sh --bootstrap-server localhost:9094 --create --topic test --command-config docker/examples/fixtures/client-secrets/client-sasl.propertiesProduce :
./bin/kafka-console-producer.sh --bootstrap-server localhost:9094 --topic test --producer.config docker/examples/fixtures/client-secrets/client-sasl.propertiesConsume :
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9094 --topic test --from-beginning --max-messages 1 --consumer.config docker/examples/fixtures/client-secrets/client-sasl.propertiesResults :