OpenClaw 新版安全加固实操指南
生产环境安全配置手册 | 含完整命令、验证步骤、故障排查
🔐 安全目标
通过本指南的配置,实现:
工作区隔离:每个 Agent 只能访问自己的工作区目录 命令白名单:仅允许执行明确授权的命令 工具禁用:禁止执行外部工具(coding-agent 等) 只读模式:审计类 Agent 只能读取不能修改 故障恢复:配置错误时的快速恢复方案
适用场景:企业多 Agent 部署、敏感数据处理环境、合规审计要求
📋 第一部分:安全架构设计
1.1 权限模型
┌─────────────────────────────┐ │ Agent 独立配置 (高优先级) │ │ ~/.openclaw/agents/{id}/ │ ├─────────────────────────────┤ │ 全局配置 (默认基线) │ │ ~/.openclaw/openclaw.json │ ├─────────────────────────────┤ │ 系统默认 (最低优先级) │ └─────────────────────────────┘1.2 安全控制维度
🔧 第二部分:企业严格模式配置
步骤 1:创建工作区
mkdir -p ~/.openclaw/workspace/enterprise_agent/{documents,data,logs,output} chmod 700 ~/.openclaw/workspace/enterprise_agent tree -L 2 -a ~/.openclaw/workspace/enterprise_agent步骤 2:创建 Agent 目录
mkdir -p ~/.openclaw/agents/enterprise_agent/agent chmod 700 ~/.openclaw/agents/enterprise_agent步骤 3:编写安全配置
nano ~/.openclaw/agents/enterprise_agent/agent/config.json完整配置内容:
{ "id": "enterprise_agent", "workspace": "/home/kylin/.openclaw/workspace/enterprise_agent", "nodes": { "allowCommands": ["file.read", "file.write", "chat.send"], "denyCommands": ["system.run", "bash", "shell"], "fs": { "scope": ["/home/kylin/.openclaw/workspace/enterprise_agent"], "readOnly": false }, "tools": {"exec": {"policy": "deny"}} } }步骤 4:验证并应用
cat config.json | jq . openclaw gateway restart openclaw agents🧪 第三部分:安全测试验证
测试 1:访问工作区内文件(应成功)
测试 2:访问工作区外文件(应失败)
测试 3:执行 bash 命令(应失败)
测试 4:使用外部工具(应失败)
🔐 第四部分:常见场景配置
只读审计 Agent:readOnly=true,allowCommands 不包含 file.write
研发 Agent(宽松):scope=[],tools.exec.policy=allow
客服 Agent:scope=["/knowledge_base"],readOnly=true
财务 Agent(高安全):allowCommands 不包含 file.edit
❓ 第五部分:故障排查
配置不生效:检查 JSON 格式、重启 Gateway、查看日志
权限不足:检查 fs.scope 路径是否正确
命令被拒绝:检查 allowCommands 列表
快速恢复:删除 nodes 配置段,使用默认配置
📊 第六部分:安全审计
启用审计日志:security.auditLog=true
查看日志:grep 'permission denied' security-audit.log
定期审计:每周生成安全报告
文档版本:v1.0 | 安全级别:企业级 | 更新:2026-04-02 | 作者:狗蛋助理
⚠️ 重要提示:生产环境部署前,请在测试环境完整验证所有配置
夜雨聆风