Enable and configure SASL authentication for Apache Kafka®
Aiven for Apache Kafka® supports multiple authentication methods, including Simple Authentication and Security Layer (SASL) over SSL.
Enable SASL authentication
To allow clients to authenticate with SASL, enable kafka_authentication_methods.sasl
on your Aiven for Apache Kafka service.
- Aiven Console
- CLI
- API
- Terraform
- In the Aiven Console, select your Aiven for Apache Kafka service.
- Click Service settings.
- Scroll to Advanced configuration and click Configure.
- Click Add configuration options.
- Select
kafka_authentication_methods.saslfrom the list and set the value to Enabled. - Click Save configurations.
The Connection information on the Overview page now shows connection details for SASL and client certificate authentication.
SASL and client certificate connections use different ports. The host, CA, and user credentials remain the same.
Enable SASL authentication for your Aiven for Apache Kafka service using Aiven CLI:
-
Get the name of the Aiven for Apache Kafka service:
avn service listNote the
SERVICE_NAMEcorresponding to your Aiven for Apache Kafka service. -
Enable SASL authentication:
avn service update SERVICE_NAME -c kafka_authentication_methods.sasl=trueParameters:
SERVICE_NAME: Name of your Aiven for Apache Kafka service.kafka_authentication_methods.sasl: Set totrueto enable SASL authentication.
Use the ServiceUpdate API to enable SASL authentication on an existing service:
curl -X PUT "https://api.aiven.io/v1/project/{project_name}/service/{service_name}" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"user_config": {
"kafka_authentication_methods": {
"sasl": true
}
}
}'
Parameters:
project_name: Name of your Aiven project.service_name: Name of your Aiven for Apache Kafka service.API_TOKEN: Personal Aiven token.kafka_authentication_methods.sasl: Set totrueto enable SASL authentication.
Set the kafka_authentication_methods.sasl attribute in your aiven_kafka resource to true.
Configure SASL mechanisms
After enabling SASL authentication, choose which SASL mechanisms clients can use.
Supported mechanisms
Aiven for Apache Kafka supports the following SASL mechanisms:
-
PLAIN: Enabled by default. Controlled by
kafka_sasl_mechanisms.plain. -
SCRAM-SHA-256: Enabled by default. Controlled by
kafka_sasl_mechanisms.scram_sha_256. -
SCRAM-SHA-512: Enabled by default. Controlled by
kafka_sasl_mechanisms.scram_sha_512. -
OAUTHBEARER: Set
kafka.sasl_oauthbearer_jwks_endpoint_urlto enable OAuth 2.0/OIDC authentication.PLAIN,SCRAM-SHA-256, andSCRAM-SHA-512remain enabled by default. Each client selects one SASL mechanism when it connects.To allow only OAuth 2.0/OIDC authentication, disable
kafka_sasl_mechanisms.plain,kafka_sasl_mechanisms.scram_sha_256, andkafka_sasl_mechanisms.scram_sha_512.Optional OIDC parameters include
kafka.sasl_oauthbearer_expected_issuer,kafka.sasl_oauthbearer_expected_audience, andkafka.sasl_oauthbearer_sub_claim_name.
When SASL authentication is enabled, at least one SASL mechanism must be available.
OAUTHBEARER satisfies this requirement when
kafka.sasl_oauthbearer_jwks_endpoint_url is set. If you disable PLAIN,
SCRAM-SHA-256, and SCRAM-SHA-512 without setting
kafka.sasl_oauthbearer_jwks_endpoint_url, the update fails because no SASL mechanism
is available.
Enable or disable PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512
Use kafka_sasl_mechanisms to enable or disable these mechanisms using one of the
following methods.
- Aiven Console
- CLI
- API
- Terraform
-
In the Aiven Console, select your Aiven for Apache Kafka service.
-
Click Service settings.
-
Scroll to Advanced configuration and click Configure.
-
In the Advanced configuration window, configure PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512:
- To enable or disable PLAIN, set
kafka_sasl_mechanisms.plainto Enabled or Disabled. - To enable or disable SCRAM-SHA-256, set
kafka_sasl_mechanisms.scram_sha_256to Enabled or Disabled. - To enable or disable SCRAM-SHA-512, set
kafka_sasl_mechanisms.scram_sha_512to Enabled or Disabled.
- To enable or disable PLAIN, set
-
Click Save configurations.
Configure SASL mechanisms for your Aiven for Apache Kafka service using Aiven CLI:
-
Get the name of the Aiven for Apache Kafka service:
avn service listNote the
SERVICE_NAMEcorresponding to your Aiven for Apache Kafka service. -
Disable the SASL mechanisms that clients do not use. By default, PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512 are enabled. For example, to disable PLAIN authentication:
avn service update SERVICE_NAME \
-c kafka_sasl_mechanisms.plain=falseSCRAM-SHA-256 and SCRAM-SHA-512 remain enabled unless you disable them.
Parameters:
SERVICE_NAME: Name of your Aiven for Apache Kafka service.kafka_sasl_mechanisms.plain: Set totrueorfalseto enable or disable PLAIN.kafka_sasl_mechanisms.scram_sha_256: Set totrueorfalseto enable or disable SCRAM-SHA-256.kafka_sasl_mechanisms.scram_sha_512: Set totrueorfalseto enable or disable SCRAM-SHA-512.
Use the ServiceUpdate API to configure PLAIN and SCRAM mechanisms on an existing service:
curl -X PUT "https://api.aiven.io/v1/project/{project_name}/service/{service_name}" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"user_config": {
"kafka_sasl_mechanisms": {
"plain": false,
"scram_sha_256": true,
"scram_sha_512": true
}
}
}'
Parameters:
project_name: Name of your Aiven project.service_name: Name of your Aiven for Apache Kafka service.API_TOKEN: Personal Aiven token.kafka_sasl_mechanisms.plain: Set totrueorfalseto enable or disable PLAIN.kafka_sasl_mechanisms.scram_sha_256: Set totrueorfalseto enable or disable SCRAM-SHA-256.kafka_sasl_mechanisms.scram_sha_512: Set totrueorfalseto enable or disable SCRAM-SHA-512.
Use the kafka_sasl_mechanisms attribute in your aiven_kafka resource
to enable or disable PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512. Set each
mechanism to true or false:
- PLAIN:
kafka_sasl_mechanisms.plain - SCRAM-SHA-256:
kafka_sasl_mechanisms.scram_sha_256 - SCRAM-SHA-512:
kafka_sasl_mechanisms.scram_sha_512
Enable public CA certificates for SASL authentication
After you enable SASL authentication, you can enable public CA certificates for clients that cannot install or trust the default project CA.
Enable public CA certificates using one of the following methods.
- Aiven Console
- CLI
- API
- Terraform
-
In the Aiven Console, select your Aiven for Apache Kafka service.
-
Click Service settings.
-
Go to the Cloud and network section and click Actions > More network configurations.
-
In the Network configuration dialog:
- Click Add configuration options.
- Find
letsencrypt_sasl(orletsencrypt_sasl_privatelinkfor PrivateLink). - Select the configuration option.
- Set the value to Enabled.
- Click Save configurations.
The Connection information on the Overview page now supports SASL connections using either Project CA or Public CA.
Enable the public CA certificates for SASL authentication using the Aiven CLI:
-
List the services in your project to find your Aiven for Apache Kafka service name:
avn service listNote the
SERVICE_NAMEcorresponding to your Aiven for Apache Kafka service. -
Enable public CA certificates for SASL authentication:
avn service update SERVICE_NAME -c letsencrypt_sasl=trueFor PrivateLink, use
-c letsencrypt_sasl_privatelink=trueinstead.Parameters:
SERVICE_NAME: Name of your Aiven for Apache Kafka service.
Use the ServiceUpdate API to enable public CA certificates for SASL authentication on an existing service:
curl -X PUT "https://api.aiven.io/v1/project/{project_name}/service/{service_name}" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"user_config": {"letsencrypt_sasl": true}}'
For PrivateLink, use letsencrypt_sasl_privatelink instead of letsencrypt_sasl.
Parameters:
project_name: Name of your Aiven project.service_name: Name of your Aiven for Apache Kafka service.API_TOKEN: Personal Aiven token.letsencrypt_sasl: Set totrueto enable public CA certificates for SASL authentication.
This Terraform example enables SASL authentication and public CA for SASL on a Kafka service. It configures SCRAM-SHA-256 and includes a data source that outputs the SASL port for connections that use the public CA.
The complete example is available in the Aiven Terraform Provider repository on GitHub.
Loading...
To apply your Terraform configuration:
-
Initialize Terraform by running:
terraform initThe output is similar to the following:
Initializing the backend...
Initializing provider plugins...
- Finding aiven/aiven versions matching ">= 4.0.0, < 5.0.0"...
- Installing aiven/aiven v4.9.2...
- Installed aiven/aiven v4.9.2
...
Terraform has been successfully initialized!
... -
To create an execution plan and preview the changes, run:
terraform plan -
To deploy your changes, run:
terraform apply --auto-approve
-
The public certificate is issued and validated by Let's Encrypt, a widely trusted certification authority. For details, see How it works.
-
When enabling the public CA over a PrivateLink connection, network configuration may take several minutes before clients can connect. A new port must be allocated and the load balancer route table updated before clients can connect.
Related pages