.. title:: Role-based access control (RBAC) quick start for Confluent Platform .. meta:: :description: Learn how to use the Confluent CLI to create RBAC roles and interact with topics in Confluent Platform. .. _rbac-cli-quickstart: Role-Based Access Control Quick Start ===================================== Role-based access control (RBAC) is administered by a :ref:`super user ` using the |confluent-cli| and distributed across an organization. This quick start demonstrates how to create roles and interact with |ak| topics in an RBAC environment. .. include:: ../../includes/rbac-demo.rst Prerequisites - :ref:`Confluent Platform `. - |confluent-cli| (included with |cp| since 5.4.x). - The |cp| commercial component ``confluent-server``. For more information, see :ref:`migrate-confluent-server`. - An RBAC-enabled cluster that you have super user access to, or the SystemAdmin role. For more information, see :ref:`rbac-predefined-roles`. Sign in to cluster ------------------ #. Sign in to the |confluent-cli| with the |rbac| |mds-long| URL (````) specified. For more information, see :confluent-cli:`confluent login |command-reference/confluent_login.html`. :: confluent login --url #. Specify the super user credentials when prompted. .. include:: ../../kafka/includes/rbac-case-sensitivity.rst :: Enter your Confluent credentials: Username: Password: Your output should resemble: :: Logged in as user .. _rbac-rolebinding-sysadmin-role: Grant the SystemAdmin role -------------------------- The user you are creating role bindings for (``my-user-name``) must be created in LDAP before you can actually log in with this user to the system. .. note:: |cp| |cr| provides a way for |ak| cluster administrators to centrally register |ak| clusters in the metadata service (MDS) to enable a more user-friendly RBAC role binding experience. For details, refer to :ref:`cluster-registry`. .. include:: ../../kafka/includes/rbac-case-sensitivity.rst #. Grant the :ref:`SystemAdmin role ` (``SystemAdmin``) to a user (````) on the |ak| cluster (````). For more information, see :confluent-cli:`confluent iam rbac role-binding create|command-reference/iam/rbac/role-binding/confluent_iam_rbac_role-binding_create.html`. .. tip:: - This user must also be created in LDAP before they can actually log in to the system, but this is not required for defining the role. - You can find the cluster ID by running this command: ``./bin/zookeeper-shell :2181 get /cluster/id``. :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --kafka-cluster-id #. Grant :ref:`SystemAdmin role ` for the |cp| components to a user. .. tip:: For more information about how to find the cluster ID, see :ref:`rbac-get-cluster-ids`. - |c3| :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --kafka-cluster-id - |kconnect| :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --kafka-cluster-id \ --connect-cluster-id - |ksqldb| :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --kafka-cluster-id \ --ksql-cluster-id - |sr| :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --kafka-cluster-id \ --schema-registry-cluster-id If the cluster you are referencing is defined in the :ref:`cluster registry `, you can specify the role binding using the cluster name only (without the cluster ID) as follows: :: confluent iam rbac role-binding create \ --principal User: \ --role SystemAdmin \ --cluster-name Grant the UserAdmin role on the Kafka cluster --------------------------------------------- The :ref:`UserAdmin role ` grants the user permission to manage permissions for other users. This command grants UserAdmin to a user. :: confluent iam rbac role-binding create \ --principal User: \ --role UserAdmin \ --kafka-cluster-id .. _grant-topic-perms: Grant topic permissions ----------------------- To interact with topics using the :ref:`Kafka CLI tools `, you must provide a JAAS configuration that enables Kafka CLI tools to authenticate with a broker. You can provide the JAAS configuration using a file (``--command-config``) or using the command line options ``--producer-property`` or ``--consumer-property`` for the producer or consumer. This configuration is required for creating topics, producing, consuming, and more. For example: :: kafka-console-producer --producer-property sasl.mechanism=OAUTHBEARER The value you specify in ``sasl.mechanism`` depends on your broker's security configuration for the port. In this case, OAUTHBEARER is used because it is the default configuration in the automated RBAC demo. However, you can use any authentication mechanism exposed by your broker. .. include:: ../../kafka/includes/oauthbearer-warning.rst To identify which roles provide write access to a topic, see :ref:`Predefined roles `. #. Create a configuration file named ``my-user-name.properties``, and specify the MDS service (````), username (````), and password (````). You can also specify these same properties using the command line. :: sasl.mechanism=OAUTHBEARER # Use SASL_SSL for production environments security.protocol=SASL_PLAINTEXT sasl.login.callback.handler.class=io.confluent.kafka.clients.plugins.auth.token.TokenUserLoginCallbackHandler sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \ username="" \ password="" \ metadataServerUrls=""; #. Grant a user permissions to a topic (````). For example, you can grant topic permissions to ResourceOwner or DeveloperManage roles on the resource level; or to the SystemAdmin role at the cluster level. To create a topic, the DeveloperManage role is required on the topic resource. Other :ref:`roles ` that grant the ability to create topics are ResourceOwner on the topic resource, or SystemAdmin at the cluster level. :: confluent iam rbac role-binding create \ --principal User: \ --role ResourceOwner \ --resource Topic:test-topic- \ --prefix \ --kafka-cluster-id #. Create a topic using the |ak| kafka-topics tool found in the ``bin`` directory with the ``my-user-name.properties`` specified. :: kafka-topics \ --bootstrap-server :9092 \ --command-config ~/my-user-name.properties \ --topic test-topic-1 \ --create \ --replication-factor 1 \ --partitions 3 ------------------ Produce to a topic ------------------ To produce to a topic, you must have (minimally) DeveloperWrite role for that topic. You are not required to be an owner of the topic to produce to it. #. Grant the user permissions to access the topic. Use DeveloperWrite role on the topic resource. :: confluent iam rbac role-binding create \ --principal User: \ --role DeveloperWrite \ --resource Topic:test-topic- \ --prefix \ --kafka-cluster-id #. Produce to a topic using the kafka-console-producer tool. :: echo "test_message" | ./kafka-console-producer \ --broker-list :9092 \ --topic test-topic-1 \ --producer.config ~/my-producer-user.properties \ --property parse.key=false Any principal used by Idempotent producers must be granted IdempotentWrite on the cluster or Write permission on any topic to initialize the producer client. Binding either the DeveloperWrite or ResourceOwner RBAC roles on the |ak| cluster grants Write permission. Note that DeveloperWrite is the less permissive of the two roles, and is the first recommendation. The following role binding ensures that Write has access to the cluster: :: confluent iam rbac role-binding create \ --principal $PRINCIPAL \ --role DeveloperWrite \ --resource Cluster:kafka-cluster \ --kafka-cluster-id $KAFKA_CLUSTER_ID The previous example only grants the IdempotentWrite operation, which is a non-destructive operation. -------------------- Consume from a topic -------------------- To consume from a topic, you must have DeveloperRead access to both the topic resource and consumer group resource. If users require the ability to delete consumer groups, then also assign the ResourceOwner role on the consumer group prefix. Note that consume does not require additional |ak| permissions to be Idempotent consumers (as producers do). To view which privileges have already been granted for each role, run the following command: .. code-block:: text confluent iam rbac role describe #. Grant permission to topic resource. :: confluent iam rbac role-binding create \ --principal User: \ --role DeveloperRead \ --resource Topic:test-topic- \ --prefix \ --kafka-cluster-id #. Grant permission to the consumer group. To consume from a topic as a member of a consumer group, you must have access to the topic resource and consumer group resource. Grant the DeveloperRead role to the topic resource and consumer group resource. As mentioned in the previous step, assign the ResourceOwner role only if users require the ability to delete consumer groups. :: confluent iam rbac role-binding create \ --principal User:my-consumer-user \ --role DeveloperRead \ --resource Group:console-consumer- \ --prefix \ --kafka-cluster-id #. Consume using the kafka-console-consumer tool. :: ./kafka-console-consumer \ --bootstrap-server :9092 \ --topic test-topic-1 \ --consumer.config ~/my-consumer-user.properties \ --from-beginning \ --property parse.key=false Related Content --------------- - .. include:: ../../includes/kb/rbac-mds.rst