title: Kafka Authentication Producer Unable to Connect Producer
body: <p>I am try to replicate the SASL_PLAIN or SASL_SSL authentication described at: <a href="http://docs.confluent.io/3.0.0/kafka/sasl.html#sasl-configuration-for-kafka-brokers" rel="noreferrer">http://docs.confluent.io/3.0.0/kafka/sasl.html#sasl-configuration-for-kafka-brokers</a></p>
  
  <p>In config/server.properties, I added the following 4 lines:</p>
  
  <pre><code>listeners=SASL_SSL://localhost:9092
  security.inter.broker.protocol=SASL_SSL
  sasl.mechanism.inter.broker.protocol=PLAIN
  sasl.enabled.mechanisms=PLAIN
  </code></pre>
  
  <p>In config/producer.properties, I added the following two lines:</p>
  
  <pre><code>security.protocol=SASL_SSL
  sasl.mechanism=PLAIN
  </code></pre>
  
  <p>Then I set the following environment variable in the server terminal:</p>
  
  <pre><code>KAFKA_OPTS=/home/kafka/kafka_server_jaas.conf
  </code></pre>
  
  <p>This file has the following content:</p>
  
  <pre><code>KafkaServer {
     org.apache.kafka.common.security.plain.PlainLoginModule required
     username="admin"
     password="admin-secret"
     user_admin="admin-secret"
     user_alice="alice-secret";
  };
  </code></pre>
  
  <p>And in the producer terminal I define the following env variable:</p>
  
  <pre><code>KAFKA_OPTS=/home/kafka/kafka_client_jaas.conf
  </code></pre>
  
  <p>And this file has the following content:</p>
  
  <pre><code>KafkaClient {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="alice"
    password="alice-dsecret";
  };
  </code></pre>
  
  <p>I start the server with the following command:</p>
  
  <pre><code>./bin/kafka-server-start.sh   config/server.properties
  </code></pre>
  
  <p>And the producer with following command:</p>
  
  <pre><code>bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
  </code></pre>
  
  <p>Both start without problems. But, as soon as I type something on the producer console, I get the following message that keeps scrolling:</p>
  
  <pre><code>WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  WARN Bootstrap broker localhost:9092 disconnected (org.apache.kafka.clients.NetworkClient)
  </code></pre>
  
  <p>If I remove the security configuration from the server and the producer configuration, everything works as expected.  I am using Kafka 0.10.0.1.</p>
  
  <p>UPDATE:
  I did some more investigations, turning log levels to DEBUG on server reveals something weird. As soon as I specify the listeners field in server.properties, the server goes in a weird state. It establishes connection to itsself that it cannot authenticate. The protocol in this case was SASL_PLAINTEXT.</p>
  
  <p>The logs as here:</p>
  
  <pre><code>2016-09-15 21:43:02 DEBUG SaslClientAuthenticator:204 - Set SASL client state to RECEIVE_HANDSHAKE_RESPONSE
  2016-09-15 21:43:02 DEBUG NetworkClient:476 - Completed connection to node 0
  2016-09-15 21:43:02 DEBUG Acceptor:52 - Accepted connection from /127.0.0.1 on /127.0.0.1:9092. sendBufferSize [actual|requested]: [102400|102400] recvBufferSize [actual|requested]: [102400|102400]
  2016-09-15 21:43:02 DEBUG Processor:52 - Processor 2 listening to new connection from /127.0.0.1:42815
  2016-09-15 21:43:02 DEBUG SaslServerAuthenticator:269 - Set SASL server state to HANDSHAKE_REQUEST
  2016-09-15 21:43:02 DEBUG SaslServerAuthenticator:310 - Handle Kafka request SASL_HANDSHAKE
  2016-09-15 21:43:02 DEBUG SaslServerAuthenticator:354 - Using SASL mechanism 'PLAIN' provided by client
  2016-09-15 21:43:02 DEBUG SaslServerAuthenticator:269 - Set SASL server state to AUTHENTICATE
  2016-09-15 21:43:02 DEBUG SaslClientAuthenticator:204 - Set SASL client state to INITIAL
  2016-09-15 21:43:02 DEBUG SaslClientAuthenticator:204 - Set SASL client state to INTERMEDIATE
  2016-09-15 21:43:02 DEBUG SaslServerAuthenticator:269 - Set SASL server state to FAILED
  2016-09-15 21:43:02 DEBUG Selector:345 - Connection with /127.0.0.1 disconnected
  java.io.IOException: javax.security.sasl.SaslException: Authentication failed: Invalid JAAS configuration [Caused by     javax.security.sasl.SaslException: Authentication failed: Invalid username or password]
  at org.apache.kafka.common.security.authenticator.SaslServerAuthenticator.authenticate(SaslServerAuthenticator.java:243)
  at org.apache.kafka.common.network.KafkaChannel.prepare(KafkaChannel.java:64)
  at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:318)
  at org.apache.kafka.common.network.Selector.poll(Selector.java:283)
  at kafka.network.Processor.poll(SocketServer.scala:472)
  </code></pre>
  
  <p>There is absolutely no other client or server running. This is one server talking to himself. </p>
  
  <p>Any thoughts?</p>