保护你的 AI Agent 技能与数据 — 基于 Skill Vetter 260K+ 下载经验
ClawHub 拥有 72,000+ 个 Skills,其中可能包含恶意代码或安全漏洞。一个不小心,你的 API Key 可能泄露、你的数据可能被窃取、你的 Agent 可能被滥用。
// 不要这样做!
const OPENAI_API_KEY = "sk-abc123..."; // ❌ 硬编码
process.env.OPENAI_KEY = "sk-abc123..."; // ❌ 明文存储
// 不要写在代码里
// config.js
export const API_KEY = "sk-abc123..."; // ❌ 会提交到 Git
// 1. 使用环境变量
// .env 文件(添加到 .gitignore)
OPENAI_API_KEY=sk-abc123...
// 代码中读取
const apiKey = process.env.OPENAI_API_KEY;
// 2. 使用 OpenClaw 的密钥管理
// ~/.openclaw/secrets.yaml
secrets:
openai:
provider: env
key: OPENAI_API_KEY
# 或者加密存储
aws:
provider: aws-secrets-manager
secret_id: arn:aws:secretsmanager:...
// 代码中读取
const apiKey = await openclaw.secrets.get('openai');
# 使用 Skill Vetter 检查
openclaw skill-vetter check clawhub/some-skill
# 深度检查
openclaw skill-vetter check clawhub/some-skill --deep
# 输出示例:
# ✅ 未检测到恶意代码
# ⚠️ 发现网络请求(预期行为)
# ⚠️ 检测到文件读取(检查权限)
# ✅ 依赖安全
# 建议:safe(安全)
# 扫描所有已安装的 Skills
openclaw skill-vetter scan-all
# 生成报告
openclaw skill-vetter scan-all --report security-report.json
# 查看报告
cat security-report.json
# ~/.openclaw/config.yaml
security:
auto_vet: true
block_unsafe: true
auto_vet_mode: strict
# 自定义规则
custom_rules:
- name: check-hardcoded-keys
pattern: "sk-[a-zA-Z0-9]{20,}"
action: block
message: "检测到可能的 API Key 硬编码"
只授予 Agent 完成任务所需的最小权限:
# ~/.openclaw/skills/my-agent/SKILL.md
---
name: my-agent
permissions:
# 只允许读取特定目录
file_read:
- /var/www/miaoquai/tools/
- /var/www/miaoquai/glossary/
# 不允许写入(除非必要)
file_write: false
# 只允许特定网络请求
network:
allowed_domains:
- api.openai.com
- miaoquai.com
blocked_domains:
- *.evil.com
# 不允许执行系统命令
exec: false
---
# My Agent with minimal permissions
# 查看 Agent 的权限
openclaw permissions list my-agent
# 检查权限使用情况
openclaw permissions audit my-agent --last 7d
# 输出示例:
# Permission Usage Report for my-agent
# - file_read: used 145 times (✅ 正常)
# - network: used 89 times (⚠️ 发现异常请求到 unknown-domain.com)
# - exec: 0 times (✅ 未使用,保持禁用)
# 确保所有 API 请求使用 HTTPS
# ~/.openclaw/config.yaml
http:
enforce_https: true
verify_ssl: true
timeout: 30000
# 加密敏感数据
# ~/.openclaw/config.yaml
encryption:
enabled: true
algorithm: aes-256-gcm
# 加密这些字段
encrypt_fields:
- '*.api_key'
- '*.password'
- '*.token'
- 'memory.semantic.user_profile'
# 密钥管理
key_provider: aws-kms # 或 local(本地密钥)
# ~/.openclaw/config.yaml
audit:
enabled: true
log_level: detailed
# 记录这些事件
events:
- skill_install
- skill_execute
- file_access
- network_request
- permission_change
- config_change
# 日志存储
storage:
type: file
path: /var/log/openclaw/audit.log
rotation: daily
retention: 90d # 保留 90 天
# 配置异常检测
# ~/.openclaw/config.yaml
anomaly_detection:
enabled: true
# 检测规则
rules:
- type: request_spike
threshold: 100 # 每分钟超过 100 次请求
action: alert
- type: unauthorized_access
pattern: "permission_denied > 10/min"
action: block
- type: data_exfiltration
pattern: "upload > 10MB to unknown domain"
action: block_and_alert
# 报警方式
alert:
- type: email
to: admin@miaoquai.com
- type: webhook
url: https://hooks.slack.com/...
# 紧急情况:禁用所有外部 Skills
openclaw skills disable-all --except core
# 紧急情况:重置所有权限
openclaw permissions reset --confirm
# 紧急情况:轮换所有 API Key
openclaw secrets rotate-all