diff --git a/content/lib/cmd_build.sh b/content/lib/cmd_build.sh index 33e18d5..6f046e8 100644 --- a/content/lib/cmd_build.sh +++ b/content/lib/cmd_build.sh @@ -83,6 +83,14 @@ _wait_for_boot() { printf '\n' ok "all VMs installed and reachable" + + if declare -F backend_finalize >/dev/null; then + step "finalize" + for name in "${VM_NAMES[@]}"; do + backend_finalize "$name" || warn "$name: finalize step failed" + done + fi + info " next: ./lab.sh status" } diff --git a/docs/instructeur.md b/docs/instructeur.md index a4afc7f..35a292c 100644 --- a/docs/instructeur.md +++ b/docs/instructeur.md @@ -123,17 +123,36 @@ L'archive contient le contenu commun, la plateforme, la documentation et la solu ### Accès des participants : VM routeur WireGuard -C'est la seule étape manuelle restante. Sur l'hôte Proxmox, créez une petite VM (Alpine ou -Debian, 512 Mo) avec deux cartes : `vmbr0` (réseau du bureau) et `vmbr10` (laboratoire). Dans -cette VM, installez WireGuard et collez la configuration produite par : +C'est la seule étape manuelle restante. Créez une petite VM (Alpine ou Debian, 512 Mo, 2 vCPU) +avec deux cartes réseau : + +| Carte | Pont | Adresse | +|---|---|---| +| `eth0` | `vmbr0` (réseau du bureau) | DHCP, pour l'administration | +| `eth1` | `vmbr10` (laboratoire) | **`10.10.10.251/24`**, sans passerelle | + +`wg0` reçoit **`10.10.10.250/32`** : une adresse seule dans le sous-réseau, pour ne pas entrer en +conflit avec le /24 de `eth1`. Le trafic vers `.250` passe par le tunnel, tout le reste par +`eth1`. Si votre carte laboratoire ne s'appelle pas `eth1`, ajustez `WG_LAB_IFACE` dans +`platforms/proxmox/lab.conf` avant de générer la configuration. ```bash ./platforms/proxmox/lab.sh peers alice bob carol -# écrit une config par participant et le wg0.conf du routeur dans $WG_DIR +# écrit .conf par participant et wg0.conf pour le routeur dans $WG_DIR ``` -Chaque participant importe son fichier `.conf` : il obtient une adresse dans `10.10.10.0/24` et -n'a plus qu'à suivre `docs/prerequis.md` (sans l'étape de route, le tunnel la fournit). +Sur le routeur : + +```bash +apt install wireguard-tools nftables +cp wg0.conf /etc/wireguard/wg0.conf +chmod 600 /etc/wireguard/wg0.conf +systemctl enable --now wg-quick@wg0 +``` + +Chaque participant importe son `.conf` (NetworkManager, `wg-quick`, ou l'application WireGuard +sur mobile). Il obtient une adresse `10.10.10.10x` et le DNS `10.10.10.10` poussés par le tunnel : +`docs/prerequis.md` devient inutile, il n'y a ni route ni DNS à configurer à la main. ## DHCP du laboratoire diff --git a/platforms/proxmox/backends/proxmox.sh b/platforms/proxmox/backends/proxmox.sh index f374ca2..57e0cb2 100644 --- a/platforms/proxmox/backends/proxmox.sh +++ b/platforms/proxmox/backends/proxmox.sh @@ -25,6 +25,18 @@ pve_running() { qm status "$1" 2>/dev/null | grep -q 'status: running'; } pve_ip() { local i; i=$(vm_index "$1"); printf '%s' "${VM_IPS[$i]}"; } # ------------------------------------------------------------------ preflight +# Which storages advertise iso content. `pvesm status --content` is not +# available on every version, so fall back to parsing storage.cfg. +pve_iso_storages() { + local out + out=$(pvesm status --content iso 2>/dev/null | awk 'NR>1{print $1}' | tr '\n' ' ') + if [[ -z ${out// /} && -r /etc/pve/storage.cfg ]]; then + out=$(awk '/^[a-z]+: /{name=$2} /^[[:space:]]*content[[:space:]]/ && /iso/ {print name}' \ + /etc/pve/storage.cfg | tr '\n' ' ') + fi + printf '%s' "$out" +} + backend_check() { if ! command -v qm >/dev/null 2>&1; then _c_fail "qm not found — this script must run on a Proxmox VE host" @@ -42,7 +54,7 @@ backend_check() { _c_fail "disk storage ${PVE_STORAGE_DISKS} not found (run pvesm status)" fi - iso_content=$(pvesm status -content iso 2>/dev/null | awk 'NR>1{print $1}' | tr '\n' ' ') + iso_content=$(pve_iso_storages) if [[ " $iso_content " == *" ${PVE_STORAGE_ISO} "* ]]; then _c_ok "iso storage ${PVE_STORAGE_ISO} present" else @@ -114,7 +126,7 @@ backend_create_disk() { --ide2 "${PVE_STORAGE_ISO}:iso/$(basename "$win"),media=cdrom" --ide0 "${PVE_STORAGE_ISO}:iso/$(basename "$seed"),media=cdrom" --boot "order=ide2;ide0" - --onboot 0 --startup 0 + --onboot 0 ) (( PVE_AGENT )) && args+=( --agent enabled=1 ) @@ -304,7 +316,8 @@ cmd_peers() { endpoint="${endpoint}:${WG_PORT}" fi - local i name addr priv pub psk peer_conf router_peers="" + local i name addr priv pub psk router_peers="" + local LAB_IFACE=${WG_LAB_IFACE:-eth1} for i in "${!names[@]}"; do name=${names[$i]} addr="10.10.10.$(( 101 + i ))/32" @@ -342,15 +355,23 @@ AllowedIPs = ${addr}" done cat > "$WG_DIR/wg0.conf" </dev/null 2>&1 || true + ok "$(printf '%-6s boots from disk (installer ISO detached)' "$name")" +} diff --git a/platforms/proxmox/lab.conf b/platforms/proxmox/lab.conf index 8fec63f..5f08e42 100644 --- a/platforms/proxmox/lab.conf +++ b/platforms/proxmox/lab.conf @@ -37,7 +37,7 @@ PVE_BRIDGE="vmbr10" # VM ids. dc01=base+0, fs01=base+1, ws01=base+2; templates use base+100. PVE_VMID_BASE=1100 -PVE_OSTYPE="win2k22" +PVE_OSTYPE="win11" # PVE has no win2k22; win11 covers Server 2022 PVE_BIOS="seabios" # Windows 11 would need ovmf + efidisk0 + tpmstate0 PVE_MACHINE="q35" PVE_CPU="host" @@ -77,3 +77,4 @@ BUILD_TIMEOUT=2700 WG_PORT=51820 WG_ENDPOINT="" # leave empty to print the LAN address instead WG_DIR="${WG_DIR:-$HOME/norbourg-peers}" +WG_LAB_IFACE="eth1" # interface name inside the router VM diff --git a/platforms/qemu/backends/qemu.sh b/platforms/qemu/backends/qemu.sh index 4d1b788..38c42ac 100644 --- a/platforms/qemu/backends/qemu.sh +++ b/platforms/qemu/backends/qemu.sh @@ -305,3 +305,7 @@ backend_destroy() { rm -f "$(qemu_pidfile "$name")" "$(qemu_monitor "$name")" "$(qemu_log "$name")" ok "$name removed" } + + +# Nothing to do: the boot order was set to "once=d" at launch time. +backend_finalize() { :; }