AWS Builder Center
Container Security on AWS: ECR, ECS, and EKS Basics

Container Security on AWS: ECR, ECS, and EKS Basics

The basics of keeping your containers and container registry secure on AWS.

Series: AWS Security 30 Days, 30 Articles Challenge (31 articles)

  1. …
  2. 24
    Container Security on AWS: ECR, ECS, and EKS Basics This article
Welcome to Day 23 of the 30 Days AWS Security Challenge. Yesterday we covered securing individual Lambda functions. Today we widen the lens to containers, which bring their own specific security considerations across the three services most people use to build and run them on AWS.

Three Services, Three Different Jobs

Before getting into security specifics, it helps to be clear on what each service actually does. ECR (Elastic Container Registry) is where you store container images. ECS (Elastic Container Service) is AWS's own container orchestration service for running those images. EKS (Elastic Kubernetes Service) is AWS's managed version of Kubernetes, for teams already using or wanting that ecosystem. Security touches all three, but in different ways.

Securing ECR: What You Store Matters

Your container images are only as trustworthy as what went into building them. A vulnerable base image, an outdated dependency, or an accidentally embedded secret all travel with the image everywhere it's deployed.
A few practical steps for ECR:
  • Enable image scanning, which uses Inspector (from Day 19) to automatically scan images for known vulnerabilities, both when pushed and on an ongoing basis afterward
  • Use immutable image tags, which prevent a tag like  latest  from being silently overwritten, so you always know exactly what image is actually running in production
  • Apply repository policies to control which accounts and roles can push or pull images, following the same least privilege approach we've used throughout this challenge
You can enable scan on push under ECR > your repository > Edit, and it's worth turning on for every repository holding anything destined for production.

Securing ECS: Task Roles and Isolation

In ECS, each task, the running unit of one or more containers, can be assigned its own IAM task role, similar in spirit to a Lambda execution role. This lets you scope permissions per task rather than granting broad access to the underlying compute, which matters especially if you're running ECS on EC2 instances shared across multiple tasks.
A few things worth checking in your ECS setup:
  • Give each task definition its own scoped task role, rather than reusing one broad role across every task
  • If running tasks on EC2 instances rather than Fargate, be aware that tasks sharing an instance also share that instance's underlying resources, so isolate sensitive workloads onto their own tasks or consider Fargate, which runs each task in its own isolated environment without shared EC2 instances underneath
  • Avoid running containers as root inside the container itself, most base images support running as a non root user, which limits what a compromised container can do even within its own boundary

Securing EKS: Kubernetes Specific Considerations

EKS brings the full complexity of Kubernetes, and with it, Kubernetes specific security concerns layered on top of everything AWS handles underneath. A few EKS specific basics worth knowing:
  • IAM Roles for Service Accounts (IRSA) lets you assign fine grained IAM permissions to individual Kubernetes service accounts, rather than giving every pod on a node the same broad node level IAM role, which is a common and risky shortcut
  • Kubernetes RBAC (Role-Based Access Control) controls who can do what inside the cluster itself, separate from AWS IAM entirely, and needs its own deliberate configuration rather than relying on defaults
  • Private API server endpoints restrict access to your cluster's control plane so it isn't reachable from the public internet at all, which is worth enabling unless you have a specific reason for public access
EKS security findings, including misconfigurations, also flow into Security Hub if you have it set up from Day 17, giving you visibility alongside your other AWS findings rather than needing a completely separate Kubernetes specific tool from day one.

A Shared Theme Across All Three

Notice how much of this maps directly to ideas from earlier in this challenge: least privilege roles, vulnerability scanning, avoiding shared broad permissions, and restricting public access by default. Containers don't require an entirely new security mindset, they require applying the same principles at a slightly different layer.

A Practical Example

Say you're running a containerized API on ECS with Fargate. A secure setup uses an ECR repository with scan on push enabled and immutable tags, a task role scoped to only the specific DynamoDB table and S3 bucket the API actually needs, and a container configured to run as a non root user. Compare that to pulling an unscanned image tagged  latest , running as root, with a broad task role attached out of convenience, and the difference in what a compromised container could actually do is significant.

Key Takeaways

  • Enable ECR image scanning and use immutable tags so you always know exactly what's running
  • Scope IAM roles per task in ECS rather than sharing one broad role across everything
  • Avoid running containers as root, and prefer Fargate for stronger isolation between tasks
  • In EKS, use IRSA for fine grained permissions and configure Kubernetes RBAC deliberately rather than relying on defaults
  • Container security is largely the same least privilege and scanning principles from earlier in this challenge, applied at a different layer
Tomorrow we look at a smaller but important piece of the application security puzzle, AWS Certificate Manager, and how it takes the pain out of managing SSL/TLS certificates.

Series: AWS Security 30 Days, 30 Articles Challenge (31 articles)

  1. …
  2. 24
    Container Security on AWS: ECR, ECS, and EKS Basics This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article