All Products
Search
Document Center

E-MapReduce:Use LDAP authentication

Last Updated:Sep 21, 2026

This topic describes how to enable LDAP authentication for EMR Kafka and provides a detailed example.

Prerequisites

You have created a Dataflow cluster and selected the Kafka and OpenLDAP services. For more information, see Create a Dataflow Kafka cluster.

Limits

  • This feature is available for EMR Kafka clusters that run EMR V3.44.0 or later, or EMR V5.10.0 or later.

  • An EMR OpenLDAP service or an external LDAP service is available in the cluster.

    This topic uses the EMR OpenLDAP service as an example.

Precautions

If you want to use user group authentication, ensure that the memberOf overlay feature is enabled for the LDAP service or that the memberOf attribute is supported for LDAP users.

Enable LDAP authentication

  1. Create a superuser.

    Note

    If you have already created a superuser, you can skip this step.

    A Kafka superuser can access all Kafka resources. The superuser handles communication between broker nodes and other components. This example uses the EMR OpenLDAP service to show how to add a Kafka superuser.

    1. Connect to the master-1-1 node of the cluster over SSH. For more information, see Log on to a cluster.

    2. Create a file named kafka.ldif with the following content.

      This topic uses the ldap command to add an LDAP user with the UID kafka and the password kafka-secret.

      dn: uid=kafka,ou=people,o=emr
      cn: kafka
      sn: kafka
      objectClass: inetOrgPerson
      userPassword: kafka-secret
      uid: kafka
    3. Run the following command to add the LDAP user.

      ldapadd -H ldap://master-1-1:10389 -f kafka.ldif -D ${uid} -w ${rootDnPW}
      Note
      • ${uid}: The value of the admin_dn parameter on the Configure page of the OpenLDAP service in the EMR console.

      • ${rootDnPW}: The value of the admin_pwd parameter on the Configure page of the OpenLDAP service in the EMR console.

      • 10389: The listening port of the OpenLDAP service.

      After you add the user, run the following command to view their information.

      ldapsearch -w ${rootDnPW}  -D ${uid} -H ldap://master-1-1:10389 -b uid=kafka,ou=people,o=emr
  2. Go to the Kafka configuration page.

    1. Log on to the EMR on ECS console.

    2. In the top navigation bar, select the required region and resource group.

    3. In the Actions column of the target cluster, click Services.

    4. On the Services page, click Configure in the Kafka service section.

  3. Modify and save the configuration.

    1. On the Configure page, click the server.properties tab.

    2. Change the value of the kafka.ssl.config.type configuration item to CUSTOM.

    3. Change the value of the authorizer.class.name configuration item to kafka.security.ldap.authorizer.SimpleLdapAuthorizer.

    4. Save the configuration.

      1. Click Save.

      2. In the dialog box, enter a reason in the Execution Reason field.

  4. Add and save custom parameters.

    1. On the server.properties tab, click Add Configuration Item.

    2. In the Add Configuration Item dialog box, add the following items.

      Parameter

      Value

      Description

      super.users

      User:kafka

      kafka is the username that you created. Replace it as needed.

      For more information, see Step 1.

      listener.name.${listener}.sasl.enabled.mechanisms

      PLAIN

      Replace ${listener} with the name of a specific listener, such as sasl_ssl.

      listener.name.${listener}.plain.sasl.jaas.config

      org.apache.kafka.common.security.plain.PlainLoginModule required username="kafka" password="kafka-secret" emr.kafka.security.ldap.user.name.attribute="uid" emr.kafka.security.ldap.user.base.dn="ou=people,o=emr" emr.kafka.security.ldap.group.name.attribute="cn" emr.kafka.security.ldap.group.base.dn="ou=groups,o=emr" emr.kafka.security.ldap.admin.name.attribute="uid" emr.kafka.security.ldap.admin.base.dn="o=emr" emr.kafka.security.ldap.url="ldaps://master-1-1:10636" emr.kafka.security.ldap.bind.user="admin" emr.kafka.security.ldap.bind.user.password="WMMuhh3P**********" emr.kafka.security.ldap.user.member.of.attribute="memberOf" emr.kafka.security.ldap.group.authorization.support="true" ;

      Replace ${listener} with the name of a specific listener, such as sasl_ssl.

      You must also replace the following LDAP-related configuration values:

      • username: The superuser that the Kafka service uses for communication between nodes.

      • emr.kafka.security.ldap.user.name.attribute: The LDAP user name attribute that is used to obtain the username.

      • emr.kafka.security.ldap.user.base.dn: The base distinguished name (DN) of the LDAP user.

      • emr.kafka.security.ldap.group.name.attribute: The attribute for the LDAP user group name.

      • emr.kafka.security.ldap.group.base.dn: The base DN of the LDAP user group.

      • emr.kafka.security.ldap.admin.name.attribute: The LDAP admin user attribute.

      • emr.kafka.security.ldap.admin.base.dn: The base DN of the LDAP admin user.

      • emr.kafka.security.ldap.url: The LDAP URL.

      • emr.kafka.security.ldap.bind.user: The LDAP administrator username that is used for user group authentication.

      • emr.kafka.security.ldap.bind.user.password: The password of the LDAP administrator.

      • emr.kafka.security.ldap.user.member.of.attribute: The attribute that indicates the groups to which a user belongs.

      • emr.kafka.security.ldap.group.authorization.support: Specifies whether to enable group authorization. If this parameter is set to true, a user inherits permissions from their assigned user groups.

      listener.name.${listener}.plain.sasl.server.callback.handler.class

      kafka.security.ldap.authenticator.LdapAuthenticateCallbackHandler

      Replace ${listener} with the name of a specific listener, such as sasl_ssl.

      sasl.mechanism.inter.broker.protocol

      PLAIN

      None

      sasl.enabled.mechanisms

      PLAIN

      None

    3. Modify other parameters.

      Modify the following configurations based on your requirements.

      Note

      You must replace the username and password in the value of the kafka.client.jaas.content parameter as needed. We recommend that you use the superuser.

      Configuration file

      Parameter

      Value

      Description

      kafka_client_jaas.conf

      kafka.client.jaas.content

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

      The value must end with a semicolon (;).

      schema-registry.properties

      schema_registry_opts

      -Djava.security.auth.login.config=/etc/taihao-apps/kafka-conf/kafka-conf/kafka_client_jaas.conf

      If this parameter already has a value, append the new content.

      kafka-rest.properties

      kafkarest_opts

      -Djava.security.auth.login.config=/etc/taihao-apps/kafka-conf/kafka-conf/kafka_client_jaas.conf

      If this parameter already has a value, append the new content.

  5. Restart the Kafka service.

    1. On the Configure page of the Kafka service, choose More > Restart.

    2. In the dialog box that appears, enter a reason for the action and click OK.

    3. In the Confirm dialog box, click OK.

