Skip to content

Gateway container can't reconnect after a restart in the same pod: wg0 already exists #7

Closed as not planned

Description

@d-o-it

Environment

K8s (k3s v1.35.9+k3s1, Flux v2.10.0), wiredoor-gateway chart 1.1.1

Describe the bug

The gateway container can't come back after a container restart inside the same pod.

In Kubernetes a container restart (liveness probe, OOM, crash) keeps the pod network namespace. wg0 and the iptables rules from PostUp live in that netns, so they survive. /etc/wireguard and /var/run/wiredoor are in the container fs, so they are gone.

connect-wiredoor then runs wiredoor connect, which writes wg0.conf and calls wg-quick up wg0. wg-quick refuses because the interface exists (wg-quick: `wg0' already exists). wiredoor drops wg-quick's stderr and prints the generic NET_ADMIN hint instead.

What happens next depends on the image:

  • v1.2.0 / v1.2.2: the script keeps going and tcpdump -i wg0 attaches to the old interface. Nothing re-runs wg-quick up. If the old interface no longer works, the liveness probe keeps restarting the container and it never recovers.
  • v1.2.3 / main: I haven't run it, but connect-wiredoor now has set -eu, so as far as I can tell the failed connect exits the container and it fails the same way on every restart. That would be a CrashLoopBackOff until the pod is deleted.

Only deleting the pod (new netns) fixes it. I think wiredoor/wiredoor#142 is the same thing: its log shows the NET_ADMIN error followed by listening on wg0, which only happens when wg0 already existed.

Possible fix in manualLinuxConnect(): after writing wg0.conf, if wg0 already exists run wg-quick down wg0 before wg-quick up wg0. That removes the interface and runs PostDown, so no rules are left behind. It would also help to log wg-quick's stderr when up fails.

Kubernetes users can't change the command through the chart, so right now the only way around it is a post-renderer. Mine:

sudo /sbin/ip link delete wg0 2>/dev/null || true
dnsmasq --server=127.0.0.11 --listen-address=0.0.0.0 --bind-interfaces
sudo wiredoor connect --url "$WIREDOOR_URL" --token "$TOKEN"
exec sudo wiredoor status --watch --interval 15

This survives restarts, but ip link delete skips PostDown, so every restart adds the PostUp rules again. After 6 restarts of one pod I have 3 copies of each FORWARD and MASQUERADE rule. wg-quick down in the CLI would avoid that, but in the entrypoint the config file is already gone at that point.

Steps to reproduce

  1. Deploy the wiredoor-gateway chart and wait until the gateway is connected.
  2. Make the container restart without deleting the pod. For me it was the liveness probe restarting it.
  3. Check kubectl logs <pod> and the restart count.

Logs or error output

ERROR: Unable to connect to tunnel, please review your user permissions or if you are inside container ensure that you have added the capability NET_ADMIN

The real error from wg-quick, which is not shown:

wg-quick: `wg0' already exists

Wiredoor version

wiredoor-cli image v1.2.0 and v1.2.2. v1.2.3 / main is the same from reading the code.

Activity

  1. d-o-it commented on Oct 30, 2026

    @d-o-it
    Author

    Correction, I got the mechanism wrong. cmd/connect_unix.go only calls Connect() when wg0 doesn't exist, otherwise it just prints the status and exits 0 (same in v1.2.0 and v1.2.2). So wg-quick up never runs against an existing wg0, and the v1.2.3 set -eu crash loop I described doesn't follow from it.

    Checked today on v1.2.2: the container got restarted by the liveness probe while the server was briefly unreachable, wiredoor connect printed "Tunnel seems active, but Wiredoor server unreachable." and the old wg0 kept working once the server was back. No duplicate iptables rules either; those came from my own ip link delete wg0 workaround.

    I can't explain the crash loop I had in June with this, so closing. Sorry for the noise, I'll open a new one if I can reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions