Lesson 1 of 5 Securing Container Workloads

Understanding Container Security

This lesson explains the container lifecycle and its risks, and how Azure's container services differ.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how containers differ from VMs.
  • Identify the risks at each lifecycle stage.
  • Describe the parts of a Kubernetes cluster.
  • Compare the Azure container services.

What makes containers different

A container packages an application with its dependencies, and shares the host's kernel with other containers. An image is the template, a registry stores images, and a platform such as Kubernetes runs them. Containers start quickly, and are replaced rather than patched, so security moves earlier in the process. Fixing a vulnerability means building a new image and deploying it, not logging in to a running system.

The shared kernel is the main point of difference from a VM. A VM has its own kernel behind a hypervisor, so an escape is difficult. A container escape, through a kernel flaw or a privileged configuration, can reach the node and every other container on it.

Risks across the lifecycle

Security engineers think of the container lifecycle in three stages, and each has its own risks and controls.

StageRisksControls
BuildVulnerable base images, secrets in layers, malicious packagesTrusted base images, scanning in pipelines, image signing
ShipUnauthorized images, tampering, a public registryPrivate registry, access control, vulnerability scanning, gated deployment
RunPrivileged containers, an exposed API server, lateral movement, driftPod security rules, network policies, runtime detection, workload identity

An image with a known vulnerability in a registry is a posture problem. A shell started unexpectedly inside a running container is a runtime threat. Exam questions separate these in the same way as posture and threats elsewhere in Defender for Cloud.

Sort into groups

Build, ship or run?

Exam skills 3.3.1

Place each risk or control in its container lifecycle stage.

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

Kubernetes in brief

A Kubernetes cluster has a control plane, including the API server that receives every command, and nodes that run workloads. The smallest deployable unit is a pod, containing one or more containers. A namespace groups resources logically, and a service account gives a pod an identity. In Azure Kubernetes Service (AKS), Microsoft runs the control plane, and the customer is responsible for nodes, workloads and configuration.

The API server is the crown jewel, as anyone who controls it controls the cluster. By default it has a public address, so securing it is usually the first priority. Namespaces are not a strong security boundary on their own, and Microsoft notes that Kubernetes is not safe for hostile multitenant workloads.

Choosing a hosting service

Azure has several places to run containers, and the security work varies with each one, as the following comparison shows.

Azure Kubernetes Service
ModelManaged Kubernetes
Customer managesNodes, pods, policies
Network isolationVirtual network, private cluster
Security surfaceLargest
Choose when Full control of orchestration
Azure Container Apps
ModelServerless application platform
Customer managesApps, ingress, identity
Network isolationInternal environment
Security surfaceModerate
Choose when Microservices without managing a cluster
Azure Container Instances
ModelSingle container groups on demand
Customer managesContainer group settings
Network isolationDelegated subnet
Security surfaceSmallest
Choose when Short tasks and simple jobs

The more control that a platform gives, the more configuration needs securing. Each of these services is treated in a following lesson.

True or false

Containers and Kubernetes

Exam skills 3.3.1 · 3.3.2

Check the basic facts about container and Kubernetes security.

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

Placing a control

A team finds that a base image with a critical vulnerability has reached production. It wants to prevent the same thing in future, and to detect if an attacker starts an unexpected process in a running container. Which stage does each need?

Stopping a vulnerable image is a ship stage control: scan images, and use gated deployment to block those that fail. Detecting an unexpected process is a run stage control, which is binary drift detection by the Defender sensor.

Scanning alone does not stop a deployment unless a gate exists. Pod security rules restrict how a pod runs, but they do not examine an image's vulnerabilities, and they do not detect a new process.

Check yourself

A running container has a vulnerable library. What is the correct way to fix it?

Show answer

Rebuild the image with the fixed library, and redeploy. Patching a running container does not last.

Exam Tips

Remember for the exam

  • Containers share the host's kernel, so an escape can reach other containers.
  • Fix a container by rebuilding its image, not by patching it in place.
  • Namespaces are not a strong security boundary.
  • The API server is the most important part of a cluster to secure.