advanced28 min studyLesson 32 in Engineering

Namespaces and containers

Separate isolated views, mapped identities, resource budgets, and trust boundaries when designing a container runtime policy.

On this page

What you’ll understand

  • Explain why an isolated identifier does not imply a separate kernel.
  • Calculate a user-namespace identity mapping.
  • Choose containment controls from a workload's actual trust requirements.

Two processes can both report process identifier one in different process-ID namespaces. Containers give a process selected views of a shared operating system. Those views help package applications and separate operational concerns, but they do not erase the shared kernel. A good platform specification explains exactly what is isolated, which authority remains available, and which failure or attack would cross the intended tenant boundary.

Treat isolation as a collection of views

Linux namespaces isolate particular global resources, such as process identifiers, mount views, network stacks, and user identities. The namespace types solve different problems. A private network stack does not independently establish a memory budget, and a private mount view does not make every reachable file harmless. Containers commonly combine namespaces with resource controls and additional restrictions, so evaluate the combination rather than attributing every property to a single mechanism.

Draw a containment matrix for a build worker: process visibility, filesystem access, network destinations, credentials, devices, and CPU or memory consumption. For each row, record the mechanism and an observable test. A worker that cannot see neighboring process IDs might still reach a credential service over the network. A reproducible packaging workflow and a hostile-code sandbox need different evidence even if both run the same image format.

uhost=b+uinside,0≤uinside<Lu_{\mathrm{host}}=b+u_{\mathrm{inside}},\qquad 0\leq u_{\mathrm{inside}}<L
This is one illustrative contiguous UID-map segment: b is its host starting UID and L its length. Real maps may contain multiple permitted segments, and mapping an identity alone does not grant arbitrary host permissions.↔ Scroll wide equations horizontally.

Map identity and reduce authority deliberately

A user namespace can map an identity inside the namespace to a different identity outside it. An apparent root user in the contained view therefore need not be host root. The mapping's permitted operations and file ownership still require careful configuration. Treat identity translation separately from the question of which files, sockets, and devices the process can access. A mounted privileged socket can defeat the intent of an otherwise narrow identity mapping.

The kernel's no_new_privs flag prevents an execution from gaining privileges through mechanisms such as set-user-ID execution or file capabilities; it is inherited and cannot be unset. It is not a universal ban on all possible privilege changes. For a platform, express the desired authority as an allowlist, remove unnecessary capabilities, and test the deployed runtime configuration. A declarative checkbox is useful only when its effective kernel behavior matches the policy being promised.

Choose the boundary that matches the workload

An internal stateless service and an arbitrary third-party compiler have different exposure. Shared-kernel containment can be a reasonable part of a defense for trusted services while a stronger boundary may be appropriate for hostile workloads. Compare kernel attack surface, patch cadence, device access, and operational recovery. Virtualization also has costs and residual risks; the choice should follow an explicit adversary and availability model rather than a claim that any one technology is categorically safe.

Measure the operational benefit without confusing it with a security proof. Layer sharing may reduce stored bytes, and a standardized runtime may simplify replacement, but neither observation establishes isolation. Test that a terminated worker loses credentials, that private mounts disappear, and that logs remain attributable to the correct tenant. When an incident spans several containers on one host, preserve enough host-level evidence to investigate the shared boundary instead of relying exclusively on each container's restricted view.

Sshared=B+nW,Sseparate=n(B+W)S_{\mathrm{shared}}=B+nW,\qquad S_{\mathrm{separate}}=n(B+W)
In this simplified storage model, B is one identical stored base layer, W is each worker's distinct writable data, and n is the worker count. It excludes compression, filesystem metadata, runtime memory, and additional layer versions.↔ Scroll wide equations horizontally.

Review identity and storage assumptions

Twenty build workers use one 300 MB base layer and each produces 40 MB of distinct writable data. A worker maps 65,536 UIDs starting at host UID 100,000. Calculate the mapping for inside UID 2,000 and compare ideal storage with twenty separate full copies.

  1. The mapping interval runs from host UID 100,000 through 165,535 inclusive. Inside UID 2,000 maps to 100,000 + 2,000 = 102,000.

  2. With a single shared base, stored bytes in the stated decimal-MB model are 300 + 20 × 40 = 1,100 MB.

  3. Twenty independent full copies would store 20 × (300 + 40) = 6,800 MB. The difference is 5,700 MB, approximately 83.8% of that separate-copy total.

  4. The storage calculation says nothing about cross-worker access. Review ownership, mounted sockets, network policy, and the kernel boundary independently of the saved bytes.

The result

UID translation and layer sharing provide concrete mechanisms with separate meanings; neither is a complete tenant-security argument.

Explore the model

Interactive lab

Interactive lab · reliability

Count available workers, then question independence

Choose n workers and k unavailable workers; the panel shows n − k and majority floor(n/2) + 1. Use it to count surviving build workers only. These workers do not require quorum to run independent builds, and shared-host failure correlations are not simulated.

Count available workers, then question independenceA replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forCounting surviving containers does not establish independent failure domains or a security boundary.

Check your understanding

A process reports UID 0 inside its container. Which conclusion is justified without further evidence?

Try it yourself

Tenant A maps 65,536 UIDs from host UID 100,000. Tenant B is proposed to start at 150,000. Do the ranges overlap? Suggest a nonoverlapping start and explain why this does not complete the isolation review.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compute the inclusive last UID of A and compare it with B's first UID.

Compare with the solution

A occupies 100,000 through 165,535. B starting at 150,000 overlaps the last 15,536 identities of A's range. Starting B at 165,536 would avoid overlap for these two contiguous segments. The platform still needs correct ownership, permissions, mounted-resource restrictions, network policy, and a suitable shared-kernel threat model. Nonoverlapping numbers do not prevent every path to another tenant's data.

Take it with you

  • Namespaces isolate specific views; containers can still share one kernel.
  • Identity mapping and authority reduction answer different questions.
  • Evaluate storage efficiency, reliability, and security with separate evidence.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.