Back

DevSecOps Labs — Solution

Runtime Security with Falco

45 minRequires: docker

The new rule is the same shape as the shell rule, with a different process list and a higher priority. The full rule is in solution/package-manager.yaml:

- rule: Package manager run in container
  desc: A package manager was executed inside a running container at runtime
  condition: >
    evt.type = execve and
    container.id != host and
    proc.name in (apk, apt, apt-get, dpkg, yum, dnf, rpm)
  output: >
    Package manager started in container
    (user=%user.name container=%container.name image=%container.image.repository
    command=%proc.cmdline)
  priority: ERROR
  tags: [container, software_mgmt, lab]

Append it to rules.d/lab-rules.yaml so the file now holds both rules. Then restart Falco so it re-reads the file:

docker compose -f labs/falco/docker-compose.yml restart falco

Now trigger it. The target container is Alpine, so install anything with apk - open a second terminal and run:

docker exec falco-target apk add --no-cache curl

Switch back to the Falco terminal and you'll see an Error line this time, not a Warning, because you set the priority to ERROR:

Error Container icinde paket yoneticisi calisti (user=root container=falco-target image=alpine command=apk add --no-cache curl)

That is the whole loop of runtime security: decide what behaviour matters, express it as a condition over syscall fields, and let Falco watch for it continuously. In production you would send these alerts to a collector (Falcosidekick fans them out to Slack, a SIEM, etc.) instead of reading them in a terminal - but the rule you just wrote is exactly what runs there.

View source on GitHub