O
OpenClaw

安全指南

OpenClaw 作为连接多个聊天应用的 AI 网关,安全配置至关重要。本文介绍最佳安全实践。

重要提醒: 默认配置允许任何人访问。生产环境使用前,务必 配置访问控制。

访问控制

使用 allowFrom 限制用户

每个频道都应该配置 allowFrom 选项,只允许特定用户访问:

{
  "channels": {
    "telegram": {
      "enabled": true,
      "botToken": "...",
      "allowFrom": ["123456789", "987654321"]
    },
    "whatsapp": {
      "enabled": true,
      "allowFrom": ["+86138xxxxxxxx", "+86139xxxxxxxx"]
    }
  }
}

群组安全

在群组中,建议启用 requireMention

"groups": {
  "*": {
    "requireMention": true,
    "mentionPatterns": ["@mybot", "AI助手"]
  }
}

API 密钥管理

环境变量

不要将 API 密钥直接写入配置文件,使用环境变量:

# ~/.zshrc 或 ~/.bashrc export ANTHROPIC_API_KEY="your-key-here" export TELEGRAM_BOT_TOKEN="your-token-here" export DISCORD_BOT_TOKEN="your-token-here"

密钥轮换

定期更换 API 密钥,尤其是怀疑泄露时:

  • Anthropic: 账户设置 → API Keys → 撤销并重新生成
  • Telegram: @BotFather → /revoke
  • Discord: Developer Portal → Bot → Reset Token

网络安全

本地部署

默认情况下,Gateway 只监听 127.0.0.1,这是安全的。如需远程访问:

  • 使用反向代理(Nginx/Traefik)
  • 启用 HTTPS
  • 配置防火墙规则
  • 考虑使用 Tailscale 等 VPN

使用 Tailscale

推荐通过 Tailscale 远程访问 Gateway:

# 安装 Tailscale # macOS: brew install tailscale # Ubuntu: curl -fsSL https://tailscale.com/install.sh | sh # 启动并登录 tailscale up # 在其他设备上访问 curl http://your-machine-name:18789/

敏感数据

日志中的敏感信息

OpenClaw 会记录会话日志,注意不要泄露:

  • 定期清理日志文件:~/.openclaw/logs/
  • 不要在公开场合分享日志
  • 敏感对话使用私密频道

记忆文件

记忆文件存储在 ~/.openclaw/workspace/memory/,可能包含敏感信息:

# 设置目录权限 chmod 700 ~/.openclaw/workspace/memory

安全清单

  • ☐ 所有频道都配置了 allowFrom
  • ☐ 群组中启用了 requireMention
  • ☐ API 密钥使用环境变量
  • ☐ 不在公开场合分享配置文件
  • ☐ 定期更新 OpenClaw 到最新版本
  • ☐ 限制日志文件访问权限