Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 38 ยท Container and Serverless Security

Container Runtime and Registry Security

Protect containers while they run and where images are stored: isolation layers, seccomp, capabilities, runtime detection, registry access control and image signing.

A secure image can still be abused once it runs, and a perfect image can be replaced with a malicious one if the registry is poorly protected. Two places deserve attention after the build: the runtime, where containers share a kernel with each other and with the host, and the registry, the storage and distribution point for every image you deploy.

This lesson explains how containers are isolated, how to shrink what a compromised container can do, how to detect odd behaviour at runtime and how to protect the supply route from registry to cluster. Tool configuration is shown read-only. The runnable parts are small Python simulations of a seccomp-style filter and of an admission check for image provenance.

Test runtime and registry controls on systems you own. Do not attempt container escapes or registry attacks against infrastructure you are not authorised to test.

How containers are isolated

A container is not a virtual machine. It is a normal Linux process wrapped by kernel features:

  • Namespaces give each container its own view of process IDs, network, mounts, hostnames and users.
  • cgroups limit CPU, memory and process counts, so one container cannot starve the rest.
  • Capabilities split root's powers into around forty pieces. Containers start with a reduced set.
  • seccomp filters which system calls the process may make.
  • LSMs (AppArmor or SELinux) add mandatory access control rules.

Because all containers on a node share one kernel, a kernel bug can break isolation. For hostile or untrusted workloads, add a stronger boundary: a sandbox runtime such as gVisor, or a lightweight VM per container such as Kata Containers or Firecracker, which is also what many serverless platforms use (see serverless security).

flowchart TB
    subgraph Node["One node, one kernel"]
      C1["Container A"] --- K["Shared Linux kernel"]
      C2["Container B"] --- K
    end
    K --- H["Hypervisor / cloud host"]
    S["Sandbox runtime or microVM"] -. "extra boundary for untrusted code" .-> C2

Containers share the kernel; a sandbox runtime or microVM adds another wall.

Reduce what a compromised container can do

A practical runtime baseline, expressed as docker run flags (read-only example):

Terminal
docker run --rm \
  --user 10001:10001 \
  --read-only \
  --tmpfs /tmp:rw,noexec,nosuid,size=16m \
  --cap-drop ALL \
  --security-opt no-new-privileges \
  --security-opt seccomp=profile.json \
  --pids-limit 200 --memory 256m --cpus 0.5 \
  registry.example.com/shop/api@sha256:EXAMPLE_DIGEST

Each flag removes an option from an attacker: no root, no writes outside a small temp area, no capabilities, no privilege gain through setuid and no fork bombs or memory exhaustion that take the node down. In Kubernetes the same ideas are expressed as securityContext fields, as covered in Kubernetes security basics.

Seccomp profiles

A seccomp profile lists allowed system calls. Anything else gets an error or kills the process. Docker's default profile already blocks dozens of risky calls, and a custom allow-list for a small service can be much tighter. A fragment looks like this (read-only):

JSON
{
  "defaultAction": "SCMP_ACT_ERRNO",
  "syscalls": [
    { "names": ["read", "write", "close", "openat", "mmap", "futex",
                "epoll_wait", "accept4", "sendto", "recvfrom", "exit_group"],
      "action": "SCMP_ACT_ALLOW" }
  ]
}

Try it: simulate a seccomp-style filter

This stand-in does not touch the kernel. It replays a list of system calls that an imaginary program makes and reports what a profile would do. That is the logic that makes allow-lists safe: unknown calls are denied by default.

Python Evaluate system calls against an allow-list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If an application fails after you apply a profile, a blocked call that the app really needs will show up in the logs. Build profiles by recording a normal run, then review the list with the developers.

Runtime detection

Prevention never catches everything, so watch what containers do. Tools such as Falco and the eBPF sensors of commercial products observe system calls and match them with rules. Typical suspicious events: a shell spawned in a container that never runs one, a write below /etc or /usr/bin, an outbound connection to an unusual address, reading the cloud metadata service or a package manager running in production. A read-only Falco-style rule (the output text is illustrative):

YAML
- rule: Shell in container
  desc: A shell was started inside a container
  condition: spawned_process and container and proc.name in (bash, sh, zsh)
  output: "Shell started (user=%user.name container=%container.name cmd=%proc.cmdline)"
  priority: WARNING

Feed such alerts to your logging pipeline; see alerting and SIEM.

Registry security

A registry (Docker Hub, ECR, ACR, GCR/Artifact Registry, Harbor) is a high-value target: whoever can push to it can change what runs in production.

  1. Authentication and least privilege. Separate pull and push rights. Build pipelines push, clusters only pull. Use short-lived tokens from your cloud identity system rather than static passwords.
  2. Private by default. Do not publish internal images publicly. Block anonymous pulls.
  3. Immutable tags. Turn on tag immutability so 1.4.2 cannot be silently overwritten.
  4. Scan on push and re-scan on a schedule; quarantine images with critical findings.
  5. Sign and verify. Sign images at the end of the pipeline (Sigstore Cosign, Notary) and verify signatures and provenance attestations before deployment.
  6. Use your own registry or a pull-through cache for third-party images so a deleted or poisoned upstream tag cannot affect you, and so you control what is allowed.
  7. Log and alert on pushes, deletes, permission changes and pulls from unusual networks.

Try it: an admission check for provenance

Policy engines (Kyverno, Gatekeeper, cloud-native admission policies) run checks like this when a pod is created. The stand-in uses a plain digest comparison instead of real cryptographic signatures, to keep the idea clear.

Python Allow only approved registries and signed digests

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Only the first request passes. The other three fail for three different reasons, and each reason matches a real attack: an unsigned (possibly tampered) image, an image from a public registry and a movable tag.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can a kernel vulnerability affect many containers on the same node?

    Containers are processes on one shared kernel. Sandbox runtimes and microVMs add an extra boundary for untrusted code.
  2. 2. What does a default-deny seccomp allow-list do with a system call that is not on the list?

    With defaultAction set to a deny action, calls that are not explicitly allowed are rejected.
  3. 3. Which registry setting stops someone from replacing the image behind the tag 1.4.2?

    Immutable tags make a pushed tag read-only. Pinning by digest goes further, because the digest identifies the exact content.
  4. 4. A cluster should only pull from the registry. Which permission model fits?

    Separating push from pull limits the damage if a cluster credential leaks.

Summary

  • Containers share a kernel; add capabilities removal, seccomp, non-root users and read-only filesystems, and use sandbox runtimes for untrusted code.
  • Detect unexpected behaviour at runtime with rule-based sensors and send the alerts to central logging.
  • Keep registries private, with least-privilege tokens, immutable tags, scanning and signed images.
  • Verify provenance at admission so only approved, signed digests run.

Next: Serverless Security