Monedula

Markdown

Part VI · Reference

Kafka troubleshooting

TransactionalIdAuthorizationException (TRANSACTIONAL_ID_AUTHORIZATION_FAILED)

Kafka error · TRANSACTIONAL_ID_AUTHORIZATION_FAILED · not retriable

org.apache.kafka.common.errors.TransactionalIdAuthorizationException

The broker refused a request that names a transactional.id because the client's principal is not allowed to use that transactional id. A transactional producer needs Write on the TransactionalId resource, so the error usually appears at initTransactions(). Add an ALLOW Write ACL for the transactional id, then start a new producer.

Reproduce it in the playground

The moment it happenstx1 stops at TRANSACTIONAL_ID_AUTHORIZATION_FAILED. t+0.150s

tx1 sets transactional.id=tx-orders and sends its first record at 100. Nisshi 0.8.2 implements no transactions: it refuses a producer with a transactional.id at InitProducerId with TRANSACTIONAL_ID_AUTHORIZATION_FAILED, which is not retriable, so tx1 stops. The simulator draws no InitProducerId step and shows the refusal when the first batch is sent, at 150.

Open at this step: step 1, tx1 stops at TRANSACTIONAL_ID_AUTHORIZATION_FAILED

What it means

A producer that sets transactional.id identifies itself by that id in every transactional request: FindCoordinator for the transaction coordinator, InitProducerId, AddPartitionsToTxn, AddOffsetsToTxn and EndTxn. On a cluster with an authorizer, each of these is checked against ACLs on the TransactionalId resource, and the producer needs Write on it (Write implies Describe). When no ACL allows it, the broker answers TRANSACTIONAL_ID_AUTHORIZATION_FAILED (error code 53) and the client throws TransactionalIdAuthorizationException, most often from initTransactions(), the first call that uses the id. The error is fatal for that producer instance: its Javadoc says to close it. Writing the topics still needs Write on each topic, and sending consumer offsets in a transaction needs Read on the consumer group; those failures have their own errors, TopicAuthorizationException and GroupAuthorizationException. Nisshi (formerly Tansu), a Kafka-compatible broker, answers this code for a different reason: release 0.8.2 implements no transactions, so it refuses any producer that sets a transactional.id at InitProducerId with TRANSACTIONAL_ID_AUTHORIZATION_FAILED, whatever the ACLs. Scenario 12.1.7 shows it; the simulator shows the refusal at the first send of the producer, since it draws no InitProducerId step.

Likely causes, most common first

  1. No ACL on the transactional id. The cluster has an authorizer and an ACL for the topic, but none for the TransactionalId resource the producer names. Topic ACLs do not cover transactional ids, so a producer that works without transactions fails once it sets transactional.id.
  2. The id does not match the ACL. A literal ACL matches one exact transactional id. Applications that build the id from an instance number or a host name (orders-tx-1, orders-tx-2) need a prefixed ACL such as --resource-pattern-type prefixed --transactional-id orders-tx-, or every new instance is refused.
  3. The principal is not the one in the ACL. As for any ACL, the principal the broker sees must match exactly: with TLS client authentication it is the whole certificate name unless ssl.principal.mapping.rules shortens it.
  4. Nisshi 0.8.2: transactions are not implemented. On a Nisshi cluster a producer with a transactional.id stops at initTransactions() with TRANSACTIONAL_ID_AUTHORIZATION_FAILED, and no ACL changes that. Idempotent producers without a transactional.id are supported on both of its storage engines.

How to fix it

  • Read the denial in the broker's authorizer log: it names the principal, the operation (WRITE) and the resource (TransactionalId:LITERAL:orders-tx, for example) that was refused.
  • Grant it: kafka-acls.sh --bootstrap-server localhost:9092 --add --allow-principal User:orders-svc --producer --topic orders --transactional-id orders-tx adds Write and Describe on the transactional id next to the producer's topic rights.
  • Use a prefixed pattern when the ids carry an instance suffix: --resource-pattern-type prefixed --transactional-id orders-tx-.
  • Close the failed producer and create a new one once the ACL exists: the error is fatal to the instance that saw it.
  • On Nisshi 0.8.2, remove transactional.id and keep enable.idempotence=true, or write the transactions to a cluster that implements them.

What not to do

  • Removing transactional.id to make the error go away: the producer then loses atomic writes across partitions and exactly-once processing.

Does the client retry it?

No. TRANSACTIONAL_ID_AUTHORIZATION_FAILED (error code 53) is an authorization error, which the KafkaProducer Javadoc lists among the fatal ones: the producer cannot go on and must be closed. Fix the ACL, then create a new producer.

Configs involved

  • transactional.id A stable name that turns on transactions for a producer (and implies idempotence); a new producer that calls initTransactions() with the same id fences the older one.
  • authorizer.class.name The class brokers and controllers use to check each request against ACLs; empty by default, so nothing is checked, and org.apache.kafka.metadata.authorizer.StandardAuthorizer on a KRaft cluster.
  • ssl.principal.mapping.rules Rules that turn the distinguished name of a client TLS certificate into the user name ACLs match; by default the whole distinguished name is the principal.

Reproduce it in the simulator

Sources

All troubleshooting pages