Reconstruction propre : orchestrateur ordonné, registre des flux + pare-feu
Rend l'écosystème reconstructible en une commande (create+deploy idempotent) et ajoute la couche « accès » (nftables least-privilege) au zéro-confiance. Orchestrateur (phase 2) : - docs/couches-deploiement.yml : registre des couches (socle → pki → services → apps → agents) - scripts/orchestrer.py : tri par couche + topo intra-couche (graphe) → playbooks/site.yml ordonné - Makefile : site / deployer-tout / flotte-creer / reconstruire / myDay (+ gardes CONFIRMER) - docs/dependances-groupes.yml : graphe complété (keycloak→openldap, dovecot, postfix, icingaweb2, nextcloud) Audit codé-en-dur (phase 1b) : labels/slug OIDC dérivés de l'intrant `organisation` (serveur_forgejo/grafana/nextcloud) — le moteur ne porte plus de nom de tenant. Registre des flux réseau (phase 0) : - meta/flux.yml pour tous les rôles (29 rôles, 63 flux ; schéma + matrice validés) - scripts/resoudre_flux.py : matrice d'audit (docs/registre-flux.md) + rulesets nftables résolus par hôte - roles/nftables_baseline : déploie le ruleset résolu (moindre-privilège) quand activé, sinon repli Correctifs : détection du coffre Vault (chemin production → inventaire réellement résolu). Outillage : make wiki-publier (publication du wiki pédagogique dans Forgejo). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
02bbba61b3
commit
f05f505b88
38 changed files with 1434 additions and 25 deletions
150
Makefile
150
Makefile
|
|
@ -128,6 +128,28 @@ aide:
|
|||
@printf '%s\n' ' Convention:'
|
||||
@printf '%s\n' ' groupe serveur_debian -> playbooks/groupes/serveur_debian.yml'
|
||||
@printf '%s\n' ''
|
||||
@printf '%s\n' 'Ecosysteme complet (orchestrateur)'
|
||||
@printf '%s\n' ' Ordre de deploiement (couches + graphe):'
|
||||
@printf '%s\n' ' make site-verifier # valide la coherence couches/graphe'
|
||||
@printf '%s\n' ' python3 scripts/orchestrer.py ordre'
|
||||
@printf '%s\n' ' (Re)generer playbooks/site.yml ordonne:'
|
||||
@printf '%s\n' ' make site'
|
||||
@printf '%s\n' ' CONFIGURER la flotte existante, couche par couche (2b, VM deja creees):'
|
||||
@printf '%s\n' ' make deployer-tout CONFIRMER=true # (MODE_CHECK=1 pour un essai a blanc idempotent)'
|
||||
@printf '%s\n' ' CREER toutes les VM du plan (2a, clone Proxmox):'
|
||||
@printf '%s\n' ' make flotte-creer CONFIRMER=true'
|
||||
@printf '%s\n' ' RECONSTRUIRE from-zero = creer les VM PUIS deployer (2a+2b, VM inexistantes):'
|
||||
@printf '%s\n' ' make reconstruire CONFIRMER=true # alias: make myDay CONFIRMER=true'
|
||||
@printf '%s\n' ''
|
||||
@printf '%s\n' 'Flux reseau (pare-feu / audit)'
|
||||
@printf '%s\n' ' Matrice d audit + apercus nftables resolus (NON actives):'
|
||||
@printf '%s\n' ' make flux # -> docs/registre-flux.md + instance/flux-genere/*.nft'
|
||||
@printf '%s\n' ' make flux-verifier # valide schema + coherence de matrice'
|
||||
@printf '%s\n' ''
|
||||
@printf '%s\n' 'Wiki pedagogique'
|
||||
@printf '%s\n' ' Publier wiki/ dans le wiki Forgejo (source versionnee -> vue browsable):'
|
||||
@printf '%s\n' ' make wiki-publier WIKI_REMOTE=https://forge.<domaine>/<proprio>/<depot>.wiki.git'
|
||||
@printf '%s\n' ''
|
||||
@printf '%s\n' 'Inventaires'
|
||||
@printf '%s\n' ' Graphe de production:'
|
||||
@printf '%s\n' ' make inventaire'
|
||||
|
|
@ -189,7 +211,7 @@ test:
|
|||
python3 scripts/tests/test_inventory_host.py
|
||||
|
||||
.PHONY: verifier
|
||||
verifier: lint test inventaire-verifier syntaxe
|
||||
verifier: lint test inventaire-verifier site-verifier flux-verifier syntaxe
|
||||
|
||||
.PHONY: inventaire hote-planifier hote-ajouter hote-groupes hote-afficher appliquer deployer deployer-groupe cloner-vm creer-vm config inventaire-ui inventaire-verifier inventaire-lister inventaire-graphe inventaire-hote inventaire-lab inventaire-production instance-utiliser instance-courante
|
||||
inventaire: inventaire-production
|
||||
|
|
@ -251,7 +273,7 @@ deployer: _instance-requise
|
|||
printf '%s\n' 'Refus: aucun playbook applicable pour HOTE=$(HOTE).'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
vault_chiffre="$$(grep -rlsIF '$$ANSIBLE_VAULT' $(SETOPS_INSTANCE)/inventories/production/group_vars 2>/dev/null | head -1 || true)"; \
|
||||
vault_chiffre="$$(grep -rlsIF '$$ANSIBLE_VAULT' $(dir $(INVENTAIRE_PRODUCTION))group_vars 2>/dev/null | head -1 || true)"; \
|
||||
if [[ -n "$$vault_chiffre" && -z "$${ANSIBLE_VAULT_PASSWORD_FILE:-}" ]]; then \
|
||||
if [[ -t 0 ]]; then \
|
||||
read -r -s -p 'Mot de passe du vault Ansible: ' mdp; echo; \
|
||||
|
|
@ -270,6 +292,128 @@ deployer: _instance-requise
|
|||
done; \
|
||||
$(MAKE) verifier-hote LIMITE="$(HOTE)"
|
||||
|
||||
.PHONY: site site-verifier deployer-tout
|
||||
site: ansible-runtime
|
||||
python3 scripts/orchestrer.py ecrire
|
||||
ansible-playbook -i $(INVENTAIRE_PRODUCTION) playbooks/site.yml --syntax-check
|
||||
|
||||
site-verifier:
|
||||
python3 scripts/orchestrer.py verifier
|
||||
|
||||
.PHONY: flux flux-verifier
|
||||
flux: ansible-runtime
|
||||
python3 scripts/resoudre_flux.py registre
|
||||
python3 scripts/resoudre_flux.py nftables
|
||||
|
||||
flux-verifier:
|
||||
python3 scripts/resoudre_flux.py verifier
|
||||
|
||||
.PHONY: wiki-publier
|
||||
wiki-publier:
|
||||
@set -e; \
|
||||
if [[ -z "$(WIKI_REMOTE)" ]]; then \
|
||||
printf '%s\n' 'Refus: URL du wiki Forgejo requise.'; \
|
||||
printf '%s\n' 'Ex: make wiki-publier WIKI_REMOTE=https://forge.<domaine>/<proprio>/<depot>.wiki.git'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
src="$(CURDIR)/wiki"; \
|
||||
tmp="$$(mktemp -d)"; \
|
||||
trap 'rm -rf "$$tmp"' EXIT; \
|
||||
printf '%s\n' "Clonage du wiki: $(WIKI_REMOTE)"; \
|
||||
if ! git clone --quiet --depth 1 "$(WIKI_REMOTE)" "$$tmp/wiki"; then \
|
||||
printf '%s\n' 'Echec du clone (URL ou acces ?). Le wiki doit exister (creer une 1re page dans Forgejo).'; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
find "$$tmp/wiki" -maxdepth 1 -name '*.md' -delete; \
|
||||
for f in "$$src"/*.md; do \
|
||||
bn="$$(basename "$$f")"; \
|
||||
[[ "$$bn" == "README.md" ]] && continue; \
|
||||
cp "$$f" "$$tmp/wiki/$$bn"; \
|
||||
done; \
|
||||
cd "$$tmp/wiki"; \
|
||||
if [[ -z "$$(git status --porcelain)" ]]; then \
|
||||
printf '%s\n' 'Wiki deja a jour (aucun changement).'; \
|
||||
exit 0; \
|
||||
fi; \
|
||||
git add -A; \
|
||||
sha="$$(git -C "$(CURDIR)" rev-parse --short HEAD 2>/dev/null || echo inconnu)"; \
|
||||
git commit --quiet -m "Publication du wiki depuis le depot (source: $$sha)"; \
|
||||
git push --quiet; \
|
||||
printf '%s\n' 'Wiki publie.'
|
||||
|
||||
deployer-tout: _instance-requise
|
||||
@set -e; \
|
||||
if [[ "$(CONFIRMER)" != "true" ]]; then \
|
||||
printf '%s\n' 'Refus: deploiement ORCHESTRE de TOUTE la flotte (action impactante).'; \
|
||||
printf '%s\n' 'Relancer avec CONFIRMER=true. Astuce: tester d abord en idempotent avec MODE_CHECK=1.'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
python3 scripts/orchestrer.py verifier; \
|
||||
python3 scripts/orchestrer.py ecrire; \
|
||||
vault_chiffre="$$(grep -rlsIF '$$ANSIBLE_VAULT' $(dir $(INVENTAIRE_PRODUCTION))group_vars 2>/dev/null | head -1 || true)"; \
|
||||
if [[ -n "$$vault_chiffre" && -z "$${ANSIBLE_VAULT_PASSWORD_FILE:-}" ]]; then \
|
||||
if [[ -t 0 ]]; then \
|
||||
read -r -s -p 'Mot de passe du vault Ansible: ' mdp; echo; \
|
||||
vf="$$(mktemp)"; printf '%s' "$$mdp" > "$$vf"; chmod 600 "$$vf"; \
|
||||
export ANSIBLE_VAULT_PASSWORD_FILE="$$vf"; \
|
||||
trap 'rm -f "$$vf"' EXIT; \
|
||||
else \
|
||||
printf '%s\n' 'Refus: vault chiffre detecte mais aucun mot de passe (entree non interactive). Fournir ANSIBLE_VAULT_PASSWORD_FILE ou le champ vault de la GUI.'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
fi; \
|
||||
$(MAKE) _verifier-acces-hote LIMITE="$(GROUPE_HOTES_ACTIFS)"; \
|
||||
$(MAKE) _verifier-privileges-hote LIMITE="$(GROUPE_HOTES_ACTIFS)"; \
|
||||
mode="$$([[ -n "$(MODE_CHECK)" ]] && printf -- '--check --diff' || true)"; \
|
||||
ansible-playbook -i $(INVENTAIRE_PRODUCTION) playbooks/site.yml --limit "$(GROUPE_HOTES_ACTIFS)" $$mode
|
||||
|
||||
# --- Reconstruction from-zero : creer TOUTES les VM (2a) puis deployer (2b) ---
|
||||
|
||||
.PHONY: flotte-creer
|
||||
flotte-creer: _instance-requise
|
||||
@set -e; \
|
||||
if [[ "$(CONFIRMER)" != "true" ]]; then \
|
||||
printf '%s\n' 'Refus: creation de TOUTES les VM actives du plan (clone Proxmox).'; \
|
||||
printf '%s\n' 'Relancer avec CONFIRMER=true.'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
hotes="$$(python3 scripts/inventory_host.py --inventaire $(INVENTAIRE_PRODUCTION) lister-actifs)"; \
|
||||
if [[ -z "$$hotes" ]]; then printf '%s\n' 'Refus: aucun hote actif dans le plan.'; exit 2; fi; \
|
||||
for h in $$hotes; do \
|
||||
printf '\n=== Creation VM: %s ===\n' "$$h"; \
|
||||
$(MAKE) creer-vm HOTE="$$h"; \
|
||||
done; \
|
||||
printf '\nToutes les VM actives sont creees.\n'
|
||||
|
||||
.PHONY: _attendre-flotte
|
||||
_attendre-flotte: ansible-runtime
|
||||
@set -e; \
|
||||
max="$${ATTENTE_MAX:-600}"; deadline=$$(( $$(date +%s) + max )); \
|
||||
printf 'Attente que la flotte reponde en SSH (max %ss)...\n' "$$max"; \
|
||||
until ansible -i $(INVENTAIRE_PRODUCTION) $(GROUPE_HOTES_ACTIFS) -m ping -e ansible_become=false >/dev/null 2>&1; do \
|
||||
if (( $$(date +%s) > deadline )); then printf 'Timeout: flotte injoignable apres %ss.\n' "$$max"; exit 1; fi; \
|
||||
sleep 10; \
|
||||
done; \
|
||||
printf 'Flotte joignable.\n'
|
||||
|
||||
.PHONY: reconstruire
|
||||
reconstruire: _instance-requise
|
||||
@set -e; \
|
||||
if [[ "$(CONFIRMER)" != "true" ]]; then \
|
||||
printf '%s\n' 'Refus: RECONSTRUCTION — cree les VM manquantes (2a) PUIS deploie tout (2b).'; \
|
||||
printf '%s\n' 'Idempotent : une VM deja presente est sautee (clone par nom), le deploiement converge.'; \
|
||||
printf '%s\n' 'Relancer avec CONFIRMER=true.'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
$(MAKE) flotte-creer CONFIRMER=true; \
|
||||
$(MAKE) _attendre-flotte; \
|
||||
$(MAKE) deployer-tout CONFIRMER=true
|
||||
|
||||
# « Go ahead, make my day. » — LE bouton rouge : alias de reconstruire (Clint Eastwood).
|
||||
# Cree toutes les VM puis deploie tout, en une commande. Garde CONFIRMER=true.
|
||||
.PHONY: myDay
|
||||
myDay: reconstruire
|
||||
|
||||
deployer-groupe:
|
||||
@if [[ -z "$(GROUPE)" ]]; then \
|
||||
printf '%s\n' 'Refus: relancer avec GROUPE=nom_groupe.'; \
|
||||
|
|
@ -291,7 +435,7 @@ verifier-deploiement: ansible-runtime
|
|||
printf '%s\n' 'Refus: aucun playbook applicable pour HOTE=$(HOTE).'; \
|
||||
exit 2; \
|
||||
fi; \
|
||||
vault_chiffre="$$(grep -rlsIF '$$ANSIBLE_VAULT' $(SETOPS_INSTANCE)/inventories/production/group_vars 2>/dev/null | head -1 || true)"; \
|
||||
vault_chiffre="$$(grep -rlsIF '$$ANSIBLE_VAULT' $(dir $(INVENTAIRE_PRODUCTION))group_vars 2>/dev/null | head -1 || true)"; \
|
||||
if [[ -n "$$vault_chiffre" && -z "$${ANSIBLE_VAULT_PASSWORD_FILE:-}" ]]; then \
|
||||
if [[ -t 0 ]]; then \
|
||||
read -r -s -p 'Mot de passe du vault Ansible: ' mdp; echo; \
|
||||
|
|
|
|||
Loading…
Reference in a new issue