mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
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:
parent
04ddc7c63c
commit
b1334c834b
4 changed files with 156 additions and 16 deletions
|
|
@ -21,10 +21,10 @@ from controller.vpn import tunnel
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Relative to the config directory.
|
||||
WIREGUARD_CONFIG = 'vpn/wireguard.conf'
|
||||
OPENVPN_CONFIG = 'vpn/openvpn.ovpn'
|
||||
OPENVPN_AUTH = 'vpn/openvpn-auth.txt'
|
||||
CONFIG_FILES = {'wireguard': WIREGUARD_CONFIG, 'openvpn': OPENVPN_CONFIG}
|
||||
WIREGUARD_CONFIG = tunnel.WIREGUARD_CONFIG
|
||||
OPENVPN_CONFIG = tunnel.OPENVPN_CONFIG
|
||||
OPENVPN_AUTH = tunnel.OPENVPN_AUTH
|
||||
CONFIG_FILES = tunnel.CONFIG_FILES
|
||||
MAX_CONFIG_BYTES = 256 * 1024
|
||||
|
||||
# The tunnel writes its status every 15 seconds; older than this, it is not running.
|
||||
|
|
@ -59,7 +59,10 @@ def read_vpn_config() -> tuple[str, str] | None:
|
|||
if not config_file:
|
||||
return None
|
||||
try:
|
||||
text = (get_config_directory() / config_file).read_text()
|
||||
text = tunnel.read_vpn_file(get_config_directory(), config_file, CONFIG_FILES.values())
|
||||
except tunnel.VPNConfigError as e:
|
||||
logger.warning(f'Ignoring the VPN config in controller.yaml: {e}')
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
return tunnel.config_kind(config_file), text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue