Manage Service Accounts on Confluent Cloud

The sections below provide detailed instructions on managing service accounts in Confluent Cloud, including creating and managing service accounts using Confluent Cloud Console, ksqlDB Console, and Confluent CLI.

Required RBAC roles:

Add a service account

You can use the Cloud Console, Confluent CLI, or Confluent Cloud APIs to create service accounts.

  1. Go to the Confluent Cloud Console, expand the sidebar, and click Accounts & access.

  2. Click Service accounts.

  3. Click + Add service account.

    The Add a new service account page appears with the Service account view.

  4. Enter the name for the service account and a description.

  5. Under the Add service account owner role, you can optionally grant an account the ResourceOwner role by selecting the account type and then the account that you want to grant the ResourceOwner role.

    For OrganizationAdmin and AccountAdmin roles, this is unnecessary. For other roles, if the user does not assign themselves as a resource owner, they are unable to manage the account after it is created.

  6. Click Next.

    The Access view appears.

  7. Assign predefined RBAC roles to the Confluent Cloud resources you want to this service account to have access to.

    If no roles are assigned, the service account has no access to any resources.

    If your Confluent Cloud resources are not available, contact your administrator to get the necessary permissions.

  8. Click Next.

    The Review view appears.

  9. Click Create service account after reviewing the details.

The service account is created and added to the list of service accounts. You are redirected to the Service accounts listing on the Accounts & access page.

After creating a service account, you’ll need to create API keys for it to enable programmatic access. See Manage API Keys in Confluent Cloud for details.

The principal is assigned the role granting access to the service account.

Grant access to a service account

You can grant access to a service account for additional principals by assigning either the Assigner or the ResourceOwner role.

  1. Go to the Confluent Cloud Console, expand the sidebar, and click Accounts & access.

  2. Click Service accounts.

  3. Click the service account name to access the service account details page.

    The service account details page appears.

  4. Under Access to this service account, click + Add role assignment.

    The Role assignment on <service-account-name> page appears.

  5. Under Account type, select the account type to add to the service account and then select the account.

  6. Under Select role, select the Assigner or the ResourceOwner role.

    Note that if you do not assign an account with ownership of the service account, the service account you cannot access the service account after you create it.

  7. Click Save.

The principal is assigned the role granting access to the service account.

Delete a service account

Follow the steps below to delete a service account. Before deleting a service account, make sure to:

  1. Go to the Confluent Cloud Console, expand the sidebar, and click Accounts & access.

  2. Click Service accounts.

  3. Click the service account name to access the service account details page.

    The service account details page appears.

  4. Click Delete service account.

    The Delete service account confirmation page appears.

  5. Review the information and to confirm the deletion, enter the service account name under Name and then click Confirm.

The service account is deleted. You can verify that the service account is deleted by reviewing the list of service accounts.

End-to-end example: Create and manage service accounts using the Confluent CLI

