Skip to content

Add: verify_running_containers.py -- runtime secret drift audit (#9355) - #9541

Merged
jsboige merged 2 commits into
mainfrom
feature/9355-runtime-secret-drift-audit
Aug 6, 2026
Merged

jsboige merged 2 commits into
mainfrom
feature/9355-runtime-secret-drift-audit

Conversation

@jsboige

@jsboige jsboige commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Grain: MED/tooling — lane myia-po-2023:CoursIA-2 — prev: MED/tooling #9354

Add: verify_running_containers.py — runtime secret drift audit (post #9355 rotation gap)

Branch : feature/9355-runtime-secret-drift-audit based on origin/main @ 502b33fd5.
See : #9355 (partial — runtime verification side), #9351 (mechanism side, PR #9354 MERGED).

Contexte

render_envs.py --check est une porte statique : elle compare master.env à chaque .env sur disque. C'est nécessaire mais pas suffisant. Un conteneur déjà lancé détient la valeur qu'il avait au moment de docker compose up ; il la garde jusqu'au prochain restart. Donc un master.env nouvellement rotaté peut apparaître « in sync » sur disque pendant que le service répond encore avec l'ancienne clé.

Cette PR ferme ce trou en lisant l'env réel du conteneur via docker inspect --format {{json .Config.Env}} et en comparant chaque variable d'auth centralisée (WHISPER_API_KEY → API_KEY, COMFYUI_*_TOKEN → même nom, plus les autres paires renommées) à master.env sur le système vivant.

Recette #9355 (chaque worker post-pull)

python scripts/secrets/render_envs.py --bootstrap-missing   # 1× par worker, ferme l'aveugle .env
# Si master.env a drifté -> éditer master.env, puis :
python scripts/secrets/render_envs.py                      # propager
python scripts/secrets/render_envs.py --check               # exit 0 = sync disque
# Relancer les services affectés :
docker compose -f docker-configurations/services/<svc>/docker-compose.yml up -d <svc>
# Vérifier runtime :
python scripts/secrets/verify_running_containers.py         # exit 0 = sync runtime

Diagnostic dérive (règle C.4 — PR review §D.5)

Cause (a) — conception originelle : --check ne regardait que les fichiers sur disque. La course « rotate master.env → écrire .env → redéployer conteneur » a 3 étapes, et le --check n'en couvre que 2. La 3ème (le conteneur tenant l'ancienne valeur jusqu'au up -d) était silencieusement hors-périmètre.

Cause (b) — fausse confiance à l'opérateur : un render_envs.py --check qui passe incite à croire que tout est aligné ; l'opérateur n'a aucune raison de relancer le conteneur si --check dit [OK]. Donc la rotation « réussit sur disque, échoue en pratique » pendant une fenêtre non bornée.

Verdict : CAUSE_FIXED (côté script). Le nouveau verify_running_containers.py rend la 3ème étape visible : tout drift runtime remonte en exit 1 avec le nom du service + la clé qui diverge. Un cron quotidien peut l'invoquer comme garde-fou.

Fichiers

  • NEW scripts/secrets/verify_running_containers.py (272 lignes) — argparse + audit par service, modes humain/JSON, masque 4 derniers chars cohérent avec render_envs.py.
  • NEW scripts/secrets/tests/test_verify_running_containers.py (243 lignes) — 18 tests : _mask, _read_master_env, _detect_auth_vars, audit_service (5 statuts : OK / DRIFT / NOT_RUNNING / MASTER_MISSING / CONTAINER_MISSING), main exit codes.

Note L948 ★★ + secrets-hygiene.md règle 6 : tous les fixtures de test sont des chaînes explicitement fake (fixture-whisper-XXXX-1234, hf_fixtureABCDEF1234567890, sk-test-fixture-value). Les vraies valeurs vivent uniquement dans .secrets/master.env (gitignored). Sans cette précaution, GitHub push protection rejette le push comme « Hugging Face User Access Token ».

Vérification firsthand

  • Tests : python -m pytest scripts/secrets/tests/ → 59/59 PASS (41 render_envs existants + 18 nouveaux).
  • Runtime sur cette machine (post chore(secrets,#9351): per-worker rotation of WHISPER_API_KEY (and other 17 services) after --bootstrap-missing lands #9355 rotation) :
    [OK] comfyui-qwen         COMFYUI_BEARER_TOKEN MASTER_MISSING (per-instance, by design)
    [OK] comfyui-video       COMFYUI_VIDEO_TOKEN → OK master=***uIsf container=***uIsf
    [NOT_RUNNING] demucs-api, funasr-api, musicgen-api, qwen-asr-api, sd-forge, tts-multi
    [OK] tts-api             TTS_API_KEY → API_KEY OK
    [NO_AUTH_VAR] forge-turbo, orchestrator, planners-fast-downward, sd-forge-main, sdnext, tts-fishaudio, vllm-zimage, whisper-webui, shared
    [OK] whisper-api         WHISPER_API_KEY → API_KEY OK (post-rotation aligned)
    
    Exit 0 global — aucun drift runtime détecté.
  • L898 ★★★ : gh pr list --state all --search "verify_running OR bootstrap-missing" → 0 PR concurrente sur ce chemin.
  • C.1 / C.2 / H.1 / H.3 : N/A (script Python hors notebook, pas de cellule, pas d'output à valider).
  • catalog-pr-hygiene : COURSE_CATALOG.generated.{json,md} byte-identique à main (touché zéro fichier catalogue).

Leçon c.9355-L1 ★★ (NEW)

La rotation de secrets a 3 étapes, pas 2. Le réflexe « master.env + render + --check » oublie la 3ème : le conteneur qui tient la valeur stale jusqu'au up -d. Sans une vérification runtime dédiée, cette 3ème étape est invisible à l'opérateur et le service répond avec l'ancienne clé sans que rien dans --check ne le signale.

Pattern : après un outil de cohérence fichier-à-fichier (--check), ajouter systématiquement un outil de cohérence runtime (state vivant = conteneurs, kernels, caches d'agent, fichiers mmapés, etc.). Le runtime ne s'aligne pas tout seul sur le disque — la seule porte est « restart the thing that holds the state ».

Liens

…9355 rotation gap)

Closes #9355 partial: render_envs.py --check is a STATIC gate (file-vs-file).
A running container still holds the credential it was launched with until
the next docker compose restart, so a rotated master.env value can look
'in sync' on disk while the running service still answers with the OLD key.
This script closes that blind spot by reading the actual container env
via 'docker inspect --format {{json .Config.Env}}' and comparing each
centralized auth var (WHISPER_API_KEY/.. -> API_KEY, COMFYUI_*-TOKEN -> same,
plus the other renamed pairs) against master.env on the live system.

One-shot exit code: 0 if every running container matches master; 1 on
DRIFT; NOT_RUNNING / MASTER_MISSING (intentionally non-centralized keys
like COMFYUI_BEARER_TOKEN per secrets-hygiene.md) are informational and
do NOT trigger exit 1. Secret values are masked (last 4 chars only) in
both human and --json modes, consistent with render_envs.py convention.

Recipe for #9355 on any worker post-pull:
  python scripts/secrets/verify_running_containers.py
  # If DRIFT reported for a service -> docker compose restart that service.

59/59 secrets tests pass (41 existing render_envs + 18 new). Verified
live on this machine: whisper-api (post-rotation aligned), tts-api
(aligned), comfyui-video (aligned), 6 services NOT_RUNNING (informational),
comfyui-qwen COMFYUI_BEARER_TOKEN MASTER_MISSING (per-instance password,
by design).

Co-Authored-By: Claude-Code <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Aug 5, 2026
…ing (#9548)

Grain: MED/lean — lane myia-ai-01:CoursIA — prev: DEEP/lean #9539

#9536 rewrote ceilLog2 via Nat.log 2 in MacroCell.lean (FR) but left the
_en sibling on the old WellFounded recursion — an i18n DRIFT that turned
'Scripts Tests (CPU)' red on main for every PR (seen on #9541/#9543).

- Port def ceilLog2 + ceilLog2_spec proof to the EN sibling (byte-identical
  code, EN docstrings/comments per sibling-pair Pattern A).
- lake build Conway.Life.MacroCell_en: SUCCESS (2947 jobs), EXIT=0.
- check_i18n_siblings.py --all: 177/179 byte-identical, 0 drift, 0 orphan.

Co-authored-by: Claude-Code <noreply@anthropic.com>
@jsboige
jsboige merged commit 13514bd into main Aug 6, 2026
13 checks passed
@jsboige
jsboige deleted the feature/9355-runtime-secret-drift-audit branch September 2, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant