fix: add workflow to fix cmd agent auth
Debug CMD Agent / Debug CMD Agent (push) Successful in 0s
Read Auth Logic / Read check_auth logic (push) Successful in 0s
Read CMD Agent Source / Read CMD Agent server.py (push) Successful in 0s
Read CMD Agent Token / Read Real Token (push) Successful in 0s

This commit is contained in:
2026-07-12 00:46:24 +08:00
parent aa8a41ddb3
commit eea9f01f7b
+43
View File
@@ -0,0 +1,43 @@
name: Fix CMD Agent Auth
on: [push]
jobs:
fix:
runs-on: host
steps:
- name: 验证不带Bearer
run: curl -s -w "\nHTTP_CODE:%{http_code}" http://127.0.0.1:18888/status -H "Authorization: xsa-f2778a6953d59948cd1e5be4d99f60f7"
- name: 验证带Bearer(应该失败)
run: curl -s -w "\nHTTP_CODE:%{http_code}" http://127.0.0.1:18888/status -H "Authorization: Bearer xsa-f2778a6953d59948cd1e5be4d99f60f7"
- name: 修复check_auth函数
run: |
cp /opt/xiaoxia-cmd-agent/server.py /opt/xiaoxia-cmd-agent/server.py.bak
python3 -c "
with open('/opt/xiaoxia-cmd-agent/server.py', 'r') as f:
content = f.read()
old = ''' def check_auth(self):
t = self.headers.get(\"Authorization\", \"\")
if t != AUTH_TOKEN:
self._j({\"error\": \"unauthorized\"}, 401); return False
return True'''
new = ''' def check_auth(self):
t = self.headers.get(\"Authorization\", \"\")
if t.startswith(\"Bearer \"):
t = t[7:]
if t != AUTH_TOKEN:
self._j({\"error\": \"unauthorized\"}, 401); return False
return True'''
content = content.replace(old, new)
with open('/opt/xiaoxia-cmd-agent/server.py', 'w') as f:
f.write(content)
print('Fixed')
"
- name: 重启服务
run: systemctl restart xiaoxia-cmd-agent
- name: 等待服务启动
run: sleep 2
- name: 修复后验证-不带Bearer
run: curl -s -w "\nHTTP_CODE:%{http_code}" http://127.0.0.1:18888/status -H "Authorization: xsa-f2778a6953d59948cd1e5be4d99f60f7"
- name: 修复后验证-带Bearer
run: curl -s -w "\nHTTP_CODE:%{http_code}" http://127.0.0.1:18888/status -H "Authorization: Bearer xsa-f2778a6953d59948cd1e5be4d99f60f7"
- name: 公网路径验证
run: curl -sk -w "\nHTTP_CODE:%{http_code}" https://127.0.0.1/cmd-agent/status -H "Authorization: Bearer xsa-f2778a6953d59948cd1e5be4d99f60f7"