contexte : etape 3, le pare-feu Proxmox lit la face reseau

La face publie le verdict des flux conditionnels ; devis_proxmox_fw y lit
inventaire, verdicts et administration. Devis identique, octet pour octet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Allaire 2026-10-05 12:51:37 -04:00
parent 44c24e62e4
commit 8c1e8c725b
5 changed files with 154 additions and 10 deletions

View file

@ -470,6 +470,46 @@ def face_publiee() -> None:
chemin.write_text(original, encoding="utf-8")
def proxmox_lit_la_face() -> None:
"""Le devis Proxmox lit la face publiee : un verdict bascule dans la face retire sa regle."""
import devis_proxmox_fw
import devis_reseau
import yaml as _yaml
couples = C.couples_hebergeur()
if not couples:
print("SAUTE aucun site frere : aucun devis Proxmox a confronter")
return
site, loc = couples[0]
face = loc.face_publiee() or {}
cible = next(((g, k) for g, v in (face.get("conditions") or {}).items() for k, ok in v.items()
if ok and k.startswith("ingress|tcp|")), None)
if cible is None:
print("SAUTE aucune condition vraie a basculer")
return
g, cle = cible
port = cle.split("|")[2]
def regles_du_port() -> int:
with C._monter(site):
bloc = next(b for b in devis_proxmox_fw.construire(devis_reseau.decouvrir_du_site())["blocs"]
if b["tenant"] == loc.nom)
return sum(1 for gr in bloc["groupes"] if gr["role"] == g
for r in gr["regles"] if str(r.get("dport")) == port)
chemin = loc.depot / C.NOM_FICHIER_FACE_RESEAU
original = chemin.read_text(encoding="utf-8")
avant = regles_du_port()
try:
f = _yaml.safe_load(original)
f["conditions"][g][cle] = False
chemin.write_text(_yaml.safe_dump(f, allow_unicode=True, sort_keys=False), encoding="utf-8")
apres = regles_du_port()
finally:
chemin.write_text(original, encoding="utf-8")
verifier(avant > 0 and apres == 0,
f"le devis Proxmox lit la face publiee : {g} {port}/tcp, {avant} regle(s), 0 une fois le verdict bascule")
def main() -> int:
with tempfile.TemporaryDirectory() as tmp:
d = Path(tmp)
@ -487,6 +527,7 @@ def main() -> int:
sorties()
fiche_deposee()
face_publiee()
proxmox_lit_la_face()
if ECHECS:
print(f"\n{len(ECHECS)} echec(s).")
return 1