Skip to main content
In this lesson, we explore how attackers might gain unauthorized access to sensitive information in a Kubernetes cluster and provide best practices to mitigate these risks. By following the principles of least privilege, secure logging, and network encryption, you can significantly reduce the attack surface.

Common Attack Vectors

Example: Over-Permissive RBAC in a Node.js Backend

Imagine a Node.js service running in the backend namespace. Its ServiceAccount (backend-sa) has read access to Secrets and ConfigMaps. An attacker who compromises the pod could enumerate sensitive data.

Secret Definition

Misconfigured RBAC

This Role grants broad read access to Secrets and pods:
Granting get/list on Secrets lets any pod with that ServiceAccount access database credentials, API keys, or other secrets.

Hardened RBAC

Limit the ServiceAccount to only the resources it truly needs:
Always follow the principle of least privilege when defining RBAC rules.

Securing Application Logs

Logging sensitive data can expose credentials, tokens, and PII if logs are compromised.

Risky Logging Example

Redacted Logging Example

Best practices for log security:
  • Avoid logging credentials, tokens, or other secrets.
  • Mask or redact sensitive fields before writing logs.
  • Centralize logs in a secure, access-controlled system (e.g., Elasticsearch with RBAC).
  • Continuously monitor log access and anomalies.

Encrypting Network Traffic

All inter-service communication should use TLS to prevent packet sniffing and man-in-the-middle attacks.

Unencrypted HTTP Example

Encrypted HTTPS Example

Enable mTLS between pods and enforce HTTPS for all east-west and north-south traffic.

Summary & Best Practices

  • Apply least-privilege RBAC so pods only have the permissions they require.
  • Never log sensitive information; mask or omit secrets in application logs.
  • Enforce TLS/mTLS for all inter-service and external communications.
  • Rotate encryption keys and Secrets regularly.
Implementing these controls will help safeguard your Kubernetes cluster against unauthorized data access.

Watch Video