Falco Rules Explained: Writing Custom Detection for Container Security

Written By:
Founder & CTO
June 23, 2025

Security in containerized environments is no longer optional. With the growing complexity of cloud-native systems, the need for dynamic, context-aware runtime protection has become vital. Enter Falco, the open-source runtime security tool that is purpose-built for modern container ecosystems like Kubernetes, Docker, and Cloud Native platforms.

In this comprehensive guide, we’ll go beyond the basics. We’ll break down Falco rules, explain how to write your own custom detection logic, and demonstrate how developers can integrate and operationalize these rules to gain deep visibility into system behavior. Whether you're just adopting Falco for container security, or trying to fine-tune existing rule sets for production, this blog gives you a complete developer-centric breakdown of Falco’s rule engine, benefits, and real-world application.

Why Focus on Falco?

Falco is the de facto standard for container runtime security. Backed by the Cloud Native Computing Foundation (CNCF), it gives developers real-time alerts when something suspicious happens inside your containers, nodes, or orchestrated workloads. Unlike traditional antivirus or host intrusion detection systems (HIDS) that rely on signatures or static policies, Falco detects behaviors, making it a perfect fit for dynamic container environments.

Some of the primary features that make Falco stand out include:

  • Lightweight kernel-level event monitoring using eBPF or syscall tracing

  • Fine-grained and extensible rule-based detection

  • Out-of-the-box integration with popular DevOps and cloud-native tools

  • Custom rule support that allows developers to tailor detection to their workloads

The keyword here is "runtime detection for containers", and Falco excels at this with its powerful rules engine.

What Are Falco Rules?

At its core, Falco functions as a rule-based engine for analyzing system calls and kernel-level activity. These rules are written in YAML format, making them accessible, readable, and easy to modify. Each rule specifies a condition under which an event is considered suspicious and triggers an alert.

A Falco rule consists of:

  • A rule name (unique identifier)

  • A desc (description of what the rule does)

  • A condition (Boolean logic to match syscall behavior)

  • An output (custom alert message with dynamic placeholders)

  • A priority (severity level like INFO, NOTICE, WARNING, ERROR, CRITICAL)

  • tags (for filtering, grouping, or categorizing rules)

  • Optional exceptions, lists, and macros to make rules reusable and tunable

Falco Rule Structure: More Than Just YAML

While YAML might seem trivial, Falco uses this declarative format to enable complex behavior modeling. By leveraging macros and condition chains, you can define rules that look for:

  • Suspicious binary execution

  • Unexpected file access or modification

  • Unauthorized network connections

  • Drift from base container images

  • Unauthorized Kubernetes actions (via Falco plugins)

All of this happens at runtime, giving developers a powerful container threat detection capability without heavy system agents or kernel modules.

The Importance of Custom Rules in Falco

Out-of-the-box, Falco comes with a comprehensive default rule set. These default Falco rules cover a wide range of suspicious activity: shell execution inside containers, privilege escalation, modifying sensitive files like /etc/shadow, and more. But they are intentionally generic and may produce either too many alerts or miss specific edge cases in your applications.

That’s where custom Falco rules come in.

Custom rules allow you to:

  • Adapt detection to your specific workloads, languages, and infrastructure

  • Minimize false positives by adding contextual exceptions

  • Define new behaviors that are unique to your containers or Kubernetes clusters

  • Automate detection logic as part of your CI/CD pipeline

In short, writing your own Falco rules puts the power of behavioral security into the hands of developers and platform engineers. It enables security as code, reducing reliance on external monitoring platforms and helping shift security left in the DevSecOps pipeline.

Understanding the Components of a Falco Rule
1. The macro – Reusable Logic Patterns

A macro is like a function in programming, use it to store a condition you plan to reuse. Macros help keep your rules clean, readable, and maintainable. For example:

- macro: container_exec

  condition: evt.type = execve and container.id != host

Here, container_exec acts as a shortcut for checking whether a process was executed within a container. You can use this in multiple rules.

2. The list – Defined Set of Values

A list lets you define a group of items like suspicious commands, IP addresses, or paths. It makes your rules modular.

- list: suspicious_binaries

  items: [nc, ncat, curl, wget]

Using lists simplifies conditions and makes updating easier.

3. The rule – The Core Detection Unit

Here’s a full example of a custom rule that detects the use of a shell within a container:

- rule: Shell launched in container

  desc: Detect when an interactive shell is launched in a container

  condition: container_exec and proc.name in (sh, bash, zsh)

  output: Shell command %proc.cmdline executed by user %user.name inside container=%container.id

  priority: WARNING

  tags: [container, shell, security, runtime-detection]

This rule checks if a shell is run in a container (which often indicates debugging, or worse, malicious activity).

