trading-system-docs/red-queen-architecture/control-plane/README.md

112 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# PRE_HERMES Control Plane — Betriebsvertrag (CP1)
Autoritative SoT für die produktive PRE_HERMES Autonomy Control Plane.
Dieses Verzeichnis ist die **einzige** Quelle für den produktiven Control-Plane-Code.
Produktiver Deploy-Pfad: `red-queen-architecture/control-plane/``/opt/control-plane/`.
## 1. Zweck
Minimale, fail-closed Sicherheitsgrundlage für zukünftige Red-Queen/Hermes-Autonomie.
**CP1 ist KEINE Autonomie-Aktivierung.** Nach CP1 ist das System mindestens so restriktiv wie vorher.
## 2. Komponenten
| Datei | Zweck |
|---|---|
| `control_reader.py` | Fail-closed, deterministischer Control-State-Reader (produktiver Code) |
| `test_control_reader.py` | Statische + adversariale Tests (AJ, 25 Fälle) |
| `deploy_control_plane.sh` | Reproduzierbarer Deployment-Pfad (root, idempotent) |
| `README.md` | Dieser Betriebsvertrag |
## 3. Control State (Source of Truth)
Produktiver Pfad: `/opt/control-plane/state/` (root:root, 0700, Dateien 0600).
| Datei | Typ | Erlaubte RAW-Werte |
|---|---|---|
| `global_autonomy` | positiv | `ON` / `OFF` (+ `boot_id=`) |
| `productive_mutations` | positiv | `ON` / `OFF` (+ `boot_id=`) |
| `save_execution` | positiv | `ON` / `OFF` (+ `boot_id=`) |
| `delete_execution` | positiv | `ON` / `OFF` (+ `boot_id=`) |
| `trading_execution` | positiv | `ON` / `OFF` (+ `boot_id=`) |
| `emergency_stop` | negativ | `ON` / `OFF` |
**Positives ON-Grant-Format:**
```
ON
boot_id=<current_kernel_boot_id>
```
## 4. Gate-Semantik (fail-closed)
- **Positives Gate:** `EFFECTIVE=ON` nur wenn `RAW==ON` UND `grant_boot_id == current_boot_id` UND `EMERGENCY_EFFECTIVE==OFF`. Sonst `OFF`.
- **Emergency Stop (negativ):** `EFFECTIVE=ON` wenn `RAW==ON` ODER Datei fehlt ODER malformed. `OFF` nur bei explizitem `RAW==OFF`.
- **UNKNOWN = MORE RESTRICTIVE.** Fehlende/unlesbare/malformed Datei → positives Gate `OFF`, Emergency `ON`.
- **Hierarchie:** `SAVE/DELETE/TRADING_EFFECTIVE` benötigen `GLOBAL_AUTONOMY_EFFECTIVE==ON` UND `MUTATIONS_EFFECTIVE==ON` UND eigenen Grant gültig UND `EMERGENCY_EFFECTIVE==OFF`. Kein spezifischer Execution-Switch umgeht den globalen Mutation-Gate.
## 5. Boot-ID-Validierung
- Quelle: `/proc/sys/kernel/random/boot_id` (Kernel-Boot-ID, ändert sich bei jedem Host-Boot).
- Positiver Grant ist nur gültig, wenn `grant_boot_id == current_boot_id`.
- `missing boot_id``EFFECTIVE=OFF`. `malformed boot_id``EFFECTIVE=OFF`.
- **Keine manuell gepflegte Epoch, kein persistenter Alt-Grant.**
## 6. Restart-Semantik (korrekt dokumentiert)
- **HOST REBOOT:** `current_boot_id` ändert sich → alle alten positiven Grants ungültig → `EFFECTIVE=OFF`. Operator muss erneut autorisieren.
- **CONTAINER RESTART OHNE HOST REBOOT:** `current_boot_id` bleibt gleich → ein gültiger positiver Grant kann weiterhin gültig bleiben (kein neuer Boot, keine neue Autorisierung nötig).
- **Negative/Deny-States** (`emergency_stop=ON`, `*_execution=OFF`) persistieren über Restart hinweg (fail-closed).
## 7. Status Projection Contract
- Produktiver Pfad: `/opt/control-plane/status/latest.txt` (root:root, 0444, read-only).
- **STATUS PROJECTION != AUTHORITY.**
- **Authority ist ausschließlich:** Control State + aktuelle Kernel-Boot-ID + fail-closed effective-state evaluation.
- `latest.txt` dient **ausschließlich der Observability**.
- Wenn die Projection fehlt/stale/malformed ist, darf das **niemals eine positive Freigabe erzeugen** (die Authority-Evaluation ist davon unabhängig).
## 8. Ownership / Permissions
- Control State: root:root, 0700 (dir), 0600 (Dateien).
- Status Projection: root:root, 0444.
- Audit: root:root, `chattr +a` (append-only).
- **Red Queen:** kein Host-Root, kein Docker-Socket, kein Schreibzugriff auf `/opt/control-plane`. RQ kann State nicht lesen (0700) und nicht schreiben. RQ erhält später nur read-only Status-Projection (Observability).
## 9. Audit-Foundation
- Pfad: `/opt/control-plane/audit/control_audit.log` (root:root, append-only `+a`).
- Format: `WHEN | WHO | WHAT | OLD | NEW | WHY | BOOT_ID`.
- RQ kann Audit nicht überschreiben (root-owned, append-only).
## 10. Deployment (reproduzierbar)
```bash
# Als root auf dem Host, aus frischem Forgejo-Checkout:
cd red-queen-architecture/control-plane
./deploy_control_plane.sh
```
- Reproduziert ausschließlich die CP1-Artefakte.
- **Überschreibt KEINE bestehenden State-Dateien** (Runtime-State bleibt unangetastet).
- Rollback: `rm -rf /opt/control-plane`.
## 11. NICHT in Git
- Aktuelle produktive State-Werte als Authority (State ist Runtime, nicht SoT).
- Aktuelle `boot_id` als persistente Authority.
- Secrets, Tokens, private Keys.
- Runtime Audit Log.
## 12. Sicherheitszustand (CP1 initial)
```
GLOBAL_AUTONOMY_EFFECTIVE=OFF
MUTATIONS_EFFECTIVE=OFF
SAVE_EFFECTIVE=OFF
DELETE_EFFECTIVE=OFF
TRADING_EFFECTIVE=OFF
EMERGENCY_EFFECTIVE=ON
A2-A5=NOT_PRESENT HEARTBEAT=NOT_PRESENT SCHEDULER=NOT_PRESENT
AUTH.4D=FROZEN P15=FALSE DELETE_CANARY=FALSE
TRADING_ENABLED=false
```