skip to content

How do you rotate broker TLS keys/certificates and CA trust without downtime?

level: principalimportance: should knowfreq 35%

answer

  1. leaf rotate = file-watch / KIP-226 dynamic reload, no restart
  2. CA rotate = add new CA first, remove old CA last
  3. trust must overlap during migration
  4. cross-sign / intermediate to shrink window
  5. automate short-lived PEM via cert-manager/Vault

basics

~20 s

Rotate leaf certs by updating each broker's keystore and reloading without a full restart — Kafka watches the keystore/truststore files and reloads them when the file changes (KIP-226 dynamic config / file watch). Rotate the CA by adding the new CA to every truststore first, migrating certs, then removing the old CA last.

solid answer

~50 s

Two rotations, handled differently. Leaf (broker) cert/key rotation: replace the keystore contents and let Kafka pick them up. Modern Kafka reloads SSL stores when the underlying file's last-modified changes (the SslEngineFactory / file-based store reload, exposed via KIP-226 dynamic broker config for ssl.keystore.* per listener), so you can swap a broker's cert without a process restart; clients re-handshake on new connections. CA (trust) rotation is the careful one and must be staged to overlap trust: (1) add the NEW CA cert to every truststore — broker and client — while keeping the old; (2) issue and deploy new leaf certs signed by the new CA across brokers; (3) only after everything trusts both and all leaves are migrated, remove the OLD CA from truststores. Doing it in the wrong order (e.g. removing the old CA or issuing new-CA leaves before truststores trust the new CA) drops connections. Keep cert lifetimes short and automate via cert-manager/Vault with PEM stores to make this routine.

go deeper

for a junior

Knows certs expire and must be replaced, and that a truststore must trust the signing CA.

for a middle

Can swap a broker keystore and add a CA to truststores; aware restarts may be avoidable.

for a senior

Performs zero-downtime leaf rotation via dynamic config and stages CA rotation with overlapping trust.

for a principal

Designs the PKI (intermediates/cross-signing), automates short-lived PEM issuance, and writes the fleet-wide rotation runbook covering inter-broker and mTLS.

## Two distinct things rotate 1. **Leaf certificate + private key** (a single broker's identity in its keystore). Rotated frequently (expiry, key compromise, hostname change). 2. **CA certificate** (the trust anchor in every truststore). Rotated rarely but high-stakes, because *everyone* trusts it. They demand different procedures. ## Leaf rotation (low risk, can be zero-downtime) Kafka can reload SSL stores dynamically: - **File-watch reload:** the file-based store loader tracks the keystore/truststore file's modification time and reloads when it changes — so atomically replacing the keystore file (write new, then rename over) makes the broker start presenting the new cert on subsequent handshakes, no restart. - **Dynamic broker config (KIP-226):** `ssl.keystore.location`/`ssl.keystore.password`/`ssl.key.password` (and the type/key/cert for PEM) are **per-listener dynamically updatable** via `kafka-configs.sh --alter --entity-type brokers`. Updating them triggers a reload of that listener's `SslEngineFactory`. Existing TLS connections keep their already-negotiated session; **new** connections use the new cert. Because Kafka clients reconnect/re-handshake over time (and on metadata refresh), the fleet converges without dropping traffic. To force faster convergence you can do a rolling reload broker-by-broker. ## CA rotation (high risk — must overlap trust) The invariant: **never have a peer present a certificate the other side doesn't yet trust, and never remove a CA that some live cert still chains to.** So stage it: **Phase 1 — distribute the new trust anchor.** Add the **new CA** certificate to *every* truststore (all brokers and all clients) alongside the old CA. Now both old- and new-CA leaf certs are trusted. Nothing presents the new CA yet. **Phase 2 — migrate leaf certs.** Roll each broker's keystore to a leaf cert signed by the **new CA** (using the dynamic reload above). Update client certs too if mTLS is in play. At all times every presented cert chains to a CA in everyone's truststore (old or new). **Phase 3 — retire the old CA.** Once *all* leaves are signed by the new CA and verified, remove the **old CA** from every truststore. Do this last, and only after confirming no live cert chains to it. If you reverse the order — e.g. issue new-CA leaves before truststores trust the new CA, or drop the old CA while old-CA leaves are still live — handshakes fail and connections drop. ## Cross-signing / intermediate strategy For large fleets, a **cross-signed** new CA (signed by the old CA) lets new-CA leaf certs validate under the existing trust anchor during transition, shrinking the truststore-distribution window. Equivalently, run a two-tier PKI (root + intermediates) and rotate intermediates while the root stays stable, so truststores rarely change. ## Inter-broker dimension Brokers are clients to each other for replication/controller traffic, so inter-broker connections must also tolerate the overlap: both old and new CAs trusted, leaf rotation rolled. The same phased order applies to the inter-broker listener. ## Automation & hygiene - Use **short-lived certs** issued by cert-manager / Vault PKI emitting **PEM** (KIP-651), so rotation is continuous and boring rather than a rare fire drill. - Monitor cert **expiry** and alert well ahead. - Test the rotation runbook in staging; the failure modes are connection storms, not data loss, but they're user-visible. ## Quick checklist - Leaf: swap keystore file / dynamic-config update → file-watch/SslEngineFactory reload → new connections use new cert. - CA: add new CA everywhere → migrate leaves → remove old CA last.

  • What is the correct ordering for a CA rotation across the cluster?
    Add the new CA to every truststore first; then migrate all leaf certs to the new CA; remove the old CA from truststores last. Reversing the order drops connections because something presents an untrusted cert or a still-live cert loses its trust anchor.
  • How can a broker pick up a new keystore without a restart?
    Kafka reloads file-based SSL stores when the file's modification time changes, and ssl.keystore.* are dynamically updatable per listener via KIP-226 (kafka-configs.sh --alter --entity-type brokers), which reloads the listener's SslEngineFactory. New connections use the new cert.
  • How does cross-signing simplify CA rotation?
    A new CA cross-signed by the old CA lets new-CA leaf certs validate under the existing trust anchor, so you don't have to distribute the new CA to every truststore before migrating leaves — shrinking the risky window.

saying these in an interview costs you the question

  • Removing the old CA before all leaf certs are migrated — live old-CA certs lose their trust anchor and connections fail.
  • Issuing new-CA leaf certs before truststores trust the new CA.
  • Assuming a full cluster restart is required to change a cert — Kafka supports dynamic/file-watch reload.
  • Forgetting the inter-broker listener and client mTLS certs during CA rotation.
  • Thinking leaf rotation and CA rotation follow the same procedure — they don't.

context