L’interface est localisée ; les présentations et documents des Skills sont traduits automatiquement par IA dans votre langue. Le code, les commandes, chemins et termes techniques restent en version originale, et le document de l’auteur fait foi.
Explorer les Skills
Déploiement et opérations · SKILL.md

implementing-runtime-security-with-tetragon

implementing-runtime-security-with-tetragon

使用 Cilium Tetragon 在 Kubernetes 集群中实施基于 eBPF 的运行时安全可观测性与执行机制,实现内核级别的威胁检测(Threat Detection)和策略执行。

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentation de la Skill

GitHub

name: implementing-runtime-security-with-tetragon description: 使用 Cilium Tetragon 在 Kubernetes 集群中实施基于 eBPF 的运行时安全可观测性与执行机制,实现内核级别的威胁检测(Threat Detection)和策略执行。 domain: cybersecurity subdomain: container-security tags: [tetragon, ebpf, runtime-security, kubernetes, cilium, container-security, observability, kernel-security, cncf] version: "1.0" author: mahipal license: Apache-2.0

使用 Tetragon 实施运行时安全

概述

Tetragon 是 Cilium 旗下的一个 CNCF 项目,使用 eBPF 提供灵活的 Kubernetes 感知型安全可观测性和运行时执行机制。Tetragon 在 Linux 内核层运行,能够以不到 1% 的性能开销监控和执行进程执行、文件访问、网络连接和系统调用策略——远比传统用户态安全代理高效。

前置条件

  • Kubernetes 集群 v1.24+,已安装 Helm 3.x
  • Linux 内核 5.4+(建议 5.10+ 以获得完整 eBPF 功能支持)
  • 具有 cluster-admin 权限的 kubectl 访问
  • 熟悉 eBPF 概念和 Kubernetes 安全原语

核心概念

基于 eBPF 的安全

Tetragon 将 eBPF 程序直接挂载到内核函数,可实现:

  • 进程生命周期追踪:监控所有 Pod 的每个进程创建、执行和终止
  • 文件完整性监控(File Integrity Monitoring):检测对敏感文件的未授权读写
  • 网络可观测性:追踪包含完整 Pod 上下文的所有 TCP/UDP 连接
  • 系统调用过滤:对 ptrace、mount、unshare 等危险系统调用执行策略

TracingPolicy 自定义资源

Tetragon 使用 TracingPolicy CRD 定义要观测的内核事件及响应操作:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: detect-privilege-escalation
spec:
  kprobes:
    - call: "security_bprm_check"
      syscall: false
      args:
        - index: 0
          type: "linux_binprm"
      selectors:
        - matchBinaries:
            - operator: "In"
              values:
                - "/bin/su"
                - "/usr/bin/sudo"
                - "/usr/bin/passwd"
          matchNamespaces:
            - namespace: Pid
              operator: NotIn
              values:
                - "host_ns"
          matchActions:
            - action: Post

执行动作

Tetragon 可直接在内核中执行三种类型的动作:

  1. Sigkill:立即终止违规进程
  2. Signal:向进程发送可配置的信号
  3. Override:覆盖内核函数的返回值以拒绝某操作

安装与配置

步骤 1:使用 Helm 安装 Tetragon

helm repo add cilium https://helm.cilium.io
helm repo update

helm install tetragon cilium/tetragon \
  --namespace kube-system \
  --set tetragon.enableProcessCred=true \
  --set tetragon.enableProcessNs=true \
  --set tetragon.grpc.address="localhost:54321"

步骤 2:安装 Tetragon CLI

GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)
curl -L --remote-name-all \
  https://github.com/cilium/tetragon/releases/latest/download/tetra-${GOOS}-${GOARCH}.tar.gz
tar -xzvf tetra-${GOOS}-${GOARCH}.tar.gz
sudo install tetra /usr/local/bin/

步骤 3:验证安装

kubectl get pods -n kube-system -l app.kubernetes.io/name=tetragon
tetra status

实践实现

检测容器逃逸尝试

创建 TracingPolicy 以检测试图逃逸容器命名空间的进程:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: detect-container-escape
spec:
  kprobes:
    - call: "__x64_sys_setns"
      syscall: true
      args:
        - index: 0
          type: "int"
        - index: 1
          type: "int"
      selectors:
        - matchNamespaces:
            - namespace: Pid
              operator: NotIn
              values:
                - "host_ns"
          matchActions:
            - action: Sigkill

监控敏感文件访问

检测对敏感凭据的读取:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: monitor-sensitive-files
spec:
  kprobes:
    - call: "security_file_open"
      syscall: false
      args:
        - index: 0
          type: "file"
      selectors:
        - matchArgs:
            - index: 0
              operator: "Prefix"
              values:
                - "/etc/shadow"
                - "/etc/kubernetes/pki"
                - "/var/run/secrets/kubernetes.io"
          matchActions:
            - action: Post

阻止加密矿工执行

阻止已知加密挖矿二进制文件执行:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: block-cryptominers
spec:
  kprobes:
    - call: "security_bprm_check"
      syscall: false
      args:
        - index: 0
          type: "linux_binprm"
      selectors:
        - matchBinaries:
            - operator: "In"
              values:
                - "/usr/bin/xmrig"
                - "/tmp/xmrig"
                - "/usr/bin/minerd"
          matchActions:
            - action: Sigkill

使用 Tetra CLI 观测事件

实时流式传输运行时事件:

# 监控所有进程执行事件
kubectl exec -n kube-system ds/tetragon -c tetragon -- \
  tetra getevents -o compact --process-only

# 过滤特定命名空间的事件
kubectl exec -n kube-system ds/tetragon -c tetragon -- \
  tetra getevents -o compact --namespace production

# 以 JSON 格式导出事件用于 SIEM 集成
kubectl exec -n kube-system ds/tetragon -c tetragon -- \
  tetra getevents -o json | tee /var/log/tetragon-events.json

与 SIEM 和告警系统集成

导出到 Elasticsearch

# tetragon-helm-values.yaml
export:
  stdout:
    enabledCommand: true
    enabledArgs: true
  filenames:
    - /var/log/tetragon/tetragon.log
  elasticsearch:
    enabled: true
    url: "https://elasticsearch.monitoring:9200"
    index: "tetragon-events"

Prometheus 指标

Tetragon 在 :2112/metrics 暴露指标:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: tetragon-metrics
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: tetragon
  endpoints:
    - port: metrics
      interval: 15s

关键指标与告警

指标描述告警阈值
tetragon_events_total观测到的安全事件总数超过基线 3 倍的峰值
tetragon_policy_events_total匹配 TracingPolicy 的事件数任何 Sigkill 动作
tetragon_process_exec_total已追踪的进程执行次数出现异常新二进制文件
tetragon_missed_events_total因缓冲区溢出丢失的事件数持续 > 0

参考资料

Skills enregistrées