OpenClaw Security Check
Fast 10-point security audit for OpenClaw config + host. Read-only by default, optional auto-fix.
Quick Start
Run the bundled script for a non-interactive report:
CODEBLOCK0
Or tell the agent: "run a security check" / "audit my OpenClaw config".
What It Checks
| # | Check | Severity if failed | What it looks at |
|---|
| 1 | Gateway Bind | CRITICAL | INLINECODE0 — must be loopback, not INLINECODE1 |
| 2 |
Gateway Auth | CRITICAL |
gateway.auth.mode — must not be
off/
none |
| 3 | Token Strength | HIGH |
gateway.auth.token — must be ≥32 chars |
| 4 | DM Policy | HIGH | Per-channel
dmPolicy —
open without
allowFrom is dangerous |
| 5 | Group Policy | HIGH | Per-channel
groupPolicy —
open/
any allows strangers to trigger the agent |
| 6 | Config Permissions | MEDIUM | File mode of
openclaw.json — should be 600 or 400 |
| 7 | Plaintext Secrets | MEDIUM | Scans config values for keys matching password/secret/apiKey/privateKey |
| 8 | Host Firewall | HIGH | UFW or firewalld must be installed and active |
| 9 | SSH Hardening | MEDIUM | PasswordAuthentication and PermitRootLogin in sshd_config |
| 10 | Exposed Ports | MEDIUM | Count of non-loopback listening ports (>8 = FAIL) |
Auto-Fix Flow
If any item is FAIL or WARN, offer fixes. Always confirm with the user first.
Fix Recipes
#1 Gateway Bind → FAIL:
Set gateway.bind to "loopback". Use openclaw CLI if available, otherwise edit openclaw.json.
#2 Gateway Auth → FAIL:
Set gateway.auth.mode to "token". Generate a strong token if missing:
CODEBLOCK1
#3 Token Strength → FAIL/WARN:
Replace with a new 48-char hex token: openssl rand -hex 24.
Warn user that paired clients will need the new token.
#4 DM Policy → FAIL:
Set affected channels to "dmPolicy": "pairing", or add specific IDs to allowFrom.
#5 Group Policy → FAIL:
Set affected channels to "groupPolicy": "allowlist".
#6 Config Permissions → FAIL/WARN:
CODEBLOCK2
#7 Plaintext Secrets → WARN:
Cannot auto-fix safely. Advise moving secrets to environment variables or .env.local.
#8 Host Firewall → FAIL:
CODEBLOCK3
#9 SSH Hardening → WARN:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo sed -i 's/^#*PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/^#*PermitRootLogin .*/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl reload ssh
CRITICAL: Ensure key-based SSH access works in a separate session before closing current one.
#10 Exposed Ports → WARN/FAIL:
Review with ss -ltnp, close unnecessary services, or restrict with firewall rules.
Fix Rules
- - Backup first: INLINECODE24
- Merge, don't overwrite: Modify only the specific keys, preserve everything else.
- SSH changes need special care: Always test access in a second session before closing the first.
- Firewall: allow SSH first, enable second. Getting this backwards locks you out.
- After config changes:
openclaw gateway restart to apply. - Re-run the check after fixes to confirm everything passes.
Integration
Heartbeat
Add to HEARTBEAT.md for periodic checks:
CODEBLOCK5
Cron
Schedule via OpenClaw cron for standalone audits:
CODEBLOCK6
Combining with healthcheck skill
This skill focuses on
fast config + host audit (10 checks, <5 seconds).
The built-in
healthcheck skill provides a
full hardening workflow (risk profiling, remediation planning, guided execution).
Use this skill for quick checks; escalate to healthcheck for comprehensive hardening.
OpenClaw 安全检查
针对 OpenClaw 配置及主机的快速 10 项安全审计。默认只读,可选自动修复。
快速开始
运行捆绑脚本以获取非交互式报告:
bash
scripts/security-check.sh # 人类可读格式
scripts/security-check.sh --json # 结构化输出
或者告诉智能体:运行安全检查 / 审计我的 OpenClaw 配置。
检查项
| # | 检查项 | 失败严重级别 | 检查内容 |
|---|
| 1 | 网关绑定 | 严重 | gateway.bind — 必须为回环地址,不能是 0.0.0.0 |
| 2 |
网关认证 | 严重 | gateway.auth.mode — 不能为 off/none |
| 3 | 令牌强度 | 高 | gateway.auth.token — 必须 ≥32 个字符 |
| 4 | 私信策略 | 高 | 各频道 dmPolicy — open 且未设置 allowFrom 存在风险 |
| 5 | 群组策略 | 高 | 各频道 groupPolicy — open/any 允许陌生人触发智能体 |
| 6 | 配置文件权限 | 中 | openclaw.json 的文件权限 — 应为 600 或 400 |
| 7 | 明文密钥 | 中 | 扫描配置值中匹配 password/secret/apiKey/privateKey 的键 |
| 8 | 主机防火墙 | 高 | 必须安装并启用 UFW 或 firewalld |
| 9 | SSH 加固 | 中 | sshd_config 中的 PasswordAuthentication 和 PermitRootLogin |
| 10 | 暴露端口 | 中 | 非回环监听端口数量(>8 = 失败) |
自动修复流程
如果任何项目为失败或警告,提供修复方案。务必先与用户确认。
修复方案
#1 网关绑定 → 失败:
将 gateway.bind 设置为 loopback。如果可用,使用 openclaw CLI,否则编辑 openclaw.json。
#2 网关认证 → 失败:
将 gateway.auth.mode 设置为 token。如果缺失,生成强令牌:
bash
openssl rand -hex 24
#3 令牌强度 → 失败/警告:
替换为新的 48 字符十六进制令牌:openssl rand -hex 24。
警告用户配对的客户端将需要新令牌。
#4 私信策略 → 失败:
将受影响的频道设置为 dmPolicy: pairing,或在 allowFrom 中添加特定 ID。
#5 群组策略 → 失败:
将受影响的频道设置为 groupPolicy: allowlist。
#6 配置文件权限 → 失败/警告:
bash
chmod 600 ~/.openclaw/openclaw.json
#7 明文密钥 → 警告:
无法安全自动修复。建议将密钥移至环境变量或 .env.local。
#8 主机防火墙 → 失败:
bash
sudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outgoing
重要:先允许 SSH 再启用!
sudo ufw allow from <受信任IP或子网> to any port 22 proto tcp
sudo ufw enable
#9 SSH 加固 → 警告:
bash
sudo cp /etc/ssh/sshdconfig /etc/ssh/sshdconfig.bak
sudo sed -i s/^#PasswordAuthentication ./PasswordAuthentication no/ /etc/ssh/sshd_config
sudo sed -i s/^#PermitRootLogin ./PermitRootLogin no/ /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl reload ssh
严重:在关闭当前会话前,确保在另一个会话中基于密钥的 SSH 访问正常工作。
#10 暴露端口 → 警告/失败:
使用 ss -ltnp 检查,关闭不必要的服务,或通过防火墙规则限制。
修复规则
- - 先备份: cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak
- 合并而非覆盖: 仅修改特定键,保留其他所有内容。
- SSH 变更需特别小心: 在关闭第一个会话前,务必在第二个会话中测试访问。
- 防火墙:先允许 SSH,再启用。 顺序搞反会导致被锁定。
- 配置变更后: 执行 openclaw gateway restart 以应用。
- 修复后重新运行检查 以确认所有项目通过。
集成
心跳检查
添加到 HEARTBEAT.md 以进行定期检查:
- - 每次心跳:运行 scripts/security-check.sh,对任何失败项发出警报
定时任务
通过 OpenClaw 定时任务安排独立审计:
bash
openclaw cron add --name security-check --schedule 0 8
* --task 运行 scripts/security-check.sh 并报告结果
与健康检查技能结合
本技能专注于
快速配置及主机审计(10 项检查,<5 秒)。
内置的 healthcheck 技能提供
完整的加固工作流程(风险分析、修复规划、引导执行)。
使用本技能进行快速检查;如需全面加固,升级至 healthcheck。