Kubernetes is powerful and complex, and a good part of the attack surface comes from that very complexity. In an EKS cluster, security depends on several layers lining up: the identity that connects the cluster to AWS, internal access control through RBAC, network isolation between pods, secrets management, image provenance, and the way services are exposed. A failure in any layer can compromise the others.
Instead of trying to cover everything, it pays to focus on the essential controls for EKS clusters, which are the ones that reduce risk the most and the ones most often misconfigured: identity, RBAC, network, secrets, and images. All of them are covered here from a defensive point of view.
Identity: IAM and IRSA
The worst practice in EKS is giving the nodes broad AWS permissions and letting every pod inherit them. The right path is IRSA, which associates a specific IAM role with a Kubernetes service account. Each workload gets only the AWS permissions it needs, and a compromised pod does not gain access to what the other workloads can do.
Also restrict access to the cluster API endpoint. An unrestricted public endpoint widens exposure. Prefer the private endpoint and, when the public one is necessary, limit it by source and protect access with strong authentication.
RBAC, network policies, and secrets
RBAC controls what each identity can do inside the cluster. Avoid granting cluster-admin broadly and model the roles on real need. On the network side, the default is that all pods can talk to each other. Network policies introduce segmentation: only the expected flows get through, and lateral movement is contained if a pod is compromised.
- Model RBAC on actual need and avoid broad cluster-admin
- Apply network policies that deny by default between namespaces
- Encrypt secrets at rest and avoid plaintext secrets in manifests
- Use namespaces to isolate environments and teams
- Restrict access to the cluster API endpoint
Network: deny by default between pods
Since every pod can talk to every other pod by default, segmentation starts with a network policy that denies ingress traffic and allows only the expected flows. Applied per namespace, it contains lateral movement, because a compromised pod can no longer reach services that should not accept its traffic. Introduce default deny carefully and map the legitimate flows first, or you will cut off communication the application needs. An example of denying ingress in the namespace:
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-deny-ingress namespace: appspec: podSelector: {} policyTypes: - IngressKubernetes secrets are only encoded by default, which is not the same as encrypted. Enable encryption of secrets at rest and, for the most sensitive data, consider an external secrets management solution. And avoid keeping them in versioned manifests.
Pod Security: security context and admission
A pod that runs as root, with elevated privilege or with a writable file system, is much closer to affecting the node if the container is compromised. The pod security context is what sets these limits: running as an unprivileged user, blocking escalation, dropping capabilities, and using a read-only file system. All of this is declared in the manifest itself and applies to practically any workload, as in:
securityContext: runAsNonRoot: true runAsUser: 10001 allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: ["ALL"]So that these limits do not depend on the discipline of whoever writes each manifest, Pod Security Admission applies a standard at the namespace level and rejects pods that do not meet it. The restricted level covers the most important practices in one go. Label your workload namespaces for enforcement and allow exceptions only with a justification, instead of letting each team decide on its own. The command is:
kubectl label namespace app \ pod-security.kubernetes.io/enforce=restrictedImages, admission control, and updates
Control image provenance. Use trusted registries, scan for vulnerabilities, and consider an admission controller that blocks images outside the policy (an image that runs as root or comes from an unapproved source, for example). Also keep the control plane and the nodes up to date. Kubernetes evolves quickly, and old versions accumulate known vulnerabilities.
Enable control plane logs and send them for analysis. Without an audit of what happens in the cluster API, investigating a Kubernetes incident becomes practically impossible.
Runtime detection and response in the cluster
Prevention reduces what can go wrong, but part of cluster security lies in noticing when something has already happened. API audit logs show who created, changed, or deleted resources, and some events deserve an immediate alert. Examples include a command executed inside a production pod, the creation of a broad role, an attempt to run a privileged pod, and repeated access to secrets. Send these events to an analysis destination that has an owner and a response deadline.
Runtime detection complements the API log. It watches behavior inside the containers, such as unexpected processes or unusual network connections, and on EKS, GuardDuty offers a runtime monitoring plan that plugs into this layer. The goal is to shorten the time between anomalous behavior and the response, whether that means isolating a pod, revoking a credential, or containing a namespace.
- Alert on commands executed inside production pods
- Alert on the creation of broad roles and on sensitive RBAC changes
- Watch for unexpected processes and connections inside the containers
- Set an owner and a response deadline for cluster alerts
Practical checklist
- Use IRSA to grant AWS permissions per workload instead of broad node permissions
- Restrict access to the cluster API endpoint
- Model RBAC on need and avoid broad cluster-admin
- Apply network policies that deny by default
- Enable encryption of secrets at rest
- Avoid plaintext secrets in versioned manifests
- Use trusted registries and scan images
- Apply admission control for image and pod policies
- Keep the control plane and nodes up to date
- Enable control plane audit logs
- Apply Pod Security Admission at the restricted level in workload namespaces
- Set a securityContext with runAsNonRoot and readOnlyRootFilesystem
- Drop capabilities and block privilege escalation in pods
- Apply a default deny network policy and allow only the expected flows
- Enable runtime detection and alert on exec into production pods
Best practices
- Grant AWS permissions per workload through IRSA, with least privilege
- Segment the cluster network with network policies
- Isolate environments and teams with namespaces and RBAC
- Control image provenance with scanning and admission control
- Stay on supported versions and update regularly
- Audit the cluster API and centralize the logs
- Apply Pod Security Admission at restricted and allow exceptions only with a justification
- Monitor execution inside the pods, in addition to the cluster configuration
Common mistakes
- Broad AWS permissions on the node, inherited by every pod
- A compromised pod gains, in AWS, the access of every workload on the node.
- cluster-admin granted broadly
- Any identity compromise turns into full control of the cluster.
- No network policies
- After an initial compromise, lateral movement between pods is unrestricted.
- Plaintext secrets in manifests stored in Git
- The credentials sit exposed in the repository, outside any access control.
- Old versions that are never updated
- Known Kubernetes vulnerabilities remain exploitable.
- Pods running as root and with elevated privileges
- A compromise in the container gets closer to affecting the node and the cluster.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.