Usage example

The operations in this example apply to open source Kafka 2.4.1. For other Kafka versions, see Apache Kafka.

  1. Create test users and user groups.

    1. If the memberOf overlay feature is not enabled for OpenLDAP, follow these steps to enable it.

      Note
      • The following configuration method is for reference only. The method to enable the memberOf overlay varies based on the LDAP service.

      • Apply this configuration to all OpenLDAP nodes.

      • Modify the parameters in all the following configuration files as needed. For example:

        • olcModulepath: For a 32-bit operating system, the path is /usr/lib/openldap.

        • dn: cn=module{0},cn=config: If the /etc/openldap/slapd.d/cn=config directory already contains a cn=module{0}.ldif file, change the number after module to 1. If it contains a cn=module{1}.ldif file, change the number to 2, and so on.

        • dn: olcOverlay={0}memberof,olcDatabase={2}hdb,cn=config: Configure this value based on the olcDatabase value in the /etc/openldap/slapd.d/cn=config directory. For example, if olcDatabase={2}hdb.ldif exists, set the value to hdb.

      1. Run the command vim memberof_config.ldif to create a new configuration file memberof_config.ldif. The content of the file is as follows.

        dn: cn=module{0},cn=config
        cn: module{0}
        objectClass: olcModuleList
        objectclass: top
        olcModuleload: memberof.la
        olcModulePath: /usr/lib64/openldap
        
        dn: olcOverlay={0}memberof,olcDatabase={2}hdb,cn=config
        objectClass: olcConfig
        objectClass: olcMemberOf
        objectClass: olcOverlayConfig
        objectClass: top
        olcOverlay: memberof
        olcMemberOfDangling: ignore
        olcMemberOfRefInt: TRUE
        olcMemberOfGroupOC: groupOfNames
        olcMemberOfMemberAD: member
        olcMemberOfMemberOfAD: memberOf
      2. Run the command vim refint1.ldif to create the configuration file refint1.ldif. The file content is as follows.

        dn: cn=module{0},cn=config
        add: olcmoduleload
        olcmoduleload: refint
      3. Run the command vim refint2.ldif to create a new configuration file refint2.ldif with the following content.

        dn: olcOverlay=refint,olcDatabase={2}hdb,cn=config
        objectClass: olcConfig
        objectClass: olcOverlayConfig
        objectClass: olcRefintConfig
        objectClass: top
        olcOverlay: refint
        olcRefintAttribute: memberof member manager owner
      4. Run the following commands to load the configuration files.

        ldapadd -Q -Y EXTERNAL -H ldapi:/// -f memberof_config.ldif
        ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f refint1.ldif
        ldapadd -Q -Y EXTERNAL -H ldapi:/// -f refint2.ldif
    2. Create test users.

      Create a file named kafka-users.ldif with the following content, and then use the ldapadd command to add the test users.

      dn: uid=kafka-user1,ou=people,o=emr
      cn: kafka-user1
      sn: kafka-user1
      uid: kafka-user1
      objectClass: inetOrgPerson
      userPassword: kafka-secret
      
      dn: uid=kafka-user2,ou=people,o=emr
      cn: kafka-user2
      sn: kafka-user2
      uid: kafka-user2
      objectClass: inetOrgPerson
      userPassword: kafka-secret
    3. Create test user groups.

      Create a file named kafka-groups.ldif with the following content, and then use the ldapadd command to add the test user groups.

      dn: cn=kafka-group1,ou=groups,o=emr
      cn: kafka-group1
      objectClass: groupOfNames
      member: uid=kafka-user1,ou=people,o=emr
      member: uid=kafka-user2,ou=people,o=emr
      
      dn: cn=kafka-group2,ou=groups,o=emr
      cn: kafka-group2
      objectClass: groupOfNames
      member: uid=kafka-user1,ou=people,o=emr
    4. On the server where LDAP is running, run the following command to check the memberOf attribute of the test users.

      ldapsearch -Q -Y EXTERNAL -H ldapi:///  -b ou=people,o=emr memberOf

      The output indicates that the memberOf attribute of kafka-user1 includes kafka-group1 and kafka-group2, and the memberOf attribute of kafka-user2 includes kafka-group1.

  2. Create client configuration files.

    1. Create a client configuration file named client.properties with the following content.

      security.protocol=SASL_PLAINTEXT
      sasl.mechanism=PLAIN
      #Replace the username and password based on the client identity.
      sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule  required username="kafka" password="kafka-secret";
    2. Create a client configuration file named kafka-user1.properties with the following content.

      security.protocol=SASL_PLAINTEXT
      sasl.mechanism=PLAIN
      #Replace the username and password based on the client identity.
      sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule  required username="kafka-user1" password="kafka-secret";
    3. Create a client configuration file named kafka-user2.properties with the following content.

      security.protocol=SASL_PLAINTEXT
      sasl.mechanism=PLAIN
      #Replace the username and password based on the client identity.
      sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule  required username="kafka-user2" password="kafka-secret";
  3. Create a test topic named test.

    kafka-topics.sh  --bootstrap-server core-1-1:9092 --command-config  client.properties --create --topic test --replication-factor 3 --partitions 2
  4. Grant permissions.

    For more information about authorization commands, see Authorization and ACLs.

    #Permissions for kafka-group2
    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --allow-principal User:kafka-group2 --allow-host "*" --operation All --cluster kafka-cluster
    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --allow-principal User:kafka-group2 --allow-host "*" --operation All --topic test
    #Permissions for kafka-group1
    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --deny-principal User:kafka-group1 --deny-host "*" --operation All --topic test
    #Permissions for kafka-user1
    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --deny-principal User:kafka-user1 --deny-host "*" --operation Read --topic test
    #Permissions for kafka-user2
    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --allow-principal User:kafka-user2 --allow-host "*" --operation Read --topic test

    You can run the following command to view the authorization results.

    kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --list --topic test

    The following information is returned:

    Current ACLs for resource `Topic:LITERAL:test`:
            User:kafka-group2 has Allow permission for operations: All from hosts: *
            User:kafka-user2 has Allow permission for operations: Read from hosts: *
            User:kafka-user1 has Deny permission for operations: Read from hosts: *
            User:kafka-group1 has Deny permission for operations: All from hosts: *
  5. Verify permissions.

    • User kafka-user1 can write to the test topic through kafka-group2.

      kafka-console-producer.sh --broker-list core-1-1:9092 --producer.config ./kafka-user1.properties  --topic test

      Enter test messages at the prompt. The write operation succeeds.

      #Enter test messages after the prompt.
      >a
      >b
      >c
      >d
    • User kafka-user1 cannot read from the test topic.

      #Grant permission to the consumer group.
      kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --allow-principal User:kafka-user1 --allow-host "*" --operation All --group kka-user1-consumer
      kafka-console-consumer.sh --bootstrap-server core-1-1:9092 --consumer.config ./kafka-user1.properties --topic test --group kafka-user1-consumer

      Authentication fails, and the user cannot access the test topic.

    • User kafka-user2 cannot write to the test topic.

      kafka-console-producer.sh --broker-list core-1-1:9092 --producer.config ./kafka-user2.properties  --topic test
      #Enter a test message after the prompt.
      >a
      #Authentication fails.

      Authentication fails.

    • User kafka-user2 can read from the test topic.

      #Grant permission to the consumer group.
      kafka-acls.sh --authorizer-properties zookeeper.connect=$KAFKA_ZOOKEEPER --add --allow-principal User:kafka-user2 --allow-host "*" --operation All --group kafka-user2-consumer
      kafka-console-consumer.sh --bootstrap-server core-1-1:9092 --consumer.config ./kafka-user2.properties --topic test --group kafka-user2-consumer --from-beginning
      #Data is consumed as expected.