Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Confine a Pod and detect abnormal activity

By updated

Improve this page

Logo Kubernetes

This challenge checks that you can, on your own, confine Pods against the kernel, encrypt and filter their flows, isolate them in a sandbox and trigger an alert when a shell opens where it should not. It is meant for people who have just followed the lessons on confining Pods, starting from the lesson Runtime Sandboxes. It runs in a dsoxlab virtual machine, on a kubeadm cluster with Kubernetes 1.37, and takes about 75 minutes. It gives no hints and teaches nothing new: it checks what the lessons of the module and their guided labs have already let you practice.

What you will learn

The lab reads the node and the cluster. It really writes files and runs chmod in the Pods, makes real connections between Pods, compares kernels, and opens a shell itself in the protected Pod before reading Falco's alerts. It checks that you can:

  • Write an AppArmor profile and a seccomp profile, load them and declare them in a Pod.
  • Require mutual TLS in a namespace of the Istio mesh.
  • Close a namespace by default, keeping the intended application flow and DNS resolution.
  • Offer the cluster a sandbox runtime with a RuntimeClass and run a Pod in it.
  • Write a Falco rule that triggers an alert for a shell opened in a namespace, and only in that one.

What should you be able to do before you start?

No step-by-step guide goes with the challenge, and choosing the right settings is part of what it checks. Everything it asks for is taught in seven lessons:

If one of these points feels unclear, reread the lesson before you start.

What does the statement ask for?

The security team took over the kubeadm cluster, and its audit is blunt: nothing is confined, nothing is required, nothing is watched.

  • In the coffre namespace, sensitive workloads run like any container: free to write anywhere, to change permissions, and sharing the machine's kernel. The Pod tresor is the protected application. The Pod ordinaire runs with the default runtime, and you leave it alone.
  • The maille namespace is in an Istio mesh: api serves a page and client-maille calls it. From exterieur, client-nu, which has no sidecar, reads that page in plain text.
  • In the donnees namespace, appli is the legitimate client of the database base (HTTP on port 80). intrus and annuaire live there too, and everyone talks to everyone, outside the namespace included.
  • Falco runs on the control plane k8s-cp.lab and writes its alerts as JSON in /var/log/falco/events.json. Nobody would notice a shell opened in tresor.

The AppArmor and seccomp profiles you write, the sandbox runtime runsc and Falco only exist on k8s-cp.lab. You work on that node, with kubectl configured and root rights through sudo. Install and uninstall nothing.

The statement says what must be true at the end, never how to get there. To confine against the kernel, in coffre (image busybox:1.37, Pods that stay running):

  1. An AppArmor profile named k8s-coffre-sans-tmp is loaded on k8s-cp.lab in enforce mode. It denies any write under /tmp and allows the rest.
  2. A Pod lecteur runs on the node where that profile is loaded and declares it.
  3. From lecteur, writing into /tmp is denied, reading the filesystem works. This requirement is blocking.
  4. A seccomp profile profiles/coffre-sans-chmod.json, in the kubelet's local profiles directory, refuses the chmod family and allows everything else by default.
  5. A Pod calcul declares that local profile and runs.
  6. In calcul, a chmod fails and creating a file works.

To encrypt and filter the flows:

  1. The maille namespace only accepts mutually authenticated traffic.
  2. client-nu no longer reaches api, client-maille still does. This requirement is blocking.
  3. The donnees namespace refuses inbound and outbound traffic by default, for all its Pods.
  4. Only appli reaches base, on port 80.
  5. Names still resolve in donnees, without reopening the rest of the outbound traffic.

To isolate in a sandbox:

  1. The sandbox runtime known to containerd is offered to the cluster under the name gvisor-coffre.
  2. A Pod isole runs in that sandbox and reads a kernel other than the machine's.

To detect:

  1. A shell opened in a container of coffre triggers the alert of a Falco rule named coffre-shell, with priority CRITICAL. This requirement is blocking.
  2. A shell opened in another namespace does not trigger that rule.
  3. The rules shipped with Falco, /etc/falco/falco_rules.yaml, stay intact.

How do you start the challenge and get graded?

You start the lab with dsoxlab run k8s-challenge-confiner-et-detecter. It prepares a cluster where Falco, the gVisor runtime (runsc) and the mesh already exist, with no profile and no rule. Two commands are then used. dsoxlab check k8s-challenge-confiner-et-detecter tells you where you stand, criterion by criterion, as many times as you like, and dsoxlab submit k8s-challenge-confiner-et-detecter returns the final result. The grade never looks at the commands you typed or at your files: the lab reads the node and the cluster, opens a shell itself in tresor, then in a Pod of another namespace, before reading the alerts Falco wrote.

Put it into practice

This lab is the challenge itself. It puts you in front of the situation described above and it reads the state of the cluster, as a colleague taking over your work would do.

How is the challenge graded?

The pass mark is 70 points out of 100. Sixteen requirements of equal weight make up the grade, in the order of the statement. Requirements 3, 8 and 14 are blocking: if one of the three is not met, the challenge fails, whatever the total.

If a requirement is not met, dsoxlab check gives the label of the criterion without saying how to fix it. Reread the lesson that covers its subject, fix it, then run dsoxlab check again.

Key points

  • The challenge is a final exercise to do alone and without hints: it explains nothing and grades the state of the cluster, not your commands.
  • Requirements 3, 8 and 14 are blocking: the write into /tmp denied, the client without a sidecar blocked while the client of the mesh gets through, and the Falco alert for a shell in coffre.
  • A detection rule is checked on both sides: it triggers in the protected namespace and not in another one.
  • dsoxlab check shows where you stand as often as you like; dsoxlab submit returns the result.