37 lines
1.6 KiB
Python
Executable File
37 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Register a TOTP token for a user of a Linux Manager VM on an LXD remote: lm-dev-otp-register.py.
|
|
|
|
The token is enrolled for --user (admin by default) of the VM --vm (lm-dev) in the project --project
|
|
(LXD_PROJECT, lm-dev by default) on the remote --remote (LXD_REMOTE): the project's Vault generates
|
|
the key in its TOTP engine as <vm>-<user> and hands it to the VM, where linuxmanager_users stores
|
|
it with its current code, replacing a token the user had. The secret stays in the Vault and the
|
|
VM; lm-dev-otp-code.py prints the user's codes.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
from lm_dev import PROJECT, enrol_otp, totp_key
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument('--remote', default=os.environ.get('LXD_REMOTE'), help='the lxc remote (LXD_REMOTE)')
|
|
parser.add_argument('--project', default=os.environ.get('LXD_PROJECT', PROJECT),
|
|
help=f'the project of the VM (LXD_PROJECT, default {PROJECT})')
|
|
parser.add_argument('--vm', default='lm-dev', help='the name of the VM (default lm-dev)')
|
|
parser.add_argument('--user', default='admin', help='the user to enrol (default admin)')
|
|
args = parser.parse_args()
|
|
if not args.remote:
|
|
parser.error('--remote or LXD_REMOTE is required')
|
|
problem = enrol_otp(args.remote, args.project, args.vm, args.user)
|
|
if problem:
|
|
sys.exit(problem)
|
|
print(f'{args.user} of {args.remote}:{args.vm} has a new TOTP token, the key {totp_key(args.vm, args.user)} '
|
|
f'of the Vault of {args.project}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|