Learn Apache Kafka - Security Best Practices & Compliance
Episode 33 of 36

Learn Apache Kafka - Security Best Practices & Compliance

This episode covers security and compliance for Kafka: hardening with least privilege and network segmentation, encryption everywhere, GDPR compliance with retention and audit logging, security monitoring to detect suspicious access, and secure development with secret management.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

After building authentication, authorization, and encryption in episodes 16-18, it's time to look at security holistically. Security isn't a single feature, but a practice spread across the whole lifecycle: configuration, data, operations, and code. Episode 33 weaves this into a hardening and compliance guide.

You'll learn hardening principles, compliance like GDPR with retention and audit logging, security monitoring to detect attacks, and secure development with secret management and automated scanning.

Security Hardening

The Principle of Least Privilege

All access is limited to the minimum needed (episode 17):

  • Every application has a separate service account with specific ACLs.
  • Don't use the super user for routine operations.
  • Restrict ClusterAction, Alter, and Delete to admin tooling only.
  • Review and revoke unused ACLs periodically.

Network Segmentation

Don't leave broker ports open to the internet. Network segmentation:

  • Internal listeners only for replication and in-VPC clients (episode 15).
  • Security groups/firewalls restrict source IPs and ports.
  • Use PrivateLink or VPN for external clients, not public exposure.
  • Separate development, staging, and production environments at the network level.

Encryption Everywhere

Apply layered encryption:

  • In transit: TLS for all client and inter-broker connections (episode 18).
  • At rest: disk encryption (EBS, LUKS) for log data (episode 18).
  • Sensitive data: additional application-level encryption for PII fields before writing.

Audit and Vulnerability Scanning

  • Regular audits: review ACLs, users, listeners, and broker versions.
  • Vulnerability scanning: scan Docker images and application dependencies regularly in the CI pipeline.
  • Follow Kafka and Confluent security releases; schedule upgrades.

Compliance Considerations

GDPR and Data Retention

Compliance like GDPR requires personal data (PII) to be handled under strict rules:

  • Retention: limit PII data age as needed. Configure retention.ms per topic; use the appropriate cleanup policy (episodes 4 and 10).
  • Right to erasure: tombstones (episode 10) are the per-key deletion mechanism for compacted topics.
  • PII handling: avoid writing raw PII to topics; anonymize or mask before publishing.
Retention for compliance
retention.ms=86400000
cleanup.policy=compact,delete
delete.retention.ms=604800000

retention.ms=86400000 limits data to 24 hours, while cleanup.policy=compact,delete combines per-key summaries with an age limit — a common pattern for data containing PII.

Audit Logging and Data Masking

  • Audit logging: enable logging of relevant requests (for example ACL changes, admin operations) to a centralized audit system.
  • Data masking: make sure sensitive fields like card numbers or emails don't appear in logs, metrics, or records leaving topics.
  • Document data flows: where data comes from, where it goes, and how long it's stored — the basis for compliance and investigation.

Security Monitoring

Watching Authentication and Authorization

Monitor security failures as early signs of attack:

  • Authentication failures: a spike in failed logins indicates brute force or wrong credentials.
  • Authorization failures: repeated ACL-denied requests indicate a client attempting forbidden access or misconfiguration.

Both metrics are available in broker logs and can be counted per principal.

Unusual Access and Data Exfiltration

  • Unusual access patterns: access from a new IP, new principal, or unusual hours — alert and investigate.
  • Data exfiltration detection: a surge in read volume from one client, or a new consumer suddenly reading an entire topic — signs of abuse. Monitor bytes-out per client and compare with baseline.
Authorization log on the broker
grep "Principal = User:app-producer" /var/log/kafka/server.log | tail -20

grep "Principal = ..." /var/log/kafka/server.log shows activity per principal. Integrate these logs with a SIEM for centralized detection.

Secure Development

Secret Management

Never put credentials in code or version-controlled configuration:

  • Store secrets in Vault, AWS Secrets Manager, or K8s Secrets.
  • Fetch secrets at runtime, not at build time.
  • Scheduled secret rotation; make sure applications reload without a full restart.

Dependency and Certificate Automation

  • Dependency scanning: scan application dependencies in CI (SBOM, tools like Snyk/Trivy).
  • Certificate rotation automation: TLS certificates are renewed automatically (episode 18), for example with cert-manager or Vault PKI.
  • Adopt security releases: subscribe to Kafka and client library security advisories.

Info

Security is a process, not an endpoint. Build habits: review ACLs and listeners quarterly, run vulnerability scans on every release, and test incident response procedures once a year. Document findings and their follow-ups.

Closing

In this episode 33 you've understood hardening with least privilege and network segmentation, GDPR compliance with retention and audit logging, security monitoring to detect suspicious access, and secure development with secret management and scanning.

The key takeaways:

  • Least privilege and network segmentation are the foundation of hardening.
  • In-transit and at-rest encryption are mandatory for production data.
  • GDPR demands controlled retention and per-key deletion mechanisms.
  • Monitor authentication failures, authorization failures, and anomalous read patterns.
  • Secrets never enter repositories; use a secret manager.
  • Automate dependency scanning and certificate rotation.

In the next episode 34 we'll discuss operational excellence and production readiness — production checklists, operational procedures like upgrades and maintenance, performance baselines, common production problems, troubleshooting, and cost optimization.

Learn Apache Kafka - Security Best Practices & Compliance | Learn Apache Kafka