Security
Runtime alerts with Falco
Watching the kernel
RBAC, admission and NetworkPolicy decide what may happen. None of them sees what a program does once its container is running. Falco watches that part: it listens to the Linux kernel on every node, compares each event with a list of rules, and raises an alert when one matches. Follow two alerts from the kernel to the people they reach: a shell opened in a web Pod, and a program that was never in the image.
- Runs as
- DaemonSet · one Pod per node
- Listens with
- an eBPF probe in the node's kernel
- Blocks anything
- no · it detects and reports
- Version
- Falco 0.45 · Helm chart 9.2
Read the whole lesson as text
1. One Pod on every node
All containers on a node share one kernel, and only something on that node can listen to it. So Falco is a DaemonSet: one Pod per node, and a new one whenever a node joins. Nothing is added to your own Pods. The chart can install two helpers as well: Falcosidekick, which forwards alerts, and Talon, which can react to them. Both are optional, and both are ordinary Deployments.
- You install Falco with its Helm chart, with Falcosidekick and Talon turned on.
- The DaemonSet controller made one Pod per node. node-2's kubelet learns about its own.
- Both Falco Pods are running. They have some work to do before they report Ready.
2. Hooks in the kernel
Look inside node-2. Before it's Ready, Falco does three things. It loads its rules and works out which kernel events they need. It loads eBPF programs and attaches them to tracepoints, hooks the kernel provides for exactly this. And it learns what is already running, reading the node's processes from /proc and its containers from containerd, because an event is little use without knowing whose it is.
- Falco compiles its rules and works out which kernel events they need.
- It loads its eBPF programs, and the kernel runs them whenever a tracepoint fires.
- Falco asks containerd for the containers already running and which Pod each belongs to.
- It fills a table with every process on the node. Now it's Ready, and watching.
3. Someone opens a shell
Say your kubeconfig was copied, and someone else uses it to run kubectl exec against a web Pod. The API server checks the certificate and RBAC, finds that this user may exec, and passes the connection on to the kubelet. Every gate has done its job and said yes. From here on the API server only carries bytes between a keyboard and a process: the commands typed inside aren't API requests, so no policy sees them.
- A kubectl with your credentials asks for a shell in a web Pod.
- The API server connects the stream to node-2's kubelet, which has the runtime start a shell in the container.
4. The kernel tells Falco
To start the shell, a process inside the container calls execve, and the kernel swaps its program for /bin/sh. At that moment the sched_process_exec tracepoint fires and Falco's probe runs, in the kernel, right there. It copies what it needs into a ring buffer shared with Falco: the arguments, the user, the terminal, the cgroup, where the file came from. Then the shell runs. It wasn't held up for a verdict, because Falco doesn't give one.
- Inside the container, a process becomes sh. The kernel does that work, so the kernel knows.
- The tracepoint fires and the kernel runs Falco's probe, which reads the new process.
- The probe writes one event into a ring buffer and is done.
5. Which Pod was it?
The kernel has never heard of Pods. What Falco reads from the buffer is a process ID, some numbers and a cgroup path. Its libraries decode the event and add it to the process table, which supplies the parent's name. The container ID is cut from the cgroup path, and the container plugin looks that ID up in the list it got from containerd. Now the event has an image, a Pod and a namespace, and can be matched by name.
- Falco reads the event and turns its bytes into fields that rules can use.
- The container ID from the cgroup path leads to a cached entry: web, in Pod x2kqp.
6. The rule matches
A rule has a condition, an output message and a priority. The condition is a true-or-false question about the fields. The default rule Terminal shell in container asks six things about the event, and this one passes them all. With the default setting, the first rule that matches wins. Its priority is only Notice, because people run kubectl exec for good reasons every day.
- The event meets the rule's condition, one part at a time. All six parts are true.
- It's a match. Falco fills in the rule's message and queues the alert.
7. The alert leaves the node
Falco writes the alert to its standard output, where your log collector picks it up like any Pod's logs. It also posts it as JSON to Falcosidekick, a single place for the alerts of every node. Falcosidekick can send each alert to many destinations, and each has its own minimum priority. Slack is set to Warning here and the alert is a Notice, so nobody is interrupted. It stays in the logs, in case something else happens in that Pod.
- The alert goes to standard output, so kubectl logs shows it too.
- It's also posted to Falcosidekick, which hears from the Falco Pod on every node.
- Slack wants Warning and above. This is a Notice, so it goes no further.
8. A file that wasn't in the image
Two minutes later the person in the shell downloads a program into /tmp and runs it. Nothing in the container stops them: it has a writable file system and a way out to the internet. But a container's image is fixed. A program that isn't in it has to be written first, and that puts it in the container's one writable layer. The kernel can see which layer a file comes from, the probe passes that on, and a rule is waiting for it.
- The downloaded program starts. Same system call, same tracepoint.
- The probe sees that the file lives in the container's writable layer.
- It's not a shell, so the first rule stays quiet. Another one matches, and it's Critical.
9. One alert, two readers
This alert takes the same road, and this time it's above every bar. Falcosidekick posts it to Slack, where the person on call sees the Pod, the command and the parent shell. It also posts it to Talon, a response engine, which has a rule of its own: for this alert, terminate the Pod. Falco is still only the one who noticed. Whether anything is done, and what, is decided here.
- The Critical alert leaves the node the same way as the first.
- Talon gets a copy and finds an action for it: terminate the Pod.
- And a message appears in Slack, with everything needed to start looking.
10. The Pod is replaced
Talon has no special powers. It is a Pod with a ServiceAccount whose ClusterRole lets it delete Pods, so it asks the API server like anyone else. The kubelet stops the containers, and the shell and the downloaded program go with them. The ReplicaSet counts two Pods instead of three and makes a fresh one from the clean image. The stolen kubeconfig still works, though. That part is for the person reading Slack.
- Talon asks the API server to delete the Pod, as its own ServiceAccount.
- node-2's kubelet stops the Pod. Every process in it ends, the attacker's included.
- The ReplicaSet controller sees one Pod too few and creates a new one.
- The new Pod is Ready, and Falco is already watching it.
11. Noise and blind spots
Rules that cry wolf get ignored, so tuning is part of running Falco. You don't edit the default file. You add your own that overrides a named piece of it, here to accept shells in a namespace meant for debugging. And know what Falco can miss. If a node is so busy that the ring buffers fill up, events are dropped, and Falco raises an alert about that too. It also sees only what its rules ask about, and never what happens outside its nodes.
- You fill in a macro the rule left empty for you: shells in the debug namespace are expected.
- On a very busy node, the probe finds no room. It counts the event as lost and moves on.
- More than a tenth of the last second's events were lost, so Falco says so.
Summary
Containers share their node's kernel, so one probe in the kernel sees them all, whatever is or isn't installed inside them. Falco turns those events into fields, adds the Pod's name, and asks its rules. A match is an alert, and that is all Falco does. Falcosidekick decides who hears about it, and something else, a person or Talon, decides what to do. The shell was allowed by every check the API server has. It was noticed because starting a program always goes through the kernel.
Next lesson: Deploy an app