Home / Data Platform / Streaming & CDC

Data PlatformHow-toAdvanced

Rotate Kafka SCRAM passwords without downtime: two users, two mechanisms and re-authentication

Changing a SCRAM password in place breaks clients that still hold the old one. Overlap credentials with a second user or mechanism, then prove the old one is unused before deleting it.

Deepak Bhardwaj7 min read

Applies toApache Kafka 3.5+ in KRaft mode and 4.x with SASL/SCRAM; most steps also apply to Confluent Platform

Goal: replace a Kafka client's SCRAM password while producers and consumers keep running.

The trap is that Kafka stores one credential per user per mechanism. Setting a new password replaces the old one. Open connections keep working, so it looks fine until a pod restarts, a broker rolls or re-authentication runs. Then clients still holding the old password fail with SaslAuthenticationException.

Pick a method

Situation Method Overlap?
Any application user Two users, A and B, rotated in turn Yes
Listener already allows SCRAM-SHA-256 and SCRAM-SHA-512 Same user, new password on the second mechanism Yes
One small app, short outage accepted Change in place and restart the app No
Inter-broker user Second broker user and rolling restart Yes
Leaked password Create a replacement, then delete the old credential quickly Short

Use two users by default. It needs no listener change and gives a clean signal in the logs. The cost is that everything tied to the principal must be copied.

Check first

BS=kafka-1.prod.example.com:9093
ADMIN=/etc/kafka/admin.properties

# Which mechanisms and quotas does the user have?
kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --describe --entity-type users --entity-name orders-a

# ACLs to copy
kafka-acls.sh --bootstrap-server $BS --command-config $ADMIN \
  --list --principal User:orders-a

# Static broker settings that matter
grep -E 'sasl.enabled.mechanisms|connections.max.reauth.ms|super.users' \
  /etc/kafka/server.properties

Script names have no .sh suffix on Confluent packages. describe shows the mechanism and iterations, never the password. Rules for User:* may not appear in the list for one principal. If you use a custom authorizer, check there as well.

Method 1: two users

1. Create user B

Generate a password without special characters. Commas, brackets and quotes can break --add-config and JAAS parsing.

NEWPW="$(openssl rand -hex 24)"

kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --alter --entity-type users --entity-name orders-b \
  --add-config "SCRAM-SHA-512=[iterations=8192,password=${NEWPW}]"

Kafka's minimum iteration count is 4096. Write the password to your secret store now.

Warning

The password is visible in the process list while this runs. Use a restricted admin host and unset NEWPW when finished.

2. Copy ACLs and quotas

kafka-acls.sh --bootstrap-server $BS --command-config $ADMIN \
  --add --allow-principal User:orders-b --producer --topic orders

kafka-acls.sh --bootstrap-server $BS --command-config $ADMIN \
  --add --allow-principal User:orders-b --consumer --topic orders --group orders-svc

# Only if user A has a quota; use its value
kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --alter --entity-type users --entity-name orders-b \
  --add-config 'producer_byte_rate=10485760'

Add --transactional-id <id> to the producer command for transactional producers. Copy any hosts, prefixed patterns, deny rules and cluster permissions from the original list. User quotas are per principal, so A and B have separate allowances during the overlap.

3. Test B with the real group and topic

# orders-b.properties
security.protocol=SASL_SSL
sasl.mechanism=SCRAM-SHA-512
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="orders-b" password="REPLACE_ME";
ssl.truststore.location=/etc/kafka/ssl/client.truststore.jks
ssl.truststore.password=REPLACE_ME
kafka-broker-api-versions.sh --bootstrap-server $BS \
  --command-config orders-b.properties | head -3

kafka-topics.sh --bootstrap-server $BS --command-config orders-b.properties \
  --describe --topic orders

kafka-consumer-groups.sh --bootstrap-server $BS \
  --command-config orders-b.properties --describe --group orders-svc

The first command tests the login. The other two check topic and group access. Don't test by consuming with the live group ID: that joins the group and causes a rebalance.

4. Roll the clients

Update the secret and restart gradually. Keep group.id and transactional.id the same. Offsets belong to the group, not the user, so consumers resume from where they were.

