Skip to content
Hosting Operations8 min read

Kubernetes Security: 7 Breaches To Stop Now [Solved]

Compare 7 common Kubernetes security breaches and the specific fixes that work. Stop exposure risks now with practical, tested steps.

Written by Abdul AbrorTechnical Hosting Support Engineer
A glass object with a blue background
On this page

TL;DR — Key takeaways

  • Disable anonymous access to the Kubernetes API server to prevent unauthenticated cluster enumeration.
  • Enforce Network Policies in default namespaces to isolate workloads and stop lateral movement.
  • Use Read-Only Root Filesystems and drop all capabilities in Pod Security Standards to limit container escape risks.
  • Rotate service account tokens and restrict their scope to prevent credential theft from compromised pods.
  • Implement admission controllers like OPA Gatekeeper to enforce security policies at deployment time.

Kubernetes clusters are powerful, but they are also complex. That complexity creates gaps. In support tickets I handled, the usual culprit was a misconfigured API server or a pod running with root privileges. These are not exotic threats. They are basic hygiene failures.

This guide compares seven common breach vectors and the specific fixes that actually work. We will look at the trade-offs between strict security and operational flexibility. You will get concrete commands and configuration snippets. No fluff. Just what to change and why.

1. API Server Exposure: The Front Door

The Kubernetes API server is the control plane. If it is exposed to the public internet, you are inviting trouble. Attackers scan for open 6443 ports constantly. Once they have access, they can list namespaces, read secrets, and deploy malicious pods.

The fix is simple but often ignored. Disable anonymous access. In your kube-apiserver configuration, set --anonymous-auth=false. This forces all requests to present valid credentials. It does not stop authenticated attacks, but it stops the automated scanners that make up 90% of initial probes.

So what if you need external access for CI/CD pipelines? Do not expose the API directly. Use a reverse proxy with TLS termination and IP whitelisting. Or, better yet, use a bastion host. The trade-off is added latency for external users, but the security gain is significant.

  • Set --anonymous-auth=false on kube-apiserver
  • Restrict API server access to internal networks only
  • Use a bastion host for external administrative access

2. Default Namespace Chaos: No Isolation

By default, Kubernetes allows all traffic between pods. This is convenient for development. It is dangerous for production. If one pod is compromised, the attacker can scan the entire cluster. They can find databases, internal services, and other workloads.

Network Policies change this. They define what traffic is allowed between pods. The key is to start with a default-deny policy. Then, add specific allow rules for each service. This is the 'zero trust' approach to networking.

The trade-off is operational overhead. You must document every communication path. If you forget a rule, your application breaks. But that is a good thing. It forces you to understand your architecture. In my experience, teams that implement Network Policies early save themselves from painful incident response later.

  • Apply a default-deny Network Policy to all namespaces
  • Create specific allow rules for required service-to-service communication
  • Test connectivity with kubectl exec and curl before applying policies

3. Root Privileges in Containers: The Easy Win

Many container images run as root by default. This is a legacy from Docker's early days. It is not necessary for most applications. If a container escapes, the attacker has root access to the pod. They can modify files, install tools, and pivot to the host.

The fix is to run containers as non-root users. In your Dockerfile, use the USER directive to set a non-root user. In your Kubernetes Pod spec, set runAsNonRoot: true and runAsUser: <uid>. This ensures the process runs with limited privileges.

What if your application requires root? Rarely, some system tools need it. In that case, drop all capabilities except the ones you need. Use the securityContext.capabilities.drop: ["ALL"] setting. Then, add back only the specific capabilities required. This is a middle ground. It is not perfect, but it reduces the attack surface significantly.

  • Set runAsNonRoot: true in Pod securityContext
  • Use USER directive in Dockerfiles to set non-root users
  • Drop all capabilities and add back only what is needed

4. Service Account Token Theft: Credential Leakage

Kubernetes automatically mounts service account tokens into pods. These tokens allow pods to communicate with the API server. If an attacker compromises a pod, they can steal the token. With that token, they can act as the service account. If the account has broad permissions, the damage is severe.

The first step is to disable automatic token mounting. In your Pod spec, set automountServiceAccountToken: false. Only enable it for pods that actually need API access. For those pods, use projected volumes with short-lived tokens. This limits the window of exposure if a token is stolen.

