Virtual machines and containers: sharing one computer
One physical server can be divided so that it behaves like many separate computers, each with its own operating system. It can also run many programs side by side in sealed boxes. Almost every cloud service and most company data centres work this way. The question is always how strong the walls between the parts are. No technical background is assumed.
By the end of this unit you will be able to:
- Explain what a hypervisor does and tell a host from a guest
- Tell apart type 1 and type 2 hypervisors and say where each is used
- Name VM escape, VM sprawl and hyperjacking and the control for each
- Explain why containers share one boundary that virtual machines do not
- Choose between a virtual machine and a container for a given workload
Forty servers that nobody owned
An illustrative example
A council's IT team moves its 30 physical servers onto three powerful machines, each divided into many virtual computers. Creating a new virtual server now takes five minutes, so every project asks for one.
Two years later an audit counts 180 virtual servers. Forty have no named owner. Twelve still run an operating system that stopped receiving fixes a year ago. One of them, a test copy of the payroll system, holds real staff records.
The move saved money and space. What did it make easier that should have been controlled, and how?
One machine pretending to be many
A block of flats turns one building into many homes. Each flat has its own door and its own bills, while the foundations, the roof and the water main are shared. Virtualisation does the same to a computer.
A virtual machine (VM) is a complete computer made of software: it has its own operating system and programs, and believes it has its own hardware. The hypervisor, also called the virtual machine monitor (VMM), is the software that creates the virtual machines and keeps them apart. It gives each one a share of the real processor, memory, disk and network.
The physical computer is the host. Each virtual machine running on it is a guest. One host may run dozens of guests belonging to different departments or, in a cloud, different customers.
The hypervisor sits beneath every guest, so it is part of each guest's . NIST's guide on virtualisation, SP 800-125, calls it a single point of security failure: a single breach of the hypervisor puts every guest on the host at high .
Two types of hypervisor
A hypervisor can sit in one of two places.
| Point | Type 1: bare metal | Type 2: hosted |
|---|---|---|
| Where it runs | Directly on the hardware, with no operating system beneath it | As a program on an ordinary operating system, the host OS |
| Typical use | Servers in data centres and clouds | Desktops and laptops, for testing or running an older system |
| What it must trust | The hardware and its own small code | The hardware, the host OS and everything else running on it |
| Attack surface | Smaller | Larger: a flaw in the host OS reaches every guest |
SP 800-125 calls the first kind bare metal, or native, virtualisation and the second kind hosted virtualisation. NIST's later guidance names them type 1 and type 2. Servers are most often virtualised with type 1, desktops with type 2.
Type 1 is first on the metal. Type 2 needs a second layer, the host operating system, underneath.
What goes wrong: escape, sprawl and hyperjacking
- VM escape
- A program inside a guest breaks out of it and reaches the hypervisor, the host or other guests. From the hypervisor an attacker could control every guest on the host.
- VM sprawl
- Virtual machines multiply faster than anyone manages them, because creating one takes minutes. Each forgotten machine is unpatched, unmonitored and a place for an attacker to start.
- Hyperjacking
- An attacker takes control of the hypervisor itself, or installs a malicious one beneath it. The guests cannot see the layer below them, so their own security tools do not notice.
Hyperjacking is not only a laboratory idea. In 2022 Mandiant reported attackers who had installed backdoors on VMware ESXi hypervisors. From there they ran commands inside guest machines and moved files in and out.
The controls follow from where the risk sits. Patch the hypervisor first, ahead of the guests, because a flaw there reaches every guest. Restrict who may administer it, and keep its management network apart from guest traffic. Keep an of every virtual machine with a named owner, and require approval to create one. Machines that are no longer needed are removed, not left switched off, because a machine switched on again after months is out of date.
Virtual desktops, virtual networks and snapshots
In virtual desktop infrastructure (VDI), each user's desktop is a virtual machine running in a data centre or cloud. Staff connect from a laptop, a thin device or a browser. Data stays on the central servers, so a lost laptop holds little, and every desktop can be rebuilt from one approved copy.
Guests on one host often talk through a virtual network that the hypervisor builds in software, with virtual switches and routers. That traffic never touches a physical cable, so monitoring placed on the physical network does not see it. It is watched inside the host instead. The hypervisor's own monitoring, security software on the host or in each guest, or a virtual security appliance on the virtual network can all see it.
The same shift from boxes to software has spread to whole networks and storage, sometimes called software-defined everything. The layout becomes a configuration file, and whoever can change the file can change the layout.
An image is a stored copy of a whole virtual machine, used as a template to create new ones. A snapshot records a running machine's state at one moment, including the contents of its memory. Both are files, easy to copy and easy to forget.
- A snapshot may hold passwords and keys that were in memory, so it is protected like the live machine.
- An image stored for months misses every released since; templates are updated on a schedule.
- Old snapshots are deleted, and restoring one brings back its old flaws and any malware it held.
Containers share one kernel
Flats share a building. Rooms in one house share far more: one front door, one kitchen, one fuse box. A container is a room, not a flat.
A container packages one application with the files and libraries it needs, and runs it apart from other applications on the same host. Unlike a virtual machine, a container has no operating system of its own. All the containers on a host share the host operating system's kernel, its core.
- Image
- The package a container is started from: the application and its libraries, built in layers.
- Registry
- The library where images are stored and from which hosts download them.
- Runtime
- The software on the host that starts containers from images and keeps them separate.
- Orchestrator
- Software that decides which host runs which container across many hosts.
NIST's container guide, SP 800-190, groups the risks under those parts and the host. Its central warning is the shared kernel. A flaw in that kernel, or a container run with too many privileges, can expose every container on the host. The isolation a container runtime gives is not as strong as the isolation a hypervisor gives.
Virtual machine or container
What a virtual machine shares, and what a container shares
Read this figure as text
Both hosts have the same hardware. What differs is how much each workload has of its own, and so how strong the wall between workloads is.
- Left: a type 1 hypervisor runs directly on the hardware and creates the virtual machines. Each virtual machine has its own guest operating system, and an application runs on that guest.
- The virtual machines share the hardware and the hypervisor. The hypervisor keeps them apart with hardware-level isolation, so a flaw in the hypervisor reaches every guest.
- Right: one host operating system runs directly on the hardware, and a container runtime on it starts containers and keeps them apart.
- Each container holds one application and its libraries, with no operating system of its own. Every container shares the host's kernel, so the isolation is software isolation within one kernel, and a flaw in that kernel can expose every container.
- Workloads that must not trust each other, such as code from different customers, need separate virtual machines or separate hosts.
| Point | Virtual machine | Container |
|---|---|---|
| What is separate | A whole computer, with its own operating system | One application and its libraries |
| What is shared | The hardware and the hypervisor | The hardware and the host's kernel |
| Boundary | Hardware-level isolation by the hypervisor | Software isolation within one kernel |
| Size and start-up | Gigabytes; starts in minutes | Megabytes; starts in seconds |
| Mixing operating systems | Windows and Linux guests on one host | Only containers built for the host's operating system family |
The choice turns on trust. Workloads that trust each other, such as parts of one company's application, can share a kernel as containers. Workloads that must not trust each other, such as code from different customers, need the stronger boundary of separate virtual machines, or separate hosts. Containers are often run inside virtual machines for exactly that reason.
A question, worked through
A software company runs code uploaded by its customers so that they can test it. Each customer's code runs in its own container, and all the containers share one host. A large new customer's security team asks how its code is kept apart from other customers' code.
Which change BEST answers the concern?
Decide on your answer, then open the reasoning
- The concern is isolation between customers whose code cannot be trusted, on a host they all share.
- Rule out b. Scanning finds known flaws in an image, but customer code is untrusted by nature and may be written to attack its neighbours.
- Rule out d. Patching narrows the window for known kernel flaws; every container still shares that one kernel.
- Between a and c: removing privileges is good practice and makes escape harder, but the boundary between customers remains one shared kernel.
- Option a gives each customer the hardware-level boundary of a hypervisor. That is the change that answers a question about separating untrusted tenants.
Answer: A. Run each customer's containers in a separate virtual machine
Choosing between good answers
- Untrusted workloads from different owners share a host
- choose the stronger boundary: separate virtual machines or hosts, not containers alone.
- A flaw is announced in the hypervisor and in some guests
- patch the hypervisor first, because it is beneath every guest.
- Virtual machines are multiplying without owners
- name it VM sprawl. Choose inventory, named owners and approval to create.
- A question asks what a container shares that a virtual machine does not
- the answer is the host's kernel.
Check your understanding
4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.
These questions are drafts that no named reviewer has approved yet.
Question 1 of 4
What to remember
- A hypervisor, or virtual machine monitor, runs guest virtual machines on a physical host and keeps them apart.
- A type 1 hypervisor runs directly on the hardware; a type 2 hypervisor runs on a host operating system and inherits its flaws.
- VM escape breaks out of a guest, VM sprawl is unmanaged growth, and hyperjacking is taking control of the hypervisor itself.
- Patch the hypervisor first, and treat images and snapshots as copies of the live machine.
- Containers share the host's kernel, so their isolation is weaker than that of virtual machines; untrusted tenants need separate virtual machines.
Say it from memory
What are the two types of hypervisor, and what are VM escape, VM sprawl and hyperjacking?
Type 1 runs directly on the hardware and is used for servers; type 2 runs on a host operating system and is used on desktops. VM escape is breaking out of a guest to the hypervisor or other guests. VM sprawl is unmanaged growth in virtual machines. Hyperjacking is taking control of the hypervisor itself. Patch the hypervisor first.
What does a container share with other containers on its host, and when is a container the wrong choice?
Containers share the host operating system's kernel, so a kernel flaw or an over-privileged container can expose every container on the host. Their isolation is weaker than a hypervisor's. Workloads that must not trust each other, such as code from different customers, belong in separate virtual machines.
What are a hypervisor, a host and a guest, and why does NIST call the hypervisor a single point of security failure?
The hypervisor, or virtual machine monitor, creates virtual machines and keeps them apart. The host is the physical computer; each virtual machine on it is a guest. The hypervisor sits beneath every guest, so a single breach of it puts every guest on the host at high risk.
Why does a type 2 hypervisor have a larger attack surface than a type 1?
A type 1 hypervisor runs directly on the hardware and trusts only the hardware and its own small code. A type 2 runs as a program on a host operating system, so it also trusts the host OS and everything else running on it. A flaw in the host OS reaches every guest.
Why must a snapshot be protected like the live machine, and what is the risk of a stored image?
A snapshot records a running machine's state, including its memory, so it may hold passwords and keys. An image stored for months misses every patch released since, so templates are updated on a schedule. Restoring an old snapshot brings back its old flaws and any malware it held.
How do a virtual machine and a container differ in what is separate and what boundary keeps them apart?
A virtual machine is a whole computer with its own operating system, kept apart by hardware-level isolation from the hypervisor. A container separates one application and its libraries, with software isolation within one shared kernel. Containers are megabytes and start in seconds; virtual machines are gigabytes and start in minutes.
Sources
- NIST SP 800-125: Guide to Security for Full Virtualization Technologies, NISTTraffic between guests on one host bypasses network-based monitoring and is watched instead through the hypervisor, introspection, host-based controls or security appliances on the virtual network. The hypervisor or virtual machine monitor, host and guest; bare metal and hosted virtualisation and where each is used; escape; the hypervisor as a single point of security failure; virtual networks; images, snapshots holding memory contents, and image sprawl; checking for hypervisor patches.
- ITL Bulletin, March 2018: Safeguards for Securing Virtualized Servers, National Institute of Standards and TechnologyType 1 hypervisors installed on bare metal and type 2 hypervisors installed on a host operating system.
- Bad VIB(E)s Part One: Investigating Novel Malware Persistence Within ESXi Hypervisors, Mandiant (Google Cloud)Attackers persisting on VMware ESXi hypervisors in 2022 and using that access to run commands in guest machines and transfer files.
- What is Azure Virtual Desktop?, MicrosoftA virtual desktop service delivering full desktops and applications to users who connect from any device or a browser.
- NIST SP 800-190: Application Container Security Guide, NISTContainers sharing the host kernel, images, registries, runtimes and orchestrators, and container isolation being weaker than a hypervisor's.