diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..2c57cda --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +dotenv_if_exists diff --git a/.gitignore b/.gitignore index 23ac7a4..1d4c4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ node_modules web/dist .venv dev.json +/.dev-build.serial +**/.env diff --git a/ADR.md b/ADR.md index 485d5be..4460182 100644 --- a/ADR.md +++ b/ADR.md @@ -259,9 +259,9 @@ P2S CA; with the VPN off a VPN user is created without a certificate, which it g is switched on (ADR-57). Only the OpenVPN client profile needs OpenVPN to be enabled. Consequences: slapd always holds the directory and the CAs exist on a configured router, even -when no P2S system uses them; with an offline root the P2S CA, and so the users' certificates, -wait for its certificate. An operator who wants a root CA of their own must place it before -choosing the platform. +when no P2S system uses them; with an offline or a Simple CA root the P2S CA, and so the users' +certificates, wait for its certificate. The source of the root, `pki.root`, is chosen with the +platform, before the root exists (ADR-27). ## ADR-11: Groups are groupOfNames entries that never become empty @@ -752,19 +752,25 @@ timer's schedules are systemd's shorthands, so all backups of one schedule start moment. A change of the users between the end of the copy and the next backup is in no backup until then. -## ADR-27: A two-level CA with dedicated issuing CAs, whose root may be offline +## ADR-27: Dedicated issuing CAs under a root the server creates, an offline root, or a Simple CA root Status: Accepted Context: One self-signed CA signed every certificate of the server with the same server and client purposes, so a certificate for any use was also a VPN client certificate, and the key that signed everything had to stay on the server. The server needs CAs for the VPN clients, for -site-to-site certificates and for the administrator's own uses, and a root whose key can be kept -elsewhere. The `simple-ca` script handled one level and ran as a separate process with its own -state file. +site-to-site certificates and for the administrator's own uses. Its root is its own, a CA the +organisation keeps offline, or the root of the organisation's Simple CA service. Moving the key of a +root the server created off the server later protects nothing that was not exposed while it was +there. The `simple-ca` script handled one level and ran as a separate process with its own state +file. -Decision: The root signs only issuing CAs, path length 1; the issuing CAs, path length 0, sign -the certificates. `p2s` signs the server's VPN server certificate and the users' certificates, +Decision: `pki.root` chooses the root at setup, fixed once the root exists, as the directory +shows it: `local`, a root the server creates and keeps the key of, which signs only issuing CAs, +path length 1; `offline`, whose certificate and the certificates of the issuing CAs, signed +offline from the CSRs the server makes, are imported with `linux-manager-ca` or `/ca`, the root +first; `simple-ca`, a Simple CA service (ADR-59). The issuing CAs, path length 0, sign the +certificates. `p2s` signs the server's VPN server certificate and the users' certificates, `s2s` the site-to-site certificates, and the CAs of `pki.issuing_cas` what their templates allow. A template fixes the key, the lifetime, the key usages, the extended key usages, the kind of common name and the subject alternative names a certificate may have; `vpn-server` and @@ -772,10 +778,9 @@ of common name and the subject alternative names a certificate may have; `vpn-se CA. The module `linuxmanager_pki.py`, with `python3-cryptography` from the Ubuntu archive, builds the keys, certificates, CSRs and CRLs in the processes that need them, as the user module does (ADR-6); the settings are the `pki` section of `linux-manager.json`, and the CAs and the -certificates are kept in the server's directory (ADR-32). Keeping the root key off the server is recommended, not required: while it is -on the server a new issuing CA is signed at once, and while it is not the CA gets its key and a -CSR, signed offline and imported with `linux-manager-ca` or `/ca`. The root key itself crosses -neither the API nor the Manager. For a certificate of something other than the server, the server +certificates are kept in the server's directory (ADR-32). A root the server creates keeps its key +there, with no command that exports or removes it; the key crosses neither the API nor the +Manager. For a certificate of something other than the server, the server signs the requester's CSR, or makes the key and returns it once in a PKCS#12 file, keeping only the certificate, so a key it gave away cannot leak from it later. The PKCS#12 file uses 3DES and SHA-1 MACs, the encryption the key stores of Windows and macOS import. strongSwan reads only the @@ -783,8 +788,10 @@ first certificate of a PEM file, so each CA has a file of its own in `/etc/swanc IKEv2 access and site-to-site name their CA in `cacerts`, which restricts the trust chain to it. Consequences: The P2S CA's certificates are accepted by IKEv2 and OpenVPN only, the site-to-site CA's by -site-to-site only. With an offline root, new issuing CAs and the root CRL need the offline step, -and a router whose P2S CA waits has no VPN server certificate and so no P2S access. The server +site-to-site only. With an offline root, the root certificate, new issuing CAs and the root CRL +need the offline step, and a router whose P2S CA waits has no VPN server certificate and so no +P2S access. A server whose root should be elsewhere is set up with that source from the start; +the source of an existing root is not changed. The server keeps the users' keys, as the OpenVPN profile embeds them. ## ADR-28: CA certificates and CRLs are published at configurable endpoints, and CRLs are short-lived @@ -850,7 +857,7 @@ Decision: An issuing CA of `pki.issuing_cas` with `acme` makes Caddy serve an AC at `/acme//` of the HTTPS status port, each in a `handle` block of its own. The issuing CA's certificate and key are given to Caddy as both the root and the intermediate of a `pki` CA, copied to `/etc/caddy/linux-manager-pki//` for Caddy's group, so that the server's root key never -reaches Caddy and may be offline. +reaches Caddy. Consequences: The certificates Caddy issues chain to the server's root through the issuing CA, are not in the server's inventory, follow no template and are not revoked; their short lifetime takes @@ -1582,17 +1589,47 @@ checks for and installs its updates through apt (ADR-24, ADR-53). A package copi server and installed from a file tests none of that, and a rebuild of an unreleased changelog entry keeps the same version, so apt sees no update. -Decision: `tests/remote/lxd-project.py` makes an LXD project for manual tests with networks of its +Decision: `bin/lm-dev-lxd-project.py` makes an LXD project for manual tests with networks of its own (`features.networks`), a WAN and two LANs, and a container `repo` that serves a signed apt repository, `resolute main`, built with `apt-ftparchive` and signed by its own key. The networks are OVN networks on an uplink bridge of the remote, as OVN is the only network type LXD creates -inside a project; they belong to the project and go with it. `tests/remote/dev-build.py` builds the newest -changelog entry as `~dev-`, `N` counted in `tmp/test-number`, by passing -`DEB_VERSION` to the build, which rewrites the version in the image only, and publishes the build -in that repository. `tests/remote/vm.py` gives a VM of the project that repository as its apt -source. The automated tests (`run.py`) keep their own project for one run and install from a -file. +inside a project; they belong to the project and go with it. `bin/lm-dev-build.py` builds the newest +changelog entry as `~dev-`, `N` counted in `.dev-build.serial`, which a +release sets to 0, by passing `DEB_VERSION` to the build, which rewrites the version in the image +only, and publishes the build in that repository. `bin/lm-dev-vm.py` gives a VM of the project +that repository as its apt source. The automated tests (`lm-dev-run.py`) keep their own project +for one run and install from a file. Consequences: Every dev build is an apt update of the one before, and the release of the entry, which sorts above all of its `~dev` builds, is an update of them all. The changelog is not changed by a dev build. Dev builds go to `out/dev/`, so `out/` holds only release builds. + +## ADR-59: A Simple CA root signs the issuing CAs through a sign-ca token of its issuing CA + +Status: Accepted + +Context: An organisation with a Simple CA service wants its servers' issuing CAs under that root, +signed without a person carrying CSRs and certificates. Simple CA's tokens are JWTs signed by the +key of their CA; a one-time setup code is exchanged once for a token, so the token itself is never +handed over. A Simple CA root that signs the issuing CAs of every server directly would give each +server's token the power of the root. + +Decision: Simple CA keeps a three-level hierarchy: its root, path length 2, signs an issuing CA, +path length 1, the upstream CA, which signs the server's issuing CAs, path length 0. The server +gets the setup code of a `sign-ca` token of the upstream CA at setup (debconf, written to +`/etc/linux-manager/pki-setup-code` and removed once used) or with `linux-manager-ca root +setup-code`, exchanges it at `/api/token-setup` over `https://` only, checked against the system's +trust store, where the administrator installs the CA of the service's certificate before setup, +and keeps the token and the +upstream CA's name on `cn=root` of the directory, unreadable to every account but root's socket, +as the keys are. Each issuing CA's CSR is signed at `//api/sign-ca`. The root and the +upstream CA are taken from the first chain Simple CA answers with, once the token's signature +verifies with the upstream CA's key, which ties the chain to the service that issued the token; +every later chain must match them. The upstream CA is `cn=upstream`, in every chain the server +gives; the root alone is the trust anchor. Their CRLs are fetched from the distribution points +of the certificates they signed, as Simple CA publishes them. + +Consequences: A stolen token signs CAs under the upstream CA only, until it expires or is revoked +in Simple CA. An issuing CA waits while Simple CA cannot be reached or the token has expired, and +a new setup code renews the token. The server cannot revoke a retired issuing CA in Simple CA; +its notice says to. Clients see a chain one CA longer than with the other sources. diff --git a/README.md b/README.md index 9440504..405a00a 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,9 @@ must have the type shown below; an unknown section or setting is an error. | `dns` | `enabled` | boolean | `false` | The primary name server of the server's domains, `wan.local_fqdn`, which must then be a DNS name (see Name server) | | `dns` | `secondary` | string | | The secondary name server of every domain, a host name other than `wan.local_fqdn`; it may transfer the domains | | `dns` | `listen` | string | `external` | The interfaces the name server answers on: `internal`, `external` or `both` | -| `dns` | `ttl` | integer | `300` | TTL of the records, 60 to 86400 seconds | +| `dns` | `ttl` | integer | `300` | The default TTL of the records, 60 to 86400 seconds: used where neither the record nor its domain has one | +| `pki` | `root` | string | `local` | Where the root CA comes from: `local`, `offline` or `simple-ca`; fixed once the root exists (see Certificates) | +| `pki` | `simple_ca_url` | string | | The `https://` URL of the Simple CA service, with `root` `simple-ca` | | `pki` | `root_name` | string | `Linux Manager Root CA` | Common name of the root CA, when the server creates it | | `pki` | `root_days` | integer | `7300` | Days the root CA's certificate is valid | | `pki` | `ca_days` | integer | `3650` | Days an issuing CA's certificate is valid | @@ -170,7 +172,6 @@ must have the type shown below; an unknown section or setting is an error. | `pki` | `issuing_cas` | object | | The general-purpose issuing CAs, each a name and `{name, templates, acme}` (see Certificates) | | `pki` | `templates` | object | | Certificate templates, each a name and the options it changes or defines (see Certificates) | | `pki` | `extended_key_usages` | object | | Custom extended key usages templates may give, each a name and its OID in dotted form (see Certificates) | -| `pki` | `root_key_warning` | boolean | `true` | `linux-manager-ca status` and `/ca` warn while the root key is on the server; `false` silences that warning | | `metrics` | `enabled` | boolean | `true` | The metrics service: collection, history and `/metrics` | | `metrics` | `listen` | string | `internal` | The interfaces `/metrics` is served on: `internal`, `external` or `both` | | `metrics` | `port` | integer | `9464` | TCP port of `/metrics` | @@ -431,8 +432,9 @@ The server has a two-level certificate authority, kept by `linux-manager-setup` uses. It is held in `ou=pki,dc=linux-manager,dc=local` of the server's directory, next to the users: ``` -cn=root the root CA; without linuxManagerPrivateKey while the root is offline -cn= an issuing CA; with linuxManagerCertificateRequest while it waits for the offline root +cn=root the root CA; its key with pki.root local, the Simple CA token with simple-ca +cn=upstream the Simple CA issuing CA that signs the issuing CAs, with simple-ca +cn= an issuing CA; with linuxManagerCertificateRequest while it waits for its certificate cn=-