先瞄一眼你们的现状——当前是本地 local 模式,token 认证,bind: loopback 只绑本地,安全性还不错。开始上课。
7.1 认证与授权
Auth Mode 三种模式:
| token | 所有 API 请求需携带 token 头 | 自建服务器,你当前用的就是这种 ✅ |
| none | 无认证,谁都能连 | 本地调试 |
| trusted-proxy | 信任上游代理(Nginx)的认证 | 生产环境后有反向代理时 |
你现在的配置:
\”auth\”: {
\”mode\”: \”token\”,
\”token\”: \”d9857707…\”
}
为什么 token 比 none 重要? Dashboard、Channel 都在调用 Gateway API,如果设成 none,局域网内任何知道地址的人都能操作你的 Agent。token 是基本防线。
Auth Profile 轮换: 如果你有多个 API Key(比如 DashScope 和 DeepSeek 各一个),Gateway 可以在一个 key 配额用完后自动切换到另一个。目前你们在用的是主模型 + fallback 的方式,本质也是一种冗余策略。
SecretRef 安全管理: API key 可以存在 ~/.openclaw/.env 文件里,不写进配置,降低泄漏风险。
认证流程示意图:
#mermaid-svg-Mm37jNPOjw4k61M4{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Mm37jNPOjw4k61M4 .error-icon{fill:#552222;}#mermaid-svg-Mm37jNPOjw4k61M4 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Mm37jNPOjw4k61M4 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Mm37jNPOjw4k61M4 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Mm37jNPOjw4k61M4 .marker.cross{stroke:#333333;}#mermaid-svg-Mm37jNPOjw4k61M4 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Mm37jNPOjw4k61M4 p{margin:0;}#mermaid-svg-Mm37jNPOjw4k61M4 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster-label text{fill:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster-label span{color:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster-label span p{background-color:transparent;}#mermaid-svg-Mm37jNPOjw4k61M4 .label text,#mermaid-svg-Mm37jNPOjw4k61M4 span{fill:#333;color:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 .node rect,#mermaid-svg-Mm37jNPOjw4k61M4 .node circle,#mermaid-svg-Mm37jNPOjw4k61M4 .node ellipse,#mermaid-svg-Mm37jNPOjw4k61M4 .node polygon,#mermaid-svg-Mm37jNPOjw4k61M4 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Mm37jNPOjw4k61M4 .rough-node .label text,#mermaid-svg-Mm37jNPOjw4k61M4 .node .label text,#mermaid-svg-Mm37jNPOjw4k61M4 .image-shape .label,#mermaid-svg-Mm37jNPOjw4k61M4 .icon-shape .label{text-anchor:middle;}#mermaid-svg-Mm37jNPOjw4k61M4 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-Mm37jNPOjw4k61M4 .rough-node .label,#mermaid-svg-Mm37jNPOjw4k61M4 .node .label,#mermaid-svg-Mm37jNPOjw4k61M4 .image-shape .label,#mermaid-svg-Mm37jNPOjw4k61M4 .icon-shape .label{text-align:center;}#mermaid-svg-Mm37jNPOjw4k61M4 .node.clickable{cursor:pointer;}#mermaid-svg-Mm37jNPOjw4k61M4 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-Mm37jNPOjw4k61M4 .arrowheadPath{fill:#333333;}#mermaid-svg-Mm37jNPOjw4k61M4 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Mm37jNPOjw4k61M4 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Mm37jNPOjw4k61M4 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Mm37jNPOjw4k61M4 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-Mm37jNPOjw4k61M4 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Mm37jNPOjw4k61M4 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster text{fill:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 .cluster span{color:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Mm37jNPOjw4k61M4 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-Mm37jNPOjw4k61M4 rect.text{fill:none;stroke-width:0;}#mermaid-svg-Mm37jNPOjw4k61M4 .icon-shape,#mermaid-svg-Mm37jNPOjw4k61M4 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Mm37jNPOjw4k61M4 .icon-shape p,#mermaid-svg-Mm37jNPOjw4k61M4 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-Mm37jNPOjw4k61M4 .icon-shape .label rect,#mermaid-svg-Mm37jNPOjw4k61M4 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Mm37jNPOjw4k61M4 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-Mm37jNPOjw4k61M4 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-Mm37jNPOjw4k61M4 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
token 模式
none 模式
trusted-proxy 模式
有效
无效
可信
不可信
Auth Profile 轮换
充足
不足
主 API Key
配额检查
使用主 Key
切换到备用 Key
客户端请求
认证模式判断
检查 Token 头
直接放行
验证上游代理



