Securing Amazon ECS and Amazon EKS Workloads
This lesson explains the controls that Amazon ECS and Amazon EKS provide for identity, isolation, network traffic, secrets and runtime threats, which address the concerns of containers sharing a host kernel under powerful control planes.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish the ECS task role from the task execution role, and describe secure secret injection.
- Control access to an EKS cluster with access entries and Kubernetes RBAC.
- Secure EKS workloads with Pod Identity, network policies and pod security standards.
Amazon ECS
Amazon ECS workloads require specific security practices. The following list describes them.
- Separate the task role (the application's permissions) from the task execution role (pull images, write logs, fetch secrets).
- Inject secrets with
secretsandvalueFromfrom Secrets Manager or Parameter Store, never plain environment variables. - Use
awsvpcnetworking so each task has its own security group. - Harden task definitions:
readonlyRootFilesystem, non-rootuser, noprivileged, drop Linux capabilities. - Fargate removes host management and isolates each task in its own micro-VM; ECS Exec access is controlled by IAM and logged.
Hardening an ECS task
Amazon EKS: access to the cluster
Access to an EKS cluster is controlled at both the AWS and the Kubernetes level. Access entries and access policies map IAM principals to cluster permissions through the EKS API. They replace the older aws-auth ConfigMap, which was easy to break and could be edited by anyone with access to the cluster. Within the cluster, Kubernetes RBAC Roles and RoleBindings grant fine-grained permissions scoped to namespaces.
A private API server endpoint keeps the Kubernetes API off the internet; alternatively, public access can be limited to specific CIDR ranges. Control plane logging sends the API server, audit and authenticator logs to CloudWatch Logs, recording who did what in the cluster. The following table summarises the controls.
| Control | Purpose |
|---|---|
| Access entries and access policies | Map IAM principals to cluster permissions through the EKS API (replacing the aws-auth ConfigMap) |
| Kubernetes RBAC | Roles and RoleBindings scoped to namespaces for fine-grained permissions |
| Private API server endpoint | Keep the Kubernetes API off the internet, or restrict public access by CIDR |
| Control plane logging | API server, audit and authenticator logs to CloudWatch Logs |
The following diagram shows three controls on a Kubernetes namespace that runs payment workloads.

Controlling access to an EKS cluster
Amazon EKS: workloads
Workloads running in EKS need their own controls. EKS Pod Identity or IRSA gives each pod its own AWS permissions, so a compromised pod cannot use the node's broader role. Pod Security Standards, enforced by Pod Security Admission, apply the restricted profile to block privileged pods, host namespaces and containers running as root. Network policies, supported by the VPC CNI, limit which pods can talk to each other, and security groups for pods limit their traffic to AWS resources such as databases.
Kubernetes secrets are stored in etcd and protected by envelope encryption with KMS, on by default in current versions; a customer managed key gives you control of the key. The Secrets Store CSI Driver mounts secrets from Secrets Manager into pods instead of storing them in Kubernetes at all. For detection, GuardDuty EKS Protection and Runtime Monitoring find suspicious API activity and runtime threats, and Inspector scans ECR images and maps vulnerabilities to running pods. The following table summarises the controls.
| Control | Purpose |
|---|---|
| EKS Pod Identity or IRSA | Per-pod AWS permissions instead of the node role |
| Pod Security Standards (Pod Security Admission) | Enforce restricted profiles: no privileged pods, no host namespaces, non-root |
| Network policies (VPC CNI) and security groups for pods | Limit pod-to-pod and pod-to-AWS traffic |
| Envelope encryption of Kubernetes secrets | KMS encryption of secrets in etcd, by default on current versions; use a customer managed key for control |
| Secrets Store CSI Driver | Mount secrets from Secrets Manager rather than storing them in Kubernetes |
| GuardDuty EKS Protection and Runtime Monitoring | Detect suspicious API activity and runtime threats |
| Inspector with ECR | Scan images and map vulnerabilities to running pods |
Securing EKS workloads
Locking down a namespace
A payments team runs workloads in the payments namespace. Pods must not run privileged, must talk only to each other and to the database, and the team's engineers must have administrative access to this namespace only:
# Enforce the restricted Pod Security Standard on the namespace
kubectl label namespace payments pod-security.kubernetes.io/enforce=restricted
# Default deny, then allow traffic only within the namespace (VPC CNI network policy support)
cat <<'EOF' | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: default-deny-except-namespace, namespace: payments }
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
ingress: [{ from: [{ podSelector: {} }] }]
egress:
- to: [{ podSelector: {} }]
- to: [{ ipBlock: { cidr: 10.0.40.0/24 } }] # database subnet
ports: [{ protocol: TCP, port: 5432 }]
- ports: [{ protocol: UDP, port: 53 }] # DNS
EOFaws eks create-access-entry --cluster-name prod --principal-arn arn:aws:iam::111111111111:role/PaymentsEngineers
aws eks associate-access-policy --cluster-name prod \
--principal-arn arn:aws:iam::111111111111:role/PaymentsEngineers \
--policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSAdminPolicy \
--access-scope type=namespace,namespaces=paymentsThe engineers' role is administrator only within payments; elsewhere in the cluster it has no rights. Combined with Pod Identity for AWS access and GuardDuty Runtime Monitoring, a compromise of one pod is contained to its namespace and quickly detected.
How are privileged pods prevented in EKS?
Show answer
By enforcing the restricted Pod Security Standard.
Exam Tips
Remember for the exam
- In ECS, give application permissions to the task role and image-pull and secret permissions to the task execution role.
- Manage EKS cluster access with access entries and namespace-scoped access policies.
- To prevent privileged pods, enforce the restricted Pod Security Standard.
- To restrict pod-to-pod traffic, use Kubernetes network policies with the VPC CNI.
- For per-pod AWS permissions, use EKS Pod Identity or IRSA, not the node role.
- For runtime threat detection in containers, enable GuardDuty Runtime Monitoring.