4. The exception – Fine-Tuning for Precision

Avoid false alarms by setting exceptions. For instance, if your CI/CD system regularly executes bash, you can exempt it:

exceptions:

  - name: known_safe_ci

    fields: [container.image.repository]

    comps: [in]

    values: [["ci-runner-image", "trusted-image"]]

Custom Rule Creation: Step-by-Step Breakdown
Step 1: Identify the Detection Goal

What abnormal behavior are you trying to catch? Some examples:

  • Executing non-whitelisted binaries inside containers

  • Writing to critical files in Kubernetes config volumes

  • Outbound network access to unknown IPs

  • Unauthorized privilege escalation

Step 2: Break It Into Logical Components

Use macros for syscall filtering, lists for matching binaries or file paths, and conditions for event logic. Modularize as much as possible.

Step 3: Tune the Rule with Exceptions

Context is king. Exceptions reduce noise and increase signal fidelity. Use user.name, container.image, or proc.exepath to filter known-good behavior.

Step 4: Monitor Output & Priority

Customize your output to be descriptive. Include container IDs, user names, process details, etc. Set appropriate priority to distinguish between INFO and CRITICAL events.

Real Use Cases for Falco Rules
Detecting Container Drift

Want to ensure your containers don’t change at runtime? Use this:

- rule: Detect new executable file in container

  desc: Alert when a new executable is written inside a running container

  condition: evt.type in (open, creat) and evt.is_open_exec=true and container

  output: Executable file %evt.arg.filename written in container=%container.id

  priority: ERROR

  tags: [drift, container, runtime-security]

Drift detection is key to ensuring immutable infrastructure and catching zero-day persistence mechanisms.

Blocking Suspicious Network Activity

Outbound calls to non-whitelisted domains or IPs? This could be data exfiltration:

- rule: Suspicious outbound network

  desc: Detect outbound connections to unknown destinations from containers

  condition: evt.type = connect and fd.sip != 127.0.0.1 and container.id != host

  output: Connection attempt to %fd.sip:%fd.sport from process=%proc.name

  priority: WARNING

  tags: [network, container, threat-detection]

Use this to monitor containers that may be communicating with C2 servers.

Developer Advantages: Why Falco Wins
Lightweight but Powerful

Falco uses efficient syscall tracing or eBPF hooks, making it ideal for clusters with limited resources. Unlike traditional endpoint security agents, it won’t bloat your containers or VMs.

Native Kubernetes & Container Support

Falco is built for cloud-native. It understands container IDs, namespaces, pod metadata, and even supports Kubernetes audit log ingestion via plugins. You can filter events using pod names, image labels, or namespace boundaries, perfect for multi-tenant Kubernetes clusters.

Event-Rich Output for Developers

Each alert includes rich metadata: user info, container image, command executed, system call used, file path, and more. This allows developers to triage incidents faster, write better postmortems, and automate mitigation.

GitOps-Friendly Detection

Rules are YAML. You can commit them to Git, use CI/CD to validate rule changes, and manage security like application code.

Seamless Integration

You can export Falco alerts as:

  • JSON logs

  • Syslog messages

  • Webhooks

  • Kafka topics

  • gRPC streams

Connect Falco with SIEMs, Slack bots, dashboards, or even custom response handlers.

Comparing Falco with Traditional Detection Tools

Falco is not a replacement for all security tools, but it fills a crucial gap that traditional tools miss.

Traditional tools often:

  • Operate outside of containers

  • Use static signatures or periodic scans

  • Lack Kubernetes or pod-level context

  • Are heavy on resource usage

Falco, in contrast:

  • Provides live, context-rich alerts

  • Integrates natively into container orchestration environments

  • Supports developer-friendly rule creation

  • Is open-source and actively maintained by the CNCF community

Best Practices for Writing Falco Rules
Keep Rules Modular

Split complex logic into macros and lists. It helps with rule reusability and version control.

Minimize False Positives Early

Use exceptions and environment-specific filters. Add tags and clear descriptions for readability and searchability.

Start with Low-Severity Rules

Run in dry-run mode or log-only mode for new rules. Observe behavior before triggering alerts in production.

Validate on Non-Prod Clusters

CI/CD pipelines can run test events against your rules. Falco supports unit testing for rule validation.

Wrapping Up: Empowering Devs With Security Visibility

Custom Falco rules transform your runtime security posture. They let developers:

  • Detect suspicious behavior across containers and Kubernetes

  • Reduce false positives with precision tuning

  • Enforce security without heavy agents or performance loss

  • Write and version rules like application code

  • Integrate alerts into their existing DevOps workflows

Falco’s power lies in its flexibility. With a solid understanding of how to write and tune custom rules, your development team becomes the first line of defense in runtime security.