# Remote tests The scripts are in `bin/` of the repository; this directory holds their data: `scenarios/`, `configs/`, `cloud-init/`, `repo/` and the files copied into instances. `bin/lm-dev-run.py` installs the package built last, a release in `out/` or a dev build in `out/dev/`, or the one `--deb` names, into instances of an LXD remote and checks the server in four scenarios: - `core`: one interface, router and VPN off; - `nat`: VPN on, router off, one interface; WireGuard and OpenVPN clients reach a target through NAT, then the VPN is switched off; - `s2s`: router and VPN on, two sites with two interfaces each, a site-to-site connection with a pre-shared key, and a routed WireGuard client; the router is then switched off while `site_to_site` is set, which setup refuses; - `oidc`: HTTPS with a certificate of the Servers CA and the OpenID Provider on; the scenario's Vault, a relying party with its `auth/oidc` method, signs the user alice in with the authorization code flow and PKCE, her password and a TOTP code of the Vault, driven in a client by `oidc_login.py` as a browser would, and a wrong code is refused. Servers are virtual machines, clients and LAN hosts containers, all from `ubuntu:26.04`. Each scenario is a module in `scenarios/` whose `run(lab)` uses the `Lab` class of `lm-dev-run.py`. `wireguard_peer.py`, `echo.py` and `oidc_login.py` are copied into the instances: the first gives the test user a WireGuard peer on the server, the second answers HTTP with the client's address, and the third signs a user in at the server's OpenID Provider. ```sh export LXD_REMOTE=... export LXD_POOL=... ``` ```sh ./build.sh bin/lm-dev-run.py core nat s2s ``` ```sh bin/lm-dev-run.py all ``` Options: | Option | Variable | Default | Meaning | |---|---|---|---| | `--remote` | `LXD_REMOTE` | required | The `lxc` remote | | `--pool` | `LXD_POOL` | required | The storage pool of the project's root disks | | `--project` | `LXD_TEST_PROJECT` | `lm-test` | The project the instances live in; it must not exist | | `--image` | `LXD_IMAGE` | `ubuntu:26.04` | The image of every instance | | `--keep` | | off | Leaves the project and the networks in place; run one scenario then | | `--deb` | | the package built last | The package to test | Each scenario creates the project and its networks (`lmt--`) and removes them at its end. Its first instance is its Vault, `lm-vault` on the bridge `lmt-vault` (`10.99.99.0/24`), reached by the Mac and the instances on the LXD host's address, port 8200, through a proxy device; every secret reaches an instance through it (see Secrets). The administrator password and the pre-shared key are generated per run and kept in the scenario's Vault, as `/admin` and `/config`; with `--keep` they stay there. The run leaves `.env` as it is. The run prints PASS, FAIL or SKIP per check and exits non-zero on a failure; WireGuard is skipped when the host kernel has no WireGuard module. The configurations in `configs/` have placeholders that are filled in for each server: - `@PSK@`: the pre-shared key, filled in on the Mac; the file reaches the server through the Vault; - `@ETH0@` and `@ETH1@`: the names of its interfaces; - `@CIDR0@`: the network of its first address. ## Secrets A secret never reaches an instance as a command-line argument or on standard input, where `ps`, `/proc//cmdline` or a log would show it. The scripts keep it in the project's Vault, HashiCorp Vault with file storage and a plain HTTP listener, which `lm_dev.py` initialises with one key share and unseals over its API, with KV v2 at `kv`, the TOTP engine at `totp` and AppRole enabled. Every instance the scripts launch, apart from the Vault and the hosts of the lab's isolated LANs, which have no route to it, gets an AppRole of its own, named after it, once it has booted: 1. The Mac makes the policy `instance-`, which reads `kv/data//*` and creates the TOTP keys `totp/keys/-*`, and the role ``, which gives batch tokens of 5 minutes and secret IDs that do not expire. 2. The helper `lm-dev-vault` goes to `/usr/local/sbin`, and the Vault's URL, the role ID and a wrapping token of a new secret ID, single-use and living 120 seconds, to `/etc/vault` (0700), the IDs readable by root only. 3. `lm-dev-vault init` removes the token, refuses it unless it wraps the role's `secret-id` request, unwraps it and keeps the secret ID in `/etc/vault/secret-id`. From then on the instance logs in with its AppRole. A file that holds a secret is stored whole by the Mac as `kv//`, and `lm-dev-vault get` writes it in the instance with the mode asked for; a program that reads the secret on standard input reads that file, which is removed right after. The debconf preseed with the admin password, `linux-manager.json` with the pre-shared key, and alice's password and OpenVPN profile take this way; the admin password is also kept as `/admin`. A WireGuard client's private key is made in the client and never leaves it. A user's TOTP token is the key `-` of the TOTP engine. The VM has the Vault generate it with `lm-dev-vault totp` and enrols its secret with its current code; the secret is never on the Mac and cannot be read back from the Vault, which gives the codes (`totp/code/-`). `lm-dev-vm.py remove` deletes the VM's role, policy, secrets and TOTP keys. The Vault's web UI is at `/ui` of its address, `http://:8200/ui`; it signs in with the root token of `vault-.json`. The state the scripts keep across clean-ups of `tmp/` is in `.lm-dev-config/` at the repository's root, mode 0700, its files 0600, ignored by git: the project's state and repository key, the Vault's address, unseal key and root token (`vault-.json`). `tmp/` holds only what can go: logs and files removed right after use. ## A VM to work with `lm-dev-vm.py create` launches one server VM, `lm-dev` by default, on the LXD remote and leaves it running. The VM is created in a project, the test project `lm-dev` by default, with that project's default profile, and takes its address from DHCP. It gets the package with the administrator `admin` and a generated password, set as `ADMIN_USERNAME` and `ADMIN_PASSWORD` in the repository's `.env`, a TOTP token for `admin` in the project's Vault unless `--no-otp` is given, and a configuration from `configs/`, `core.json` by default; `@ETH0@` is the interface of the VM's default route. In a test project made by `lm-dev-lxd-project.py`, the VM installs the package from the project's repository, so later dev builds reach it as updates; in another project it installs `--deb`, or else the package built last, in `out/` or `out/dev/`. The leased address is pinned on the VM's NIC, and these ports lead to the VM: - `7080` to the Manager; - `7081` to the status web service; - `2222` to SSH, port `22`. In a test project they lead through a network forward on the project's `wan`, whose listen address is `--forward-address`, or else one LXD allocates from the uplink's `--routes`, as LXD refuses NAT proxy devices in a project with networks of its own. In another project NAT proxy devices listen on the LXD host address `--listen`, by default the IPv4 address of the host in the remote's URL (`lxc remote list`), which must be an address of the LXD host itself. The script prints the VM's address, where the administrator's password is kept, the URLs, the command of a shell in it and the command that removes it; it never prints the password. ```sh bin/lm-dev-vm.py create ``` ```sh bin/lm-dev-vm.py remove ``` `create` needs the project's Vault (`lm-dev-lxd-project.py vault create`): the VM gets its AppRole there, and reads the preseed and the configuration, kept as `/preseed` and `/config`, and creates the TOTP key `-admin` with it. `remove` deletes the VM, its forward and what the Vault keeps for it; `.env` is left as it is. Options: | Option | Variable | Default | Meaning | |---|---|---|---| | `--remote` | `LXD_REMOTE` | required | The `lxc` remote | | `--project` | `LXD_PROJECT` | `lm-dev` | The project of the VM | | `--vm` | | `lm-dev` | The name of the VM; it must not exist for `create` | | `--image` | `LXD_IMAGE` | `ubuntu:26.04` | The image of the VM | | `--config` | | `core.json` | The configuration from `configs/` | | `--listen` | `LXD_LISTEN` | the remote URL's host | Outside a test project, the address the proxies listen on | | `--forward-address` | `LXD_FORWARD_ADDRESS` | allocated | In a test project, the forward's listen address, one of the uplink's routes, so a recreated VM keeps it | | `--no-otp` | | off | With `create`, enrol no TOTP token for `admin` | | `--deb` | | the package built last | Outside a test project, the package to install | ## A test project with dev builds `lm-dev-lxd-project.py create` makes a project for manual tests that stays until `lm-dev-lxd-project.py remove`; `lm-dev-run.py` keeps making and removing its own projects. The project has: - networks of its own (`features.networks`), OVN networks on the physical uplink `--uplink`: `wan`, with NAT and DHCP on a subnet LXD picks, and `lana` and `lanb`, on subnets LXD picks without DHCP; OVN gives each network's router an address, which LAN hosts don't use as their gateway; - a default profile with a root disk on the pool and `eth0` on `wan`; - the container `repo`, whose nginx serves a signed apt repository of the dev builds, `resolute main` for amd64 and arm64, at its pinned address; - the container `vault`, the project's Vault (see Secrets), reached by the Mac through a forward of port 8200 on `wan` at `--vault-address` (`LXD_VAULT_ADDRESS`), or an allocated address, and by the instances on its pinned address. What the other scripts need, the repository's URL among it, is written to `.lm-dev-config/lxd-project-.json`, and the repository's key to `.lm-dev-config/lxd-project-.gpg`. `remove` deletes the project's instances, its networks, the project and those files. ```sh bin/lm-dev-lxd-project.py vault create # the Vault of an existing project bin/lm-dev-lxd-project.py vault unseal # after a restart of the vault container bin/lm-dev-lxd-project.py vault remove ``` The remote needs OVN, set up as LXD's standalone OVN guide describes, and a host bridge on the LAN, whose host address stays on the bridge. `uplink setup` creates on it, once per remote, the physical network `--uplink` that the OVN networks use as uplink: - `--gateway`: the LAN's gateway, as address/prefix; - `--dns`: the LAN's name servers, comma-separated; - `--ovn-ranges`: free LAN addresses outside the LAN's DHCP pool, as `FIRST-LAST`, one for the router of each OVN network; - `--routes`: a free LAN subnet, in CIDR, whose addresses network forwards listen on. OVN answers ARP for its routers' and forwards' addresses on the LAN (`ovn.ingress_mode` `l2proxy`, LXD's default), so the LAN needs no route. `uplink setup` leaves an existing network of that name as it is; `uplink remove` deletes it. ```sh bin/lm-dev-lxd-project.py uplink setup ``` ```sh bin/lm-dev-lxd-project.py uplink remove ``` ```sh bin/lm-dev-lxd-project.py create ``` ```sh bin/lm-dev-lxd-project.py remove ``` | Option | Variable | Default | Meaning | |---|---|---|---| | `--remote` | `LXD_REMOTE` | required | The `lxc` remote | | `--pool` | `LXD_POOL` | required by `create` | The storage pool of the project's root disks | | `--project` | `LXD_PROJECT` | `lm-dev` | The project | | `--image` | `LXD_IMAGE` | `ubuntu:26.04` | The image of the repository container | | `--vault-address` | `LXD_VAULT_ADDRESS` | allocated | The listen address of the Vault's forward, one of the uplink's routes | | `--uplink` | `LXD_UPLINK` | `uplink` | The physical uplink network of the OVN networks | | `--parent` | `LXD_UPLINK_PARENT` | required by `uplink setup` | The host bridge on the LAN | | `--gateway` | `LXD_UPLINK_GATEWAY` | required by `uplink setup` | The LAN's gateway, address/prefix | | `--dns` | `LXD_UPLINK_DNS` | required by `uplink setup` | The LAN's name servers | | `--ovn-ranges` | `LXD_UPLINK_OVN_RANGES` | required by `uplink setup` | LAN addresses for OVN routers | | `--routes` | `LXD_UPLINK_ROUTES` | required by `uplink setup` | A LAN subnet for network forwards | `lm-dev-build.py` builds and publishes the next dev build. Its version is the newest changelog entry's with `~dev` before the Debian revision, `0.41.0~dev7-1` for `0.41.0-1`, so the release of that entry is newer than its dev builds. `N` is that of the last dev build, kept in `.dev-build.serial` of the repository; each build that succeeds writes its own, one higher, and `release.py` writes 0 when it releases, so the next entry's builds start at `~dev1`. `./build.sh` builds it, with `CONTAINER_RUNTIME` and `DOCKER_CONTEXT` from the environment; the build is moved to `out/dev/`, copied into the repository and published there. A VM of the project then gets it with Check update and Upgrade in the Manager, or `apt-get update` and `apt-get upgrade`. ```sh bin/lm-dev-build.py ``` `--project` (`LXD_PROJECT`, `lm-dev` by default) names the project; the remote is the project's, read from its state file, so the script takes no `--remote`. ## A TOTP token for a user of a test VM `bin/lm-dev-otp-register.py` enrols a new TOTP token for a user of a VM, `admin` of `lm-dev` by default, replacing a token the user had. The project's Vault generates the key `-` in its TOTP engine and hands it to the VM (see Secrets), where the package's `linuxmanager_users` stores it. `bin/lm-dev-otp-code.py` prints the user's current code, read from the Vault, for the Manager's sign-in, SSH or `sudo`. ```sh bin/lm-dev-otp-register.py ``` ```sh bin/lm-dev-otp-code.py ``` | Option | Variable | Default | Meaning | |---|---|---|---| | `--remote` | `LXD_REMOTE` | required by `lm-dev-otp-register.py` | The `lxc` remote | | `--project` | `LXD_PROJECT` | `lm-dev` | The project of the VM | | `--vm` | | `lm-dev` | The name of the VM | | `--user` | | `admin` | The user | ## A command-line authenticator app `bin/otp.py` is an authenticator app on the command line, in place of one on a phone, not tied to Linux Manager or LXD. It keeps a secret in the file `--secret-file` or `OTP_FILE` names, readable by its owner only: the base32 secret alone, or with `--url` its `otpauth://` URI, without a line end, so Vault's TOTP engine imports the file as it is. The codes are RFC 6238's, SHA-1, 6 digits and 30 seconds by default; a file holding a URI gives the URI's. Options of both actions: | Option | Variable | Default | Meaning | |---|---|---|---| | `--secret-file` | `OTP_FILE` | required | The file of the base32 secret or its `otpauth://` URI | | `--algorithm` | | `sha1` | `sha1`, `sha256` or `sha512` | | `--digits` | | `6` | The digits of a code, 6 to 10 | | `--period` | | `30` | The seconds a code is valid | `new` makes a new secret of 20 random bytes in the file and prints its `otpauth://` URI, with the algorithm, digits and period, for a server or an app that enrols a given secret: ```sh bin/otp.py new --account admin --issuer lm-dev ``` Either file is a key of Vault's TOTP engine, the secret with its settings, or the URI with all of them: ```sh vault write totp/keys/admin key=@secret-file issuer=lm-dev account_name=admin vault write totp/keys/admin url=@otpauth-file ``` | Option | Default | Meaning | |---|---|---| | `--account`, `--issuer` | none | The label of the URI | | `--url` | off | Store the `otpauth://` URI instead of the secret alone | | `--force` | off | Replace an existing secret | `code` prints the current code of the secret, for the Manager's sign-in, SSH or `sudo`: ```sh bin/otp.py code ``` | Option | Default | Meaning | |---|---|---| | `--at` | now | The Unix time of the code | ## Scope of the tests Not covered by `lm-dev-run.py`: IKEv2 client access, HTTPS with Let's Encrypt, passkeys, PowerDNS answering from outside, and the Azure and GCP platform modules.