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

Unable to enable SASL mechanism for Kafka #3899

Closed
Schachte opened this issue Mar 20, 2021 · 2 comments
Closed

Unable to enable SASL mechanism for Kafka #3899

Schachte opened this issue Mar 20, 2021 · 2 comments

Comments

@Schachte
Copy link

  public static KafkaContainer kafka =
      new KafkaContainer(DockerImageName.parse(KAFKA_TEST_IMAGE))
              .withNetwork(Network.newNetwork())
              .withEnv("KAFKA_AUTO_CREATE_TOPICS_ENABLE", "false")
              .withEnv("KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND", "true")
              .withEnv("KAFKA_SUPER_USERS", "User:OnlySuperUser")
              .withEnv("KAFKA_SASL_ENABLED_MECHANISMS", "PLAIN,SASL_PLAINTEXT")
              .withEnv("KAFKA_SASL_JAAS_CONFIG", JAAS_CONFIG);

and I get the following error:

org.apache.kafka.common.errors.IllegalSaslStateException: Unexpected handshake request with client mechanism PLAIN, enabled mechanisms are []

The client seems to be setup fine, but the configured mechanism (PLAIN) seems like it's being ignored completely.

@anton-instana
Copy link

This is an overlay or env vars to enable SASL_PLAINTEXT with TestContainer's KafkaContainer:

  public KafkaContainer buildBrokerInstance() {
    final Map<String, String> env = new LinkedHashMap<>();
    env.put("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:SASL_PLAINTEXT");

    env.put("KAFKA_LISTENER_NAME_PLAINTEXT_SASL_ENABLED_MECHANISMS", "PLAIN");

    env.put("KAFKA_LISTENER_NAME_PLAINTEXT_PLAIN_SASL_JAAS_CONFIG", "org.apache.kafka.common.security.plain.PlainLoginModule required " +
        "username=\"admin\" " +
        "password=\"admin-secret\" " +
        "user_admin=\"admin-secret\" " +
        "user_producer=\"producer-secret\" " +
        "user_consumer=\"consumer-secret\";");

    env.put("KAFKA_SASL_JAAS_CONFIG", "org.apache.kafka.common.security.plain.PlainLoginModule required " +
        "username=\"admin\" " +
        "password=\"admin-secret\";");

    return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.2"))
        .withEmbeddedZookeeper()
        .withStartupAttempts(1)
        .withEnv(env);
  }

@eddumelendez eddumelendez changed the title Unable to enable SASL mechanism for Kafka TestContainer Unable to enable SASL mechanism for Kafka Apr 18, 2023
@eddumelendez
Copy link
Member

I've added some examples demonstrating SASL with JAAS. See #7763

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

No branches or pull requests

3 participants