Fix a Custom Falco Rule That Stays Silent
Scenario
The cluster has a single node, cplane-01, and Falco runs on it with the modern eBPF driver.
The security team added a custom rule for interactive shells in Pods in /etc/falco/rules.d/interactive-shells.yaml:
- rule: Interactive Shell in Pod
desc: Detect an interactive shell started in a Kubernetes Pod
condition: spawned_process and container and proc.name in (sh, ash, bash) and proc.tty != 0
output: "[CUSTOM] Interactive shell in Pod (pod=%k8s.pod.name ns=%k8s.ns.name shell=%proc.name image=%container.image.repository:%container.image.tag)"
priority: WARNING
tags: [custom]
A few minutes ago, someone opened an interactive shell in the Pod web in the shop namespace.
Falco reported the shell with a Notice alert from a default rule.
The custom rule stayed silent, although falco -V reports it as valid.
The security team watches the [CUSTOM] alerts, so nobody there noticed the shell.
Falco is already installed here. To practice the installation and a first custom rule, try the challenge Install Falco and Catch curl and wget in Pods With a Custom Rule.
Task
- Make Falco report the custom alert next to the default alert for the same event.
Keep both rules as they are: do not change
falco_rules.yamlorinteractive-shells.yaml, and do not disable any rule. - Open an interactive shell in the Pod again, leave it with
exit, and check the logs of the Falco service. They must show both alerts for this shell:kubectl exec -it -n shop web -- sh
Hint 1: Reading the alerts
Falco runs as a systemd service, and the name of the unit depends on the driver.
systemctl list-units with a 'falco*' pattern shows it, and journalctl -u <unit> prints its logs, alerts included.
An alert shows the output text of the rule that matched. Search /etc/falco/falco_rules.yaml for that text to find the default rule.
Docs:
- Falco Outputs (Falco)
- journalctl(1) (Linux manual page)
Hint 2: Why the custom rule stays silent
Both rules match the same event, and Falco loads the default rules first.
The main configuration file, /etc/falco/falco.yaml, has a setting that decides whether Falco keeps checking the other rules after the first match.
The comments above each setting in that file explain what it does.
Hint 3: Applying the change
Falco watches its configuration files and reloads when one of them changes. The service logs show the reload. A restart of the service works too.