security: 迁移活消费者到主密钥 + keyfile 读取(legacy 行删除收口)

- plugins/hermes-zhiyi/__init__.py: ZHIYI_API_KEY 读 keyfile 主密钥(env 优先)
- cli-anything/.../client.py: DEFAULT_KEY 读 keyfile
- deploy/zhiyi-backup.sh: curl 用 $ZHIYI_KEY(从 keyfile 取)
- 配合 keyfile 删除 legacy: 行后全系统活消费者零旧 key 残留
This commit is contained in:
小唯
2026-09-22 01:07:10 +08:00
parent 2150e94cb8
commit 003f43834d
3 changed files with 19 additions and 3 deletions
@@ -6,7 +6,14 @@ import urllib.error
DEFAULT_BASE = "http://localhost:7821"
DEFAULT_KEY = "zhiyi-dev-key-2026"
def _default_key():
try:
for _l in open("/var/lib/memoryweave/.api-key"):
_s=_l.strip()
if _s and not _s.startswith("#") and not _s.startswith("legacy:"): return _s
except Exception: pass
return ""
DEFAULT_KEY = _default_key()
class ZhiYiClient:
+1 -1
View File
@@ -16,7 +16,7 @@ mkdir -p "$BACKUP_DIR"
# 1. 调用 API 触发备份
echo "[backup] Triggering admin/backup API..."
curl -s -X POST http://localhost:7821/api/v1/admin/backup \
-H "X-API-Key: zhiyi-dev-key-2026" > /dev/null 2>&1 || true
-H "X-API-Key: $ZHIYI_KEY" > /dev/null 2>&1 || true
# 2. LanceDB checkpoint + SQLite + Redis
echo "[backup] Creating archive..."
+10 -1
View File
@@ -45,7 +45,16 @@ DEFAULT_ZHIYI_URL = "http://localhost:7821"
ZHIYI_TIMEOUT = 10 # seconds per request
# API Key — read from .env ZHIYI_API_KEY
ZHIYI_API_KEY = os.environ.get("ZHIYI_API_KEY", "zhiyi-dev-key-2026")
def _read_main_key():
try:
for _l in open("/var/lib/memoryweave/.api-key"):
_s=_l.strip()
if _s and not _s.startswith("#") and not _s.startswith("legacy:"):
return _s
except Exception:
pass
return "" # keyfile 无主密钥/读取失败时留空(调用将 401,提示检查 keyfile)
ZHIYI_API_KEY = os.environ.get("ZHIYI_API_KEY") or _read_main_key()
# 日志中只暴露 key 的前 4 位,用于调试
_ZHIYI_KEY_PREFIX = ZHIYI_API_KEY[:4] if ZHIYI_API_KEY else "NONE"