feature: the PKI's schema is a file of its own that another slapd loads, a certificate can carry the name an application files it under, and the members of pki-managers manage the PKI with its keys.
Release / release (push) Successful in 24s

This commit is contained in:
slawek committed 2026-11-24 14:30:50 +01:00
1 parent 6911d16fa3
commit b61d1593b7
14 files changed
+378 -169

No files matched your search

+25 -7
View File
@@ -25,6 +25,8 @@ ROOT = pathlib.Path(__file__).resolve().parent.parent
TESTS = ROOT / 'tests' / 'remote'
# The project of the manual tests, which lm-dev-lxd-project.py makes.
PROJECT = 'lm-dev'
# The default VM of the manual tests, which lm-dev-vm.py makes.
VM = 'router'
# The state of the scripts that outlives a clean-up of tmp/: settings, project and Vault states, keys and secrets; 0700.
CONFIG = ROOT / '.lm-dev-config'
# The settings of the scripts, the defaults of their options: a JSON object of LXD_* names and their values.
@@ -290,11 +292,13 @@ def totp_key(instance, user):
def enrol_otp(remote, project, instance, user):
"""Enrol a new TOTP token for the user of the VM, replacing one the user had; the problem, or None.
"""Enrol a TOTP token for the user of the VM, replacing one the user had; the problem, or None.
The VM has the Vault generate the key with its AppRole and enrols its secret with its current code; the codes are
read from the Vault (otp_code). When the user is the administrator of the VM's credentials_path, the key's otpauth
URI, read from the VM's file before it is removed, is kept there as otp_url, to add the token to an authenticator.
When the user is the administrator of the VM's credentials_path and the file has otp_url, the Vault's key is made
from that otpauth URI and the VM receives it through the Vault (hand_over), so the token stays the same. Otherwise
the VM has the Vault generate a new key with its AppRole, and for the administrator the key's otpauth URI, read
from the VM's file before it is removed, is kept in the file as otp_url, to add the token to an authenticator. The
VM enrols the key's secret with its current code; the codes are read from the Vault (otp_code).
"""
state = vault_state(project)
if state is None:
@@ -308,9 +312,23 @@ def enrol_otp(remote, project, instance, user):
credentials = credentials_path(project, instance)
known = json.loads(credentials.read_text(encoding='utf-8')) if credentials.is_file() else {}
keep = known.get('username') == user
steps = (('install', '-d', '-m', '0700', HANDOVER_DIR), (HELPER, 'totp', key, instance, user, target, '0600'),
*((('cat', target),) if keep else ()), ('python3', '-c', OTP_ENROL, user, target))
for command in steps:
reuse = known.get('otp_url') if keep else None
prepared = lxc_exec(remote, project, instance, 'install', '-d', '-m', '0700', HANDOVER_DIR)
if prepared.returncode != 0:
return f'{HANDOVER_DIR} cannot be made in {instance}: {prepared.stderr.strip()}'
if reuse:
try:
vault_call(state['url'], 'POST', f'/v1/{TOTP_MOUNT}/keys/{key}', {'url': reuse},
token=state['root_token'])
except VaultError as error:
return f'the TOTP key {key} cannot be made from otp_url: {error}'
problem = hand_over(remote, project, instance, state, 'otp-url', reuse + '\n', target, '0600')
if problem:
return problem
steps = ()
else:
steps = ((HELPER, 'totp', key, instance, user, target, '0600'), *((('cat', target),) if keep else ()))
for command in (*steps, ('python3', '-c', OTP_ENROL, user, target)):
result = lxc_exec(remote, project, instance, *command)
if result.returncode != 0:
return f'{user} was not enrolled: {(result.stderr.strip().splitlines() or ["lxc exec failed"])[-1]}'