Proxmox hardening from a dry run and stub tests
- PVE has no win2k22 ostype; Server 2022 maps to win11 - drop --startup 0, which is not a valid order value - after install, repoint the boot order at sata0 and detach the installer ISO, so a stray keypress cannot re-enter Setup - ISO storage detection falls back to storage.cfg when pvesm has no --content flag - router wg0 is now 10.10.10.250/32 with the lab NIC at .251/24: two /24s on one host made routing ambiguous - nft rules use the router's own interface name (WG_LAB_IFACE), not vmbr10
This commit is contained in:
@@ -83,6 +83,14 @@ _wait_for_boot() {
|
|||||||
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
ok "all VMs installed and reachable"
|
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"
|
info " next: ./lab.sh status"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-6
@@ -123,17 +123,36 @@ L'archive contient le contenu commun, la plateforme, la documentation et la solu
|
|||||||
|
|
||||||
### Accès des participants : VM routeur WireGuard
|
### 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
|
C'est la seule étape manuelle restante. Créez une petite VM (Alpine ou Debian, 512 Mo, 2 vCPU)
|
||||||
Debian, 512 Mo) avec deux cartes : `vmbr0` (réseau du bureau) et `vmbr10` (laboratoire). Dans
|
avec deux cartes réseau :
|
||||||
cette VM, installez WireGuard et collez la configuration produite par :
|
|
||||||
|
| 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
|
```bash
|
||||||
./platforms/proxmox/lab.sh peers alice bob carol
|
./platforms/proxmox/lab.sh peers alice bob carol
|
||||||
# écrit une config par participant et le wg0.conf du routeur dans $WG_DIR
|
# écrit <nom>.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
|
Sur le routeur :
|
||||||
n'a plus qu'à suivre `docs/prerequis.md` (sans l'étape de route, le tunnel la fournit).
|
|
||||||
|
```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
|
## DHCP du laboratoire
|
||||||
|
|
||||||
|
|||||||
@@ -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]}"; }
|
pve_ip() { local i; i=$(vm_index "$1"); printf '%s' "${VM_IPS[$i]}"; }
|
||||||
|
|
||||||
# ------------------------------------------------------------------ preflight
|
# ------------------------------------------------------------------ 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() {
|
backend_check() {
|
||||||
if ! command -v qm >/dev/null 2>&1; then
|
if ! command -v qm >/dev/null 2>&1; then
|
||||||
_c_fail "qm not found — this script must run on a Proxmox VE host"
|
_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)"
|
_c_fail "disk storage ${PVE_STORAGE_DISKS} not found (run pvesm status)"
|
||||||
fi
|
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
|
if [[ " $iso_content " == *" ${PVE_STORAGE_ISO} "* ]]; then
|
||||||
_c_ok "iso storage ${PVE_STORAGE_ISO} present"
|
_c_ok "iso storage ${PVE_STORAGE_ISO} present"
|
||||||
else
|
else
|
||||||
@@ -114,7 +126,7 @@ backend_create_disk() {
|
|||||||
--ide2 "${PVE_STORAGE_ISO}:iso/$(basename "$win"),media=cdrom"
|
--ide2 "${PVE_STORAGE_ISO}:iso/$(basename "$win"),media=cdrom"
|
||||||
--ide0 "${PVE_STORAGE_ISO}:iso/$(basename "$seed"),media=cdrom"
|
--ide0 "${PVE_STORAGE_ISO}:iso/$(basename "$seed"),media=cdrom"
|
||||||
--boot "order=ide2;ide0"
|
--boot "order=ide2;ide0"
|
||||||
--onboot 0 --startup 0
|
--onboot 0
|
||||||
)
|
)
|
||||||
(( PVE_AGENT )) && args+=( --agent enabled=1 )
|
(( PVE_AGENT )) && args+=( --agent enabled=1 )
|
||||||
|
|
||||||
@@ -304,7 +316,8 @@ cmd_peers() {
|
|||||||
endpoint="${endpoint}:${WG_PORT}"
|
endpoint="${endpoint}:${WG_PORT}"
|
||||||
fi
|
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
|
for i in "${!names[@]}"; do
|
||||||
name=${names[$i]}
|
name=${names[$i]}
|
||||||
addr="10.10.10.$(( 101 + i ))/32"
|
addr="10.10.10.$(( 101 + i ))/32"
|
||||||
@@ -342,15 +355,23 @@ AllowedIPs = ${addr}"
|
|||||||
done
|
done
|
||||||
|
|
||||||
cat > "$WG_DIR/wg0.conf" <<CONF
|
cat > "$WG_DIR/wg0.conf" <<CONF
|
||||||
# Router VM — paste into /etc/wireguard/wg0.conf and: systemctl enable --now wg-quick@wg0
|
# Router VM — /etc/wireguard/wg0.conf, then: systemctl enable --now wg-quick@wg0
|
||||||
|
#
|
||||||
|
# The VM needs TWO interfaces:
|
||||||
|
# eth0 on vmbr0 (your LAN) — optional, for management
|
||||||
|
# eth1 on vmbr10 (the lab bridge) — give it 10.10.10.251/24
|
||||||
|
# wg0 is a /32 inside the lab subnet so it does not collide with those /24s:
|
||||||
|
# traffic to .250 goes through the tunnel, everything else through eth1.
|
||||||
|
# Adjust LAB_IFACE below if your lab NIC is not eth1.
|
||||||
[Interface]
|
[Interface]
|
||||||
Address = 10.10.10.250/24
|
Address = 10.10.10.250/32
|
||||||
ListenPort = ${WG_PORT}
|
ListenPort = ${WG_PORT}
|
||||||
PrivateKey = $(<"$WG_DIR/server.key")
|
PrivateKey = $(<"$WG_DIR/server.key")
|
||||||
# Participants reach the DC first; the lab subnet is routed over vmbr10.
|
|
||||||
PostUp = sysctl -w net.ipv4.ip_forward=1
|
PostUp = sysctl -w net.ipv4.ip_forward=1
|
||||||
PostUp = nft add rule ip filter forward iifname "wg0" oifname "vmbr10" accept
|
PostUp = nft add rule inet filter forward iifname "wg0" oifname "${LAB_IFACE}" accept
|
||||||
PostUp = nft add rule ip filter forward iifname "vmbr10" oifname "wg0" ct state established,related accept
|
PostUp = nft add rule inet filter forward iifname "${LAB_IFACE}" oifname "wg0" ct state established,related accept
|
||||||
|
PostDown = nft delete rule inet filter forward iifname "wg0" oifname "${LAB_IFACE}" accept
|
||||||
|
PostDown = nft delete rule inet filter forward iifname "${LAB_IFACE}" oifname "wg0" ct state established,related accept
|
||||||
${router_peers}
|
${router_peers}
|
||||||
CONF
|
CONF
|
||||||
chmod 600 "$WG_DIR/wg0.conf"
|
chmod 600 "$WG_DIR/wg0.conf"
|
||||||
@@ -359,3 +380,13 @@ CONF
|
|||||||
ok "peer configs in ${WG_DIR}"
|
ok "peer configs in ${WG_DIR}"
|
||||||
info " router config: ${WG_DIR}/wg0.conf (address 10.10.10.250 on the lab bridge)"
|
info " router config: ${WG_DIR}/wg0.conf (address 10.10.10.250 on the lab bridge)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# After a successful install, stop booting from the installer CD: otherwise
|
||||||
|
# every boot waits five seconds and a stray keypress re-enters Setup.
|
||||||
|
backend_finalize() {
|
||||||
|
local name=$1 vmid
|
||||||
|
vmid=$(pve_vmid "$name")
|
||||||
|
qm set "$vmid" --boot 'order=sata0' --delete ide2 >/dev/null 2>&1 || true
|
||||||
|
ok "$(printf '%-6s boots from disk (installer ISO detached)' "$name")"
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ PVE_BRIDGE="vmbr10"
|
|||||||
|
|
||||||
# VM ids. dc01=base+0, fs01=base+1, ws01=base+2; templates use base+100.
|
# VM ids. dc01=base+0, fs01=base+1, ws01=base+2; templates use base+100.
|
||||||
PVE_VMID_BASE=1100
|
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_BIOS="seabios" # Windows 11 would need ovmf + efidisk0 + tpmstate0
|
||||||
PVE_MACHINE="q35"
|
PVE_MACHINE="q35"
|
||||||
PVE_CPU="host"
|
PVE_CPU="host"
|
||||||
@@ -77,3 +77,4 @@ BUILD_TIMEOUT=2700
|
|||||||
WG_PORT=51820
|
WG_PORT=51820
|
||||||
WG_ENDPOINT="" # leave empty to print the LAN address instead
|
WG_ENDPOINT="" # leave empty to print the LAN address instead
|
||||||
WG_DIR="${WG_DIR:-$HOME/norbourg-peers}"
|
WG_DIR="${WG_DIR:-$HOME/norbourg-peers}"
|
||||||
|
WG_LAB_IFACE="eth1" # interface name inside the router VM
|
||||||
|
|||||||
@@ -305,3 +305,7 @@ backend_destroy() {
|
|||||||
rm -f "$(qemu_pidfile "$name")" "$(qemu_monitor "$name")" "$(qemu_log "$name")"
|
rm -f "$(qemu_pidfile "$name")" "$(qemu_monitor "$name")" "$(qemu_log "$name")"
|
||||||
ok "$name removed"
|
ok "$name removed"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Nothing to do: the boot order was set to "once=d" at launch time.
|
||||||
|
backend_finalize() { :; }
|
||||||
|
|||||||
Reference in New Issue
Block a user