Install
openclaw skills install davidme6-auth-guardClawHub Security found sensitive or high-impact capabilities. Review the scan results before using.
授权保护技能 - 所有外部 API 操作必须经过用户明确授权。这是最高优先级的安全层,确保没有任何自动化可以擅自使用你的授权。核心原则:用户指令是唯一且最优先级。
openclaw skills install davidme6-auth-guard授权保护技能 - 为你的所有 API 授权添加强制确认层
# 启用授权保护(必须)
AUTH_GUARD_ENABLED=true
# 运行模式:STRICT | WHITELIST | AUDIT
AUTH_GUARD_MODE=STRICT
# 超时时间(秒),超时后自动拒绝
AUTH_GUARD_TIMEOUT=300
# 通知渠道:feishu | telegram | webhook
AUTH_GUARD_NOTIFY=feishu
# Webhook URL(可选,用于推送确认请求)
AUTH_GUARD_WEBHOOK_URL=https://your-webhook.com/auth-guard
创建 ~/.auth_guard_whitelist.json:
{
"allowed_operations": [
{
"service": "google-mail",
"action": "messages.get",
"max_per_hour": 100
}
],
"blocked_operations": [
{
"service": "*",
"action": "messages.send",
"reason": "发送邮件必须人工确认"
},
{
"service": "slack",
"action": "chat.postMessage",
"reason": "发送消息必须人工确认"
}
],
"time_windows": {
"google-mail.messages.get": 600
}
}
from auth_guard import AuthGuard
guard = AuthGuard()
# 请求授权
response = guard.request_authorization(
service="google-mail",
action="messages.send",
params={
"to": "recipient@example.com",
"subject": "Test",
"body": "Hello"
},
reason="发送测试邮件"
)
if response["authorized"]:
# 执行操作
send_email(...)
else:
# 被拒绝
print(f"拒绝原因:{response['reason']}")
启动授权服务:
python -m auth_guard.server --port 8765
请求授权:
curl -X POST http://localhost:8765/authorize \
-H "Content-Type: application/json" \
-d '{
"service": "google-mail",
"action": "messages.send",
"params": {...},
"reason": "发送通知邮件"
}'
在调用外部 API 前,先通过 auth-guard 检查:
import requests
def guarded_api_call(service, action, params):
# 1. 请求授权
auth_response = requests.post('http://localhost:8765/authorize', json={
'service': service,
'action': action,
'params': params,
'requester': 'api-gateway'
})
auth_data = auth_response.json()
if not auth_data.get('authorized'):
raise PermissionError(f"操作被拒绝:{auth_data.get('reason')}")
# 2. 执行实际操作
result = execute_api(service, action, params)
# 3. 记录审计日志
requests.post('http://localhost:8765/audit', json={
'service': service,
'action': action,
'result': 'success',
'auth_token': auth_data['auth_token']
})
return result
当收到授权请求时,你会看到:
🔐 授权请求 #12345
═══════════════════════════════════════
服务:Google Mail
操作:发送邮件
请求者:api-gateway
时间:2026-03-15 12:30:45
───────────────────────────────────────
详情:
收件人:recipient@example.com
主题:月度报告
内容预览:您好,附件是本月报告...
───────────────────────────────────────
风险等级:🟡 中等(外部通信)
───────────────────────────────────────
操作:
✅ 批准(本次)
✅ 批准并记住(同类操作 1 小时内免确认)
❌ 拒绝
⏸️ 稍后决定(5 分钟后提醒)
═══════════════════════════════════════
所有授权请求都会记录到 ~/.auth_guard/audit_log.jsonl:
{"timestamp":"2026-03-15T12:30:45Z","request_id":"req_12345","service":"google-mail","action":"messages.send","requester":"api-gateway","status":"approved","user":"admin","ip":"127.0.0.1"}
{"timestamp":"2026-03-15T12:31:00Z","request_id":"req_12346","service":"slack","action":"chat.postMessage","requester":"auto-bot","status":"denied","reason":"非用户本人请求"}
查看日志:
# 查看所有拒绝的请求
cat ~/.auth_guard/audit_log.jsonl | jq 'select(.status=="denied")'
# 查看今天的授权统计
cat ~/.auth_guard/audit_log.jsonl | jq 'select(.timestamp > "2026-03-15")' | jq -s 'group_by(.status) | map({status: .[0].status, count: length})'
~/.auth_guard/config.json{
"enabled": true,
"mode": "STRICT",
"timeout_seconds": 300,
"notification": {
"channel": "feishu",
"webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/xxx"
},
"security": {
"api_key": "your-secure-api-key",
"allowed_ips": ["127.0.0.1"],
"rate_limit": {
"requests_per_hour": 100
}
},
"audit": {
"log_path": "~/.auth_guard/audit_log.jsonl",
"retention_days": 90
}
}
POST /authorize
请求体:
{
"service": "服务名称",
"action": "操作类型",
"params": {"参数": "值"},
"reason": "请求原因",
"requester": "请求者标识",
"priority": "normal|high|urgent"
}
响应:
{
"authorized": true,
"auth_token": "xxx",
"expires_at": "2026-03-15T13:00:00Z",
"conditions": ["single_use"]
}
POST /revoke
{
"auth_token": "xxx"
}
GET /pending
响应:
{
"pending_requests": [
{
"request_id": "req_12345",
"service": "google-mail",
"action": "messages.send",
"requested_at": "2026-03-15T12:30:45Z"
}
]
}
POST /batch-decide
{
"request_ids": ["req_12345", "req_12346"],
"decision": "approve|deny"
}
修改 api-gateway 调用流程:
# 在 api-gateway 中拦截所有请求
def gateway_request(service, path, method, data):
# 1. 通过 auth-guard 检查
auth = auth_guard.request(
service=service,
action=path,
params=data,
reason=f"API 调用:{method} {path}"
)
if not auth['authorized']:
raise AuthGuardError(f"被 auth-guard 拒绝:{auth['reason']}")
# 2. 添加授权令牌到请求头
headers['Authorization'] = f"Bearer {maton_key}"
headers['Auth-Guard-Token'] = auth['auth_token']
# 3. 执行请求
return execute_request(service, path, method, data)
在安装新技能时自动检查是否需要 auth-guard:
# skill-vetter 检查清单中添加:
- [ ] 是否需要 auth-guard 保护?
- [ ] 是否已配置白名单?
- [ ] 审计日志是否启用?
检查:
解决:
# 查看所有待处理请求
curl http://localhost:8765/pending
# 批量拒绝所有待处理
curl -X POST http://localhost:8765/batch-decide \
-H "Content-Type: application/json" \
-d '{"request_ids": ["all"], "decision": "deny"}'
优化:
# 查看状态
auth-guard status
# 查看待处理请求
auth-guard pending
# 批准请求
auth-guard approve req_12345
# 拒绝请求
auth-guard deny req_12345
# 查看审计日志
auth-guard audit --today
# 紧急停止所有授权
auth-guard emergency-stop
# 导出审计报告
auth-guard report --format pdf --output report.pdf
⚠️ 重要:
AUTH_GUARD_ENABLED 设置为 falseAUTH_GUARD_MODE 设置为 AUDIT(除非仅用于测试)~/.auth_guard/audit_log.jsonl~/.auth_guard/config.json 中的 API 密钥你的授权,你做主。没有任何自动化可以绕过。 🔐🦀