Table of contents
- Why are containers awesome?
- Why Do We Need Security?
- How Does Azure Keep Containers Safe?
- โ ๏ธ Common Security Risks in Containers
- ๐ Demo 1: Scanning a Vulnerable Container in Azure container registry (ACR)
- ๐ฌ DEMO 2: Lock the Container with Role-Based Access Control (RBAC)
- ๐ก How to Secure Your Containers in Azure
- Common Questions on Container Security
๐ "Think of containers like lunchboxes for your appsโhow do we keep them safe?"
๐ Containers are the backbone of modern cloud applications, but are they secure? What happens if a hacker exploits a vulnerability inside a container? In this post, weโll explore container security in Azure, scan a vulnerable container for security risks, and learn how to protect applications in production.
(What are containers; Easy Explanation)
Imagine you have a lunchbox ๐ฆ. Inside, you pack your food (your app).
A container is like that lunchboxโit holds an app and everything it needs to run.
Containers help apps run anywhere (like carrying lunch to school, home, or a picnic).
Why are containers awesome?
โ
Fast ๐ (No need to start a full kitchen, just open the lunchbox).
โ
Portable ๐ (Works anywhere).
โ
Saves space ๐พ (Shares the same kitchen/OS with others).
Why Do We Need Security?
Imagine someone poisons your lunch ๐๐ต!
Or steals your lunchbox ๐โโ๏ธ๐จ!
Or you forget to close your lunchbox properly and bugs get in ๐!
Thatโs what happens when containers arenโt secured in the cloud.
๐จโ๐ป Hackers can:
โ Change your app.
โ Steal data.
โ Make it stop working.
Example: Imagine you run a food delivery app inside a container. If an attacker hacks into it, they can steal customer orders, send fake promotions, or even delete your entire database!
How Does Azure Keep Containers Safe?
Azure has security guards that help keep your containers safe! ๐ฎโโ๏ธ๐
Danger ๐จ | How to Stay Safe in Azure ๐ |
๐ Bad food (Bad Code in Containers) | Scan your container lunchbox before using it. (Azure Defender) |
๐ Lunchbox left open (No Security) | Lock it! Use passwords and permissions. (RBAC) |
๐ Lunchbox stolen (Hacker Attack) | Hide it in a safe place. (Private Network, Firewall) |
๐ Food goes bad (Old, insecure code) | Always check for updates. (Azure Policy) |
โ ๏ธ Common Security Risks in Containers
Before jumping into the demo, here are some common security vulnerabilities:
๐ด Hardcoded Secrets โ Storing passwords directly in code.
๐ด SQL Injection โ Hackers stealing data via unsecured database queries.
๐ด Outdated Software โ Older versions of software often have security holes.
๐ด Open APIs โ Exposed services allow unauthorized access.
๐ก The Solution? Regular scanning, secure configurations, and automated security tools.
๐ Demo 1: Scanning a Vulnerable Container in Azure container registry (ACR)
๐ Think of this as checking your lunchbox for bad food before eating! ๐ง
๐ Overview of the Demo
Weโll:
1๏ธโฃ Deploy a vulnerable container to Azure Container Registry (ACR).
2๏ธโฃ Scan the container using Microsoft Defender for Containers.
3๏ธโฃ Review the security vulnerabilities detected in the scan.
4๏ธโฃ Apply security best practices to fix issues.
๐ Prerequisites: What You Need to Follow Along in this Demo Lab
โ Basic knowledge of containers and Docker (no worries if youโre new, Iโll simplify!)
โ An active Azure subscription (create a free account at Azure Free Tier)
โ Azure CLI installed (Download Azure CLI)
โ Docker installed (Install Docker)
โ Microsoft Defender for Cloud-enabled (Guide)
๐ Step 1: Set Up Azure Container Registry (ACR)
First, letโs log in to Azure and create a private container registry.
๐น Commands:
az login # First Log in to Azure
az group create --name MyResourceGroup --location eastus # This creates a resource group called MyResourceGroup in the East US region.
az acr create --resource-group MyResourceGroup --name myvulnerableregistry --sku Basic # This creates a private container registry where weโll store our vulnerable container.
โ If it fails, confirm if you have Azure CLI properly installed
๐ Step 2: Log in to ACR
Before pushing images, log in to your Azure Container Registry.
az acr login --name myvulnerableregistry
โ
If successful, you'll see a message like:
Login succeeded.
๐ Step 3: Pull, tag & Push the Vulnerable Container to ACR
Weโll use the OWASP Juice Shop container, which is deliberately insecure.
๐น Commands:
# Pull the vulnerable container from Docker Hub
docker pull bkimminich/juice-shop
# Tag it for Azure
docker tag bkimminich/juice-shop myvulnerableregistry.azurecr.io/juice-shop:v1
# Push it to Azure Container Registry
docker push myvulnerableregistry.azurecr.io/juice-shop:v1
โ Explanation:
docker pull
downloads the vulnerable container from the internet.docker tag
renames the container for Azure.docker push
uploads it to Azure Container Registry (ACR).
If it fails, confirm if you have docker installed and is in running state
๐ Step 4: Scan the Container in Azure Defender
Once the container is uploaded, we scan it for vulnerabilities.
๐น Steps in Azure Portal:
1๏ธโฃ Go to Azure Portal โ Microsoft Defender for Cloud
2๏ธโฃ Click Workload Protections โ Containers
3๏ธโฃ Select Vulnerability Assessment
4๏ธโฃ Find our uploaded container (Juice Shop) and check the security scan results.
๐ What Weโll See: A list of security vulnerabilities inside the container.
๐ Step 4: Understanding the Vulnerabilities Found
The scan may show security issues like:
โ Hardcoded passwords in the application code.
โ Outdated Node.js runtime, which attackers can exploit.
โ Weak authentication, allowing anyone to log in.
๐ฏ The Goal: Fix these issues before deploying the container to production.
๐ฌ DEMO 2: Lock the Container with Role-Based Access Control (RBAC)
๐ Think of this as locking your lunchbox so only trusted people can open it! ๐
Step 1: Open Access Control (IAM) in ACR
1๏ธโฃ Go to Azure Portal โ Open Container Registry (mysecurecontainer
).
2๏ธโฃ Click Access Control (IAM) โ Click + Add Role Assignment.
3๏ธโฃ Choose Role โ Select Reader (Read-only access).
4๏ธโฃ Assign it to a User or Service Principal (e.g., yourself for testing).
5๏ธโฃ Click Review and assignโ
.
๐ Now only trusted users can access the container!
๐ก How to Secure Your Containers in Azure
โ Scan containers before deployment (use Microsoft Defender).
โ Store secrets securely (use Azure Key Vault, not environment variables).
โ Use trusted base images (official images from Docker Hub).
โ Enable Azure Web Application Firewall (WAF) to block attacks.
โ Apply Role-Based Access Control (RBAC) to limit container access.
Common Questions on Container Security
๐ฅ Q1: What happens if my container is hacked?
โ If a hacker exploits a container, they can steal data, inject malware, or take control of the app.
โ Prevent it by scanning containers, limiting access, and using Azure Security tools.
๐ฅ Q2: How do I know if my container has vulnerabilities?
โ Use Microsoft Defender for Containers to scan your images.
โ
Alternative tools: Trivy (trivy image <image-name>
) and Docker Scout.
๐ฅ Q3: Can I block attackers automatically in Azure?
โ Yes! Azure has built-in security tools:
Microsoft Defender for Containers โ Alerts on security threats.
Azure Web Application Firewall (WAF) โ Blocks suspicious traffic.
Azure Security Center โ Gives security recommendations.
๐ Final Takeaways & Next Steps
๐น Lesson 1: Scan containers before deployment to prevent security risks.
๐น Lesson 2: Fix vulnerabilities early to avoid attacks.
๐น Lesson 3: Use Azure Defender & WAF for continuous protection.
โ Defender is like a security guard ๐ก๏ธ.
โ Scanning is like checking food before eating ๐.
โ RBAC is like locking your lunchbox ๐.
๐ Ready to Secure Your Containers?
๐ก Try it out! Deploy a vulnerable container, scan it, and fix security flaws.
๐ฌ Have questions or want to learn more? Drop a comment below!
๐ข Follow me for more cloud security tips! ๐๐
Remember to clean up your resources to avoid unncessarry costs
az group delete --name MyResourceGroup --yes --no-wait
โ This removes all resources from Azure to avoid extra costs.
๐ Free Resources to Learn More About Container Security
๐น Microsoft Learn โ Secure your containers
๐น Azure Defender for Containers Documentation