Skip to content

KAFKA-20419 : Add SASL_PLAINTEXT docker compose examples and sanity test - #22023

Merged
viktorsomogyi merged 2 commits into
apache:trunkfrom
muralibasani:KAFKA-20419
May 15, 2026
Merged

KAFKA-20419 : Add SASL_PLAINTEXT docker compose examples and sanity test#22023
viktorsomogyi merged 2 commits into
apache:trunkfrom
muralibasani:KAFKA-20419

Conversation

@muralibasani

@muralibasani muralibasani commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

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 :

  • Adding sasl_plain docker compose examples
  • Updated readme
  • Added sasl_flow tests (only combined and isolated modes)

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 -d

Create a topic :

./bin/kafka-topics.sh --bootstrap-server localhost:9094 --create --topic test --command-config docker/examples/fixtures/client-secrets/client-sasl.properties

Produce :

./bin/kafka-console-producer.sh --bootstrap-server localhost:9094 --topic test --producer.config docker/examples/fixtures/client-secrets/client-sasl.properties

Consume :

./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.properties

Results :

  • Topic test is created
  • Producer sends and consumer receives a message over SASL_PLAINTEXT

@github-actions github-actions Bot added the triage PRs from the community label Apr 10, 2026
@muralibasani muralibasani changed the title Adding sasl_plain docker compose examples KAFKA-20419 : Adding sasl_plain docker compose examples Apr 10, 2026
@github-actions github-actions Bot added the docker Official Docker image label Apr 10, 2026
@muralibasani muralibasani changed the title KAFKA-20419 : Adding sasl_plain docker compose examples KAFKA-20419 : docker - Adding sasl_plain docker compose examples Apr 10, 2026
Comment thread docker/examples/README.md
- `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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this sasl config doesn't work on native image, adding this condition to run only on jvm based image

@github-actions github-actions Bot removed the triage PRs from the community label Apr 11, 2026
@muralibasani

Copy link
Copy Markdown
Contributor Author

@chia7712 updated the pr with test instructions. Pls take a look. Thank you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docker/examples/README.md Outdated
- 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)).
Comment thread docker/examples/README.md Outdated
- 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viktorsomogyi good point, indeed. Updated.

Comment thread docker/test/docker_sanity_test.py Outdated
Comment on lines +149 to +167
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to remove the duplicate blocks.

@viktorsomogyi viktorsomogyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@muralibasani muralibasani changed the title KAFKA-20419 : docker - Adding sasl_plain docker compose examples KAFKA-20419 : Add SASL_PLAINTEXT docker compose examples and sanity test May 10, 2026
@muralibasani

muralibasani commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@viktorsomogyi
viktorsomogyi merged commit 1695e95 into apache:trunk May 15, 2026
25 checks passed
@viktorsomogyi

Copy link
Copy Markdown
Contributor

@muralibasani merged it, thanks for your contribution!

JiayaoS pushed a commit to JiayaoS/kafka that referenced this pull request May 21, 2026
…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'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved docker Official Docker image

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants