Skip to content

feat(security): log every command in webapp via a Falco custom rule - #26

Merged
leeclay95 merged 1 commit into
mainfrom
feat/falco-command-rule
Jul 17, 2026
Merged

leeclay95 merged 1 commit into
mainfrom
feat/falco-command-rule

Conversation

@leeclay95

Copy link
Copy Markdown
Owner

What

Adds a Falco customRules entry so every command run in the webapp namespace is logged — not just the shell spawn.

Follow-up to #25. The default Terminal shell in container rule fires when a shell opens, but the individual commands typed after a kubectl exec (id, cat /etc/shadow, ls) produce no default alert. That's the exact visibility Falco was added for, so this bakes in a rule to capture it.

Changes

  • terraform/cluster/falco.tf — customRules → Command run in webapp container:
    condition: spawned_process and container and k8s.ns.name = webapp
    output:    "Command in webapp container (cmd=%proc.cmdline pod=%k8s.pod.name ...)"
    
  • docs/falco.md — documents the two rules, the per-command test flow (no TTY needed now), and the shipper re-roll after a Falco restart.

Verified live (end to end)

  • kubectl exec -n webapp POD -- sh -c 'id; cat /etc/hostname; ls /' → Falco fires one alert per command.
  • Alerts ship to floci CloudWatch /k8s/falco:
    Command run in webapp container | webapp webapp-xxxx | id
    Command run in webapp container | webapp webapp-xxxx | cat /etc/hostname
    Command run in webapp container | webapp webapp-xxxx | ls /
    
  • helm template renders the rule into the falco-rules ConfigMap; terraform validate clean; local security-gates.sh → all four gates PASS.

Note

The rule is noisy by design (every exec in webapp). Fine for the lab/demo; for real use, scope it or exclude known process names.

🤖 Generated with Claude Code

The default ruleset logs the shell *spawn* ("Terminal shell in container"), not
the commands typed after a kubectl exec — which is the whole reason Falco is
here. Add a custom rule that logs every process in the webapp namespace, so
`id`, `cat`, `ls`, ... each produce an alert.

- falco.tf: customRules "Command run in webapp container"
  (spawned_process and container and k8s.ns.name = webapp).
- docs/falco.md: document the two rules, the per-command test flow (no TTY
  needed), and the shipper re-roll needed after a Falco restart.

Verified live: exec into webapp -> each command fires the rule -> alerts ship
to floci CloudWatch /k8s/falco.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@leeclay95
leeclay95 merged commit 8a4d407 into main Jul 17, 2026
1 check passed
@leeclay95
leeclay95 deleted the feat/falco-command-rule branch July 17, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant