Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: VM or container (20 minutes)
Which of these needs a VM: a Windows program on a Linux host, a Python web app on Linux, a test of a new kernel?
Done when: the Windows program and the kernel test need a VM, the Python app can use a container.
Hint
the kernel must match.
Easy 2: Count the namespaces (20 minutes)
Which of the eight kinds did the launcher of section 2 create, and which did it not?
Done when: created: mount, PID, UTS, network; not created: user, IPC, cgroup, time.
Hint
compare with the table in page 4.
Easy 3: Space saved (20 minutes)
Fifty containers use an image of 200 MB, each with 5 MB of its own changes. What is the total with layers, and how many times less than without?
Done when: 450 MB, 22.2 times less than 10,000 MB.
Hint
200 + 50 x 5.
Medium
Medium 1: Build the rootfs (45 minutes)
Make a root directory with sh and ls, copy their libraries with ldd, and run the launcher on it. Report the size of the directory and the output of ls /.
Done when: a size in megabytes, and a listing of the directories of the root.
Hint
ldd $(which sh) lists the libraries.
Medium 2: Compare namespaces (45 minutes)
Run ls -l /proc/self/ns inside the container and on the host. List which kinds differ.
Done when: mount, network, PID and UTS differ, and the rest are equal.
Hint
use the ls -l /proc/self/ns listing.
Medium 3: Overlay test (45 minutes)
Build the overlay test of section 5 with your own files. Report what changes in the lower and upper directories after you edit, add and delete one file each.
Done when: the lower is unchanged, the upper holds the edited file, the new file and a whiteout.
Hint
mount -t overlay overlay -o lowerdir=...,upperdir=...,workdir=... merged.
Hard
Hard 1: Harden the launcher (90 minutes)
Extend the launcher with CLONE_NEWUSER (and a map written by the parent), and drop all capabilities in the child. Run id and cat /proc/self/status | grep CapEff inside and compare with the original.
Done when: a user namespace number that differs from the host's, and CapEff zero if capabilities were dropped.
Hint
write 0 0 1 style lines to /proc/CHILD/uid_map.
Hard 2: Add a limit (90 minutes)
Make the launcher create its own cgroup (a directory), write a memory limit and its child's ID to cgroup.procs before the exec. Show that a memory test inside is killed and the launcher survives.
Done when: the memory test is killed, and the launcher prints that its child ended with signal 9.
Hint
the group file is cgroup.procs of the new directory.
Hard 3: Choose (90 minutes)
A company runs code uploaded by strangers. Choose between plain containers, containers inside VMs and VMs only. Give the reasons and one cost for each.
Done when: containers in VMs or VMs for strangers (the kernel is shared otherwise), with costs such as memory per guest and start time.
Hint
think about who writes the code and what it can reach.