Securing data at rest in Kafka
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka, a distributed event streaming platform, is widely used for building real-time data pipelines and streaming applications. However, when dealing with sensitive data, securing it both in transit and at rest becomes paramount. Here we focus specifically on securing data at rest in Kafka.
Understanding Data at Rest in Kafka
Data at rest refers to all data stored on physical media, waiting to be processed or already processed but stored for further use or archiving purposes. In Kafka, this translates to data stored in topics' log files on the disk.
Encryption at Rest
Encrypting data at rest is crucial to prevent unauthorized data access and meet compliance requirements such as GDPR, HIPAA, and more. Kafka does not inherently support encryption at rest, so this needs to be handled at the storage layer.
Filesystem Encryption
Using encrypted filesystems is one common approach. On Linux, this can be achieved with tools like dm-crypt linked with LUKS (Linux Unified Key Setup) as well as eCryptfs and EncFS. For Windows environments, BitLocker provides a straightforward solution.
Example: Configuring dm-crypt with LUKS
After setting up the encrypted volume, Kafka's data directories can be configured to use these secured mounts.
Cloud Provider Solutions
Most cloud services like AWS, Azure, and GCP provide options to manage encrypted storage volumes:
- AWS: Amazon EBS volumes can be encrypted with AWS KMS.
- Azure: Azure Managed Disks offer encryption using platform-managed keys or customer-managed keys.
- GCP: Persistent disks can be encrypted with customer-supplied encryption keys (CSEK).
Access Control
In addition to encryption, proper access control on the filesystem where Kafka bandwidth resides helps safeguard data. Ensuring that only the Kafka service and authorized administrators have access to data directories is essential.
Managing Access Permissions on Linux
Auditing and Monitoring
Maintaining visibility into access and modifications to data-at-rest can detect and respond to unauthorized access attempts. File integrity monitoring tools, such as AIDE for Linux, can be configured to watch Kafka's data directories.
Example: Setting up AIDE
Regulatory Compliance
Enabling encryption and strict access controls can aid in compliance adherence. Each regulation (e.g., GDPR, PCI-DSS) may have specific requirements and standards that need to be met when handling and storing sensitive data.
Summary Table
| Feature | Description | Tools/Commands |
| Filesystem Encryption | Secures data at the storage level | dm-crypt, LUKS, BitLocker |
| Access Control | Restricts filesystem access | POSIX permissions chown, chmod |
| Auditing and Monitoring | Tracks changes and access to data storage | AIDE, Auditd, etc. |
| Compliance | Meets legal and regulatory requirements | Implementation specific to regulations (GDPR, HIPAA) |
Conclusion
While Kafka itself does not offer built-in capabilities for encrypting data at rest, integrating storage-level encryption, proper access control, and vigilant monitoring into your Kafka installation can protect sensitive data effectively and ensure compliance with prevailing regulations. Remember, every layer of security adds to safeguarding data in today's increasingly hostile cyber environment.
Related reading
- See size of Kafka Topics in Bytes
- Seeing partition doesn't exist warnings/failures after kafka using kafka partition re-assignment tool
- Select an element from a stream with uniform distributed probability
- Send bulk of messages Kafka Producer
- Securing REST API using custom tokens stateless, no UI, no cookies, no basic authentication, no OAuth, no login page
- Securing Spring Boot API with API key and secret
- Send byte array to storm kafka bolt
- Send Custom Java Objects to Kafka Topic

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.