🎯 做完你会得到
Gateway 接入点有认证保护,只有授权用户才能使用
🛠 需要什么
- filesystem
👤 适合谁
- OpenClaw管理员
- 运维工程师
⚡ 效果预览
配置多层鉴权和访问控制,OpenClaw Gateway安全加固一步到位
🔧 Step 0:先配置消息接收渠道
⚠️ 本案例需要发送通知到你的手机,先配置消息渠道 👉 去配置 Telegram/飞书/微信接入 →
这个场景解决什么问题
OpenClaw Gateway 默认在本地或服务器上监听,如果不设置认证,任何能访问到端口的人都能使用你的 AI 助手(消耗你的 API 费用)。这篇案例涵盖最重要的几个安全配置。
直接复制这段:一键生成 Token 并开启认证
openclaw config set gateway.auth.mode token
openclaw config set gateway.auth.token "$(openssl rand -hex 32)"
openclaw config get gateway.auth.token # 复制这个 token 备用
openclaw gateway restart
核心步骤
第一步:设置 Gateway Token 认证
v2026.3.7+ 版本必须显式配置,否则 Gateway 不启动:
# 方式一:命令行快速配置
openclaw config set gateway.auth.mode token
openclaw config set gateway.auth.token "$(openssl rand -hex 32)"
# 查看生成的 token
openclaw config get gateway.auth.token
或在 ~/.openclaw/openclaw.json 中添加:
{
"gateway": {
"auth": {
"mode": "token",
"token": "your-very-long-random-secret-token"
}
}
}
第二步:限制消息来源(白名单)
只允许指定用户发消息:
{
"channels": {
"telegram": {
"allowFrom": ["123456789"],
"groups": {
"*": {
"requireMention": true,
"allowFrom": ["123456789", "987654321"]
}
}
},
"feishu": {
"allowFrom": ["user@company.com"]
}
}
}
第三步:限制 Web Dashboard 访问
默认 Web Dashboard 绑定 127.0.0.1(只本地访问),远程访问需要显式配置:
{
"gateway": {
"http": {
"host": "127.0.0.1",
"port": 18789
}
}
}
如需远程访问,使用 Tailscale 内网穿透代替直接暴露端口。
第四步:配置 HTTPS(生产环境)
{
"gateway": {
"http": {
"host": "0.0.0.0",
"port": 18789,
"tls": {
"enabled": true,
"cert": "/etc/ssl/certs/openclaw.crt",
"key": "/etc/ssl/private/openclaw.key"
}
}
}
}
第五步:限制工具权限
不需要所有工具时,收紧 profile:
{
"tools": {
"profile": "default",
"denyList": ["exec_command", "write_file"]
}
}
关键配置
最小安全配置清单:
- 设置 gateway.auth.mode 和 token
- 配置 allowFrom 白名单
- 确认 Web Dashboard 不对外暴露
- tools.profile 按需收紧
- 定期轮换 token(建议每月一次)
预期结果
- 没有 token 的请求被拒绝
- 非白名单用户发消息不响应
- Web Dashboard 只有授权访问
- API 费用不会被他人盗用
安全审计一键扫描
# 运行安全审计(扫描常见配置漏洞)
openclaw security audit
# 深度扫描
openclaw security audit --deep
# 自动修复已知问题
openclaw security audit --fix
注意事项
- Token 要足够复杂,建议使用
openssl rand -hex 32生成 - 修改配置后必须重启 Gateway 生效
- 白名单 ID 的格式因渠道不同而异(Telegram 是数字 ID,飞书是邮箱)
- 记录好 token,忘了只能重新生成(重新生成后所有客户端需要更新)
#安全#Gateway认证#Token#白名单#HTTPS
⚔️ 同类副本推荐 ⚔️