🎯 做完你会得到
Gateway 接入点有认证保护,只有授权用户才能使用
👤 适合谁
- OpenClaw Gateway 认证加固:防止
⚡ 效果预览
输入需求后,AI 会围绕「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,忘了只能重新生成(重新生成后所有客户端需要更新)
🦞 跑完这个副本了?
加入虾农微信群,跟 300+ 玩家交流踩坑经验、分享配置技巧
二维码过期?添加微信 深夜开发者LND 备注「虾农」拉你入群
AI Agent exec 热力图:哪类命令最频繁、最慢、最容易出错
用 OpenClaw 把 exec 调用做成热力图,统计不同命令的频次、耗时和失败率,帮助优化自动化链路。
AI API 网关:一次接入 100+ 平台,一个 AI 统一调用
用 OpenClaw 的 API Gateway 技能一次接入 Google/GitHub/Notion/Slack 等 100+ 平台——OAuth 授权一次完成,AI 统一调度所有工具,不需要为每个平台单独配置,大幅简化 AI 工具管理。
AI自主配置Google Cloud OAuth
当AI需要Google API时,它会自己判断入口、打开浏览器、完成整个OAuth授权流程,全程无需人工介入
AI 自主配置 API 凭证
OpenClaw 发现缺少 API Key 时,自己打开浏览器、进入控制台、完成 OAuth 配置、生成 Token,全程无需你动手。