Zum Hauptinhalt springen

Falco

Falco는 eBPF 기반의 런타임 보안 모니터링 시스템입니다. 컨테이너와 호스트에서 발생하는 비정상적인 시스템 콜, 파일 접근, 네트워크 활동을 실시간으로 탐지합니다.

아키텍처

구성 요소

Falco Agent

  • 배포 방식: DaemonSet (모든 노드에 배포)
  • 드라이버: modern_ebpf (컴파일 불필요)
  • 이미지: zot.lumie-infra.com/falcosecurity/falco:0.43.0
  • 리소스: CPU 35m, Memory 138Mi

Falcosidekick

  • 역할: Falco 이벤트 전달 및 변환
  • 이미지: zot.lumie-infra.com/falcosecurity/falcosidekick:2.32.0
  • 리소스: CPU 23m, Memory 121Mi

드라이버 설정

Falco는 modern_ebpf 드라이버를 사용하여 커널 모듈 컴파일 없이 동작합니다:

driver:
enabled: true
kind: modern_ebpf # 최신 eBPF 기능 사용

장점:

  • 커널 헤더 불필요
  • 동적 컴파일 없음
  • 높은 호환성
  • 낮은 오버헤드

보안 규칙

기본 매크로

# 프로세스 실행 감지
- macro: spawned_process
condition: (evt.type in (execve, execveat) and evt.dir=<)

# 파일 읽기 감지
- macro: open_read
condition: (evt.type in (open,openat,openat2) and evt.is_open_read=true and fd.typechar='f' and fd.num>=0)

# 컨테이너 환경 감지
- macro: container
condition: (container.id != host)

# 안전한 프로세스 목록
- macro: known_safe_processes
condition: >
proc.name in (sh, bash, node, python, java, nginx, postgres,
trivy, minio, vault, containerd-shim, runc,
pidof, cat, ls, grep, find, head, tail,
kubectl, helm, git, curl, wget)

# 안전한 컨테이너 이미지
- macro: known_safe_images
condition: >
(container.image.repository contains "trivy" or
container.image.repository contains "aquasec" or
container.image.repository contains "postgres" or
container.image.repository contains "minio" or
container.image.repository contains "vault" or
container.image.repository contains "falco")

커스텀 규칙

1. 무단 프로세스 실행 탐지

- rule: Unauthorized Process in Container
desc: Detect unexpected processes in containers
condition: >
spawned_process and container and
not known_safe_processes and
not known_safe_images
output: >
Unauthorized process started in container
(user=%user.name command=%proc.cmdline container=%container.name image=%container.image.repository)
priority: WARNING
tags: [container, process]

2. 민감한 파일 접근 탐지

- rule: Sensitive File Access
desc: Detect access to sensitive files
condition: >
open_read and container and
fd.name in (/etc/shadow, /root/.ssh/id_rsa, /root/.ssh/authorized_keys) and
not known_safe_images
output: >
Sensitive file accessed
(user=%user.name file=%fd.name container=%container.name image=%container.image.repository)
priority: CRITICAL
tags: [file, security]

설정

Falco 메인 설정

falco:
# JSON 출력 활성화 (파싱 용이)
json_output: true
json_include_output_property: true

# 로그 설정
log_stderr: true
log_syslog: false
log_level: info

# 성능 튜닝
buffered_outputs: true

# 규칙 파일 (기본 규칙 비활성화로 성능 향상)
rules_files:
- /etc/falco/falco_rules.local.yaml
- /etc/falco/rules.d # 커스텀 규칙만 로드

알림 설정

Loki 연동

falcosidekick:
config:
loki:
hostport: "http://loki.loki.svc.cluster.local:3100"
minimumpriority: "" # 모든 우선순위 전송
format: "json" # JSON 형식으로 전송

Slack 연동 (선택적)

falcosidekick:
config:
slack:
webhookurl: "https://hooks.slack.com/services/..."
minimumpriority: "warning"

모니터링

Prometheus 메트릭

metrics:
enabled: true

serviceMonitor:
create: true
interval: 30s
labels:
release: prometheus

주요 메트릭:

  • falco_events_total: 총 이벤트 수
  • falco_outputs_total: 출력된 알림 수
  • falco_duration_seconds: 규칙 처리 시간

Grafana 대시보드

Loki에 저장된 Falco 이벤트를 Grafana에서 시각화:

# 시간별 보안 이벤트 수
sum(rate(falco_events_total[5m])) by (priority)

# 컨테이너별 이벤트 분포
topk(10, sum by (container_name) (rate(falco_events_total[5m])))

성능 최적화

규칙 최적화

기본 Falco 규칙(25개)은 높은 CPU 사용량을 유발하므로 비활성화하고 필요한 규칙만 활성화:

rules_files:
# - /etc/falco/falco_rules.yaml # 비활성화
- /etc/falco/falco_rules.local.yaml
- /etc/falco/rules.d

노이즈 감소

일반적인 운영 활동을 화이트리스트에 추가:

# 비활성화된 규칙 예시 (너무 많은 이벤트 생성)
# - rule: Container Drift Detection
# desc: Detect file modifications in containers
# condition: ...
# Reason: trivy, postgres, minio가 지속적으로 파일 작성

배포 설정

ArgoCD Application

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: falco
namespace: argocd
spec:
project: default
sources:
- repoURL: https://falcosecurity.github.io/charts
chart: falco
targetRevision: 8.0.1
helm:
valueFiles:
- $values/security/falco/helm-values.yaml
- repoURL: https://github.com/Lumie-Edu/lumie-infra.git
targetRevision: main
ref: values
path: security/falco
kustomize: {}
destination:
server: https://kubernetes.default.svc
namespace: falco

DaemonSet 설정

controller:
kind: daemonset
daemonset:
updateStrategy:
type: RollingUpdate

# 모든 노드에 배포
tolerations:
- operator: Exists

문제 해결

로그 확인

# Falco 로그 확인
kubectl logs -n falco -l app.kubernetes.io/name=falco

# Falcosidekick 로그 확인
kubectl logs -n falco -l app.kubernetes.io/name=falcosidekick

이벤트 테스트

# 테스트 컨테이너에서 의심스러운 활동 실행
kubectl run test-pod --image=alpine --rm -it -- sh
# 컨테이너 내에서: cat /etc/shadow

성능 모니터링

# Falco CPU/메모리 사용량 확인
kubectl top pods -n falco

# 이벤트 처리 속도 확인
kubectl logs -n falco -l app.kubernetes.io/name=falco | grep "Events processed"

보안 고려사항

권한 설정

Falco는 시스템 수준 모니터링을 위해 특별한 권한이 필요합니다:

securityContext:
privileged: true # eBPF 프로그램 로드를 위해 필요

# 호스트 네임스페이스 접근
hostNetwork: true
hostPID: true

네트워크 정책

Falco 트래픽을 제한하여 보안을 강화:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: falco-network-policy
namespace: falco
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: falco
egress:
- to:
- namespaceSelector:
matchLabels:
name: loki
ports:
- protocol: TCP
port: 3100

관련 문서