๐Ÿ” Container Security in Azure: Detecting & Fixing Vulnerabilities

๐Ÿ” Container Security in Azure: Detecting & Fixing Vulnerabilities

ยท

7 min read

๐Ÿ‘‰ "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

๐Ÿ”นSecure Your Azure Resources with Azure RBAC

๐Ÿ”นRBAC documentaion

ย