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:
@@ -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" <<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]
|
||||
Address = 10.10.10.250/24
|
||||
Address = 10.10.10.250/32
|
||||
ListenPort = ${WG_PORT}
|
||||
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 = nft add rule ip filter forward iifname "wg0" oifname "vmbr10" 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 "wg0" oifname "${LAB_IFACE}" 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}
|
||||
CONF
|
||||
chmod 600 "$WG_DIR/wg0.conf"
|
||||
@@ -359,3 +380,13 @@ CONF
|
||||
ok "peer configs in ${WG_DIR}"
|
||||
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")"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user