feature: the VPN, the router, the name server and WebDAV are components switched on the System tab and installed on demand, Caddy from the Ubuntu archive is a dependency and serves every HTTP and HTTPS port, HTTPS is chosen at install, its certificate is of the Servers Issuing CA or self-signed by default, of ACME or of another CA, the issuing CAs are in one tab, a locked account is unlocked again, the name of a CA is fixed once the CA exists, and a run of setup is no longer cut short by a change.
Release / release (push) Failing after 8s

This commit is contained in:
slawek committed 2026-11-24 05:51:27 +01:00
1 parent a649331aa2
commit a7bfabcb89
97 files changed
+4498 -1834

No files matched your search

+3 -1
View File
@@ -19,13 +19,15 @@ def run(lab):
'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.refuse('core: no VPN or router package installed', r'(?m)^installed$', 'lm-core', 'sh', '-c',
"dpkg-query -W -f='${db:Status-Status}\\n' strongswan-swanctl openvpn 2>/dev/null")
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: p2s and s2s CAs off', states.get('p2s') == 'off' and states.get('s2s') == 'off')
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'))
+2 -2
View File
@@ -47,8 +47,8 @@ def run(lab):
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.hand_over('lm-nat-client', 'openvpn-profile', profile, '/root/alice.ovpn')
lab.hand_over('lm-nat-client', 'alice', f'alice\n{lab.admin_password}\n', '/root/alice.pass')
lab.on('lm-nat-client', 'sh', '-c', f'echo "{server} 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', target, '255.255.255.255',
+111
View File
@@ -0,0 +1,111 @@
"""OpenID Provider: the lab's Vault signs the user alice in through the server's provider, as a relying party
(auth/oidc) with the authorization code flow and PKCE, the sign-in driven in a client as a browser would."""
import secrets
import urllib.parse
from lm_dev import TESTS, VaultError, enrol_otp, otp_code, store_secret, vault_call
#: The FQDN of the server, the host of its issuer.
FQDN = 'lm-oidc.test'
#: The server's OpenID Provider, the HTTPS site of its web service.
ISSUER = f'https://{FQDN}:7444'
#: The redirect URI of Vault's CLI convention, registered on both sides; the driver reads it, nothing follows it.
REDIRECT = 'http://localhost:8250/oidc/callback'
#: The server's root CA, which the server trusts and publishes.
ROOT_PEM = '/usr/local/share/ca-certificates/linux-manager-ca.crt'
def vault(lab, method, path, body=None, token=None):
"""A call to the lab's Vault with the root token, or the token given; the answer, or None with the problem printed."""
try:
return vault_call(lab.vault['url'], method, path, body, token or lab.vault['root_token'])
except VaultError as error:
print(f'oidc: {error}')
return None
def sign_in(lab, url, code):
"""Hand the client the authorization URL, alice's password and the code, and run the driver; its answer or {}."""
ok = (lab.push_text(url, 'lm-oidc-client', '/run/lm-dev/oidc-url') and
lab.push_text('alice', 'lm-oidc-client', '/run/lm-dev/oidc-name') and
lab.hand_over('lm-oidc-client', 'oidc-password', lab.admin_password, '/run/lm-dev/oidc-password') and
lab.hand_over('lm-oidc-client', 'oidc-code', code, '/run/lm-dev/oidc-code'))
return (lab.json_of('lm-oidc-client', 'python3', '/root/oidc_login.py') or {}) if ok else {}
def run(lab):
lab.network('lmt-oidc-ext', '172.31.12.1/24')
lab.instance('lm-oidc', 'vm', 'server.yaml', ('lmt-oidc-ext', '00:16:3e:4c:12:10', '172.31.12.10/24', '172.31.12.1'))
lab.instance('lm-oidc-client', 'container', 'client.yaml',
('lmt-oidc-ext', '00:16:3e:4c:12:30', '172.31.12.30/24', '172.31.12.1'))
if not lab.ready('lm-oidc', 'lm-oidc-client'):
lab.result('oidc: instances ready', False)
lab.result('oidc: package installed and configured', lab.server('lm-oidc', 'oidc.json'))
server = str(lab.address('lm-oidc').ip)
lab.result('oidc: user alice added', lab.vpn_user('lm-oidc'))
lab.result('oidc: TOTP token of alice enrolled', enrol_otp(lab.remote, lab.project, 'lm-oidc', 'alice') is None)
# The client: a service account with the redirect URI, its secret handed over as a file and kept in the Vault.
secret = secrets.token_urlsafe(24)
store_secret(lab.vault, 'lm-oidc/vault-client', {'secret': secret})
file = '/run/lm-dev/vault-client.secret'
registered = lab.hand_over('lm-oidc', 'vault-client', f'{secret}\n', file) and lab.on(
'lm-oidc', 'sh', '-c', f'linux-manager-user --json add vault --service --display-name Vault --redirect-uri '
f'{REDIRECT} < {file}; status=$?; rm -f {file}; exit $status').returncode == 0
lab.result('oidc: client vault registered', registered)
root = lab.on('lm-oidc', 'cat', ROOT_PEM).stdout
hosts = f'echo "{server} {FQDN}" >>/etc/hosts'
lab.on('lm-oidc-client', 'sh', '-c', hosts)
lab.push_text(root, 'lm-oidc-client', '/root/oidc-root.pem')
lab.push(TESTS / 'oidc_login.py', 'lm-oidc-client', '/root/oidc_login.py')
lab.expect('oidc: discovery answers over HTTPS with the server CA', rf'"issuer": ?"{ISSUER}"',
'lm-oidc-client', 'curl', '-s', '--cacert', '/root/oidc-root.pem',
f'{ISSUER}/.well-known/openid-configuration')
# Vault, a relying party of the server, configured with the root token.
lab.on('lm-vault', 'sh', '-c', hosts)
vault(lab, 'POST', '/v1/sys/auth/oidc', {'type': 'oidc'})
configured = vault(lab, 'POST', '/v1/auth/oidc/config', {
'oidc_discovery_url': ISSUER, 'oidc_discovery_ca_pem': root, 'oidc_client_id': 'vault',
'oidc_client_secret': secret, 'default_role': 'lab'})
lab.result('oidc: Vault reads the discovery document', configured is not None)
role = vault(lab, 'POST', '/v1/auth/oidc/role/lab', {
'role_type': 'oidc', 'user_claim': 'preferred_username', 'groups_claim': 'groups',
'oidc_scopes': ['profile', 'email', 'groups'], 'allowed_redirect_uris': [REDIRECT],
'claim_mappings': {'email': 'email'}, 'token_policies': ['default']})
lab.result('oidc: Vault role lab written', role is not None)
# The authorization code flow: Vault's URL, the sign-in in the client, the code back to Vault.
url = ((vault(lab, 'POST', '/v1/auth/oidc/oidc/auth_url', {'role': 'lab', 'redirect_uri': REDIRECT}) or {})
.get('data') or {}).get('auth_url') or ''
query = urllib.parse.parse_qs(urllib.parse.urlsplit(url).query)
lab.result('oidc: authorization URL asks for PKCE S256', query.get('code_challenge_method') == ['S256'])
answer = sign_in(lab, url, otp_code(lab.project, 'lm-oidc', 'alice')) if url else {}
lab.result('oidc: sign-in page shown', answer.get('page') is True)
location = urllib.parse.parse_qs(urllib.parse.urlsplit(answer.get('location') or '').query)
lab.result('oidc: sign-in redirects with a code and the state',
answer.get('status') == 302 and bool(location.get('code')) and location.get('state') == query.get('state'))
login = vault(lab, 'GET', '/v1/auth/oidc/oidc/callback?' + urllib.parse.urlencode({
'state': (location.get('state') or [''])[0], 'code': (location.get('code') or [''])[0],
'nonce': (query.get('nonce') or [''])[0]})) if location.get('code') else None
token = ((login or {}).get('auth') or {}).get('client_token')
lab.result('oidc: Vault issues a token for alice', bool(token))
looked = vault(lab, 'GET', '/v1/auth/token/lookup-self', token=token) if token else None
entity = (looked or {}).get('data', {}).get('entity_id')
aliases = ((vault(lab, 'GET', f'/v1/identity/entity/id/{entity}') or {}).get('data') or {}).get('aliases', []) \
if entity else []
alias = next((item for item in aliases if item.get('name') == 'alice'), {})
lab.result('oidc: the token is of the entity alias alice', bool(alias))
lab.result('oidc: the email claim is mapped', (alias.get('metadata') or {}).get('email') == 'alice@example.org')
# A wrong code: the sign-in page again, no redirect.
url = ((vault(lab, 'POST', '/v1/auth/oidc/oidc/auth_url', {'role': 'lab', 'redirect_uri': REDIRECT}) or {})
.get('data') or {}).get('auth_url') or ''
wrong = f'{(int(otp_code(lab.project, "lm-oidc", "alice")) + 1) % 1000000:06d}'
answer = sign_in(lab, url, wrong) if url else {}
lab.result('oidc: a wrong code is refused without a redirect', answer.get('status') == 401 and not answer.get('location'))