Thai testbed VPN gateway
How we share the single-session Thai testbed OpenVPN key with the whole team. One server (nuc-b) holds the OpenVPN session and acts as a Tailscale/Headscale subnet router. Team members never use the .ovpn themselves; they just reach <TESTBED_CIDR> through the tailnet.
Last verified: 2026-10-26
Summary¶
| Item | Value |
|---|---|
| Testbed network | <TESTBED_CIDR> (a /23) |
| OpenVPN endpoint | <TESTBED_VPN_ENDPOINT_IP> UDP 1194 (outbound only) |
| Gateway server | nuc-b — Headscale node ID 2, tailnet IP <NUC_B_TAILSCALE_IP>, LAN IP <NUC_B_LAN_IP> |
| Gateway tunnel interface | tun0 (<NUC_B_TUNNEL_IP> ↔ <TUNNEL_PEER_IP>) |
| OpenVPN service | openvpn-client@thai-testbed |
| OpenVPN config | /etc/openvpn/client/thai-testbed.conf |
Routes advertised by nuc-b |
<OFFICE_LAN_CIDR> (existing) and <TESTBED_CIDR> (testbed) |
| Control plane | Headscale v0.28.0 on k3s, https://headscale.castis.io |
| Policy | policy.json inside headscale/Headscale-configmap.yaml |
| Key owner | the testbed contact |
The key allows only one session at a time. Nobody else may connect with the
.ovpndirectly, ornuc-bis disconnected and everyone loses testbed access.
Architecture¶
Team member (Tailscale client)
│ tailnet (WireGuard)
▼
Headscale on k3s ─ control plane only: logins, routes, ACL (no user traffic)
│
▼
nuc-b (tailscale0) ── forward + Tailscale SNAT ──► tun0 (OpenVPN) ──► Testbed <TESTBED_CIDR>
└── existing subnet route <OFFICE_LAN_CIDR> (unchanged)
How a packet flows when a user pings <TESTBED_HOST_IP>:
- The client has a route for
<TESTBED_CIDR>vianuc-b(advertised bynuc-b, approved in Headscale, allowed by the ACL). - The packet reaches
nuc-bontailscale0. - Kernel forwarding passes it to
tun0(net.ipv4.ip_forward = 1,FORWARDpolicyACCEPT). - Tailscale's
ts-postroutingchain masquerades it, so the testbed sees the source as<NUC_B_TUNNEL_IP>and can reply. No manual iptables rule is needed. - The reply returns through
tun0and is sent back over the tailnet.
How it was set up on nuc-b¶
1. Install OpenVPN and load the key¶
sudo apt update && sudo apt install -y openvpn
sudo cp thai-testbed.ovpn /etc/openvpn/client/thai-testbed.conf
sudo chmod 600 /etc/openvpn/client/thai-testbed.conf
The name after @ in the service name must match the config file name (thai-testbed.conf).
2. Extra lines appended to the bottom of the config¶
route-nopull
route <TESTBED_NETWORK> 255.255.254.0
persist-tun
persist-key
resolv-retry infinite
keepalive 10 60
| Line | Purpose |
|---|---|
route-nopull |
Ignore routes pushed by the testbed server. nuc-b is a k3s/Docker node, so an unexpected pushed route could overlap cluster ranges (<K3S_POD_CIDR>, 172.x) and break networking. |
route <TESTBED_NETWORK> 255.255.254.0 |
The only route we want through the tunnel (/23). |
persist-tun / persist-key |
Keep tun0 and keys across reconnects so routes are not lost. |
resolv-retry infinite |
Keep retrying name resolution of the server (harmless with an IP). |
keepalive 10 60 |
Ping every 10 s, restart after 120 s of silence. |
The original file has no redirect-gateway and no auth-user-pass (certificate login only). If a new file contains redirect-gateway, remove it, because route-nopull does not block a directive written in the file itself.
3. systemd drop-in (custom OpenSSL workaround + auto-restart)¶
nuc-b has a custom OpenSSL in /usr/local/lib/streamer/ (used by the streamer software). The system openvpn binary loaded it and crashed with:
Force the service to use the system OpenSSL, only for this unit:
sudo mkdir -p /etc/systemd/system/openvpn-client@thai-testbed.service.d
sudo tee /etc/systemd/system/openvpn-client@thai-testbed.service.d/override.conf >/dev/null <<'UNIT'
[Service]
Environment=LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
Restart=always
RestartSec=10
UNIT
sudo systemctl daemon-reload
sudo systemctl enable --now openvpn-client@thai-testbed
Do not remove
/usr/local/opensslor thestreamerlibrary path from the system config. Other software may depend on it.
4. Advertise the testbed route (keep the old one!)¶
--advertise-routes replaces the whole list, so always list every route.
5. Approve the routes in Headscale¶
alias hs='kubectl exec -n headscale headscale-0 -- headscale'
hs nodes approve-routes --identifier 2 --routes <OFFICE_LAN_CIDR>,<TESTBED_CIDR>
hs nodes list-routes
approve-routes also replaces the approved list. Always pass all routes, or the old one is un-approved.
6. ACL rule¶
Added to policy.json in headscale/Headscale-configmap.yaml:
Without it Headscale silently drops the traffic. The old route kept working while the testbed timed out, which is the symptom to remember.
Apply the change:
kubectl annotate application <app-name> -n argocd argocd.argoproj.io/refresh=hard --overwrite
# sync the app, then reload the policy (it is read at startup):
kubectl rollout restart statefulset/headscale -n headscale
kubectl rollout status statefulset/headscale -n headscale
Giving someone access¶
hs users create <name>
hs users list # note the ID
hs preauthkeys create --user <ID> --expiration 24h
- Add a rule in
Headscale-configmap.yaml("src": ["<name>@"],"dst": ["<TESTBED_CIDR>:*"]), sync with Argo CD, restart the Headscale pod. - On the user's machine:
Mac, Windows and mobile: set the login server in the app and enable subnet routes ("Use Tailscale subnets" on macOS). Linux needs --accept-routes.
- Test:
ping <TESTBED_HOST_IP>.
To remove someone, delete their rule (or the node with hs nodes delete --identifier <ID>). The OpenVPN key does not need to change.
Verification¶
On nuc-b:
systemctl is-active openvpn-client@thai-testbed
ip a show tun0
ip route | grep <TESTBED_NETWORK> # <TESTBED_CIDR> via <TUNNEL_PEER_IP> dev tun0
ping -c3 <TESTBED_HOST_IP>
sudo iptables -t nat -S ts-postrouting # MASQUERADE for mark 0x40000/0xff0000
On a client:
ip route get <TESTBED_HOST_IP> # Linux: should show dev tailscale0
route -n get <TESTBED_HOST_IP> # macOS: should show a utun interface
ping -c3 <TESTBED_HOST_IP> # testbed
ping -c3 <NUC_B_LAN_IP> # old route still works
Troubleshooting¶
| Symptom | Likely cause | Check / fix |
|---|---|---|
Service fails, Assertion failed ... legacy_provider |
OpenVPN loading the custom OpenSSL in /usr/local/lib/streamer |
Make sure the drop-in LD_LIBRARY_PATH is present (systemctl cat openvpn-client@thai-testbed) |
TLS key negotiation failed |
Outbound UDP 1194 blocked, or someone else is using the key | Test connectivity to <TESTBED_VPN_ENDPOINT_IP>; confirm nobody else is connected; journalctl -u openvpn-client@thai-testbed -n 50 |
tun0 missing |
Service not running | sudo systemctl status openvpn-client@thai-testbed |
| Old route works, testbed times out from clients | ACL missing the <TESTBED_CIDR> rule, or policy not reloaded |
hs policy get; restart the Headscale pod |
Client has no route to <TESTBED_CIDR> |
Route not approved, or --accept-routes off |
hs nodes list-routes; client accept-routes / "Use Tailscale subnets" |
Packets on tailscale0 but none on tun0 |
Forwarding blocked | sysctl net.ipv4.ip_forward; sudo iptables -S FORWARD |
Requests on tun0 but no replies |
NAT missing | sudo iptables -t nat -S ts-postrouting; as a last resort sudo iptables -t nat -A POSTROUTING -d <TESTBED_CIDR> -o tun0 -j MASQUERADE |
| Old route stopped working after a change | advertise-routes or approve-routes replaced the list |
Re-run steps 4 and 5 with both routes |
Useful capture while a client pings (run each in its own terminal on nuc-b):
Maintenance¶
Certificate lifetimes (checked 2026-10-26)¶
| Item | Ends |
|---|---|
| Client certificate | 2032-11-15 |
| CA certificate | 2030-04-25 |
Check again with:
sudo sed -n '/<cert>/,/<\/cert>/p' /etc/openvpn/client/thai-testbed.conf | sed '1d;$d' | openssl x509 -noout -enddate
sudo sed -n '/<ca>/,/<\/ca>/p' /etc/openvpn/client/thai-testbed.conf | sed '1d;$d' | openssl x509 -noout -enddate
The chat card for the original file showed Expiry: ~06/11/2569 BE (6 Nov 2026). It does not match any certificate in the file and is most likely the chat app's file-retention date, but this is unconfirmed. Ask the testbed contact whether the key has an end date or is revoked on the testbed side.
Replacing the .ovpn¶
- Copy the new file to
/etc/openvpn/client/thai-testbed.conf(chmod 600). - Re-append the lines from "Extra lines appended to the bottom of the config".
- Check there is no
redirect-gatewayin the file. sudo systemctl restart openvpn-client@thai-testbed, thenping <TESTBED_HOST_IP>.
Keep a copy of the working config in a secure place (password manager or encrypted vault). Never commit it to git — it contains the client private key and the tls-auth key.
After a reboot of nuc-b¶
Confirm openvpn-client@thai-testbed is active, the route exists and the ping works. Tailscale recreates its own NAT rules at startup. Do not use netfilter-persistent save on this node, because it is a k3s/Docker host and would save and later restore stale cluster rules.
Rollback¶
sudo tailscale set --advertise-routes=<OFFICE_LAN_CIDR>
hs nodes approve-routes --identifier 2 --routes <OFFICE_LAN_CIDR>
sudo systemctl disable --now openvpn-client@thai-testbed
Optionally remove the <TESTBED_CIDR> rule from Headscale-configmap.yaml and redeploy.
Notes and gotchas¶
- Everyone using the testbed appears to it as one identity (
nuc-b). Tell the testbed contact that the key is shared through a gateway. - The
tls-authkey was once pasted into a chat. Ask the testbed contact to rotate the key if that is a concern, and never paste.ovpncontents (<ca>,<cert>,<key>,<tls-auth>) into chats or tickets. <TESTBED_CIDR>must not overlap any local network. Current LANs onnuc-b(<OFFICE_LAN_CIDR>,<NUC_B_UPSTREAM_LAN_CIDR>, k3s<K3S_POD_CIDR>, Docker<DOCKER_BRIDGE_CIDR>,<DOCKER_NETWORK_CIDR>) do not.- If
nuc-bis down, both the testbed route and the<OFFICE_LAN_CIDR>route are unavailable.