Lesson 5 of 6 Compute Security: EC2, Containers and Lambda

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 secrets and valueFrom from Secrets Manager or Parameter Store, never plain environment variables.
  • Use awsvpc networking so each task has its own security group.
  • Harden task definitions: readonlyRootFilesystem, non-root user, no privileged, 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.
Select all that apply

Hardening an ECS task

Exam skills 3.2.1 · 3.2.2

Pick the settings that harden an ECS task definition.

Log in to try this activity Interactive activities are free with an account.

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.

ControlPurpose
Access entries and access policiesMap IAM principals to cluster permissions through the EKS API (replacing the aws-auth ConfigMap)
Kubernetes RBACRoles and RoleBindings scoped to namespaces for fine-grained permissions
Private API server endpointKeep the Kubernetes API off the internet, or restrict public access by CIDR
Control plane loggingAPI server, audit and authenticator logs to CloudWatch Logs

The following diagram shows three controls on a Kubernetes namespace that runs payment workloads.

Three controls on the payments namespace. The restricted Pod Security Standard forbids privileged pods; a network policy denies all traffic except within the namespace, to the database subnet on 5432 and DNS; and an EKS access entry makes PaymentsEngineers administrators of this namespace only.
The scenario is illustrative.
Match the pairs

Controlling access to an EKS cluster

Exam skills 3.2.2 · 4.2.3

Match each EKS access control with its purpose.

Log in to try this activity Interactive activities are free with an account.

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.

ControlPurpose
EKS Pod Identity or IRSAPer-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 podsLimit pod-to-pod and pod-to-AWS traffic
Envelope encryption of Kubernetes secretsKMS encryption of secrets in etcd, by default on current versions; use a customer managed key for control
Secrets Store CSI DriverMount secrets from Secrets Manager rather than storing them in Kubernetes
GuardDuty EKS Protection and Runtime MonitoringDetect suspicious API activity and runtime threats
Inspector with ECRScan images and map vulnerabilities to running pods
Match the pairs

Securing EKS workloads

Exam skills 3.2.2 · 3.2.3

Match each EKS workload control with what it provides.

Log in to try this activity Interactive activities are free with an account.
Worked example

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
EOF
aws 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=payments

The 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.

Check yourself

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.