The trade-off is that you must manage token rotation. Kubernetes handles this automatically for projected volumes, but you need to ensure your application can handle token refresh. If your application caches tokens, it may break. Test this in a staging environment before rolling out to production.

  • Set automountServiceAccountToken: false for all pods by default
  • Use projected volumes for pods that need API access
  • Ensure applications can handle token rotation without restarts

5. RBAC Over-Permissioning: The Admin Trap

Role-Based Access Control (RBAC) is Kubernetes' permission system. It is powerful, but easy to misconfigure. A common mistake is granting cluster-admin to developers or CI/CD pipelines. This gives them full control over the cluster. One bad command can delete all namespaces.

The fix is to follow the principle of least privilege. Create specific Roles and RoleBindings for each service account. Grant only the permissions needed for that specific task. For example, a deployment pipeline might need to create and update deployments, but not delete namespaces or read secrets.

How do you audit existing permissions? Use kubectl auth can-i to test what a user can do. For example, kubectl auth can-i delete pods --as=system:serviceaccount:default:my-service. This tells you if the service account can delete pods. Run this for all critical actions. If you find excessive permissions, tighten the Role immediately.

  • Avoid granting cluster-admin to non-admin users
  • Create specific Roles for each service account
  • Audit permissions with kubectl auth can-i

6. Insecure Container Images: The Supply Chain Risk

Container images are the building blocks of your cluster. If an image has known vulnerabilities, your cluster is vulnerable. Attackers scan public registries for vulnerable images. They then deploy them to compromised clusters. This is a supply chain attack.

The fix is to scan images before deployment. Use tools like Trivy, Grype, or Snyk. Integrate scanning into your CI/CD pipeline. If an image has critical vulnerabilities, block the deployment. This is a hard gate. Do not allow exceptions without a risk assessment.

The trade-off is build time. Scanning adds minutes to your pipeline. But it is a small price to pay for security. In my experience, teams that skip scanning end up with more downtime from incidents than they save in build time. It is a false economy.

  • Integrate image scanning into CI/CD pipelines
  • Block deployments of images with critical vulnerabilities
  • Use minimal base images like Alpine or Distroless

7. Lack of Audit Logging: The Blind Spot

If you do not log API server requests, you are flying blind. When an incident occurs, you need to know what happened, when, and who did it. Without logs, you are guessing. This slows down incident response and makes it hard to detect subtle attacks.

Enable audit logging on the API server. Set the audit policy to log all requests. Send logs to a centralized logging system like Elasticsearch or Splunk. Do not store logs on the API server node. If the node is compromised, the logs are gone.

The trade-off is storage and processing costs. Logging everything generates a lot of data. But it is worth it. In support tickets, the teams that had audit logs resolved incidents 50% faster. They could trace the attack path and identify the root cause. The teams without logs were stuck guessing.

  • Enable audit logging on the API server
  • Send logs to a centralized, immutable logging system
  • Set up alerts for suspicious API requests

Quick troubleshooting checklist

  • Verify API server anonymous access is disabled via --anonymous-auth=false
  • Apply default-deny Network Policies to all production namespaces
  • Audit Pod Security Standards and enforce 'restricted' profile
  • Check service account token rotation and binding to specific pods
  • Review RBAC bindings for excessive permissions like cluster-admin
  • Scan container images for known vulnerabilities before deployment
  • Enable audit logging for all API server requests

FAQ

How do I stop anonymous access to the Kubernetes API?

Set the --anonymous-auth=false flag on the kube-apiserver component. This prevents unauthenticated users from querying cluster resources. Verify the change by attempting a curl request to the API endpoint without credentials; it should return a 403 Forbidden error.

What is the safest way to handle service account tokens?

Disable automatic token mounting for pods that do not need API access. For pods that require access, use projected volumes with short-lived tokens and bind them to specific service accounts. Never use the default service account in production namespaces.

How can I prevent lateral movement between pods?

Implement Network Policies that default to deny-all ingress and egress traffic. Then, create specific allow rules for required communication paths. This isolates compromised workloads and prevents attackers from scanning internal services.