feat: rebranded from vpn-router to linux-manager.
This commit is contained in:
1 parent
8efe21bfa6
commit
85a1ffa21f
238 files changed
+5010
-3761
No files matched your search
@@ -0,0 +1 @@
|
||||
"""The scenarios of run.py; each module's run(lab) creates its networks and instances and runs its checks."""
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Core only: one interface, router and VPN off."""
|
||||
|
||||
|
||||
def run(lab):
|
||||
lab.network('lmt-core-ext', '172.31.10.1/24')
|
||||
lab.instance('lm-core', 'vm', 'server.yaml', ('lmt-core-ext', '00:16:3e:4c:10:10', '172.31.10.10/24', '172.31.10.1'))
|
||||
lab.instance('lm-core-client', 'container', 'client.yaml',
|
||||
('lmt-core-ext', '00:16:3e:4c:10:30', '172.31.10.30/24', '172.31.10.1'))
|
||||
if not lab.ready('lm-core', 'lm-core-client'):
|
||||
lab.result('core: instances ready', False)
|
||||
lab.result('core: package installed and configured', lab.server('lm-core', 'core.json'))
|
||||
|
||||
lab.expect('core: setup succeeded', r'^success$',
|
||||
'lm-core', 'systemctl', 'show', '-p', 'Result', '--value', 'linux-manager-setup')
|
||||
lab.refuse('core: no failed units', r'\S', 'lm-core', 'systemctl', '--failed', '--plain', '--no-legend')
|
||||
lab.expect('core: firewall active', r'^Status: active', 'lm-core', 'ufw', 'status')
|
||||
lab.check('core: no sysctl file', 'lm-core', 'test', '!', '-e', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
lab.refuse('core: no NAT, IPsec or MSS rules', r'ROUTER NAT|IPSEC RULES|ROUTER MSS',
|
||||
'lm-core', 'cat', '/etc/ufw/before.rules')
|
||||
for unit in ('strongswan', 'wg-quick@wg0', 'openvpn-server@linux-manager', 'linux-manager-resolver'):
|
||||
lab.refuse(f'core: {unit} inactive', r'^active', 'lm-core', 'systemctl', 'is-active', unit)
|
||||
lab.expect('core: schema under the PEN arc', r"1\.3\.6\.1\.4\.1\.67380\.10\.1\.2\.2\.1 NAME 'linuxManagerAccount'",
|
||||
'lm-core', 'slapcat', '-n', '0', '-o', 'ldif-wrap=no')
|
||||
lab.expect('core: base DN dc=linux-manager,dc=local', r'^dn: dc=linux-manager,dc=local$',
|
||||
'lm-core', 'slapcat', '-b', 'dc=linux-manager,dc=local', '-o', 'ldif-wrap=no')
|
||||
status = lab.json_of('lm-core', 'linux-manager-ca', '--json', 'status') or {}
|
||||
states = {authority.get('name'): authority.get('state') for authority in status.get('authorities', [])}
|
||||
lab.result('core: p2s and s2s CAs missing', states.get('p2s') == 'missing' and states.get('s2s') == 'missing')
|
||||
lab.result('core: VPN user added', lab.vpn_user('lm-core'))
|
||||
user = lab.alice('lm-core')
|
||||
lab.result('core: VPN user has no certificate', user is not None and not user.get('certificate'))
|
||||
lab.result('core: OpenVPN profile refused with status 4',
|
||||
lab.on('lm-core', 'linux-manager-user', '--json', 'profile', 'alice').returncode == 4)
|
||||
lab.expect('core: web state has router and vpn false', r'"router": false, "vpn": false',
|
||||
'lm-core', 'cat', '/run/linux-manager/web.json')
|
||||
lab.expect('core: status web service answers the client', r'^200$',
|
||||
'lm-core-client', 'curl', '-s', '-o', '/dev/null', '-w', '%{http_code}', 'http://172.31.10.10:7081/status')
|
||||
@@ -0,0 +1,66 @@
|
||||
"""VPN on, router off: one interface, the VPN clients reach local.cidrs through NAT."""
|
||||
|
||||
import re
|
||||
import time
|
||||
|
||||
|
||||
def run(lab):
|
||||
lab.network('lmt-nat-ext', '172.31.11.1/24')
|
||||
lab.instance('lm-nat', 'vm', 'server.yaml', ('lmt-nat-ext', '00:16:3e:4c:11:10', '172.31.11.10/24', '172.31.11.1'))
|
||||
lab.instance('lm-nat-target', 'container', 'host.yaml',
|
||||
('lmt-nat-ext', '00:16:3e:4c:11:20', '172.31.11.20/24', '172.31.11.1'))
|
||||
lab.instance('lm-nat-client', 'container', 'client.yaml',
|
||||
('lmt-nat-ext', '00:16:3e:4c:11:30', '172.31.11.30/24', '172.31.11.1'))
|
||||
if not lab.ready('lm-nat', 'lm-nat-target', 'lm-nat-client'):
|
||||
lab.result('nat: instances ready', False)
|
||||
if not lab.client('lm-nat-client'):
|
||||
lab.result('nat: client tools installed', False)
|
||||
lab.result('nat: package installed and configured', lab.server('lm-nat', 'nat.json'))
|
||||
lab.echo_server('lm-nat-target')
|
||||
ext = re.escape(lab.nic_of('lm-nat', 0) or '')
|
||||
|
||||
lab.expect('nat: setup succeeded', r'^success$',
|
||||
'lm-nat', 'systemctl', 'show', '-p', 'Result', '--value', 'linux-manager-setup')
|
||||
lab.expect('nat: sysctl file forwards', r'^net\.ipv4\.ip_forward = 1$',
|
||||
'lm-nat', 'cat', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
lab.refuse('nat: sysctl file keeps rp_filter', r'rp_filter', 'lm-nat', 'cat', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
lab.expect('nat: WireGuard pool masqueraded', rf'-A POSTROUTING -s 10\.66\.0\.0/24 -o {ext} -j MASQUERADE',
|
||||
'lm-nat', 'iptables', '-t', 'nat', '-S', 'POSTROUTING')
|
||||
lab.expect('nat: OpenVPN pool masqueraded', rf'-A POSTROUTING -s 10\.67\.0\.0/24 -o {ext} -j MASQUERADE',
|
||||
'lm-nat', 'iptables', '-t', 'nat', '-S', 'POSTROUTING')
|
||||
lab.refuse('nat: no IPsec rules', r'IPSEC RULES', 'lm-nat', 'cat', '/etc/ufw/before.rules')
|
||||
lab.result('nat: VPN user added', lab.vpn_user('lm-nat'))
|
||||
user = lab.alice('lm-nat')
|
||||
lab.result('nat: VPN user has a certificate', user is not None and user.get('certificate') is True)
|
||||
|
||||
if lab.wireguard_module('lm-nat-client'):
|
||||
if lab.wireguard_client('lm-nat-client', 'lm-nat', '172.31.11.10', '10.66.0.2', '172.31.11.20/32'):
|
||||
lab.expect('nat: WireGuard client reaches the target from the server address', r'^172\.31\.11\.10$',
|
||||
'lm-nat-client', 'curl', '-s', '--max-time', '10', 'http://172.31.11.20:8080/')
|
||||
else:
|
||||
lab.result('nat: WireGuard client set up', False)
|
||||
lab.on('lm-nat-client', 'bash', '/usr/bin/wg-quick', 'down', 'wg0')
|
||||
else:
|
||||
lab.skip('nat: WireGuard (no wireguard module on the host)')
|
||||
|
||||
profile = (lab.json_of('lm-nat', 'linux-manager-user', '--json', 'profile', 'alice') or {}).get('profile', '')
|
||||
lab.push_text(profile, 'lm-nat-client', '/root/alice.ovpn', '0600')
|
||||
lab.push_text(f'alice\n{lab.admin_password}\n', 'lm-nat-client', '/root/alice.pass', '0600')
|
||||
lab.on('lm-nat-client', 'sh', '-c', 'echo "172.31.11.10 lm-nat.test" >>/etc/hosts')
|
||||
lab.on('lm-nat-client', 'openvpn', '--config', '/root/alice.ovpn', '--auth-user-pass', '/root/alice.pass',
|
||||
'--route-nopull', '--disable-dco', '--route', '172.31.11.20', '255.255.255.255',
|
||||
'--daemon', '--log', '/root/openvpn.log')
|
||||
for _ in range(12):
|
||||
if lab.on('lm-nat-client', 'grep', '-q', 'Initialization Sequence Completed', '/root/openvpn.log').returncode == 0:
|
||||
break
|
||||
time.sleep(5)
|
||||
lab.expect('nat: OpenVPN client reaches the target from the server address', r'^172\.31\.11\.10$',
|
||||
'lm-nat-client', 'curl', '-s', '--max-time', '10', 'http://172.31.11.20:8080/')
|
||||
lab.on('lm-nat-client', 'pkill', 'openvpn')
|
||||
|
||||
lab.configure('lm-nat', 'nat-off.json')
|
||||
lab.refuse('nat: VPN off stops WireGuard', r'^active', 'lm-nat', 'systemctl', 'is-active', 'wg-quick@wg0')
|
||||
lab.refuse('nat: VPN off stops OpenVPN', r'^active',
|
||||
'lm-nat', 'systemctl', 'is-active', 'openvpn-server@linux-manager')
|
||||
lab.refuse('nat: VPN off removes the NAT rules', r'MASQUERADE', 'lm-nat', 'iptables', '-t', 'nat', '-S', 'POSTROUTING')
|
||||
lab.check('nat: VPN off removes the sysctl file', 'lm-nat', 'test', '!', '-e', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Router and VPN on: two interfaces, site-to-site with a pre-shared key, WireGuard routed.
|
||||
|
||||
Each site's local.cidrs is a network behind a LAN host, which holds its first address on lo.
|
||||
"""
|
||||
|
||||
|
||||
def run(lab):
|
||||
lab.network('lmt-s2s-wan', '172.31.20.1/24')
|
||||
lab.network('lmt-s2s-lana', None)
|
||||
lab.network('lmt-s2s-lanb', None)
|
||||
lab.instance('lm-s2s-a', 'vm', 'server.yaml',
|
||||
('lmt-s2s-wan', '00:16:3e:4c:20:10', '172.31.20.10/24', '172.31.20.1'),
|
||||
('lmt-s2s-lana', '00:16:3e:4c:21:10', '172.31.21.10/24'))
|
||||
lab.instance('lm-s2s-b', 'vm', 'server.yaml',
|
||||
('lmt-s2s-wan', '00:16:3e:4c:20:20', '172.31.20.20/24', '172.31.20.1'),
|
||||
('lmt-s2s-lanb', '00:16:3e:4c:22:10', '172.31.22.10/24'))
|
||||
lab.instance('lm-s2s-host-a', 'container', 'host.yaml', ('lmt-s2s-lana', '00:16:3e:4c:21:20', '172.31.21.20/24'))
|
||||
lab.instance('lm-s2s-host-b', 'container', 'host.yaml', ('lmt-s2s-lanb', '00:16:3e:4c:22:20', '172.31.22.20/24'))
|
||||
lab.instance('lm-s2s-client', 'container', 'client.yaml',
|
||||
('lmt-s2s-wan', '00:16:3e:4c:20:30', '172.31.20.30/24', '172.31.20.1'))
|
||||
if not lab.ready('lm-s2s-a', 'lm-s2s-b', 'lm-s2s-host-a', 'lm-s2s-host-b', 'lm-s2s-client'):
|
||||
lab.result('s2s: instances ready', False)
|
||||
if not lab.client('lm-s2s-client'):
|
||||
lab.result('s2s: client tools installed', False)
|
||||
|
||||
lab.on('lm-s2s-host-a', 'ip', 'addr', 'add', '172.31.31.1/32', 'dev', 'lo')
|
||||
lab.on('lm-s2s-host-a', 'ip', 'route', 'add', '172.31.32.0/24', 'via', '172.31.21.10')
|
||||
lab.on('lm-s2s-host-a', 'ip', 'route', 'add', '10.66.0.0/24', 'via', '172.31.21.10')
|
||||
lab.on('lm-s2s-host-b', 'ip', 'addr', 'add', '172.31.32.1/32', 'dev', 'lo')
|
||||
lab.on('lm-s2s-host-b', 'ip', 'route', 'add', '172.31.31.0/24', 'via', '172.31.22.10')
|
||||
lab.echo_server('lm-s2s-host-a')
|
||||
lab.echo_server('lm-s2s-host-b')
|
||||
|
||||
lab.result('s2s: site A installed', lab.server('lm-s2s-a', 's2s-a.json'))
|
||||
lab.result('s2s: site B installed', lab.server('lm-s2s-b', 's2s-b.json'))
|
||||
|
||||
lab.expect('s2s: sysctl file forwards', r'^net\.ipv4\.ip_forward = 1$',
|
||||
'lm-s2s-a', 'cat', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
lab.expect('s2s: sysctl file loosens rp_filter', r'^net\.ipv4\.conf\.all\.rp_filter = 0$',
|
||||
'lm-s2s-a', 'cat', '/etc/sysctl.d/99-linux-manager.conf')
|
||||
lab.expect('s2s: RETURN before MASQUERADE', r'-A POSTROUTING -s 172\.31\.31\.0/24 -d 172\.31\.32\.0/24 -j RETURN',
|
||||
'lm-s2s-a', 'iptables', '-t', 'nat', '-S', 'POSTROUTING')
|
||||
lab.on('lm-s2s-a', 'swanctl', '--initiate', '--child', 'to-b')
|
||||
lab.expect('s2s: connection established on A', r'ESTABLISHED', 'lm-s2s-a', 'swanctl', '--list-sas')
|
||||
lab.expect('s2s: connection established on B', r'ESTABLISHED', 'lm-s2s-b', 'swanctl', '--list-sas')
|
||||
lab.expect('s2s: host A reaches host B with its own address', r'^172\.31\.31\.1$',
|
||||
'lm-s2s-host-a', 'curl', '-s', '--max-time', '10', '--interface', '172.31.31.1',
|
||||
'http://172.31.32.1:8080/')
|
||||
|
||||
lab.result('s2s: VPN user added on A', lab.vpn_user('lm-s2s-a'))
|
||||
if lab.wireguard_module('lm-s2s-client'):
|
||||
if lab.wireguard_client('lm-s2s-client', 'lm-s2s-a', '172.31.20.10', '10.66.0.2', '172.31.31.1/32'):
|
||||
lab.expect('s2s: WireGuard client reaches host A with its tunnel address', r'^10\.66\.0\.2$',
|
||||
'lm-s2s-client', 'curl', '-s', '--max-time', '10', 'http://172.31.31.1:8080/')
|
||||
else:
|
||||
lab.result('s2s: WireGuard client set up', False)
|
||||
else:
|
||||
lab.skip('s2s: WireGuard (no wireguard module on the host)')
|
||||
|
||||
lab.render('lm-s2s-a', 's2s-a-router-off.json')
|
||||
if lab.setup_run('lm-s2s-a'):
|
||||
lab.result('s2s: router off with site_to_site refused', False)
|
||||
else:
|
||||
lab.expect('s2s: router off with site_to_site refused', r'site-to-site connections need router\.enabled',
|
||||
'lm-s2s-a', 'journalctl', '-u', 'linux-manager-setup', '-n', '50', '--no-pager')
|
||||
Reference in new issue
Block a user