Enable and configure SASL authentication
Aiven for Apache Kafka® provides multiple authentication methods to secure Kafka data, including Simple Authentication and Security Layer (SASL) over SSL.
Enable SASL authentication
- Aiven Console
- CLI
- API
- Access the Aiven Console and 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 in the Overview page now allows connections via SASL or Client certificate.
Although these connections use a different port, the host, CA, and user credentials remain consistent.
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://console.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.
Configure SASL mechanisms
After enabling SASL authentication, fine-tune the active SASL mechanisms for your Aiven for Apache Kafka service. By default, all mechanisms (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512) are enabled. Configure these settings only to disable any mechanisms.
- Aiven Console
- CLI
- API
-
Access the Aiven Console and select your Aiven for Apache Kafka® service.
-
Click Service settings.
-
Scroll to Advanced configuration and click Configure.
-
In the Advanced configuration window, set the corresponding
kafka_sasl_mechanismsvalue to eitherEnabledorDisabled:- PLAIN:
kafka_sasl_mechanisms.plain - SCRAM-SHA-256:
kafka_sasl_mechanisms.scram_sha_256 - SCRAM-SHA-512:
kafka_sasl_mechanisms.scram_sha_512
- PLAIN:
-
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 list
Note the SERVICE_NAME corresponding to your Aiven for Apache Kafka service.
-
Configure specific mechanisms:
avn service update SERVICE_NAME \
-c kafka_sasl_mechanisms.plain=true \
-c kafka_sasl_mechanisms.scram_sha_256=true \
-c kafka_sasl_mechanisms.scram_sha_512=trueParameters:
SERVICE_NAME: Name of your Aiven for Apache Kafka service.kafka_sasl_mechanisms.plain: Set totrueto enable the PLAIN mechanism.kafka_sasl_mechanisms.scram_sha_256: Set totrueto enable the SCRAM-SHA-256 mechanism.kafka_sasl_mechanisms.scram_sha_512: Set totrueto enable the SCRAM-SHA-512 mechanism.
Use the ServiceUpdate API to enable SASL authentication on an existing service:
curl -X PUT "https://console.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: API token for authentication.kafka_sasl_mechanisms.plain: Set totrueorfalseto enable or disable the PLAIN mechanism.kafka_sasl_mechanisms.scram_sha_256: Set totrueorfalseto enable or disable the SCRAM-SHA-256 mechanism.kafka_sasl_mechanisms.scram_sha_512: Set totrueorfalseto enable or disable the SCRAM-SHA-512 mechanism.
- At least one SASL mechanism must remain enabled. Disabling all results in an error.
OAUTHBEARERis enabled ifsasl_oauthbearer_jwks_endpoint_urlis specified.
Enable public CA for SASL authentication
After enabling SASL authentication, enable the public CA if Kafka clients cannot install or trust the default project CA.
- Aiven Console
- CLI
- API
- Terraform
-
Access the Aiven Console and select your Aiven for Apache Kafka service.
-
Click Service settings.
-
Go to the Cloud and network section, 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 for SASL authentication using the Aiven CLI:
-
List the services in your project to find the Kafka service name:
avn service listNote the
SERVICE_NAMEfor the Kafka service. -
Enable public CA for SASL authentication:
avn service update SERVICE_NAME -c CONFIG_NAME=trueParameters:
SERVICE_NAME: Name of your Aiven for Apache Kafka service.CONFIG_NAME: Name of the configuration parameter to set. Useletsencrypt_saslfor enabling public CA for SASL authentication via regular routes orletsencrypt_sasl_privatelinkvia PrivateLink connection.
Use the ServiceUpdate API to enable public CA for SASL authentication on an existing service:
curl -X PUT "https://console.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}}' # or letsencrypt_sasl_privatelink for PrivateLink
- Create or update your Aiven for Apache Kafka service resource:
resource "aiven_kafka" "example_kafka" {
plan = "business-4"
project = data.aiven_project.example_project.project
service_name = "example-kafka"
kafka_user_config {
letsencrypt_sasl = true # or letsencrypt_sasl_privatelink for PrivateLink
}
}
-
To find the correct
portto use for a specific route, use the read-onlycomponentslist with appropriate filters in theaiven_service_componentdata sourceFor example:
data "aiven_service_component" "sc1" {
project = aiven_kafka.kafka.project
service_name = aiven_kafka.example_kafka.service_name
component = "kafka"
route = "dynamic"
kafka_authentication_method = "sasl"
kafka_ssl_ca = "letsencrypt"
}
-
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