Encryption at Rest in Apache Kafka
How to protect the data Kafka stores on disk, why Kafka does not encrypt its own logs, the four practical approaches from volume encryption to client-side encryption, and how to manage keys, performance and operations safely.
Imagine a company that keeps its most sensitive paperwork in a filing room. The door has a good lock and a guard, which is like the login and permission checks on a Kafka cluster. Now imagine a burglar who does not go through the door at all. Instead, they lift the entire filing cabinet onto a truck and drive away. The guard and the lock made no difference, because the papers inside were written in plain language for anyone to read. If the papers had been written in a secret code, the stolen cabinet would be a heap of useless paper. Encryption at rest is that secret code for data that sits on disks.
This tutorial explains the topic from the ground up. We look at what “at rest” means, what Kafka stores on disk, what Kafka does and does not do about encryption by itself, and the practical options for protecting stored data. We then cover keys and their lifecycle, side effects on performance and features, operating routines, migration and monitoring. Every new term is explained the first time it appears, with an everyday comparison.
1Why Stored Data Needs Protection
Access controls guard the front door. Encryption at rest protects the data when someone gets around the door.
A quick Kafka refresher
Apache Kafka stores streams of events in topics. Producers write events, consumers read them, and brokers, the servers of the cluster, store and serve them. Unlike many messaging systems that delete a message once it is read, Kafka keeps events on disk for a configured time, which may be days, months or even indefinitely. That means a Kafka cluster is often one of the largest stores of business data in an organisation, containing orders, payments, customer activity and much more.
How stored data leaks
Attackers and accidents do not always come through the network. Stored data can be exposed in several quiet ways.
Stolen or lost hardware
A disk or server leaves the data centre through theft, loss or careless disposal.
Leaked snapshots and backups
A copy of a volume, made for backup or testing, ends up somewhere less protected than the original.
Recycled storage
Disks or cloud volumes that are reused or returned still hold traces of old data.
Misused administrator access
A person with access to the storage layer, but not meant to see the business data, reads files directly.
Think of moving house. A locked front door does not help if the removal van is left unattended with all your unpacked boxes in the open. Packing everything in sealed, coded containers means that even if the van is taken, the contents stay private.
2Three States of Data: In Transit, At Rest and In Use
Security people describe data as being in one of three states, and each needs its own protection.
In transit
Data moving across a network, between clients and brokers, or between brokers. Protected by TLS encryption.
At rest
Data sitting on disks or in storage, such as Kafka’s log files and backups. The subject of this tutorial.
In use
Data loaded into memory and being processed by programs. Protected by access controls, careful design and, in special cases, confidential computing hardware.
flowchart LR
P["Producer memory: in use"] -->|"Network: in transit, protected by TLS"| B["Broker memory: in use"]
B -->|"Written to disk: at rest"| D[("Log files on disk")]
D -->|"Read from disk"| B
B -->|"Network: in transit, protected by TLS"| C["Consumer memory: in use"]
A letter is in transit when the postman carries it, at rest when it sits in a drawer, and in use when someone is reading it at a desk. A sealed envelope protects it in the post, a locked drawer protects it in storage, and the reader’s privacy protects it during reading. Locking only the envelope leaves the drawer open.
Believing that turning on TLS protects stored data. TLS protects the network path only. The moment the broker writes the event to disk, the network protection has ended, and the stored file is readable unless separate at-rest protection exists.
3What Is Encryption at Rest?
The idea is simple to state: store data in a scrambled form that only someone holding the right key can turn back into readable data.
The building blocks
Encryption uses an algorithm, a mathematical recipe for scrambling data, and a key, a secret value that controls the scrambling. The original readable data is called plaintext, and the scrambled result is called ciphertext. With the correct key, decryption turns ciphertext back into plaintext. Without the key, the ciphertext is practically impossible to read, even for someone who knows the algorithm.
Symmetric encryption for stored data
Stored data is almost always protected with symmetric encryption, where the same key locks and unlocks. It is fast, which matters when large volumes of data are read and written. A widely used and trusted algorithm for this purpose is AES, and modern processors include special instructions that make it very fast.
Encryption at rest, in one sentence
Encryption at rest means that data is encrypted before it is written to storage and decrypted only when it is read by someone who is allowed to use the key.
A safe deposit box holds valuables that look like ordinary papers to anyone who steals the box, but a thief without the key cannot make sense of them. The lock is the algorithm, the key is the secret, and the papers inside are the plaintext turned into a puzzle.
The strength of encryption at rest is not in hiding the algorithm. It is in protecting the key. If the key sits next to the data, the encryption gives almost no protection.
4What Kafka Does and Does Not Do by Itself
This is the most important fact in the whole topic, and it often surprises newcomers.
Kafka does not encrypt its log files
Apache Kafka, in its open-source form, does not provide built-in encryption of the data it writes to disk. When a broker receives an event, it appends the bytes to a log file on the local file system exactly as received. If the file is copied, anyone with the copy can read the event contents using simple tools.
Why it was designed this way
Kafka’s performance comes from a very simple storage design: it appends to files and, when serving consumers, can pass data straight from the file system cache to the network without touching it. Adding encryption inside the broker would complicate this, cost performance, and raise difficult questions about where keys should live. The project leaves at-rest protection to layers below or above Kafka.
What Kafka does offer nearby
Encryption in transit
Kafka supports TLS for connections between clients and brokers and between brokers, protecting data on the network.
Authentication and authorization
Login checks and permission rules control who can read and write through Kafka. They do not protect the files themselves from someone who reaches the disk.
Encrypted dynamic secrets
Passwords stored in dynamic broker configuration can be kept in encrypted form using a secret configured for the broker. This covers those secrets, not event data.
Hooks for client-side protection
Serializers, interceptors and headers give client applications places to add their own encryption before data is sent.
Kafka is like a warehouse that stacks boxes quickly and hands them out on request. The warehouse has guards and a visitor log, but it does not seal the boxes. If you want the contents hidden, you either lock the whole building’s storage area, or pack the items in sealed containers before you send them.
A default Kafka installation stores event data in readable form on disk. If your policy requires encryption at rest, you must add it deliberately. It will not happen by turning on a Kafka setting.
5Where Kafka Data Actually Rests
Protecting data starts with knowing every place it is written. The broker’s main log is only part of the picture.
flowchart TB
subgraph BR["On each broker disk"]
L["Partition log segments: event data"]
I["Index and time index files"]
S["Producer state and snapshots"]
CP["Checkpoint files"]
M["Metadata log"]
IT["Internal topics: offsets, transactions"]
CF["Configuration and key store files"]
end
subgraph AROUND["Around the brokers"]
BK["Backups and volume snapshots"]
MR["Mirrored copies in other clusters"]
TS["Tiered storage in object stores"]
ST["Stream processing local state"]
CN["Connect internal topics and offsets"]
LG["Logs, dumps and exports"]
end
| Location | What It Contains | Sensitivity |
|---|---|---|
| Partition log segments | The actual event keys, values and headers | Highest: the business data itself |
| Index files | Offsets and timestamps, but not payloads | Low, but may reveal activity patterns |
| Internal topics for consumer offsets and transactions | Group names, positions, transactional identifiers | Moderate: reveals who consumes what |
| Metadata log | Topics, configurations and sometimes credential data | High: cluster structure and secrets |
| Configuration and key store files | Passwords, keys and certificates | Highest: unlocks other protections |
| Backups and snapshots | Full copies of the above | Same as the source, often less guarded |
| Tiered storage | Older log segments moved to object storage | Same as the log segments |
| Stream processing state stores | Aggregates and lookups derived from events | Often as sensitive as the events |
| Logs and dumps | Diagnostics that may include record contents | Variable, often forgotten |
When you secure a house, you do not only lock the front door. You also think about the garage, the shed, the spare key, the photographs on your phone and the copies of documents stored at a relative’s home. Data has many hiding places too.
Make a written inventory of every location where Kafka data or its derivatives are stored. Protection is only as good as the least protected copy.
6Who Are You Defending Against? The Threat Model
There is no single encryption that stops every threat. Picking the right approach starts with asking who might get at the data, and how.
Someone who steals or receives a disk or copy
A thief takes a drive, or a decommissioned volume is resold, or a backup copy leaks. Almost any at-rest encryption defeats this, provided the key is not stored with the data.
A cloud or storage administrator
Staff who manage the storage platform can see raw volumes but should not see business data. Encryption where the key is controlled by your organisation, not the platform, helps here.
A person with operating system access to a running broker
An administrator or an intruder logged into the broker machine sees decrypted data, because the disk is unlocked while running. Volume encryption alone does not stop this. Only encryption applied before the data reaches the broker does.
A user with valid Kafka credentials but the wrong permissions
This is an access control problem, not an encryption-at-rest problem, though client-side encryption can add a second barrier by making data unreadable without the decryption key.
Legal and regulatory demands
Rules and contracts may require encryption at rest, control over keys, or the ability to make data permanently unreadable on request. These shape which approach is acceptable.
flowchart TD
T["Threat"] --> A{"Stolen disk, snapshot or backup?"}
A -- "Yes" --> V["Volume or storage encryption helps"]
T --> B{"Administrator on the running broker?"}
B -- "Yes" --> C["Only encryption before data reaches the broker helps"]
T --> D{"Storage platform staff?"}
D -- "Yes" --> E["Customer-controlled keys or client-side encryption help"]
A locked safe protects the money from a burglar who carries the safe away, but not from the manager who has the combination and stands in the room. If you fear the manager, you must hide the money in a way the manager cannot open.
7The Four Layers Where You Can Encrypt
Since Kafka leaves the job to other layers, the practical question is which layer to use.
flowchart TB
L4["Layer 4: Application, client-side encryption of messages"] --> L3["Layer 3: Kafka broker, stores the bytes it receives"]
L3 --> L2["Layer 2: File system and operating system encryption"]
L2 --> L1["Layer 1: Disk, volume or cloud storage encryption"]
Disk and volume encryption
The whole storage device or cloud volume is encrypted. Transparent to Kafka and to applications.
File system encryption
The operating system encrypts files or directories, so protection is tied to the file system rather than the whole device.
Broker-level encryption
Not provided by open-source Kafka. Some commercial platforms and managed services add related features.
Client-side encryption
Producers encrypt messages, or selected fields, before sending. Only consumers with keys can decrypt.
| Layer | Protects Against | Does Not Protect Against | Effort |
|---|---|---|---|
| Volume or storage | Stolen disks, leaked snapshots, recycled storage | Anyone with access to the running broker | Low |
| File system | Stolen disks, some file-level access | Anyone with access to the running system | Medium |
| Client-side | Storage admins, broker admins, leaked copies, even broker compromise | Compromise of the client or its keys | High |
You can protect a letter by locking the entire mail room, locking the mailbox drawers, or writing the letter itself in code. The more inside the letter you go, the fewer people can read it, but the more work each writer and reader must do.
Many organisations use volume encryption for all data as a baseline, and add client-side encryption only for the most sensitive fields. The two layers complement each other.
8Option One: Disk and Volume Encryption
The most common and least disruptive approach is to encrypt the storage underneath Kafka.
How it works
Below the file system sits a layer that encrypts every block of data as it is written to the disk and decrypts it as it is read. Kafka and the file system see ordinary readable data, and the disk holds only ciphertext. On Linux, this is often done with a standard block-level encryption feature of the operating system. In cloud platforms, the provider offers encrypted volumes, where the encryption is turned on when the volume is created and keys are managed through the provider’s key service.
flowchart TB
K["Kafka broker writes readable data"] --> FS["File system"]
FS --> E["Encryption layer: encrypts on write, decrypts on read"]
E --> D[("Disk holds only ciphertext")]
KM["Key from a key management service"] -.-> E
Advantages
- No change to Kafka, clients or data formats
- Covers everything on the volume, including indexes, snapshots and internal topics
- Low overhead on modern processors with hardware acceleration
- Keeps Kafka’s efficient data transfer paths intact
- Easy to standardise across many clusters
Disadvantages / Trade-offs
- Data is decrypted for anyone who can read files on the running broker
- Does not stop misuse by a privileged administrator
- Key handling at boot needs planning
- Encrypting an existing unencrypted volume in place is often not possible
Volume encryption is like a self-locking filing room. When the last person leaves and the power is cut, the room seals itself. While people are working inside, the files are open on their desks, but a thief who removes the whole room finds only a sealed box.
Why it does not disturb Kafka’s speed
Kafka reads and writes files through the operating system’s cache. Volume encryption sits below that cache, so data stays in memory in readable form after it has been read once, and later reads do not need to be decrypted again. Efficient transfers of cached data to the network remain possible. The cost appears only when data moves between the cache and the physical disk, and hardware-accelerated encryption keeps that cost small.
Choose processors with hardware support for the encryption algorithm and confirm it is in use. Without it, the overhead can be noticeable on busy brokers. Test with your workload before rolling out.
9Option Two: File System Encryption
A related option encrypts at the level of files and directories instead of the whole device.
How it differs from volume encryption
Some operating systems can encrypt individual directories, so that only the Kafka data directory is protected while the rest of the machine is not. Files are encrypted when stored, and decrypted for programs that have the right access. It offers more flexibility, for example different keys for different directories, but it is generally less common for Kafka brokers than encrypting the whole volume.
Where it makes sense
Shared machines with mixed data
When a machine holds both sensitive Kafka data and other material, encrypting just the data directory can keep the setup simple.
Separate keys per directory
Where different topics or tenants are stored on different directories, separate keys allow finer control over which data can be unlocked.
Environments where whole-device encryption is not possible
Some storage setups do not allow device-level encryption, leaving file-level encryption as the practical choice.
Instead of locking the whole building, you lock just the drawer where the sensitive folders are kept. The rest of the office stays open, and you can give different drawers different keys.
File-level encryption can add more overhead than block-level encryption and may not be tested as widely with Kafka’s access patterns. Run performance tests, and check that all Kafka files, including snapshots and indexes, are inside the protected area.
10Option Three: Cloud Storage and Managed Kafka Services
If you run Kafka in the cloud or use a managed service, much of the work is done by the platform, but you still choose the key model.
Encrypted cloud volumes
Cloud providers offer encrypted disks, usually with a simple switch at creation time and integration with their key management service. The provider handles the mechanics. For self-managed Kafka on virtual machines, this is often the easiest route to encryption at rest, and many organisations make encrypted volumes mandatory through policy.
Managed Kafka services
Managed Kafka offerings from cloud and Kafka vendors typically encrypt stored data by default, using keys managed by the provider. Many also allow you to bring or control your own keys, so that you can revoke the provider’s ability to read the data. The details, such as which key options exist and whether they cover all storage tiers, differ between providers and change over time, so verify them in the current documentation of your chosen service.
Who holds the key?
| Key Model | Who Controls the Key | Benefit | Caution |
|---|---|---|---|
| Provider-managed key | The cloud or Kafka provider | Zero effort, on by default | You depend fully on the provider’s controls |
| Customer-managed key in the provider’s key service | You, through policies in the provider’s key service | You can restrict or revoke access, and audit key use | If you disable or lose the key, the data becomes unreadable |
| Externally held key | You, in a system outside the provider | Highest control over key location | Greater complexity and a dependency on availability of your own key system |
Renting a storage unit from a company that locks it for you is easy but you trust the company. Renting one where you bring your own padlock and keep the only key gives you more control, and also more responsibility if you lose the key.
With customer-managed keys, accidentally deleting, disabling or losing access to the key makes the encrypted data permanently unreadable. Protect key policies and deletion rights with the same care as the data itself.
11Option Four: Client-Side (End-to-End) Encryption
The strongest approach encrypts the message before it ever reaches Kafka, so Kafka never sees the readable data.
How it works
The producer application encrypts the sensitive part of each event, or the whole payload, before sending it. Kafka receives, stores, replicates and delivers ciphertext, without knowing what it means. Consumer applications that have access to the right key decrypt the data after reading. Anyone who reads the brokers’ files, the network traffic or the backups sees only ciphertext.
sequenceDiagram
participant P as Producer
participant K as Key service
participant B as Kafka broker
participant C as Consumer
P->>K: Request encryption key
K-->>P: Key
P->>P: Encrypt the sensitive data
P->>B: Send ciphertext
B->>B: Store and replicate ciphertext only
B-->>C: Deliver ciphertext
C->>K: Request decryption key
K-->>C: Key, if permitted
C->>C: Decrypt the data
Where the encryption plugs in
Applications can add encryption in their own code before calling the producer, or use hooks built into Kafka’s client libraries such as serializers or interceptors. Some platforms provide ready-made features for this, for example field-level encryption defined alongside schemas and applied by the client libraries. Details vary by product and version, so check what your platform offers before building your own.
Advantages
- Protects against storage admins, broker admins and stolen copies alike
- Data stays protected even if the broker is compromised
- Can encrypt only the sensitive fields
- Enables per-customer or per-topic keys and precise revocation
- Also protects backups, mirrors and tiered copies automatically
Disadvantages / Trade-offs
- Every producer and consumer must handle encryption correctly
- Key access becomes a dependency for every application
- Broker-side features that inspect data no longer work on encrypted parts
- Extra CPU cost and larger messages
- Bugs or key loss can make data unrecoverable
Instead of trusting the courier company not to peek, you write your letter in code before handing it over. The couriers, the sorting office and the storage depot all handle it without being able to read it, and only the intended recipient with the code book can.
12Envelope Encryption and Key Hierarchies
Real systems do not use one key for everything. They use layers of keys, which makes rotation and control practical.
The problem with a single key
If one master key encrypted all data directly, using it would mean sending large amounts of data to the key service, or spreading the master key across many machines, which is risky. Changing that key would mean re-encrypting everything.
The envelope idea
In envelope encryption, data is encrypted with a data key, a key that is generated for a specific purpose such as one topic, one customer or one batch. The data key is then itself encrypted with a stronger key held in a key management service, called the key-encrypting key. The encrypted data key is stored alongside the data, like a sealed envelope stapled to the document. To read the data, an application asks the key service to unwrap the data key, and then uses it locally.
flowchart TB
MK["Root or master key: inside a key service or hardware module"] --> KEK["Key-encrypting key: wraps data keys"]
KEK --> DK1["Data key for topic A"]
KEK --> DK2["Data key for topic B"]
KEK --> DK3["Data key for customer 42"]
DK1 --> D1["Encrypted data for topic A"]
DK2 --> D2["Encrypted data for topic B"]
DK3 --> D3["Encrypted data for customer 42"]
A hotel has one grand master key locked in the manager’s safe. The manager gives each floor a floor key, and each room has its own key. Losing one room key does not expose the whole hotel, and replacing a floor key does not require changing every lock in the building.
Cheap rotation
Rotating the wrapping key means re-wrapping small data keys, not re-encrypting all the data.
Limited blast radius
A leaked data key exposes only the data it protects, not everything.
Fewer key service calls
Applications fetch and cache data keys instead of calling the key service for every message.
Fine-grained control
Access to individual data keys can be granted, audited and revoked separately.
Volume encryption in the cloud uses the same idea internally: the volume has its own data key, wrapped by a key in the provider’s key service.
13Key Management: The Real Work
Encryption moves the security problem from the data to the keys. Managing keys well is what decides whether encryption at rest is real or cosmetic.
Where keys should live
Keys belong in a dedicated key management service or hardware security module, a tamper-resistant device or service designed to hold keys and perform cryptographic operations without exposing the keys themselves. They should never be stored on the same disk as the data they protect, or in configuration files in shared repositories.
The lifecycle of a key
Generation
Keys are created using strong random sources inside the key service, never invented by hand or derived from guessable text.
Distribution and use
Applications and volumes receive only the access they need, through policies tied to their identities, and every use is logged.
Rotation
Keys are replaced on a schedule and after any suspected exposure. New data uses the new key, and old keys remain available to read old data until it is re-encrypted or expires.
Backup and recovery
Key material is backed up securely, with strict controls, because losing a key means losing all data encrypted with it.
Revocation and retirement
Compromised or unneeded keys are disabled. Retirement is planned so that no data still needed depends on a key that is being removed.
Destruction
Keys are deleted only when data protected by them has been deleted, moved or intentionally made unreadable, and with approval.
Key management is like looking after the keys to a bank vault. They are cut in a secure place, handed to named people, changed regularly, duplicated safely for emergencies, taken away from leavers, and destroyed only when the vault is emptied.
Separation of duties
The people who administer Kafka and the people who control the keys should ideally be different, with different accounts and approvals. If a single person can both read the encrypted files and obtain the key, the separation that encryption is meant to create disappears.
Keeping the key in a file on the very machine that holds the encrypted data, just to make restarts easy. A thief who takes the machine or its disk takes both, and the encryption protects nothing.
14Side Effects of Client-Side Encryption on Kafka Features
Because Kafka can no longer read encrypted parts of a message, some features behave differently. Knowing this early saves painful redesigns.
Compression becomes ineffective
Encrypted data looks random, so compression algorithms cannot shrink it. If compression matters, compress the data first and then encrypt it, inside the application, or encrypt only small sensitive fields and let the rest compress normally.
Keys and partitioning
Kafka uses the message key to choose a partition and to decide which records to keep in compacted topics. If the key is encrypted with a method that gives a different result every time, records for the same entity are scattered across partitions and compaction cannot work. Either keep the key readable, use a non-sensitive identifier as the key, or use a method that always produces the same ciphertext for the same key, which has its own trade-offs.
Schema validation and schema registries
Checks that look at message structure, on the client or the broker, cannot see inside encrypted parts. Encrypt individual fields inside a structured message, rather than the whole message, so the structure remains checkable.
Stream processing and filtering
Programs that filter, route or aggregate by field values cannot use fields that are encrypted unless they decrypt them first, so they need key access too.
Debugging and support
Engineers can no longer look at messages with simple tools to diagnose problems. Provide controlled, audited ways to decrypt samples for troubleshooting.
Headers and metadata
Message headers can carry the information needed to decrypt, such as the key identifier and algorithm version. Keep sensitive facts out of headers, since headers are usually left readable.
| Kafka Feature | Effect of Encrypted Payloads | Common Remedy |
|---|---|---|
| Compression | Little or no size reduction | Compress before encrypting, or encrypt only sensitive fields |
| Partitioning by key | Breaks if keys are encrypted randomly | Keep a non-sensitive key, or use deterministic methods carefully |
| Log compaction | Needs stable keys | Keep keys readable or stable |
| Schema checks | Cannot inspect encrypted parts | Field-level encryption inside a checkable structure |
| Filtering and joins | Cannot use encrypted fields | Decrypt in the processing application, or use separate readable fields |
If you put a letter inside a coded envelope, the sorting office can no longer read the address on the letter itself. It can still sort by the address on the outside of the envelope, which you deliberately leave readable. Deciding what stays on the outside is the design task.
15Crypto-Shredding: Deleting Data from an Immutable Log
Kafka logs are designed to be append-only, which makes deleting one person’s data difficult. Encryption offers a clever way around it.
The deletion problem
Privacy rules in many regions give people the right to have their personal data erased. In a Kafka topic, events are stored in segments that are not edited in place, and copies may exist on replicas, in backups, in mirrored clusters and in downstream systems. Finding and deleting every copy of one person’s events is slow and error-prone.
The crypto-shredding idea
If each person’s data is encrypted with a key unique to that person, then deleting that key makes every copy of their data, wherever it sits, permanently unreadable at once. The encrypted bytes may remain, but they are indistinguishable from random noise. This technique is called crypto-shredding.
flowchart LR
A["Erasure request for customer 42"] --> B["Delete customer 42's key in the key service"]
B --> C["All copies of customer 42's data become unreadable"]
C --> D["Logs, replicas, backups and mirrors"]
B --> E["Other customers unaffected"]
Imagine every person’s diary is locked with its own padlock, and copies of the diaries are scattered around many cupboards. Instead of hunting down each copy, you melt the one key that opens that person’s padlock. Every copy becomes a locked box that can never be opened.
Advantages
- Erases data across replicas, backups and mirrors in one action
- Works with an append-only log
- Fast and auditable
- Does not disturb data of other people
Disadvantages / Trade-offs
- Requires a key per person or per subject, which adds management effort
- Only works if the personal data is always encrypted before reaching Kafka
- Legal acceptance of the technique varies, so confirm with your compliance team
- Accidental key deletion is irreversible
Crypto-shredding works only if no readable copy of the data exists elsewhere, such as in a log file, a cache or a derived topic. Decide early which systems may hold plaintext, and make sure erasure covers them too.
16Performance and Cost
Encryption is never completely free, but each layer has a different price, and most of it is small when done well.
Low CPU cost
Hardware-accelerated encryption adds a small cost when data moves between memory and disk. Cached reads are not affected.
CPU on every client
Producers and consumers spend CPU time encrypting and decrypting, and this scales with message volume and size.
Larger messages
Encryption adds overhead such as initialisation values and authentication tags, plus wrapped keys, making each message a little larger.
Calls to the key service
Key fetches add latency and cost, especially if not cached, and the service must be highly available.
Keeping the overhead in check
Encrypt only what needs it
Encrypting a few sensitive fields costs far less than encrypting entire large messages, and preserves compression and inspection for the rest.
Cache data keys
Fetch a data key once and reuse it for many messages within a defined lifetime, instead of calling the key service per message.
Use hardware acceleration
Make sure the processors and libraries in use take advantage of hardware encryption instructions.
Compress before encrypting
If you must encrypt whole payloads, compress first. Compressing afterwards achieves nothing.
Test with your own data
Measure throughput and latency with realistic message sizes and rates, before and after enabling encryption, to know the real cost.
Putting every item in a locked box takes time at both ends. Locking only the valuable items, and keeping the box keys in your pocket instead of fetching them from the bank each time, keeps the routine quick.
Actual overhead depends on hardware, message sizes and design. Test with your own workload before deciding, and treat published numbers as rough guidance only.
17Beyond the Broker Log: Streams State, Connect, Tiered Storage and Backups
Data spreads to many places around Kafka. Each one needs its own answer to the at-rest question.
Kafka Streams local state
Stream processing applications keep local state stores on the machines where they run, holding aggregates and lookups derived from events. Encrypt the volumes those applications use, and remember their backup topics are ordinary Kafka topics that follow the same protection as any other topic.
Kafka Connect internal topics and offsets
Connect stores its configurations, offsets and status in Kafka topics. Connector configurations may include passwords, so use secret providers rather than putting secrets directly into configurations.
Tiered storage
In recent Kafka versions, older log segments can be moved to remote object storage to save broker disk. Those objects hold the same data as the local segments and need their own at-rest protection, typically through the object store’s encryption with keys you control. Confirm that your version and remote storage plug-in support what you need.
Backups and volume snapshots
Snapshots taken from encrypted volumes stay encrypted in most cloud platforms, but check that backups copied elsewhere retain encryption and that their keys are available for restore.
Mirrored and replicated clusters
Data copied to another cluster is stored there in whatever form that cluster uses. The target cluster needs at least the same level of protection as the source.
Logs, dumps and exports
Debug logs, memory dumps and data exports for analysts may hold readable event data. Control where these go, encrypt them and delete them when no longer needed.
flowchart LR
BR[("Broker volumes: encrypted")] --> TS[("Tiered storage in object store: encrypted with managed keys")]
BR --> BK[("Backups and snapshots: encrypted")]
BR --> MR[("Mirrored cluster volumes: encrypted")]
BR --> ST[("Stream processing state volumes: encrypted")]
A business that locks its head office but leaves photocopies of key documents in a branch office, a storage unit and an employee’s briefcase has not really protected its documents. Every copy needs protection.
18Protecting Secrets in Configuration Files
Encrypted data is safe only if the passwords and keys that unlock it are not lying around in plain sight.
What secrets Kafka configuration holds
Broker and client configuration files often contain passwords for key stores and trust stores, credentials for authentication, and secrets for connecting to other systems. Left in plain text in files that are shared, copied or committed to repositories, they undermine every other protection.
Ways to reduce exposure
External configuration providers
Kafka can read sensitive settings from protected files or directories at start-up through configuration providers, so the main configuration holds only a reference. These can be connected to a secrets manager.
Encrypted dynamic broker settings
Password-type settings that are changed dynamically are stored in encrypted form, using a secret supplied to the broker. Protect that secret carefully, and do not change it casually since it is needed to read the stored values.
Restricted file permissions
Configuration files and key stores should be readable only by the account running the broker, and stored on encrypted volumes too.
Keep secrets out of repositories
Never commit real passwords or keys to code repositories, even private ones. Use templates with placeholders and inject values at deployment time.
Rotate after exposure
If a secret may have been seen by someone who should not have seen it, treat it as compromised and replace it.
A strong safe is useless if the combination is written on a sticky note on the door. Secrets in configuration are the sticky notes of the digital world.
Encrypting the data volumes carefully while leaving the key store password in a plain configuration file on the same volume, mounted and readable for anyone who gets access to the running machine.
19Operating Encrypted Brokers: Boot, Restart and Recovery
Encryption changes routine operations. Restarts and disasters need thought in advance.
Unlocking volumes at boot
An encrypted volume must be unlocked before Kafka can use it. In the cloud, this often happens automatically when the volume is attached, based on the machine’s permission to use the key. On self-managed hardware, the options range from typing a passphrase, which does not scale, to network-based unlocking services or hardware-backed keys that release the secret only to a trusted, unmodified machine.
sequenceDiagram
participant M as Machine starts
participant K as Key service
participant V as Encrypted volume
participant B as Kafka broker
M->>K: Prove identity, request volume key
K-->>M: Key released if policy allows
M->>V: Unlock volume
V-->>M: Volume available
M->>B: Start Kafka using the volume
What if the key service is unavailable?
If a broker restarts while the key service cannot be reached, it may be unable to unlock its volume and will stay down. If many brokers restart at once, for example after a power failure, the cluster cannot recover until the key service returns. Design the key service for high availability, test restarts, and avoid restarting all brokers simultaneously.
Disaster recovery
Keys must be recoverable elsewhere
A disaster recovery site needs access to the keys, or to replicated key material, or the backups cannot be read. Test a full restore, including key access, from time to time.
Regional key services
If keys live in a single region and that region fails, encrypted data elsewhere may be unreadable. Use multi-region keys or replicated key material where the design requires it.
Replacement machines
When a broker machine is lost, replacing it means creating a new encrypted volume and letting replication fill it. New volumes must be created encrypted by policy, not by memory.
A bank vault with a time lock opens automatically each morning only if the central office sends the code. If the central office is closed due to a storm, no branch can open. Good banks plan for that day.
20Migrating a Running Cluster to Encrypted Storage
Most teams adopt encryption at rest on clusters that are already serving traffic, and the trick is to let Kafka’s own replication do the heavy lifting.
flowchart TD
A["Stage 1: Inventory data locations and choose the approach"] --> B["Stage 2: Set up the key service, policies and access"]
B --> C["Stage 3: Add new brokers with encrypted volumes"]
C --> D["Stage 4: Move partition replicas to the new brokers"]
D --> E["Stage 5: Remove the old brokers and wipe their disks"]
E --> F["Stage 6: Encrypt backups, mirrors, tiers and state stores"]
F --> G["Stage 7: Verify, monitor and document"]
Decide and inventory
Choose volume, file system or client-side encryption, or a combination, and list every data location that will be covered.
Prepare keys and policies
Create keys, define who and what may use them, and enable logging of key use. Test unlocking on a non-production machine.
Add encrypted brokers
Bring new brokers into the cluster with encrypted volumes from the start. They join like any other broker.
Move data by reassigning replicas
Use Kafka’s partition reassignment to move replicas from old brokers to the new ones, in controlled batches, while watching load and replication health.
Retire old brokers safely
Once no replicas remain on them, shut down the old brokers, and securely destroy or wipe their disks and any old snapshots.
Cover the surroundings
Apply encryption to backups, mirrored clusters, tiered storage and stream processing state, using the same key policies.
Verify and document
Check that no unencrypted volume or copy remains, record the key owners and procedures, and add the checks to regular audits.
Instead of rebuilding a busy shop around its customers, you open a new secure shop next door, move the stock across shelf by shelf while trading continues, and then close and clear out the old shop properly.
Moving replicas adds network and disk load. Throttle the movement, do it outside peak hours, and monitor under-replicated partitions throughout.
21Compliance and Governance
For many organisations, encryption at rest is not optional. It is a requirement written into policies, contracts and regulations.
Why rules ask for it
Standards and laws covering payment card data, health records, personal data of individuals and financial services commonly expect that stored sensitive data is protected, and that encryption is one accepted way to do so. The exact wording, scope and accepted methods differ between rules and regions, so involve your compliance and legal teams and record how your design meets each requirement.
What auditors usually ask
What is encrypted?
Evidence that all locations holding sensitive Kafka data are covered, including backups and copies.
With what strength?
Proof of accepted algorithms and key sizes, and that they are current.
Who controls the keys?
Documented ownership, separation of duties and access policies for key use.
How are keys rotated and recovered?
Schedules, procedures and evidence that they are followed and tested.
How is access logged?
Audit trails of key use and of administrative actions on the cluster.
How is data deleted?
Retention rules, and methods such as crypto-shredding or secure disposal of media.
Data classification
Classify topics by sensitivity, and apply stronger protection to the more sensitive ones. Not every topic needs client-side encryption, but every topic should have a clear classification.
Policy as code
Use automated checks to make sure every new volume is encrypted and every new sensitive topic has the right controls. This avoids relying on memory.
Documented exceptions
If some environments, such as short-lived test clusters, are not encrypted, record the reasoning, the data allowed there and the expiry of the exception.
Auditors are like building inspectors. They do not just ask whether there are locks. They ask where each lock is, who holds each key, how often locks are changed and whether records exist to prove it.
22Monitoring and Auditing Encryption at Rest
A control you do not check drifts away. A small set of signals keeps encryption honest.
| Signal | What It Tells You | Typical Response |
|---|---|---|
| Volumes without encryption enabled | Configuration drift or a new unprotected machine | Alert and remediate immediately, then find the root cause |
| Key service errors and latency | Risk to unlocking, decryption and startup | Investigate availability, quotas and network paths |
| Key access logs | Who and what is using keys, and when | Review for unusual users, times or volumes |
| Key age and rotation status | Keys overdue for rotation | Rotate and update the schedule |
| Decryption failures in consumers | Missing key access, wrong key version or corrupted data | Check key policies and message key identifiers |
| Disk and CPU performance after enabling encryption | Encryption overhead in practice | Tune, use hardware acceleration or resize |
| Backups without encryption | Copies outside protection | Fix backup settings, then re-check restores |
| Old volumes and snapshots still present | Leftover plaintext after migration | Wipe or delete with approval and record it |
Regular verification
Schedule periodic checks that inspect the actual state of volumes, buckets and backups, not just the documents describing them. Where possible, test that a copy of a data file is truly unreadable without the key, and test restores from encrypted backups.
Alerts worth having
Alert when a new volume appears without encryption, when key use spikes or comes from a new identity, when a key is scheduled for deletion, when keys pass their rotation dates, and when key service errors rise.
A security guard does not just install locks. They walk the corridors each night to test that the doors are actually shut, and they read the key log to see who used the master key.
23Design Patterns and Anti-Patterns
Habits that keep encrypted Kafka platforms safe and workable, and the traps that quietly defeat them.
Patterns worth adopting
Encrypt every volume by default
Make encryption on storage the default for all brokers, and enforce it by policy so no unencrypted volume can be created.
Layer client-side encryption for the crown jewels
Use field-level encryption for the most sensitive data, such as national identifiers or card numbers, and leave the rest to volume encryption.
Envelope encryption with per-purpose keys
Use separate data keys for topics or customers, wrapped by keys in a managed key service, so rotation and revocation are cheap and precise.
Separate key custody from cluster administration
Give key control to a different team or role than day-to-day Kafka operations, with approvals for sensitive actions.
Anti-patterns to avoid
Problem
Assuming that enabling TLS or authentication also encrypts data on disk.
Why It’s Harmful
Stored data remains readable in files, snapshots and backups. A stolen disk or copy exposes everything despite the network protections.
Correct Approach
Treat in-transit and at-rest as separate requirements, and implement each explicitly.
Problem
Storing the encryption key on the same machine or volume as the encrypted data.
Why It’s Harmful
Anyone who obtains the machine or its disk obtains the key too, so the encryption offers little protection.
Correct Approach
Keep keys in a separate key management service or hardware module with strict access policies.
Problem
Encrypting the primary volumes but ignoring backups, mirrors, tiered storage and diagnostic dumps.
Why It’s Harmful
Attackers go for the weakest copy. A single unencrypted backup exposes the same data that the primary encryption was meant to protect.
Correct Approach
Inventory every place data rests, and apply and verify encryption at each one.
Problem
Encrypting message keys with a method that gives a different result each time, in topics that use keys for partitioning or compaction.
Why It’s Harmful
Records for the same entity spread across partitions, ordering is lost and compaction cannot keep the latest value.
Correct Approach
Keep a non-sensitive, stable key, and encrypt the sensitive content in the value instead.
Problem
Having no tested plan for key loss, key service outages or disaster recovery.
Why It’s Harmful
A lost or unreachable key means permanently unreadable data or a cluster that cannot start, turning a protective measure into an outage.
Correct Approach
Back up keys under strict controls, run the key service with high availability and rehearse recovery, including key access at the recovery site.
24Choosing the Right Approach
A simple path from your risks and requirements to a sensible combination of layers.
flowchart TD
S["Does the data need encryption at rest?"] --> Q1{"Any sensitive or regulated data?"}
Q1 -- "No" --> N["Still consider volume encryption as a low-cost default"]
Q1 -- "Yes" --> V["Enable volume or storage encryption everywhere"]
V --> Q2{"Must admins or the platform be unable to read data?"}
Q2 -- "No" --> Q3{"Need per-person erasure by deleting keys?"}
Q2 -- "Yes" --> C["Add client-side encryption for sensitive fields"]
Q3 -- "Yes" --> C
Q3 -- "No" --> Q4{"Need control over key location or revocation?"}
Q4 -- "Yes" --> K["Use customer-managed keys for the storage layer"]
Q4 -- "No" --> D["Provider-managed keys may suffice"]
Classify the data
Decide which topics carry sensitive or regulated data, and what the impact of exposure would be.
Name the threats
State who you are defending against: thieves, storage staff, broker administrators, or all of them.
Set the baseline
Encrypt all volumes, backups and remote storage using managed keys with clear policies.
Add stronger layers only where needed
Apply client-side encryption to the fields that justify the extra effort, and design keys, partitioning and compression around it.
Plan keys and operations
Agree on custody, rotation, recovery and monitoring before turning anything on.
Test, measure and audit
Measure performance, rehearse recovery and schedule regular verification.
For most organisations, encrypted volumes with managed keys are the right starting point, and client-side encryption is added selectively for the most sensitive fields, not applied everywhere.
25Best Practices and Common Mistakes
A checklist to keep beside you when designing or reviewing encryption at rest for Kafka.
Best Practices
- Encrypt all broker volumes by policy, from day one
- Inventory every place Kafka data rests, and cover each
- Keep keys in a key management service, never beside the data
- Use envelope encryption with per-purpose data keys
- Add client-side encryption for the most sensitive fields
- Keep message keys stable and readable when partitioning matters
- Rotate keys and rehearse recovery regularly
- Separate key custody from cluster administration
- Verify encryption status with automated checks and audits
Common Mistakes
- Believing TLS protects data on disk
- Storing keys on the same volume as the data
- Forgetting backups, mirrors, tiered storage and dumps
- Encrypting whole messages and expecting compression to work
- Encrypting message keys in a way that breaks partitioning
- Deleting or losing a key without a recovery plan
- Leaving secrets in plain text in configuration files
- Relying on volume encryption against administrators on running brokers
- Never testing restarts or restores with keys in play
Encryption at rest defends against particular threats, mainly stolen or copied storage. It does not replace authentication, permissions, network security or monitoring. It is one layer in a stack.
Locking valuables in a coded safe does not replace locking the front door, fitting an alarm and knowing who has the keys. Each measure covers a different way things can go wrong.
26Real-World Scenarios
Five common situations show how the choices fit together.
Scenario 1: A retailer in the cloud with a basic compliance need
The company runs Kafka on virtual machines with encrypted cloud volumes and provider-managed keys, enforced by policy. Backups inherit encryption, and a monthly check confirms no unencrypted volumes exist. The effort is small and satisfies the policy for ordinary business data.
Scenario 2: A payments company protecting card data
Volumes are encrypted with customer-managed keys, and card numbers are additionally encrypted field by field in the producer before reaching Kafka. Only the payment processing service can decrypt them. Other topics fields stay readable so analysis and routing still work.
Scenario 3: A platform serving European customers with erasure rights
Personal fields are encrypted with a key per customer, held in a key service. When a customer asks for erasure, the key is deleted, making all copies in logs, backups and mirrors unreadable. The company confirms with legal advisers that this approach is acceptable to its regulators.
Scenario 4: An on-premises data centre with strict physical rules
Brokers use block-level disk encryption with keys released by a network-based unlocking service to machines that pass integrity checks. The key service runs in several racks to survive failures. Decommissioned disks are cryptographically wiped by destroying their keys and are physically destroyed afterwards.
Scenario 5: A managed service with a bring-your-own-key requirement
A company uses a managed Kafka service and configures the service to use a key it controls in its own key service. It documents that disabling the key would make the data inaccessible, restricts who can change the key policy, and tests the procedure in a non-production environment.
| Scenario | Layers Used | Key Concern |
|---|---|---|
| Cloud retailer | Encrypted volumes, provider keys | Enforcing by policy and checking drift |
| Payments company | Volumes plus field-level client-side encryption | Design of keys, partitioning and access |
| Erasure rights platform | Per-customer keys, crypto-shredding | No plaintext copies elsewhere, legal acceptance |
| On-premises data centre | Block encryption with network unlocking | Key service availability and disk disposal |
| Managed service with own key | Customer-controlled key for the service | Protecting key policy against accidental loss |
27Frequently Asked Questions
No. Open-source Kafka writes event data to disk exactly as received. Encryption at rest must be added through storage encryption, file system encryption, a managed service or client-side encryption.
No. TLS protects data in transit over the network. Once the broker writes the data to disk, TLS no longer applies and separate at-rest protection is needed.
Encrypting the disks or volumes under the brokers, especially with the built-in options of cloud platforms or the operating system. It needs no changes to Kafka or client applications.
Not on a running broker. The volume is unlocked while in use, so someone with access to the machine can read the files. To defend against that, use client-side encryption so data is unreadable before it reaches the broker.
Producers encrypt data, or selected fields, before sending, and consumers decrypt after reading. Use it for highly sensitive data, when administrators or the platform must not see readable data, or when you need per-subject keys for erasure.
Volume encryption with hardware acceleration usually has a small cost. Client-side encryption adds CPU work and message size on clients. Measure with your own workload to know the real effect.
Encrypted data looks random, and compression works by finding patterns. Compress before encrypting, or encrypt only small sensitive fields and let the rest compress normally.
You can, but be careful. Kafka uses keys to choose partitions and to compact topics. Randomised encryption of keys breaks both. Prefer stable, non-sensitive keys, and encrypt sensitive data in the value.
Encrypting each person’s data with its own key and deleting that key when erasure is required, so all copies of the data become permanently unreadable without rewriting logs or backups.
The data protected by that key becomes unreadable for good. That is why keys need secure backups, controlled deletion and tested recovery procedures.
Add new brokers with encrypted volumes, use partition reassignment to move replicas onto them gradually, then retire and securely wipe the old brokers. Kafka’s replication does the data movement.
Typically yes, by default, with provider-managed keys, and many offer customer-managed key options. The exact features vary by provider and change over time, so check the current documentation for yours.
28Summary and Key Takeaways
Kafka keeps large volumes of business data on disk for long periods, and open-source Kafka stores it in readable form. Encryption at rest closes the gap for stolen disks, leaked snapshots and misused storage access. Because Kafka leaves the job to other layers, you choose among encrypted volumes, file system encryption, managed services with managed or customer-controlled keys, and client-side encryption for the most sensitive fields.
The encryption itself is the easy part. The hard parts are the keys, the many copies of data around Kafka, the side effects on compression and partitioning, and the operations of unlocking, rotating, recovering and monitoring. If you remember one sentence, let it be this: encryption is only as strong as the protection of its keys and the completeness of its coverage.
Key Takeaways
- Kafka does not encrypt its logs itself — event data is written to disk as received, so at-rest protection must be added deliberately.
- TLS is not encryption at rest — it covers the network only, and stored files, snapshots and backups need their own protection.
- Volume encryption is the baseline — it is simple, low cost and transparent, and it defends against stolen or copied storage, but not against access on a running broker.
- Client-side encryption is the strongest layer — it hides data from brokers, storage staff and backups, at the cost of key handling in every application and changed behaviour of compression, partitioning and inspection.
- Keys are the real security — keep them in a key management service, use envelope encryption, rotate them, back them up, separate custody from administration and plan for loss and outages.
- Cover every copy — brokers, backups, mirrors, tiered storage, stream state, dumps and configuration secrets all hold data or keys and must be protected.
- Operate and verify — plan boot unlocking and disaster recovery, migrate by replacing brokers through replication, monitor drift and key use, and audit regularly.