fix(awooop): Phase 2 第二批 P0 安全強化 + Redis key 命名空間修正

## P0-05 Callback Nonce 防偽造(ADR-116)
- security_interceptor.py:generate_callback_nonce() 新增 HMAC-SHA256[:16] 附加
  - 新 5-part 格式:{action}:{short_id}:{ts}:{rand}:{hmac16}
  - CALLBACK_HMAC_SECRET 未設定時降級 warning(向後相容)
- security_interceptor.py:parse_callback_data() 新增 5-part 分支 + HMAC 驗證
- config.py:新增 CALLBACK_HMAC_SECRET: str = Field(default="")

## P0-06 Webhook HMAC Replay 防護(ADR-116)
- security_interceptor.py:新增 check_webhook_nonce()(Service 層,get_redis 在此層合法)
- webhooks.py:verify_webhook_signature() 新增兩個可選 Header
  - X-Webhook-Timestamp:±300s 窗口驗證(若提供)
  - X-Webhook-Nonce:呼叫 check_webhook_nonce()(Redis NX dedup,fail open)
  - 移除直接 get_redis import(leWOOOgo 積木化修正)

## P0-11 ollama:current_primary Redis key 遷移 Phase A(ADR-110)
- ollama_auto_recovery.py:_REDIS_PRIMARY_KEY = "platform:ollama:current_primary"
  - 雙寫舊 key "ollama:current_primary"(Phase A 30 天)
  - 讀取以新 key 為主,fallback 舊 key

## P0-12 consensus Redis key 加 project namespace Phase A
- consensus_engine.py:新增 _consensus_key() / _consensus_legacy_key() helper
  - 新 key:{project_id}:consensus:{consensus_id}
  - project_id=None 時 fallback __platform__:consensus:{consensus_id}
  - Phase A 雙寫 + fallback 讀取,現有呼叫方零修改

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-05-04 13:54:38 +08:00
parent 2b2359e367
commit f2f5148ca6
6 changed files with 265 additions and 22 deletions

View File

@@ -6,6 +6,24 @@
---
## 2026-05-04 | AwoooP Phase 2 初批 P0 修正 + Phase 1.7 Testscommit 14bf86a4
### 修正
- **P0-08 telemetry.py**`_validate_endpoint()` 移除硬碼 IP assert → `OTEL_ALLOWED_ENDPOINTS` / `OTEL_FORBIDDEN_ENDPOINTS` config-drivenEwoooC 可覆寫
- **P0-13 mcp_bridge.py**5 處 `"awoooi-prod"` hardcode → `settings.AWOOOI_K8S_NAMESPACE`config.py 新增此欄位
- **P1-24 decision_manager.py**`f"telegram_silence:{target}"``SILENCE_KEY_PREFIX` 從 telegram_gateway import消除雙重定義
- **Phase 1 Task 1.7**:新增 `tests/integration/test_awooop_phase1_schema.py`31 test casesrevision 不可變性 / VIEW draft 隔離 / active_pointer_guard / RLS fail-closed / outbox FK
### 下一步Phase 2 剩餘 P0
- P0-05: security_interceptor.py nonce 重設計PoC 確認漏洞)
- P0-06: webhooks.py replay 防護
- P0-11: ollama:current_primary 加 platform: 前綴Redis 雙寫遷移 Batch A
- P0-12: consensus_engine.py CONSENSUS_PREFIX 加 project 前綴
- P1-16: nl_gateway.py hermes Redis key 加 project 前綴
- P1-17: anomaly_counter.py per-project 改造
---
## 2026-05-04 | AwoooP Phase 1 Critic 修正4 Critical
critic review 發現的 4 個 Critical + 3 個 Major 問題全部修正: