OpenVPN Ansible / Ansible Syntax Check (push) Successful in 41s
OpenVPN Ansible / Ansible Lint (push) Successful in 58s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Failing after 1m13s
OpenVPN Ansible / Generate SBOM (push) Skipped
OpenVPN Ansible / Scan SBOM with Trivy (push) Skipped
110 lines
4.7 KiB
Markdown
110 lines
4.7 KiB
Markdown
# VPN node configuration
|
|
|
|
Ansible configuration for Ubuntu 24.04 VPN nodes. Host packages are installed
|
|
through Ubuntu's package manager, so package architecture selection is
|
|
automatic.
|
|
|
|
## Supported platforms
|
|
|
|
- `linux/amd64` (`x86_64`)
|
|
- `linux/arm64` (`aarch64`)
|
|
|
|
The common role checks the Ubuntu release and architecture before
|
|
making changes. Networking sysctl configuration uses the interfaces reported
|
|
by Ansible rather than assuming a particular NIC name. The OpenVPN RADIUS
|
|
plugin path is discovered after package installation, including Debian's
|
|
architecture-specific library directories.
|
|
|
|
## Run
|
|
|
|
Configure inventory in `inventories/prod/hosts.ini`, then run:
|
|
|
|
```sh
|
|
ansible-playbook playbooks/openvpn.yml
|
|
```
|
|
|
|
The target hosts must run Ubuntu 24.04 and Ansible must gather facts.
|
|
|
|
## Private VM internet access
|
|
|
|
The `vpn-gateway` VM provides NAT for private VPN nodes. A private VM sends
|
|
internet-bound traffic to the Hetzner private-network router (`10.0.0.1`). The
|
|
Hetzner network route for `0.0.0.0/0` then delivers it to the gateway's private
|
|
address (`10.100.0.4`), where iptables masquerades it out `eth0`. The route in
|
|
Hetzner's network and the operating-system default route on each private VM are
|
|
separate settings: both must exist. The gateway itself keeps its public default
|
|
route through `eth0`.
|
|
|
|
`vpn_nodes` contains private VPN nodes and `nat_gateways` contains only the
|
|
gateway. Add new private VMs to `vpn_nodes` with their management address and
|
|
private address, and set the private routing role variables in host/group vars
|
|
if their interface or gateway differs. Do not add a gateway to `vpn_nodes`.
|
|
The routing role detects Netplan or systemd-networkd and adds only a route
|
|
fragment; review the host's existing route metrics and manager before rollout.
|
|
The Netplan fragment adds a metric 100 default route. Internal destinations
|
|
continue to use more-specific routes; validate the FreeRADIUS NodePort path on
|
|
each host.
|
|
|
|
Install required collections with `ansible-galaxy collection install -r
|
|
requirements.yml`, then check syntax and deploy independently:
|
|
|
|
```sh
|
|
ansible-playbook --syntax-check playbooks/nat-gateway.yml
|
|
ansible-playbook --syntax-check playbooks/private-vpn-routing.yml
|
|
ansible-playbook --check playbooks/nat-gateway.yml --limit nat_gateways
|
|
ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
|
ansible-playbook --check playbooks/private-vpn-routing.yml --limit vpn_nodes
|
|
ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
|
```
|
|
|
|
Check mode cannot validate actual kernel routes or persistence and may report
|
|
handlers without applying them. `netplan apply` and restarting
|
|
systemd-networkd can briefly interrupt remote connectivity; schedule route
|
|
rollout with console access or a maintenance window. Do not reboot automatically.
|
|
|
|
Verify the gateway after deployment (and separately after a planned reboot):
|
|
|
|
```sh
|
|
sysctl net.ipv4.ip_forward
|
|
iptables -t nat -S POSTROUTING
|
|
iptables -S FORWARD
|
|
systemctl is-enabled nat-gateway-firewall.service
|
|
systemctl status nat-gateway-firewall.service --no-pager
|
|
ip -4 route show default
|
|
```
|
|
|
|
Expect forwarding value `1`, the subnet-specific MASQUERADE and two narrow
|
|
FORWARD rules, an enabled firewall persistence service, and the gateway public
|
|
default via `eth0`. The service re-adds only these scoped rules at boot and
|
|
does not save or flush the full firewall ruleset. On each private VM:
|
|
|
|
```sh
|
|
ip -4 route show default
|
|
ip -4 route get 8.8.8.8
|
|
getent hosts google.com
|
|
curl -I --max-time 10 https://google.com
|
|
```
|
|
|
|
Also connect to the existing FreeRADIUS NodePort endpoint using its configured
|
|
address and port. DNS and NodePort checks require live network access. The
|
|
inventory gateway IP/interface values are taken from the supplied task; verify
|
|
them against the live Hetzner VM before applying.
|
|
|
|
## Monitoring exporter
|
|
|
|
Run `playbooks/monitoring-exporter.yml` for the VPN nodes and NAT gateway.
|
|
Set `monitoring_vm_ip` in `inventories/prod/group_vars/all.yml` to the monitoring
|
|
VM's address on the `10.100.0.x` private network. It is the only allowed source
|
|
to TCP port 9100. The identical `node_exporter` role defaults to port 9100,
|
|
binds to `private_ip` then `keepalived_src_ip` then `ansible_host`, and uses
|
|
`monitoring_vm_ip` as its firewall source. It creates the root-owned,
|
|
world-readable `/var/lib/node_exporter/textfile` directory and enables
|
|
systemd, conntrack, filesystem, netdev, textfile, time, and timex collectors;
|
|
`node_exporter_systemd_unit_filter` restricts unit metrics.
|
|
|
|
On the NAT gateway, `nat_gateway_node_exporter_port` defaults to 9100 and
|
|
`nat_gateway_node_exporter_allowed_source` uses `monitoring_vm_ip`. Both the
|
|
ACCEPT for that source and DROP for all other sources on the port are written
|
|
into `ensure-nat-gateway-firewall.j2`, so the gateway firewall persistence
|
|
service owns them.
|