09 安全

Estimated reading: 2 minutes 43 views

09

SAFE

安全加固

~13 分钟 · 安全基线与多维度加固

“安装后不做安全加固,OpenClaw 可能暴露在已知攻击面中。”

9.1

安全背景

1 min

OpenClaw 采用 一个可信操作者 → 一个 Gateway → 多个 Agent 的安全模型。Gateway 是唯一入口,所有外部请求必须经过 Gateway 鉴权。

已知风险:

ClawHub 恶意技能

ClawHavoc 事件,已被 Koi Security、The Hacker News 等报道;第三方技能可包含恶意指令

ClawJacked 漏洞

被 Dark Reading 等安全媒体报道,涉及技能劫持攻击链

结论

安装后不做安全加固,OpenClaw 可能暴露在已知攻击面中。默认配置优先”开箱即用”而非安全。

9.2

60 秒安全基线

2 min

为什么需要基线?

默认配置优先”开箱即用”而非安全——Gateway 可能无鉴权、工具权限全开、DM 通道不设限。

一次性覆盖最关键攻击面:Gateway 鉴权 + 工具最小权限 + 消息通道管控

⚠️ 本地 vs 云端部署

以下为本地部署基线。云端部署请将 mode 改为 "gateway"bind 改为 "0.0.0.0" 或具体内网 IP,否则外部无法连入会掉线。

完整 hardened baseline JSON —— 写入 ~/.openclaw/openclaw.json

本地部署(默认):

{ gateway: { mode: “local”, bind: “loopback”, auth: { mode: “token”, token: “replace-with-long-random-token” } } }

云端部署:

{ gateway: { mode: “gateway”, bind: “0.0.0.0”, auth: { mode: “token”, token: “replace-with-long-random-token” } } }

其余字段两种部署方式通用:

{ session: { dmScope: “per-channel-peer” }, tools: { profile: “messaging”, deny: [“group:automation”, “group:runtime”, “group:fs”, “sessions_spawn”, “sessions_send”], fs: { workspaceOnly: true }, exec: { security: “deny”, ask: “always” }, elevated: { enabled: false } }, channels: { whatsapp: { dmPolicy: “pairing”, groups: { “*”: { requireMention: true } } } } }

生成 token:openclaw doctor --generate-gateway-token

9.3

Gateway 访问控制

2 min

作用:Gateway 是所有外部请求进入 OpenClaw 的唯一入口。

为什么:默认 Gateway 在本地端口监听但没鉴权,同网络任何人可直接调用。

解决bind: "loopback" 限本机;auth.mode: "token" 要求密钥。

{ gateway: { bind: “loopback”, auth: { mode: “token”, token: { $ref: “env:OPENCLAW_GATEWAY_TOKEN” } } } }

环境变量OPENCLAW_GATEWAY_TOKEN 或 OPENCLAW_GATEWAY_PASSWORD

bind 可选值:loopback(默认)、lan、tailnet、custom

云端部署必须使用 lan 或 0.0.0.0loopback 仅限本机

远程访问:推荐 SSH 隧道或 Tailscale Serve,不要暴露公网端口

9.4

工具权限控制

2 min

作用:控制 Agent 能调用哪些工具。

为什么:ClawHub 第三方技能可能包含恶意指令(ClawHavoc 已证实)。

解决:deny 禁高危工具组;exec.security: "deny"fs.workspaceOnly: trueelevated: false

{ tools: { profile: “messaging”, deny: [“group:automation”, “group:runtime”, “group:fs”, “sessions_spawn”, “sessions_send”], fs: { workspaceOnly: true }, exec: { security: “deny”, ask: “always” }, elevated: { enabled: false } } }

tools.exec.host:”sandbox”(推荐)或 “gateway”

危险工具组:group:automation、group:runtime、group:fs

elevated{ enabled: false } 禁用提权

9.5

Docker 沙箱隔离

2 min

作用:每个 Agent 运行在独立 Docker 容器中。

为什么:即使工具权限控制到位,Agent 代码仍可能通过漏洞逃逸,沙箱是第二道防线。

解决network: "none" 防数据外泄;readOnlyRoot: true 防篡改;capDrop: ["ALL"] 防提权;user: "1000:1000" 非 root。

{ sandbox: { engine: “docker”, network: “none”, readOnlyRoot: true, capDrop: [“ALL”], user: “1000:1000”, tmpfs: { “/tmp”: “size=64m,noexec” } } }

永远不挂载 Docker socket,避免容器逃逸

readOnlyRoot: true 防止运行时篡改文件系统

网络默认 “none”,需要时用 “bridge”,永远不用 “host”

9.6

密钥管理 SecretRef

1 min

作用:将 API Key 等敏感凭据从配置文件分离。

为什么:配置文件可能被提交 Git、被日志记录、被其他进程读取。

解决:SecretRef 只存指针,支持 env / file / exec(1Password / Vault / SOPS)。

{ openai: { apiKey: { $ref: “env:OPENAI_API_KEY” } }, anthropic: { apiKey: { $ref: “file:~/.openclaw/secrets/anthropic.key” } }, custom: { token: { $ref: “exec:op read op://vault/openclaw/token” } } }

支持 3 种 source:env(环境变量)/ file(文件)/ exec(命令,如 1Password CLI)

绝不在配置文件明文存储 API Key

检查泄露openclaw secrets audit --check

9.7

其他安全设置

2 min

DM/群组策略

{ channels: { whatsapp: { dmPolicy: “pairing”, // 要求配对确认 groups: { “*”: { requireMention: true } } // 群组需 @提及 } } }

日志脱敏

{ logging: { redactSensitive: “tools” // 自动遮蔽敏感字段 } }

mDNS 发现

{ discovery: { mode: “minimal” // 或设置环境变量 OPENCLAW_DISABLE_BONJOUR=1 } }

浏览器 SSRF 防护

{ browser: { dangerouslyAllowPrivateNetwork: false // 阻止访问私有网络 } }

9.8

文件权限与 CLI 命令

1 min

文件权限

chmod 700 ~/.openclaw chmod 600 ~/.openclaw/openclaw.json chmod 600 ~/.openclaw/secrets.json

~/.openclaw/ —— 主配置目录,仅 owner 可访问

openclaw.json —— 主配置文件,含 Gateway token

secrets.json —— SecretRef 凭据文件

CLI 安全命令

# 安全审计 openclaw security audit openclaw security audit –deep openclaw security audit –fix openclaw security audit –json # 密钥管理 openclaw secrets audit –check openclaw secrets configure # Gateway openclaw doctor –generate-gateway-token

留下回复

您的邮箱地址不会被公开。 必填项已用 * 标注

分享此文档

09 安全

复制链接

目录