Skip to content

fix(pia): complete native WireGuard reconnect handling - #1

Draft
m4r1k wants to merge 43 commits into
neilcorp2kx:feat/pia-wireguard-nativefrom
m4r1k:fix/pia-wireguard-pr3393
Draft

fix(pia): complete native WireGuard reconnect handling#1
m4r1k wants to merge 43 commits into
neilcorp2kx:feat/pia-wireguard-nativefrom
m4r1k:fix/pia-wireguard-pr3393

Conversation

@m4r1k

@m4r1k m4r1k commented Aug 24, 2026

Copy link
Copy Markdown

Type

Please tick which one the following applies to your pull request:

  • it is AI generated 🤖 and I did review it 👨👩
  • it is humanly written like the good old days 👨‍🎨👩‍🎨
  • it is AI generated 🤖 I did not review it 💤

Description

This is a follow-up review branch for passteque#3393. It targets neilcorp2kx:feat/pia-wireguard-native, not upstream master.

The branch first synchronizes passteque#3393 with current upstream master, then addresses the review and live-test failures reported on the original PR:

  • replace the custom SO_MARK bootstrap firewall implementation with the merged internal/restrictednet source-port-scoped DoH and HTTPS path
  • make server-list lookup, token retrieval, and addKey registration independent of tunnel DNS during reconnects
  • fix port forwarding shutdown so clearing runtime connection state does not fail validation before the keepalive service stops
  • cycle through every matching live PIA WireGuard server instead of repeatedly selecting the first endpoint
  • try the addKey server_vip directly for port forwarding before the existing OpenVPN-derived gateway fallbacks
  • reject user-supplied private keys, pre-shared keys, and interface addresses for PIA's dynamically registered connection
  • disable IPv6 routes for PIA's IPv4-only WireGuard registration
  • keep the PIA feature scoped by removing the unrelated global healthcheck startup retry change
  • repair the stale-branch test syntax, Go 1.26 compatibility, formatting, and current lint issues

The persisted PIA port-forward payload intentionally remains server-independent. PIA documents payload and signature reuse across servers, and the live reconnect test below successfully rebound the same port after switching endpoints.

Verification

Repository checks:

  • docker build --no-cache --target lint .
  • docker build --target mocks .
  • docker build --target xcompile .
  • focused go test -race across settings, firewall, restrictednet, PIA provider/updater, provider utilities, port forwarding, VPN, and healthcheck packages
  • go test -tags=integration ./internal/restrictednet
  • final application image build

Authenticated PIA test against CA Vancouver with the firewall and port forwarding enabled:

  • established a kernelspace WireGuard tunnel and confirmed PIA public egress
  • obtained a forwarded TCP port and reached it from a separate container
  • inspected iptables OUTPUT after bootstrap; only the active WireGuard endpoint and tunnel rules remained
  • deleted tun0 to reproduce the reported health failure
  • observed port forwarding stop cleanly and remove its firewall rule, without server name not set
  • automatically fetched a fresh server list and addKey registration through restrictednet
  • connected to a different Vancouver endpoint and restored public egress
  • rebound the same saved forwarded port and reached it externally again
  • stopped cleanly, removed the allowed input port, and cleared the forwarded-port file

Traditional PIA OpenVPN regression against CA Vancouver with the same image:

  • completed the normal OpenVPN initialization path and established tun0
  • confirmed PIA public egress
  • obtained a PIA forwarded TCP port and reached it from a separate container
  • inspected iptables OUTPUT; only the OpenVPN endpoint and tunnel rules were present

The default full test-container run still reports the same internal/netlink and internal/pmtud/tcp failures as current upstream master on the test host. SELinux audit records show container_t being denied module_request for rtnl-link-wireguard and ipt_mark; these are host-policy failures, not branch-only failures. The authenticated tunnel test was run during a user-controlled temporary permissive window.

AI was used for code analysis and code generation. I reviewed the resulting changes, tests, and live verification output before proposing them.

Issue (optional)

Follow-up fixes for passteque#3393.

Gluetun wiki associated pull request (optional)

None.

qdm12 and others added 30 commits July 19, 2026 13:15
- Go upgraded from 1.25 to 1.26
- `golangci-lint` upgraded from v2.4.0 to v2.11.4
- `mockgen` and `gomock` upgraded from `golang/mock` to `uber-go/mock` v0.6.0
…que#3400)

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

Thanks also to @arturhoo for also trying to resolve this issue in passteque#3410
Co-authored-by: OctoBored <212877535+OctoBored@users.noreply.github.com>
- enforce format with warning message
- ask the user to tick a type for the PR (AI generated, human written, etc.)
- Precise issue linking is optional
- Add optional gluetun wiki PR linking section
- `UPDATER_PROTONVPN_TOTP_SECRET` option (and `-proton-totp-secret` cli updater flag) to provide the TOTP long key to set TOTP permanently
- Updater CLI flag `-proton-totp-code` to provide a TOTP 6 digits code
- Human verification support showing the URL and using it for a subsequent request retry
- Fix passteque#3440
qdm12 and others added 13 commits August 23, 2026 12:28
# Conflicts:
#	internal/firewall/interfaces.go
#	internal/firewall/iptables/iptables.go
Replace SO_MARK and system-resolver bootstrap traffic with source-port-scoped DoH and HTTPS connections. This keeps server discovery, token retrieval, and key registration independent of tunnel DNS during reconnects.
Use the prospective VPN state when applying partial settings so tunnel shutdown can clear PIA runtime fields and stop the keepalive service.
Reject user-provided pre-shared keys and disable IPv6 routes for PIA's dynamically registered IPv4-only tunnels.
Keep every matching live PIA endpoint and use the shared connection picker so reconnect attempts do not remain pinned to the first server returned by the API.
Probe addKey's server_vip directly for port forwarding, then retain the existing OpenVPN-derived gateway addresses as fallbacks.
Leave global startup check timing unchanged so the native PIA WireGuard work can be reviewed independently.
Keep validation and error formatting readable under the current complexity, security, and style checks without changing the connection behavior.
PIA assigns the interface address during addKey registration, so reject user-provided addresses instead of silently replacing them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants