implementing-runtime-security-with-tetragon
使用 Cilium Tetragon 在 Kubernetes 集群中实施基于 eBPF 的运行时安全可观测性与执行机制,实现内核级别的威胁检测(Threat Detection)和策略执行。
Best use case
implementing-runtime-security-with-tetragon is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用 Cilium Tetragon 在 Kubernetes 集群中实施基于 eBPF 的运行时安全可观测性与执行机制,实现内核级别的威胁检测(Threat Detection)和策略执行。
Teams using implementing-runtime-security-with-tetragon should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/implementing-runtime-security-with-tetragon/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How implementing-runtime-security-with-tetragon Compares
| Feature / Agent | implementing-runtime-security-with-tetragon | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用 Cilium Tetragon 在 Kubernetes 集群中实施基于 eBPF 的运行时安全可观测性与执行机制,实现内核级别的威胁检测(Threat Detection)和策略执行。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 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 定义要观测的内核事件及响应操作:
```yaml
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
```bash
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
```bash
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:验证安装
```bash
kubectl get pods -n kube-system -l app.kubernetes.io/name=tetragon
tetra status
```
## 实践实现
### 检测容器逃逸尝试
创建 TracingPolicy 以检测试图逃逸容器命名空间的进程:
```yaml
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
```
### 监控敏感文件访问
检测对敏感凭据的读取:
```yaml
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
```
### 阻止加密矿工执行
阻止已知加密挖矿二进制文件执行:
```yaml
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 观测事件
实时流式传输运行时事件:
```bash
# 监控所有进程执行事件
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
```yaml
# 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` 暴露指标:
```yaml
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 |
## 参考资料
- [Tetragon 官方文档](https://tetragon.io/docs/)
- [Cilium Tetragon GitHub 仓库](https://github.com/cilium/tetragon)
- [CNCF Tetragon 项目页面](https://www.cncf.io/projects/tetragon/)
- [eBPF 安全可观测性与 Tetragon - CoreWeave](https://docs.coreweave.com/security/tutorials/ebpf-observability)
- [Kubernetes 安全:eBPF 与 Tetragon 运行时监控](https://medium.com/@noah_h/kubernetes-security-ebpf-tetragon-for-runtime-monitoring-policy-enforcement-819b6ed97953)Related Skills
triaging-security-incident
使用 NIST SP 800-61r3 和 SANS PICERL 框架对安全事件进行初始分类,确定严重性、范围和所需响应行动。 按类型对事件分类,根据业务影响分配优先级,并路由到相应的响应团队。适用于事件分类、 安全告警分类、严重性评估、事件优先级排序或初始事件分析等请求场景。
triaging-security-incident-with-ir-playbook
使用结构化 IR Playbook 对安全事件进行分类和优先排序,确定严重性、分配响应团队并启动适当的响应程序。
triaging-security-alerts-in-splunk
在 Splunk Enterprise Security 中对安全告警进行分类,通过 SPL 查询和事件审查(Incident Review) 仪表板对重要事件进行严重性分类、调查、关联相关遥测并做出升级或关闭决策。 适用于 SOC 分析师需要处理关联搜索产生的告警队列、确定调查优先级, 或需要为交接给二/三级分析师记录分类决策时。
testing-websocket-api-security
测试 WebSocket API 实现中的安全漏洞,包括 WebSocket 升级时缺少身份认证、跨站 WebSocket 劫持(Cross-Site WebSocket Hijacking,CSWSH)、通过 WebSocket 消息进行的注入攻击、输入校验不足、通过消息泛洪实施拒绝服务,以及通过 WebSocket 帧造成的信息泄露。测试人员使用 Burp Suite 拦截 WebSocket 握手和消息,构造恶意 payload,并测试 WebSocket 通道上的授权绕过。适用于 WebSocket 安全测试、WS 渗透测试、CSWSH 攻击或实时 API 安全评估相关请求。
testing-jwt-token-security
在安全测试活动中,评估 JSON Web Token(JWT)实现中的密码学弱点、算法混淆攻击和授权绕过漏洞。
testing-api-security-with-owasp-top-10
使用自动化和手工测试技术,针对 OWASP API 安全 Top 10 风险对 REST 和 GraphQL API 端点进行系统性评估。
performing-wireless-security-assessment-with-kismet
使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。
performing-ssl-tls-security-assessment
使用 sslyze Python 库评估 SSL/TLS 服务器配置,评估加密套件、证书链、协议版本、HSTS 头部,以及 Heartbleed 和 ROBOT 等已知漏洞。
performing-soap-web-service-security-testing
通过分析 WSDL 定义,测试 XML 注入(XML Injection)、XXE、WS-Security 绕过和 SOAPAction 欺骗,对 SOAP Web 服务执行安全测试。
performing-serverless-function-security-review
对 AWS Lambda、Azure Functions 和 GCP Cloud Functions 中的无服务器函数(Serverless Function)执行安全审查,识别过度宽松的执行角色(Execution Role)、不安全的环境变量、注入漏洞和缺失的运行时保护措施。
performing-scada-hmi-security-assessment
对 SCADA 人机界面(HMI, Human-Machine Interface)系统进行安全评估,识别基于 Web 的 HMI、瘦客户端配置、认证机制以及 HMI 与 PLC 之间通信信道中的漏洞,符合 IEC 62443 和 NIST SP 800-82 指南要求。
performing-s7comm-protocol-security-analysis
对西门子SIMATIC S7 PLC使用的S7comm和S7CommPlus协议进行安全分析,识别漏洞,包括重放攻击、完整性绕过、未授权的CPU停止命令以及针对S7-300、S7-400、S7-1200和S7-1500控制器弱点的程序下载操控。