How to pass JAAS configuration kafka env variables kubernetes

4/23/2019

I am trying to authenticate my Kafka rest proxy with SASL but I am having trouble transferring the configs made in my local docker compose to Kubernetes.

I am using JAAS configuration to achieve this. My JAAS file looks like this.

KafkaClient {
       org.apache.kafka.common.security.plain.PlainLoginModule required
       username="rest"
       password="rest-secret";
};

Client {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="rest"
       password="restsecret";
};

and then in my docker compose I have done:

KAFKA_OPTS: -Djava.security.auth.login.config=/etc/kafka/secrets/rest_jaas.conf

How will I transfer this same logic to Kubernetes? I have tried passing the env variable like this:

env:
  - name: KAFKA_OPTS
    value: |
      KafkaClient {
        org.apache.kafka.common.security.plain.PlainLoginModule required
        username="rest"
        password="rest-secret";
      };
      Client {
        org.apache.zookeeper.server.auth.DigestLoginModule required
        username="rest"
        password="rest-secret";
      };

but it still fails. Here is what my logs say:

Error: Could not find or load main class KafkaClient
/bin/sh: 3: org.apache.kafka.common.security.plain.PlainLoginModule: not found
/bin/sh: 6: Syntax error: "}" unexpected

Your help will be highly appreciated.

-- kevinsamoei
apache-kafka
docker
docker-compose
kubernetes

1 Answer

4/23/2019

Save your Kafka JAAS config file as rest_jaas.conf. Then execute:

kubectl create secret generic kafka-secret --from-file=rest_jaas.conf

Then in your deployment you insert:

      env:
      - name: KAFKA_OPTS 
        value: -Djava.security.auth.login.config=/etc/kafka/secrets/rest_jaas.conf
      volumeMounts:
      - name: kafka-secret
        mountPath: /etc/kafka/secrets
        subPath: rest_jaas.conf
    volumes:
    - name: kafka-secret
      secret:
        secretName: kafka-secret
-- Vasily Angapov
Source: StackOverflow