Back to articles
Security & Anti-DDoS

Using eBPF Falco to Detect and Automatically Isolate Container Violations of Docker Hardening Policies

A detailed guide on deploying Falco with eBPF to detect and automatically isolate containers violating Docker Hardening policies, enhancing container security on DPTCloud.

DPTCloud Engineering4 min read
Using eBPF Falco to Detect and Automatically Isolate Container Violations of Docker Hardening Policies

Introduction to eBPF and Falco in Container Security

Trong môi trường container hóa hiện nay, việc bảo vệ hệ thống Docker khỏi hành vi bất thường là rất quan trọng. Falco là một công cụ giám sát sự kiện hệ thống nguồn mở được thiết kế để phát hiện vi phạm chính sách bảo mật trong môi trường containerized. Khi kết hợp với eBPF (Extended Berkeley Packet Filter), nó có thể hoạt động hiệu quả ở cấp kernel, cho phép giám sát thời gian thực các hệ thống gọi, hoạt động I/O và thay đổi cấu hình mà không cần sửa đổi mã ứng dụng.

Hướng dẫn này trình bày cách triển khai Falco với eBPF để phát hiện và tự động cách ly các container vi phạm chính sách hardening Docker, nâng cao bảo mật cho hệ thống container trên DPTCloud.

Prerequisites: Environment Setup

Để triển khai Falco với eBPF, hãy đảm bảo các điều kiện tiên quyết sau được đáp ứng:

  • Ubuntu 20.04+ or CentOS 8+ with kernel 5.10 or higher (to support eBPF)
  • Docker installed and running
  • eBPF tools: bpftool, libbpf, and clang
  • Root access to a DPTCloud VPS
  • Ability to install monitoring tools such as sysdig (used by Falco)

Deploying Falco with eBPF

We will deploy Falco using Docker and configure it to use eBPF instead of traditional sysdig. First, install the required eBPF tools:

sudo apt update
sudo apt install -y clang llvm bpftool libbpf-dev

Tiếp theo, chạy Falco bằng Docker:

docker run -d --name falco \
  --privileged \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /dev:/dev \
  -v /proc:/host/proc:ro \
  -v /boot:/host/boot:ro \
  -v /lib/modules:/lib/modules:ro \
  -v /usr/src:/usr/src:ro \
  -v /etc/falco/falco.yaml:/etc/falco/falco.yaml:ro \
  -v /var/log/falco:/var/log/falco \
  falcosecurity/falco:latest

In the /etc/falco/falco.yaml configuration file, enable eBPF and define rules for detecting Docker Hardening policy violations:

---
# Use eBPF instead of sysdig
ebpf:
  enabled: true
  # Optional: specify the eBPF program path
  program_path: /usr/share/falco/eBPF/falco_bpf.o

# Define rules to detect violations of Docker Hardening policies
rules:
  - rule: Detect container with privileged mode
    desc: "Container running with privileged mode, which violates Docker Hardening policy"
    condition: container and privileged and not container_name: "falco"
    output: "Privileged container detected (container=%container.name)"
    priority: Critical
    tags: [container, privilege]

  - rule: Detect container with host network
    desc: "Container using host network, violating Docker Hardening policy"
    condition: container and host_network and not container_name: "falco"
    output: "Container using host network (container=%container.name)"
    priority: High
    tags: [container, network]

  - rule: Detect container with mounted host filesystem
    desc: "Container mounted host filesystem, violating Docker Hardening policy"
    condition: container and mount_host_fs and not container_name: "falco"
    output: "Container mounted host filesystem (container=%container.name)"
    priority: High
    tags: [container, filesystem]

Running and Testing

Sau khi cấu hình, kiểm tra xem Falco đang hoạt động:

docker logs falco

Nếu Falco hoạt động đúng, bạn sẽ thấy các sự kiện được ghi lại. Để kiểm tra phát hiện, hãy tạo một container với chế độ đặc quyền:

docker run --privileged -it ubuntu /bin/bash

Falco will immediately detect this behavior and log a warning. You can configure Falco to automatically isolate the violating container by integrating with tools like iptables or the docker API to block traffic from the affected container.

Verifying and Troubleshooting

To verify eBPF is loaded correctly, run:

bpftool prog list

Nếu chương trình Falco xuất hiện trong danh sách, eBPF đã được tải thành công. Nếu không, hãy kiểm tra:

  • Kernel support for eBPF (verify with uname -r)
  • Correct installation of libbpf and clang
  • Whether bpftool is installed

If Falco fails to detect events, review logs at /var/log/falco/falco.log for errors.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478