From df489fa14798ae59cc7fa24de458956cf9204d29 Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Mon, 16 Nov 2026 09:35:19 +0100 Subject: [PATCH] fix(deploy): keep existing manual TUN passthrough on reused CTs (#6) create-ct.sh only recognised devN passthrough and added dev0 on top of a manual lxc.mount.entry for /dev/net/tun (left by earlier Tailscale setups), so the CT failed to start in the autodev hook (EEXIST). Detection now lives in ct-config.sh with a regression test. --- deploy/README.md | 4 +++- deploy/proxmox/create-ct.sh | 4 +++- deploy/proxmox/ct-config.sh | 7 +++++++ deploy/test/ct-config.test.sh | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100755 deploy/proxmox/ct-config.sh create mode 100755 deploy/test/ct-config.test.sh diff --git a/deploy/README.md b/deploy/README.md index 2475dc9..b498dfa 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -58,6 +58,8 @@ apt signing-key compatibility issues on Debian 13. Rerun the installer to update Node 22 security releases; unattended upgrades cover Debian packages only. Build tools support node-pty compilation. Claude uses its native installer. -Local deployment regression: `bash deploy/test/template-picker.test.sh`. +Local deployment regressions: `bash deploy/test/template-picker.test.sh` and +`bash deploy/test/ct-config.test.sh`. Existing CTs with a manual TUN mount entry +(earlier Tailscale setups) keep it; no `dev0` is added on top. The scripts require bash, use LF endings, and avoid early-consuming pipelines under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation. diff --git a/deploy/proxmox/create-ct.sh b/deploy/proxmox/create-ct.sh index fdb7f30..43a0b8f 100755 --- a/deploy/proxmox/create-ct.sh +++ b/deploy/proxmox/create-ct.sh @@ -4,6 +4,8 @@ set -euo pipefail script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=deploy/proxmox/template-picker.sh source "$script_dir/template-picker.sh" +# shellcheck source=deploy/proxmox/ct-config.sh +source "$script_dir/ct-config.sh" ctid=${CTID:-501} [[ $ctid =~ ^[0-9]+$ ]] || { echo 'Invalid CTID' >&2; exit 1; } arch=$(dpkg --print-architecture) @@ -44,7 +46,7 @@ if [[ $features != *nesting=1* ]]; then needs_restart=1 fi pct set "$ctid" --onboot 1 -if [[ $config != *'path=/dev/net/tun'* && $config != *'dev0: /dev/net/tun'* ]]; then +if ! has_tun_passthrough <<< "$config"; then [[ $config != *'dev0:'* ]] || { echo 'dev0 already occupied; configure /dev/net/tun passthrough manually' >&2; exit 1; } pct set "$ctid" --dev0 /dev/net/tun needs_restart=1 diff --git a/deploy/proxmox/ct-config.sh b/deploy/proxmox/ct-config.sh new file mode 100755 index 0000000..f13c0f2 --- /dev/null +++ b/deploy/proxmox/ct-config.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Input: pct config output. True if /dev/net/tun already reaches the CT, either as a +# devN passthrough or as a manual lxc.mount.entry (e.g. an earlier Tailscale setup). +# Adding dev0 on top of a manual entry makes the CT fail to start (autodev hook, EEXIST). +has_tun_passthrough() { + grep -Eq '^(dev[0-9]+: (path=)?/dev/net/tun(,|$)|lxc\.mount\.entry: */dev/net/tun[[:space:]])' +} diff --git a/deploy/test/ct-config.test.sh b/deploy/test/ct-config.test.sh new file mode 100755 index 0000000..a1fe9bf --- /dev/null +++ b/deploy/test/ct-config.test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +# shellcheck source=deploy/proxmox/ct-config.sh +source "$(dirname "${BASH_SOURCE[0]}")/../proxmox/ct-config.sh" +base='arch: amd64 +features: nesting=1 +unprivileged: 1' +has_tun_passthrough <<< "$base +dev0: /dev/net/tun" +has_tun_passthrough <<< "$base +dev1: path=/dev/net/tun,mode=0666" +# Manual Tailscale-style setup: adding dev0 on top makes the CT fail to start (EEXIST). +has_tun_passthrough <<< "$base +lxc.cgroup2.devices.allow: c 10:200 rwm +lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" +if has_tun_passthrough <<< "$base"; then exit 1; fi +if has_tun_passthrough <<< "$base +dev0: /dev/net/tunnel"; then exit 1; fi +printf '5 CT config checks passed\n'