repo:
evidence-agent。依據design-agent-auth.mdv2 + 後端計劃 §1 契約。 範圍:agent 自我註冊 + 心跳 + 設備指紋 + 資料面認證 + TLS。資料面/blob既有,沿用。 依賴契約:BE 計劃 §1(register/heartbeat/cert/JWT/X-Agent-Fingerprint)。可對 mock 雲端先開發。 📋 進度回填:開工/完成/卡住都更新 TRACKER。
device_uuid = sha256(product_uuid|machine_id|primary_mac)。POST <endpoint>/api/1.0/agents/register {token, device_uuid, base_url, hardware_info, agent_version, status, csr} → 拿 {agent_uid, certificate, ca_certificate, jwt_public_key, heartbeat_interval_sec}。heartbeat_interval_sec:POST /api/1.0/agents/heartbeat {device_uuid, status}(mTLS,帶拿到的 cert)。Authorization: Bearer <JWT> → 驗;回應加 X-Agent-Fingerprint。config:讀 env REGISTRATION_TOKEN、CLOUD_ENDPOINT、cert 存放路徑(AGENT_CERT_DIR)、host 識別碼路徑(/host/product_uuid、/host/machine-id、/host/mac)。core/fingerprint.py(新):
product_uuid = read('/host/product_uuid') # 缺則 ''
machine_id = read('/host/machine-id')
mac = read('/host/mac') # 部署腳本寫入
device_uuid = sha256(f"{product_uuid}|{machine_id}|{mac}")
開機算一次、快取。缺某來源 graceful(記 log,不崩)。core/enroll.py(新):
POST /agents/register(帶 token + device_uuid + csr) → 存回傳 cert/CA/jwt_public_key 到 AGENT_CERT_DIR。heartbeat_interval_sec POST /agents/heartbeat(mTLS 帶 cert)。before_request(blob 路由):mode=full 時驗 Authorization JWT —— 用 jwt_public_key 驗簽 + exp + aud==agent_uid + bound_fp==本地 device_uuid;任一不過 → 401。X-Agent-Fingerprint: <device_uuid>(after_request)。GET /agent-info → {device_uuid, agent_version, status}(供雲端/除錯)。deploy/collect-host-id.sh(抓 host MAC 寫 host-id/mac)。
deploy/docker-compose.yml:file-agent 掛 /sys/.../product_uuid:ro、/etc/machine-id:ro、./host-id/mac:ro、AGENT_CERT_DIR volume;新增 nginx service。AGENT_AUTH_MODE=none 時 before_request 略過(維持現 demo)。AGENT_AUTH_MODE 包覆,過程不破壞 121 demo;最後切 full。collect-host-id.sh 寫檔掛入(見 design §2.2)。