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.
| Stage | Risks | Controls |
|---|---|---|
| Build | Vulnerable base images, secrets in layers, malicious packages | Trusted base images, scanning in pipelines, image signing |
| Ship | Unauthorized images, tampering, a public registry | Private registry, access control, vulnerability scanning, gated deployment |
| Run | Privileged containers, an exposed API server, lateral movement, drift | Pod 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.
Build, ship or run?
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.
The more control that a platform gives, the more configuration needs securing. Each of these services is treated in a following lesson.
Containers and Kubernetes
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.
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.