VPN: read only the VPN files the Controller writes (#1037)

* VPN: read only the VPN files the Controller writes

controller.yaml's vpn.config_file and vpn.auth_file were joined to the
config directory as-is. The tunnel runs as root, so an absolute or ../
path would have it read (and send to the VPN server) any file, and the
Controller API would return any file's text as the VPN config.

Both now accept only vpn/wireguard.conf, vpn/openvpn.ovpn, and
vpn/openvpn-auth.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* VPN: refuse a VPN file which links outside the vpn directory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* VPN: read each VPN file once, never through a symlink

The check resolved the path, then the file was opened again later: by
root OpenVPN for the login (--auth-nocache re-reads it). The wrolpi user,
who owns the library, could swap the file for a symlink in between.

read_vpn_file() opens with O_NOFOLLOW and reads once. OpenVPN gets a
0600 copy of the login in the run directory, removed when the tunnel
goes down.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-30 15:05:37 -07:00 • committed by GitHub
parent 04ddc7c63c
commit b1334c834b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 156 additions and 16 deletions

View file

@ -166,6 +166,16 @@ class TestSettings:
assert not (drive / vpn.OPENVPN_AUTH).exists()
@pytest.mark.parametrize('config_file', ['../outside.conf', 'vpn/../../outside.conf', 'vpn/other.ovpn'])
def test_reads_only_the_files_wrolpi_writes(self, drive, config_file):
"""The API returns the config's text, so a hand-edited controller.yaml must not point it at other files."""
(drive.parent / 'outside.conf').write_text(WIREGUARD)
(drive / 'vpn').mkdir(parents=True, exist_ok=True)
(drive / 'vpn/other.ovpn').write_text(OPENVPN)
vpn._save_settings(config_file=config_file)
assert vpn.read_vpn_config() is None
class TestEndpoints:
def test_need_resolving(self, drive, resolver):