This hands-on guide teaches how to install Falco on Ubuntu, generate security alerts, and view them in the terminal.
In this hands-on guide, you’ll learn how to install Falco on an Ubuntu VM running a Kubernetes cluster, generate security alerts, and view them directly in your terminal. Falco is a runtime security tool for detecting anomalous activity in your containers and hosts.
Installing kernel headers is required for the Falco DKMS module to build against your running kernel.
After installation, you should see output similar to:
Copy
Ask AI
Unpacking falco (0.29.0) ...Setting up falco (0.29.0) ...Loading new falco-… DKMS files...Building initial module for <your-kernel-version>Installing to /lib/modules/<your-kernel-version>/updates/dkms/depmod...DKMS: install completed.
# Create an nginx pod named 'n1'kubectl run n1 --image=nginx# Confirm the pod is runningkubectl get pod n1# Exec into the container to spawn a shellkubectl exec -it n1 -- bash# Inside the container, exit to complete the sessionroot@n1:/# exit
As soon as the shell spawns inside the container, Falco will emit a notice:
Copy
Ask AI
20:15:32.123456 Notice A shell was spawned in a container with an attached terminal (command="bash" user=root container=n1 pod=n1 namespace=default image="nginx:latest")
This alert output references dynamic fields such as %proc.cmdline, %user.name, %container.name, %k8s.pod.name, %k8s.ns.name, and %container.image.
Falco’s built-in rules are defined in falco_rules.yaml. To view the rule that detects terminal shells in containers:
Copy
Ask AI
grep -A15 -i "A shell was spawned in a container with an attached terminal" /etc/falco/falco_rules.yaml
Example snippet:
Copy
Ask AI
- rule: Terminal shell in container desc: Detect when a shell is spawned in a container with an attached terminal condition: spawned_process and container.id != host and proc.name in (bash, sh, csh, ksh, tcsh, zsh, dash) and fd.is_tty=true output: > A shell was spawned in a container with an attached terminal (command=%proc.cmdline user=%user.name container=%container.name pod=%k8s.pod.name namespace=%k8s.ns.name image=%container.image) priority: NOTICE tags: [container, shell]
Macros like in_container and lists such as shell_binaries are defined elsewhere in the configuration. For full details on writing and customizing rules, see the Falco documentation.