Add safe artifact migration and status fixes

This commit is contained in:
phamnazage-jpg
2026-05-25 10:48:04 +08:00
parent 5e76fb20d0
commit 497e5d91b4
10 changed files with 875 additions and 70 deletions

View File

@@ -18,6 +18,72 @@
- 只把“latest-head / fresh-host / current-code”直接相关的证据放进“最终证据”
- 纯预跑、空目录、只到 preflight、已被后续更完整证据覆盖的目录放入“可清理”
## Security 分层(新增硬规则)
### A. `safe` artifact可入库
满足以下条件时,才允许留在 `artifacts/real-host-acceptance/` 并被文档直接引用:
- 不包含完整 upstream / managed / user API key
- 不包含完整 bearer token
- 不包含 Redis cache key 原文
- 不包含可直接执行的明文 SQL 凭据操作
- headers 已去掉 `Authorization` / `Cookie` / `Set-Cookie` / `x-api-key`
- 身份类字段user_id / admin_user_id / managed_user_email已改为 hash 或摘要
### B. `debug` artifact本地敏感
以下材料只能作本地短时调试使用,不得视为主证据入库:
- 明文 SQL例如 subscription access prep 原始语句)
- 带完整 key/token 的 runtime context
- 未脱敏 headers / raw body
- Redis cache key 原文
### C. 解释规则
- 文档中的“最终证据”默认指 `safe` artifact
- 若某目录只能在 `debug` 模式下复现价值,则应迁出主视图或只保留摘要版(例如 `21-summary.json` / `99-semantic-summary.json`
### D. 历史目录迁移脚本
当历史 `artifacts/real-host-acceptance/` 目录里仍残留旧版敏感材料时,使用:
```bash
python3 scripts/migrate_historical_artifacts.py artifacts/real-host-acceptance
```
默认行为:
- 原地把可安全化文件改写成 `safe` 版本
- 把明文敏感文件移动到 sibling 目录:
- `artifacts/real-host-acceptance-sensitive/`
- 为旧的 `05-subscription-access-prep.sql` 生成:
- `05-subscription-access-prep.summary.json`
- 为旧的 `07-redis-targeted-invalidation.txt` 生成:
- `07-redis-targeted-invalidation.json`
当前脚本会处理的典型历史文件:
- `00-local-key-source.json`
- `01-runtime-context.json`
- `00-context.json`
- `05-subscription-access-prep.sql`
- `07-redis-targeted-invalidation.txt`
- `08-subscription-group-state.json`
- `*.headers.txt`
- `00-managed-key.txt`
- `00-raw-user-key.txt`
脚本不会替你决定“最终证据 / 归档 / 清理”的业务分类;它只负责把旧目录先迁移到可安全审阅的形态。
- 第二轮迁移已补覆盖复杂 JSON 快照:
- `summary.json`
- `99-summary.json`
- `99-semantic-summary.json`
- `05a-batch-detail-pre-access.json`
- `07-access-status.json`
- `10-batch-detail.json`
- 对这类文件,脚本会递归处理常见敏感字段,并额外解析:
- `DetailsJSON`
- `details_json`
- `probe_summary_json`
这三类 JSON-in-string 字段,先反序列化再脱敏后写回。
- 当前仍需人工关注的残留主要是非标准手工文本快照,例如:
- `00-managed-key-corrected.txt`
- 其他不在固定命名集合中的手工 probe 文本
这些不影响“标准 artifact 已安全化”的结论,但不能直接把主目录视为 100% 无人工遗留。
## 1. 可保留为最终证据
这些目录应长期保留,属于当前 Gate=`APPROVED` 的核心证据。