Securing and Connecting Clusters

Securing and Connecting Clusters in Apache Kafka: A Kafka cluster concentrates risk in a way individual services do not.

A Kafka cluster concentrates risk in a way individual services do not. One orders topic can carry names, addresses, emails and payment references from every part of the business, and it retains them. An unauthenticated listener is not "an internal service with no auth" — it is a readable copy of the company's event history.

The three layers, and why all three are needed

 ENCRYPTION    ── is the traffic readable on the wire?          TLS
 AUTHENTICATION ── who is this client?                          SASL / mTLS
 AUTHORIZATION  ── what is this identity allowed to do?         ACLs

Each one alone is insufficient. TLS without authentication encrypts traffic from anyone. Authentication without ACLs means every authenticated client can read every topic — which, in a company with fifty services, is not a meaningful boundary.

Listeners and protocols

Brokers expose named listeners, each with a security protocol. Internal and external traffic usually get separate listeners.

ProtocolEncryptedAuthenticatedUse
PLAINTEXTNoNoLocal development only
SSLYesOptional, via mutual TLS client certificatesCertificate-based fleets
SASL_PLAINTEXTNoYesOnly inside an already-encrypted network path; rarely correct
SASL_SSLYesYesThe normal production choice

Inter-broker traffic has its own setting. Encrypting client traffic while brokers replicate in plaintext leaves the entire dataset exposed on the replication path, which is the highest-volume traffic in the cluster.

SASL mechanisms

MechanismHow it authenticatesNotes
PLAINUsername and passwordOnly over TLS. Credentials are typically static configuration, which makes rotation awkward
SCRAM-SHA-256 / SCRAM-SHA-512Salted challenge-response, credentials stored in the clusterGood default when you have no existing identity system; supports per-user rotation
GSSAPI (Kerberos)Kerberos ticketsFits organisations that already run Kerberos
OAUTHBEARERBearer tokens from an identity providerFits modern token-based platforms; centralises identity and expiry
mutual TLS (not SASL)Client certificateIdentity is the certificate subject; rotation means certificate management

The engineering question is not "which is most secure" but "which identity lifecycle can you actually operate". A mechanism you cannot rotate credentials for becomes a permanent shared secret in a config repository.

ACLs and least privilege

An ACL binds a principal, an operation, and a resource. The pattern that catches people out:

A consumer needs:
  Read  on the TOPIC(s) it consumes
  Read  on the GROUP it uses          ← forgotten constantly

A producer needs:
  Write on the TOPIC(s) it produces to
  (Describe is usually implied by Read/Write on the same resource)

A transactional producer also needs:
  Write + Describe on the TRANSACTIONAL_ID

A Kafka Streams application needs:
  Read on input topics, Write on output topics,
  Read on its group, and All on its internal topics
  (prefixed by application.id)

Missing the group ACL produces a confusing failure: the client authenticates successfully, then cannot join the group. Missing internal-topic permissions for Streams produces an app that starts and then dies on its first stateful operation.

Use prefixed ACLs to keep this manageable — grant a team All on topics prefixed with their domain rather than enumerating topics forever. Keep the superuser list tiny, and grant Create on the cluster to almost nobody.

Which brings us to the setting that belongs in every production cluster:

auto.create.topics.enable=false

With auto-creation on, a typo in a topic name creates a brand-new topic with default partition count and replication factor. The symptom is "my consumer reads nothing", with no error anywhere and no clue in the logs. With it off, the client gets an unknown-topic error, which is a far better afternoon. The same logic argues for delete.topic.enable being restricted rather than freely available.

Two more that are easy and worth doing: disable unclean.leader.election.enable (from Module 4 — it trades committed data for availability), and audit who holds cluster-level Alter since that covers configuration changes to every topic.

Cross-cluster replication

Sooner or later you need data in more than one cluster. Three legitimate reasons:

DISASTER RECOVERY            GEO-DISTRIBUTION            AGGREGATION

  primary ──► standby        eu-cluster ◄──► us-cluster    edge-1 ──┐
  (failover target)          (local reads, both ways)      edge-2 ──┼─► central
                                                           edge-3 ──┘

Replication runs as a set of connectors built on Kafka Connect (MirrorMaker 2), which copies records, topic configuration, and consumer-group offset checkpoints. Remote topics are conventionally prefixed with the source cluster's alias, so orders from cluster eu arrives as eu.orders. That prefix is deliberate: it prevents an infinite replication loop in active-active setups, and it means consumers must be prepared to read both local and remote topic names after a failover.

The caveat that shapes every failover plan

Offsets do not match across clusters. The target cluster's partitions are written independently; a record at offset 4,182,003 on the primary can be at a different offset on the standby. Anything that assumes offset equivalence is wrong.

 primary   orders-p0: [..., 4182001, 4182002, 4182003]
 standby   eu.orders-p0: [..., 913442, 913443, 913444]
                          same records, different offsets

Consequences to plan for:

  • You cannot copy __consumer_offsets verbatim. Replication tooling maintains a checkpoint mapping between source and target offsets, and can translate group offsets on the target. Treat translation as approximate: it lands you near the right place, not exactly on it.
  • Failover means duplicates, gap risk, or both. Replication is asynchronous, so at the moment of failure the standby is behind by some amount. That lag is your RPO, and it is never zero. Resuming slightly early means reprocessing; resuming late means missing records.
  • Idempotent consumers are a DR requirement, not a nicety. The design work from Module 3 is precisely what makes a failover survivable.
  • Timestamp-based positioning is often the more practical tool. Consumers can seek by timestamp on the target cluster, which is a business-meaningful position even when offsets are not comparable.
  • Failback is a project, not a button. Once the standby has taken writes, the clusters have diverged. Decide in advance whether you fail back by replicating in reverse or by rebuilding.

Active-active is harder than it looks

Two clusters both accepting writes for the same logical stream gives you local latency and no failover step, at the price of conflict semantics: two events for the same key written in two regions have no global order. Either partition ownership by region (each key is only ever written in one place), or make your consumers order-insensitive. Do not assume the replication layer resolves it, because it cannot.

A security review checklist

[ ] TLS on client listeners AND inter-broker traffic
[ ] SASL (or mTLS) so every client has an identity you can name
[ ] ACLs per principal: topics it reads, topics it writes, its own group
[ ] Prefixed ACLs for team-owned namespaces; tiny superuser list
[ ] auto.create.topics.enable=false
[ ] unclean.leader.election.enable=false
[ ] Credential rotation procedure that has actually been rehearsed
[ ] DR topology documented with an RPO derived from measured replication lag
[ ] Failover runbook that does not assume offsets match

Exercise: A company runs a single Kafka cluster on SASL_SSL with per-service SCRAM users, but every service's ACLs were granted as All on all topics "to unblock the migration". They now want a warm standby cluster in a second region with an RPO of five minutes. Describe the ACL changes you would make first and the failure each one prevents, then explain what the standby gives them and, precisely, what a consumer group must tolerate when it is restarted against the standby after a real failover.