The following example shows a typical end-to-end workflow that works for Confluent Cloud running on any cloud provider. Specifically, the example shows how to use the Confluent CLI to:

  • Create a Kafka cluster and make it active
  • Add topics in the cluster
  • Set up a service account and ACLs
  • Create an API key resource-scoped to the Kafka cluster
  1. Create a Confluent Cloud Kafka cluster (sales092020):

    confluent kafka cluster create sales092020 --cloud aws --region us-west-2 --type basic
    It may take up to 5 minutes for the Kafka cluster to be ready.
    +--------------+-----------------------------------------------------------+
    | ID           | lkc-abc123                                                |
    | Name         | sales092020                                               |
    | Type         | BASIC                                                     |
    | Ingress      |                                                       100 |
    | Egress       |                                                       100 |
    | Storage      |                                                      5000 |
    | Cloud        | aws                                                       |
    | Availability | single-zone                                               |
    | Region       | us-west-2                                                 |
    | Status       | UP                                                        |
    | Endpoint     | SASL_SSL://pkc-v8wpn.us-west-2.aws.confluent.cloud:9092   |
    | ApiEndpoint  | https://pkac-95yx5.us-west-2.aws.confluent.cloud          |
    +--------------+-----------------------------------------------------------+
    

    Note

    Make note of your cluster ID. You will need to specify it in subsequent steps. If at any time you are unsure of the ID, run the confluent kafka cluster list command to view all your Kafka clusters and corresponding cluster IDs.

  2. Make the newly-created Kafka cluster the active cluster:

    confluent kafka cluster use lkc-abc123
    Set Kafka cluster "lkc-abc123" as the active cluster for environment "env-123abc"
    
  3. Create topics (raw_pageview_data and analytics_enriched_events) in the Kafka cluster:

    confluent kafka topic create raw_pageview_data
    confluent kafka topic create analytics_enriched_events
    
  4. Create a service account named analytics. You must include a description:

    confluent iam service-account create analytics \
      --description "My API analytics and secrets service account"
    
    +-------------+---------------------------------------+
    | ID          | sa-1a2b3c                             |
    | Name        | analytics                             |
    | Description | My API analytics and secrets service  |
    |             | account.                              |
    +-------------+---------------------------------------+
    

    Tip

    Name requirements:

    • A maximum of 64 characters
    • Allowed character types:
      • Unicode characters from the following classes: letter, mark, and number.
      • Only the following special characters: hyphen (-), underscore (_), period (.), and colon (:).

    If you ever lose track of the service account ID, run confluent iam service-account list to retrieve it.

  5. Create a READ ACL for the topic raw_pageview_data.

    confluent kafka acl create --allow --service-account sa-1a2b3c --operations read --topic raw_pageview_data
      Principal        | Permission | Operation | ResourceType | ResourceName      | PatternType
    +------------------+------------+-----------+--------------+-------------------+------------+
      User:sa-1a2b3c   | ALLOW      | READ      | TOPIC        | raw_pageview_data | LITERAL
    

    Optionally, you can create ACLs using the --prefix option, which Kafka uses to match all resource names that are prefixed with the specified value. This example shows how to create a READ ACL that applies for all consumer groups that use the prefix keyreaders:

    confluent kafka acl create --allow --service-account sa-1a2b3c --operations read --prefix --consumer-group keyreaders
      Principal        | Permission | Operation | ResourceType | ResourceName      | PatternType
    +------------------+------------+-----------+--------------+-------------------+------------+
      User:sa-1a2b3c   | ALLOW      | READ      | GROUP        | keyreaders        | PREFIXED
    
  6. Create ACLs for all topics that use a specific prefix. This example shows how to specify a CREATE ACL for topics with the prefix analytics_. Running this command creates ACLs that provide CREATE and WRITE access to any topic whose name starts with analytics_:

    confluent kafka acl create --allow --service-account sa-1a2b3c --operations create --prefix --topic analytics_
      Principal        | Permission | Operation | ResourceType | ResourceName      | PatternType
    +------------------+------------+-----------+--------------+-------------------+------------+
      User:sa-1a2b3c   | ALLOW      | CREATE    | TOPIC        | analytics_        | PREFIXED
    
  7. Create a WRITE ACL to a analytics_enriched_events topic with a prefix:

    confluent kafka acl create --allow --service-account sa-1a2b3c --operations write --prefix --topic analytics_
      Principal        | Permission | Operation | ResourceType | ResourceName      | PatternType
    +------------------+------------+-----------+--------------+-------------------+------------+
      User:sa-1a2b3c   | ALLOW      | WRITE     | TOPIC        | analytics_        | PREFIXED
    
  8. Create an API key resource-scoped to the Kafka cluster for service account sa-1a2b3c. Be sure to replace the service account ID and Kafka cluster ID values shown here with your own:

    confluent api-key create --service-account sa-1a2b3c --resource lkc-abc123
    It may take a couple of minutes for the API key to be ready.
    Save the API key and
    API secret. The API secret is not retrievable later.
    +-------------+------------------------------------------------------------------+
    | API Key     | 12A3BCDEFGHI4JKL                                                 |
    | API Secret  | aB+c12dEfghiJkLMNopqr3StUVWxyzabCdEFGHiJ4kL5mnop6QrS78TUVwxyzaB9 |
    +-------------+------------------------------------------------------------------+
    

    Warning

    Save the API key and API secret. You require this information to configure your client applications. Be aware that this is the only time you can access and view the key and secret.

    Optionally, if you are using the Confluent Cloud Metrics or Health+ and you require a Confluent Cloud API key:

    confluent api-key create --service-account sa-1a2b3c --resource cloud
    It may take a couple of minutes for the API key to be ready.
    Save the API key and secret. The secret is not retrievable later.
    +-------------+------------------------------------------------------------------+
    | API Key     | AB1CDEF2GHI3J4KL                                                 |
    | API Secret  | j3Am6e+loCkCJUQ43iq9Es1z5KO7kKZQGmBvjg7jombv1PR0kxCvjsh6IDrz9LHY |
    +-------------+------------------------------------------------------------------+
    

    Note that ACLs are not supported against Confluent Cloud API keys.

Important

Client applications that connect to the Confluent Cloud cluster must have at least the following three parameters configured:

  • API key – available when you initially create the API key pair
  • API secret – available when you initially create the API key pair
  • bootstrap.servers – set to the Endpoint in the output of confluent kafka cluster describe

For details about Confluent CLI service account commands, see Confluent CLI.

Use Confluent Cloud service accounts to produce and consume

After creating a service account, you can use it to control application access to Confluent Cloud produce and consume topics:

# Produce to topic
confluent kafka topic produce <topic-service-account-writes-to>
# Consume from topic (-b consumes from beginning of topic)
confluent kafka topic consume -b <topic-service-account-reads-from>