AWS ECS - how are you keeping your containers secure?

So assuming it’s either Fargate or EC2

I understand AWS keeps the host OS secure

And the developers need to keep the container images secure?

If a container has an underlying Linux or windows OS… regardless what the containers are running on(host) , developers need to keep an eye on latest security updates and patches? Then rebuild the images?

If above is true what are best practices for automating this? Just rebuild nightly and deploy?

All images are treated as immutable and aren’t modified after the build between environments. All changes, be they application, dependency, configuration, or OS updates are considered changes and go through the full CI/CD process, fully tested, and deployed up through the environments, with production being a blue/green deployment.

Yes, all correct.

Generally, you need to be aware of all the software components you use and how & when to update them. Tools like Github’s Dependabot (notification of updated dependencies) and Amazon Inspector (vulnerability scanning) can help with that.

You’ve got the right idea about the division of responsibility. With Fargate, AWS abstracts away the host OS, allowing developers to focus more on the container itself. For EC2 instances, developers are also responsible for the AMI’s security.

Indeed, developers need to be vigilant about their container images, ensuring they’re free of vulnerabilities. This often involves regularly scanning the images for security issues, keeping an eye on the updates and patches for the base OS, and updating dependencies.

Rebuilding images regularly is a good practice. Nightly might be overkill for some, depending on the rate of change and the critical nature of the updates. But it’s crucial to establish a cadence that aligns with your risk profile and operational dynamics.

For automating this process, consider the following:

Automated Scanning: Implement automated scanning of container images in the CI/CD pipeline. Tools like AWS Inspector or third-party solutions can be integrated to scan for vulnerabilities at every build.

Base Image Updates: Use a base image that is regularly updated by the community or maintainers. Some organizations use a minimal base image to reduce the attack surface.

Patch Management: Employ a patch management strategy that automatically applies the latest security patches to your images. You can use tools like AWS Systems Manager to automate patching on your EC2 instances.

Immutable Infrastructure: Treat your containers as immutable. Once a vulnerability is detected, don’t patch the container; rebuild and replace it.

Deployment Automation: Automate the deployment of updated containers using services like AWS CodeDeploy or ECS Blue/Green deployments to reduce downtime and risk during updates.

Remember, it’s not just about rebuilding and deploying regularly; it’s about doing it intelligently, based on the vulnerabilities detected, and ensuring that changes go through proper testing. Integrating security into your CI/CD pipeline will enable you to maintain a strong security posture while deploying at the speed required for your business.

Sure but you can still have issues like LOG4J with remote code execution, in your immutable container. How are you detecting that?

Log4j is a code vulnerability issue, not an OS one. It should be picked up in the build pipeline.

A zero day cannot be picked up in the build pipeline. Some CVE’s are known after the fact.

How do you monitor you have those running, and if there is some anomaly in network traffic.

If it’s zero day then nothing is going to pick it up.

Patching is only part of the solution, you still don’t expose containers directly to the internet, you use load balancers and security groups and WAFs.

That’s an interesting approach’s when you use EKS (or any other k8s), any sane company would monitor workloads and network traffic with Datadog, Rapid7 and or netflow logs.

But when you move it to Fargate, the passive nature of a container becomes enough?

That’s not enterprise worthy IMO

How would any of that catch a zero day exploit?

Just monitor it like you’d monitor it. Nothing prevents you from doing that in ECS.

So sidecart rapid7 with every Fargate deployment..? :wink:

Sounds like a shitty licensing model to me.

We have a detailed guide on how to create more secure containers, located here: https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/security-tasks-containers.html

The two key points that are applicable to your question are:

  • Create minimal or use distroless images
  • Use Amazon ECR static vulnerability scanning

One thing you’ll need to do is perform container image vulnerability scans. Tools like Trivy help accomplish this, by looking up package metadata against vulnerability databases. Include this container image scanning step after the container image is built, in your CI/CD pipelines.

I’m not familiar with rapid7 but have used similar tools. Isn’t this the use-case for a rapid7 network sensor on an ec2 that is the target for vpc traffic mirroring from ECS?

When using Fargate for tasks there’s a little extra work needed to keep the ENI’s in sync as tasks are redeployed and eni’s change but it’s fairly trivial to automate with eventbridge events.

That can absolutely be one way of monitoring it. I’m asking here how other people are currently doing it and am downvoted into oblivion because containers are immutable

Add support for vuln scanning on Amazon Linux 2023! It’s a glaring oversight.

How would you compare this solution, to using AWS inspector?

Inspector is a layer on top of ECR vulnerability scanning. It unifies various scanning capabilities and signals from a variety of sources in your AWS account.