kubectl -n orders rollout restart deployment/orders-svc
kubectl -n orders rollout status deployment/orders-svc --timeout=10m
kubectl -n orders logs deployment/orders-svc --since=10m \
  | grep -E 'SaslAuthentication|AuthorizationException' || echo "no auth errors"

kubectl logs deployment/... reads one pod; use a label selector or your log platform to check them all. A running client doesn't reread sasl.jaas.config when the secret changes, so the restart is required.

Method 2: second mechanism

If user orders has a SHA-256 credential and clients use it, add a SHA-512 credential with a new password:

kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --alter --entity-type users --entity-name orders \
  --add-config "SCRAM-SHA-512=[iterations=8192,password=${NEWPW}]"

The listener must have both mechanisms in sasl.enabled.mechanisms. Change the client's sasl.mechanism and password together. ACLs and quotas stay the same because the principal doesn't change. Rotate back the other way only if SHA-256 still meets your policy.

Prove the old credential is unused

Don't delete on faith. Check for at least one full cycle of batch jobs.

  • With the standard authorizer, search the authorizer log for the old principal. Allowed operations are logged at DEBUG, so absence at the normal log level proves nothing.
  • For method 1, check consumer group members for hosts you didn't restart.
  • For method 2, the principal is the same, so use each client's deployed sasl.mechanism as the evidence.
  • Ask owners about monthly jobs, Connect workers, MirrorMaker and desktop tools.
grep -h 'User:orders-a' /var/log/kafka/kafka-authorizer.log* | tail -5

kafka-consumer-groups.sh --bootstrap-server $BS --command-config $ADMIN \
  --describe --group orders-svc --members --verbose

Remove the old credential

Caution

After this, any client still using the credential fails on its next authentication. Keep the old password in the secret store until the soak period ends, so you can recreate it.

# Method 1
kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --alter --entity-type users --entity-name orders-a \
  --delete-config 'SCRAM-SHA-512'

# Method 2
kafka-configs.sh --bootstrap-server $BS --command-config $ADMIN \
  --alter --entity-type users --entity-name orders \
  --delete-config 'SCRAM-SHA-256'

Roll back by running --add-config with the saved password. Remove user A's ACLs after the soak period, not at the same time.

Existing connections are not closed

Credential changes apply to new authentications. connections.max.reauth.ms on the broker limits how long a SASL session can last; its default of 0 disables re-authentication. With a positive value, clients that support it re-authenticate before the session ends, and expired connections are closed when they are next used.

# server.properties: SASL sessions last at most one hour
connections.max.reauth.ms=3600000

Apply it with a rolling restart. Test old clients first: versions without re-authentication support will see periodic disconnects. If a password has leaked and this is 0, deleting the credential isn't enough. Under method 1, remove the old principal's ACLs or add deny ACLs too, since authorization is checked on each request.

Inter-broker users

Create the second broker user, give it the same cluster permissions or add it to super.users on every broker and controller, and roll that change out first. Only then change sasl.jaas.config to log in as the new user, one broker at a time.

Warning

Never change the inter-broker password in place. A broker that reconnects with the wrong password can't replicate. Wait for zero under-replicated partitions before each restart.

kafka-topics.sh --bootstrap-server $BS --command-config $ADMIN \
  --describe --under-replicated-partitions

KRaft controllers can't use SCRAM between themselves, because the credentials live in the metadata log they serve. Rotate that listener with its own method, such as mTLS or PLAIN.

Errors and fixes

Symptom Cause Fix
invalid credentials with SASL mechanism SCRAM-SHA-512 Wrong password, or no credential for that mechanism Describe the user; align mechanism and password
UnsupportedSaslMechanismException Mechanism not enabled on the listener Fix sasl.enabled.mechanisms and roll brokers
Login works, then TopicAuthorizationException ACLs not copied to user B Compare both ACL lists
Fails hours later Old client restarted or re-authenticated Restore the old credential, then find the client
Throughput drops after the switch User falls under a default quota Copy the user quota

Prevent it next time

  • Create A and B users for every application from day one and grant ACLs to both.
  • Keep users, ACLs and quotas in code so both stay identical.
  • Set a tested connections.max.reauth.ms so revocation has a known time limit.
  • Use a separate user per application. A shared user is much harder to rotate safely.
  • Alert on the broker's failed-authentication-rate metric, and record a rotation date for each secret.