Watch
0
0
Fork
You've already forked hyperhive
0

full-setup and the host swarmctl reach the controller as a pod, not through a host socket

This commit is contained in:
atlas 2026-11-26 09:22:29 +01:00 • committed by maia
commit ee6b5f69f6
12 changed files with 222 additions and 157 deletions

View file

@ -174,6 +174,9 @@ It prints a generated password once — record it. Keep both flags:
it. Without it you log in fine and are then refused. it. Without it you log in fine and are then refused.
- **`--email`** — the forge won't create an account without one. - **`--email`** — the forge won't create an account without one.
This step writes authelia's users file and calls no controller, so it needs nothing from the controller. The first verb that calls the controller is
`swarmctl forge make-admin` in step 3, after `swarmctl login`.
Fix either afterwards with `swarmctl user update mara --add-group admins Fix either afterwards with `swarmctl user update mara --add-group admins
--email …`. Details: [`2-handbook/swarm/sso.md`](../2-handbook/swarm/sso.md). --email …`. Details: [`2-handbook/swarm/sso.md`](../2-handbook/swarm/sso.md).
@ -186,7 +189,8 @@ needs a real DNS record. → [`2-handbook/swarm/ui.md`](../2-handbook/swarm/ui.m
Signing in to the forge once through SSO creates your forge account under the Signing in to the forge once through SSO creates your forge account under the
same username. Then, _on the swarm-controller's host_, log `swarmctl` in once. The host's same username. Then, _on the swarm-controller's host_, log `swarmctl` in once. The host's
`swarmctl` reaches the controller through the swarm's gateway as your own SSO account, so every `swarmctl` reaches the controller through the swarm's gateway as your own SSO account, so every
verb that calls the controller needs this login: verb that calls the controller (`forge make-admin`, `agent create`, `schedule`, the agent steps of
`setup status`) needs this login, and the controller has no socket on the host to use instead:
```bash ```bash
swarmctl login swarmctl login

View file

@ -66,7 +66,7 @@ swarm-level operator CLI
* `--users-file <PATH>` — Host-side path of authelia's users database — that is, the path inside the container, prefixed with the container's root. * `--users-file <PATH>` — Host-side path of authelia's users database — that is, the path inside the container, prefixed with the container's root.
This is the only user store: it's read before every change and written in place, and `swarm-authelia-bridge` writes the same file. This is the only user store: it's read before every change and written in place, and `swarm-authelia-bridge` writes the same file.
* `--swarm <URL>` — The swarm's domain, as `https://<domain>` or the bare domain. Given, the `agent`, `schedule` and `forge` verbs, and the agent checks and steps of `setup`, go through its gateway as the account `swarmctl login` logged in, instead of over the controller's socket. Falls back to `SWARMCTL_SWARM`; `login` then falls back to `SWARMCTL_LOGIN_DEFAULT_SWARM`. The swarm-controller nix module sets both to its host's own swarm, so there the verbs use the gateway and need `swarmctl login` once; an empty `SWARMCTL_SWARM` or `--swarm ""` puts them back on the controller's socket * `--swarm <URL>` — The swarm's domain, as `https://<domain>` or the bare domain. Given, the `agent`, `schedule` and `forge` verbs, and the agent checks and steps of `setup`, go through its gateway as the account `swarmctl login` logged in, instead of over the controller's socket. Falls back to `SWARMCTL_SWARM`; `login` then falls back to `SWARMCTL_LOGIN_DEFAULT_SWARM`. The swarm-controller nix module sets both to its host's own swarm, so there the verbs use the gateway and need `swarmctl login` once. With no swarm, they use the socket that `--controller-socket` or `SWARM_CONTROLLER_SOCKET` names; the module sets neither
* `--ca-file <PATH>` — A PEM CA certificate to trust beside the system roots, for a swarm whose gateway serves a certificate from the swarm's own CA. Falls back to `SWARMCTL_CA_FILE` * `--ca-file <PATH>` — A PEM CA certificate to trust beside the system roots, for a swarm whose gateway serves a certificate from the swarm's own CA. Falls back to `SWARMCTL_CA_FILE`
@ -123,7 +123,7 @@ No approval gate guards this: the caller is root on the controller's host, or lo
The agent writes it on its first start, and only when it has no `AGENTS.md` yet: re-creating an agent never replaces an existing file. The controller refuses a file over 64 KiB. The agent writes it on its first start, and only when it has no `AGENTS.md` yet: re-creating an agent never replaces an existing file. The controller refuses a file over 64 KiB.
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -145,7 +145,7 @@ Queues and returns, the same way `agent create` does — watch the swarm UI's jo
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -172,7 +172,7 @@ No approval gate guards this: the caller is root on the controller's host, or lo
* `--yes` — Confirm `destroyed`, which can't be undone * `--yes` — Confirm `destroyed`, which can't be undone
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -192,7 +192,7 @@ The swarm-level counterpart of `hivectl agent watch`, read from the swarm-contro
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -228,7 +228,7 @@ Show what the swarm sets for an agent, naming the fields it doesn't set, and the
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -252,7 +252,7 @@ Set fields for an agent. Only the flags given change; the others keep what's sto
* `--subagent-models <MODELS>` — The models it may start subagents on, comma-separated. Stored and shown; the agent doesn't apply it yet * `--subagent-models <MODELS>` — The models it may start subagents on, comma-separated. Stored and shown; the agent doesn't apply it yet
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -270,7 +270,7 @@ Clear every field for an agent, so it goes back to its own values
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -304,7 +304,7 @@ Show the permissions the swarm grants an agent, or that it sets none
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -327,7 +327,7 @@ Replace the permissions the swarm grants an agent; the internet flag stays unles
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -345,7 +345,7 @@ Clear the agent's permissions, so the default applies again
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -378,7 +378,7 @@ Print an agent's AGENTS.md on stdout, and its revision on stderr
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -400,7 +400,7 @@ The diff names `a/AGENTS.md` and `b/AGENTS.md`, as `diff -u a/AGENTS.md b/AGENTS
* `--base <REVISION>` — The revision you made the diff against, as `get` printed it. It's the git blob id of that text, so `git hash-object` of the unedited file prints it too * `--base <REVISION>` — The revision you made the diff against, as `get` printed it. It's the git blob id of that text, so `git hash-object` of the unedited file prints it too
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -441,7 +441,7 @@ Without `--every` it fires once. Without `--at` its first fire is now.
* `--paused` — Add it paused * `--paused` — Add it paused
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -456,7 +456,7 @@ List scheduled prompts, one row each, with their agents and next fire time
* `--agent <AGENT>` — Show only the prompts that fire in this agent * `--agent <AGENT>` — Show only the prompts that fire in this agent
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -483,7 +483,7 @@ Only the flags given change, and the id stays. `--at` and `--every` move the fir
* `--remove-agent <AGENT>` — Agent to stop firing it in. Repeatable. Fails if the agent isn't a target, or if no agent would remain * `--remove-agent <AGENT>` — Agent to stop firing it in. Repeatable. Fails if the agent isn't a target, or if no agent would remain
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -501,7 +501,7 @@ Stop a scheduled prompt firing. Times that pass while it's paused aren't fired w
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -519,7 +519,7 @@ Let a paused scheduled prompt fire again, from its next time on
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -537,7 +537,7 @@ Remove a scheduled prompt from every agent it names
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -647,7 +647,7 @@ The forge creates a human's account on their first SSO login, and this fails unt
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -670,7 +670,7 @@ For scripts, use `setup status` and the individual verbs.
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.
@ -688,7 +688,7 @@ Exits 0 when every step it can see has finished, and 1 otherwise, including when
* `--controller-socket <PATH>` — swarm-controller's unix socket. * `--controller-socket <PATH>` — swarm-controller's unix socket.
Supplied by the nix module that installs this binary, from the same `socketPath` option the daemon binds; falls back to `SWARM_CONTROLLER_SOCKET`. Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to `SWARM_CONTROLLER_SOCKET`. The controller runs as a pod and has no socket on the host, so name the swarm instead.

View file

@ -171,8 +171,8 @@ of more than one node needs one before the controller may run there.
and the script's tools. and the script's tools.
- **`swarmctl`.** The controller's socket lives inside the pod, so the host's - **`swarmctl`.** The controller's socket lives inside the pod, so the host's
`swarmctl` reaches the controller only through the gateway: run `swarmctl` reaches the controller only through the gateway: run
`swarmctl login` once, then use `--swarm <url>` or a wrapper that defaults `swarmctl login` once. The host's wrapper defaults `--swarm` to the host's own
to it. A socket path on the host serves nothing. swarm and sets no socket path, since a socket path on the host serves nothing.
- **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on - **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on
`/healthz` and readiness on `/readyz`. Readiness needs the queue connection `/healthz` and readiness on `/readyz`. Readiness needs the queue connection
and a fresh store login, so a store role that refuses the pod's token leaves and a fresh store login, so a store role that refuses the pod's token leaves

View file

@ -136,14 +136,6 @@ let
SWARM_CONTROLLER_AGENT_PKI_ROLE = deployCfg.bao.agentPkiRoleName; SWARM_CONTROLLER_AGENT_PKI_ROLE = deployCfg.bao.agentPkiRoleName;
}; };
# Where `swarmctl agent create` posts to. Unconditional: this binary is
# only installed where the daemon runs, so the socket is always the one
# right below it — and it is the same `socketPath` the daemon binds, read
# once rather than restated.
controllerSocketEnv = {
SWARM_CONTROLLER_SOCKET = deployCfg.swarm-controller.socketPath;
};
forgeCfg = config.services.hyperhive.swarm.forge; forgeCfg = config.services.hyperhive.swarm.forge;
swarmDomain = config.services.hyperhive.swarm.domain; swarmDomain = config.services.hyperhive.swarm.domain;
matrixCfg = config.services.hyperhive.swarm.matrix; matrixCfg = config.services.hyperhive.swarm.matrix;
@ -159,10 +151,8 @@ let
# The swarm the host's `swarmctl` talks to: this host's own, through the # The swarm the host's `swarmctl` talks to: this host's own, through the
# gateway, as the operator's own SSO account (`swarmctl login`). The # gateway, as the operator's own SSO account (`swarmctl login`). The
# controller socket then serves the gateway alone, which always sets # controller runs as a pod and has no socket on the host, so the gateway is
# `Remote-User`. Both are defaults, so an operator's own value wins: an # the only way in. Both are defaults, so an operator's own value wins.
# empty `SWARMCTL_SWARM` puts the socket verbs back on the socket for
# root.
swarmDefaultEnv = lib.optionalAttrs (swarmDomain != null) { swarmDefaultEnv = lib.optionalAttrs (swarmDomain != null) {
SWARMCTL_SWARM = "https://${swarmDomain}"; SWARMCTL_SWARM = "https://${swarmDomain}";
SWARMCTL_LOGIN_DEFAULT_SWARM = "https://${swarmDomain}"; SWARMCTL_LOGIN_DEFAULT_SWARM = "https://${swarmDomain}";
@ -341,7 +331,7 @@ let
wrapProgram $out/bin/swarmctl ${ wrapProgram $out/bin/swarmctl ${
lib.concatStringsSep " " ( lib.concatStringsSep " " (
lib.mapAttrsToList (name: value: "--set ${name} ${lib.escapeShellArg value}") ( lib.mapAttrsToList (name: value: "--set ${name} ${lib.escapeShellArg value}") (
controllerSocketEnv // swarmctlTrustEnv // deployCfg.swarm-controller.swarmctlEnvironment swarmctlTrustEnv // deployCfg.swarm-controller.swarmctlEnvironment
) )
++ lib.mapAttrsToList ( ++ lib.mapAttrsToList (
name: value: "--set-default ${name} ${lib.escapeShellArg value}" name: value: "--set-default ${name} ${lib.escapeShellArg value}"
@ -662,10 +652,8 @@ in
per-agent sockets, and the directory is `0750` owned by the per-agent sockets, and the directory is `0750` owned by the
`${clientsGroup}` group. Members of that group (the gateway's `${clientsGroup}` group. Members of that group (the gateway's
nginx, for `/api/` and `/webhook/forge/`) and root (which bypasses mode nginx, for `/api/` and `/webhook/forge/`) and root (which bypasses mode
bits) can reach the socket. The host's `swarmctl` goes through the bits) can reach the socket. The host's `swarmctl` does not open it: it
gateway by default, so only a root-run verb with an empty goes through the gateway, and sets no socket path. What keeps `0666` safe is that
`SWARMCTL_SWARM` opens it; every other local
user gets `EACCES` at the directory. What keeps `0666` safe is that
the directory holds exactly one socket. the directory holds exactly one socket.
Moving this path under a directory that carries anything else — Moving this path under a directory that carries anything else —
`/run/hyperhive`, which holds the host admin socket, above all — `/run/hyperhive`, which holds the host admin socket, above all —
@ -838,7 +826,7 @@ in
internal = true; internal = true;
description = '' description = ''
Variables the installed `swarmctl` wrapper sets, on top of the Variables the installed `swarmctl` wrapper sets, on top of the
controller's socket path. Empty unless another module on this host trust bundle. Empty unless another module on this host
supplies some: ./glue-controller-env.nix adds the configured authelia supplies some: ./glue-controller-env.nix adds the configured authelia
where authelia runs here. where authelia runs here.
''; '';

View file

@ -154,13 +154,14 @@ let
or null == "https://matrix.hive.t.local"; or null == "https://matrix.hive.t.local";
} }
{ {
# The host's swarmctl reaches the gateway by default and the socket only when # The host's swarmctl reaches the gateway by default and sets no controller socket: the
# the operator empties `SWARMCTL_SWARM`: `--set-default` lets that empty value # controller is a pod, so the host has none. `--set-default` lets an operator's own value
# through, `--set` would not. The socket variable is the control that the # through, `--set` would not. The trust variable is the control that the wrapper text was
# wrapper text was found at all. # found at all.
name = "the host's swarmctl defaults to its own swarm's gateway, and an operator's own value wins"; name = "the host's swarmctl defaults to its own swarm's gateway with no controller socket, and an operator's own value wins";
ok = ok =
lib.hasInfix "--set SWARM_CONTROLLER_SOCKET " swarmctlWrapperCmd lib.hasInfix "--set SSL_CERT_FILE " swarmctlWrapperCmd
&& !(lib.hasInfix "SWARM_CONTROLLER_SOCKET" swarmctlWrapperCmd)
&& lib.hasInfix "--set-default SWARMCTL_SWARM https://t.local" swarmctlWrapperCmd && lib.hasInfix "--set-default SWARMCTL_SWARM https://t.local" swarmctlWrapperCmd
&& lib.hasInfix "--set-default SWARMCTL_LOGIN_DEFAULT_SWARM https://t.local" swarmctlWrapperCmd && lib.hasInfix "--set-default SWARMCTL_LOGIN_DEFAULT_SWARM https://t.local" swarmctlWrapperCmd
&& !(lib.hasInfix "--set SWARMCTL_SWARM" swarmctlWrapperCmd); && !(lib.hasInfix "--set SWARMCTL_SWARM" swarmctlWrapperCmd);

View file

@ -9,16 +9,16 @@
# needs a TPM). A pkcs11 store unseals itself at init, so here # needs a TPM). A pkcs11 store unseals itself at init, so here
# the unseal comes right after init, before the granter. # the unseal comes right after init, before the granter.
# 2 SSO account `swarmctl user add mara --group admins`. # 2 SSO account `swarmctl user add mara --group admins`.
# 8 spawn `POST /api/agents` on the controller socket, as the swarm # 8 spawn `POST /api/agents` on the controller pod's listener, as the swarm
# UI's create form does, with the reviewer archetype's defaults. # UI's create form does, with the reviewer archetype's defaults.
# 9 first agent The same endpoint, for `iris`: `swarmctl agent create` has no # 9 first agent The same endpoint, for `iris`: `swarmctl agent create` has no
# archetype flag, and a custom agent's config repo would need # archetype flag, and a custom agent's config repo would need
# inputs the VM cannot resolve offline. # inputs the VM cannot resolve offline.
# `swarmctl setup status` is read before the agents deploy: steps 1-6 done; step 9 # The script reaches the controller pod's TLS listener as the gateway does (ClusterIP, services
# (the product's hard-coded `ruth`) stays undone, as no root agent exists here. Not # root, gateway client leaf). `swarmctl login` needs a browser, so the host's swarmctl stops at
# scripted yet: step 3, the first SSO login to the forge (an OIDC code flow against # "not logged in": `setup status` leaves steps 9 and 10 unknown, `schedule list` names the login.
# authelia), and `swarmctl forge make-admin`. # Not scripted yet: step 3, the first SSO login to the forge, and `swarmctl forge make-admin`.
# Green when `GET /api/agents/status` on the controller socket lists `iris` and # Green when `GET /api/agents/status` on the controller pod's listener lists `iris` and
# `spawn` with `freshness` fresh and `needs_login` true. # `spawn` with `freshness` fresh and `needs_login` true.
# #
# Offline: the test seeds the swarm's forge with `hyperhive/hyperhive` (one # Offline: the test seeds the swarm's forge with `hyperhive/hyperhive` (one
@ -140,7 +140,12 @@ in
# find their binaries on the node's PATH. # find their binaries on the node's PATH.
test.overrideTestDerivation (old: { test.overrideTestDerivation (old: {
env = (old.env or { }) // { env = (old.env or { }) // {
FULL_SETUP_SOCKET = deploy.swarm-controller.socketPath; FULL_SETUP_CONTROLLER_NAME = swarm.controller.tcp.domain;
FULL_SETUP_CONTROLLER_PORT = toString swarm.controller.tcp.port;
FULL_SETUP_CONTROLLER_SERVICE = deploy.swarm-controller.tcp.serviceHost;
FULL_SETUP_CONTROLLER_CERT = deploy.swarm-controller.tcp.gatewayClientCertFile;
FULL_SETUP_CONTROLLER_KEY = deploy.swarm-controller.tcp.gatewayClientKeyFile;
FULL_SETUP_SERVICES_ROOT = "${deploy.hive-controller.tls.stateDir}/swarm-services-root.pem";
FULL_SETUP_FORGE_DOMAIN = swarm.forge.domain; FULL_SETUP_FORGE_DOMAIN = swarm.forge.domain;
FULL_SETUP_SWARM_DOMAIN = swarm.domain; FULL_SETUP_SWARM_DOMAIN = swarm.domain;
FULL_SETUP_HIVE = hive; FULL_SETUP_HIVE = hive;

View file

@ -2,8 +2,6 @@ import json
import os import os
import shlex import shlex
API = "http://localhost"
SOCKET = os.environ["FULL_SETUP_SOCKET"]
FORGE = "https://" + os.environ["FULL_SETUP_FORGE_DOMAIN"] FORGE = "https://" + os.environ["FULL_SETUP_FORGE_DOMAIN"]
HIVE = os.environ["FULL_SETUP_HIVE"] HIVE = os.environ["FULL_SETUP_HIVE"]
TOPLEVELS = json.loads(os.environ["FULL_SETUP_TOPLEVELS"]) TOPLEVELS = json.loads(os.environ["FULL_SETUP_TOPLEVELS"])
@ -11,10 +9,19 @@ REPO = os.environ["FULL_SETUP_HYPERHIVE_REPO"]
CONTROL_NIX = os.environ["FULL_SETUP_CONTROL_NIX"] CONTROL_NIX = os.environ["FULL_SETUP_CONTROL_NIX"]
# Where `swarmctl bao init` saves what `bao operator init` printed, for root. # Where `swarmctl bao init` saves what `bao operator init` printed, for root.
INIT = "/root/.local/state/swarmctl/bao-init.json" INIT = "/root/.local/state/swarmctl/bao-init.json"
# The host's swarmctl defaults to the swarm's gateway, where each controller verb needs a # The controller is a pod, so the host reaches its TLS listener the way the gateway does: the
# `swarmctl login`, which a VM without a browser cannot do. An empty `SWARMCTL_SWARM` puts a # Service's ClusterIP, the swarm services root as trust, and the gateway's client leaf. The host's
# verb on the controller socket. # swarmctl goes through the gateway instead, where each controller verb needs a `swarmctl login`,
VIA_SOCKET = "SWARMCTL_SWARM=" # whose browser flow a VM cannot complete.
CONTROLLER_NAME = os.environ["FULL_SETUP_CONTROLLER_NAME"]
CONTROLLER_PORT = os.environ["FULL_SETUP_CONTROLLER_PORT"]
CONTROLLER_URL = f"https://{CONTROLLER_NAME}:{CONTROLLER_PORT}"
CONTROLLER_CURL = (
f"curl --silent --cacert {os.environ['FULL_SETUP_SERVICES_ROOT']} "
f"--cert {os.environ['FULL_SETUP_CONTROLLER_CERT']} --key {os.environ['FULL_SETUP_CONTROLLER_KEY']} "
f"--resolve {CONTROLLER_NAME}:{CONTROLLER_PORT}:"
f"$(getent ahostsv4 {os.environ['FULL_SETUP_CONTROLLER_SERVICE']} | awk 'NR==1 {{print $1}}')"
)
SWARM_URL = "https://" + os.environ["FULL_SETUP_SWARM_DOMAIN"] SWARM_URL = "https://" + os.environ["FULL_SETUP_SWARM_DOMAIN"]
FORGE_AUTH = "/root/forge-auth.header" FORGE_AUTH = "/root/forge-auth.header"
NIX = "nix --extra-experimental-features nix-command" NIX = "nix --extra-experimental-features nix-command"
@ -26,17 +33,6 @@ POLICY_UNITS_ACTIVE = (
) )
def controller(method, path, body=None, check="--fail-with-body"):
data = (
f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}"
if body
else ""
)
return machine.succeed(
f"curl {check} --silent --unix-socket {SOCKET} -X {method} {API}{path} {data}"
)
def forge(method, path, body=None): def forge(method, path, body=None):
data = ( data = (
f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}"
@ -84,8 +80,8 @@ def create_agent(body):
# archetype list comes from the builder's evaluation), so ask again. # archetype list comes from the builder's evaluation), so ask again.
for _ in range(60): for _ in range(60):
status, out = machine.execute( status, out = machine.execute(
f"curl --silent --unix-socket {SOCKET} -o /root/create.out -w '%{{http_code}}' " f"{CONTROLLER_CURL} -o /root/create.out -w '%{{http_code}}' "
f"-X POST {API}/api/agents -H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" f"-X POST {CONTROLLER_URL}/api/agents -H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}"
) )
if out.strip().startswith("2"): if out.strip().startswith("2"):
return return
@ -306,7 +302,7 @@ with subtest(
"step 8: spawn, a reviewer-archetype agent, through the endpoint the swarm UI calls" "step 8: spawn, a reviewer-archetype agent, through the endpoint the swarm UI calls"
): ):
machine.wait_until_succeeds( machine.wait_until_succeeds(
f"curl --fail --silent --unix-socket {SOCKET} {API}/api/permissions >/dev/null", f"{CONTROLLER_CURL} --fail {CONTROLLER_URL}/api/permissions >/dev/null",
timeout=900, timeout=900,
) )
# A custom root agent (ruth, as the UI creates her) is a follow-up, not covered yet. # A custom root agent (ruth, as the UI creates her) is a follow-up, not covered yet.
@ -343,8 +339,10 @@ with subtest("internal/meta holds the flake the toplevels were built from"):
) )
with subtest("swarmctl setup status reports the steps done so far"): with subtest("swarmctl setup status reports the steps done so far"):
# Step 9 names ruth, the root agent of the real setup; this test creates none, so the report # The host's swarmctl goes through the gateway and no login exists in the VM, so steps 1-6,
# ends on step 9 not done and the exit status is 1. # which read the host, are reported and the two that read the controller are unknown, with
# the login named as the reason. Step 9 names ruth, the root agent of the real setup, which
# this test does not create, so the exit status is 1 either way.
reported = [ reported = [
"✅ 1 secret store initialised", "✅ 1 secret store initialised",
"✅ 2 secret store unsealed", "✅ 2 secret store unsealed",
@ -352,12 +350,14 @@ with subtest("swarmctl setup status reports the steps done so far"):
"✅ 4 granting units active", "✅ 4 granting units active",
"✅ 5 store unsealed after the granting units", "✅ 5 store unsealed after the granting units",
"✅ 6 SSO account in the admins group", "✅ 6 SSO account in the admins group",
"👉 9 ruth created and up",
"✅ 10 another agent [optional]",
] ]
unreadable = ["❓ 9 ", "❓ 10 "]
for _ in range(60): for _ in range(60):
lines = machine.execute(f"{VIA_SOCKET} swarmctl setup status")[1].splitlines() lines = machine.execute("swarmctl setup status")[1].splitlines()
if all(any(line.startswith(prefix) for line in lines) for prefix in reported): if all(
any(line.startswith(prefix) for line in lines)
for prefix in reported + unreadable
):
break break
machine.sleep(10) machine.sleep(10)
else: else:
@ -365,23 +365,25 @@ with subtest("swarmctl setup status reports the steps done so far"):
"swarmctl setup status did not report the steps done so far:\n" "swarmctl setup status did not report the steps done so far:\n"
+ "\n".join(lines) + "\n".join(lines)
) )
assert machine.execute(f"{VIA_SOCKET} swarmctl setup status >/dev/null")[0] == 1 for prefix in unreadable:
line = next(line for line in lines if line.startswith(prefix))
assert f"not logged in to {SWARM_URL}" in line, line
assert machine.execute("swarmctl setup status >/dev/null")[0] == 1
with subtest( with subtest(
"the host's swarmctl reaches the controller through the gateway by default" "the host's swarmctl reaches the controller through the gateway, and stops at the login"
): ):
# No login exists in the VM, so a verb that names the controller stops at the login, and # No login exists in the VM, so a verb that names the controller says which swarm it went to
# says which swarm it went to. Over the socket the same verb needs none. # and that it is not logged in.
status, out = machine.execute("swarmctl schedule list 2>&1") status, out = machine.execute("swarmctl schedule list 2>&1")
assert status != 0 and f"not logged in to {SWARM_URL}" in out, (status, out) assert status != 0 and f"not logged in to {SWARM_URL}" in out, (status, out)
machine.succeed(f"{VIA_SOCKET} swarmctl schedule list")
with subtest("swarmctl login discovers the swarm's SSO provider from the gateway"): with subtest("swarmctl login discovers the swarm's SSO provider from the gateway"):
# The swarm's own CA signs the gateway's leaf. A VM has no browser, so the login runs to the # The swarm's own CA signs the gateway's leaf. A VM has no browser, so the login runs to the
# point where it prints the authorization URL and waits for the answer, which the timeout ends. # point where it prints the authorization URL and waits for the answer, which the timeout ends.
# Reaching that URL takes the gateway's 401 challenge, its published metadata, and authelia # Reaching that URL takes the gateway's 401 challenge, its published metadata, and authelia
# accepting the pushed authorization request. # accepting the pushed authorization request.
ca = "/var/lib/hive-tls/swarm-services-root.pem" ca = os.environ["FULL_SETUP_SERVICES_ROOT"]
auth = f"https://auth.{SWARM_URL.removeprefix('https://')}" auth = f"https://auth.{SWARM_URL.removeprefix('https://')}"
challenge = machine.succeed( challenge = machine.succeed(
f"curl --silent --cacert {ca} -D - -o /dev/null {SWARM_URL}/api/" f"curl --silent --cacert {ca} -D - -o /dev/null {SWARM_URL}/api/"
@ -408,7 +410,7 @@ with subtest("swarmctl login discovers the swarm's SSO provider from the gateway
with subtest("the agents are deployed and need a login"): with subtest("the agents are deployed and need a login"):
settle( settle(
f"curl --fail --silent --unix-socket {SOCKET} {API}/api/agents/status " f"{CONTROLLER_CURL} --fail {CONTROLLER_URL}/api/agents/status "
"| jq -e '[.[] | select(.hive == \"" "| jq -e '[.[] | select(.hive == \""
+ HIVE + HIVE
+ '" and .freshness == "fresh" and .needs_login == true)' + '" and .freshness == "fresh" and .needs_login == true)'

View file

@ -136,7 +136,7 @@ let
# evaluate no node. # evaluate no node.
scriptWith = scriptWith =
{ {
controllerSocket, controller,
publicNames, publicNames,
swarm, swarm,
nameOf, nameOf,
@ -149,8 +149,14 @@ let
import shlex import shlex
import time import time
API = "http://localhost" # The controller is a pod: the swarm machine reaches its TLS listener the way the gateway
SOCKET = "${controllerSocket}" # does, by the Service's ClusterIP with the services root as trust and the gateway's client leaf.
CONTROLLER_URL = "https://${controller.name}:${toString controller.port}"
CONTROLLER_CURL = (
"curl --silent --cacert ${controller.root} --cert ${controller.cert} --key ${controller.key} "
"--resolve ${controller.name}:${toString controller.port}:"
"$(getent ahostsv4 ${controller.service} | awk 'NR==1 {print $1}')"
)
FORGE = "https://${publicNames.forge}" FORGE = "https://${publicNames.forge}"
HIVE = "${hiveName}" HIVE = "${hiveName}"
TOPLEVELS = ${builtins.toJSON toplevelPaths} TOPLEVELS = ${builtins.toJSON toplevelPaths}
@ -297,12 +303,6 @@ let
diagnose(swarm, "openbao", "${swarm.bao.machine}") diagnose(swarm, "openbao", "${swarm.bao.machine}")
raise raise
def controller(method, path, body=None, check="--fail-with-body"):
data = f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" if body else ""
return swarm.succeed(
f"curl {check} --silent --unix-socket {SOCKET} -X {method} {API}{path} {data}"
)
def forge(method, path, body=None): def forge(method, path, body=None):
data = f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" if body else "" data = f"-H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" if body else ""
return swarm.succeed( return swarm.succeed(
@ -315,8 +315,8 @@ let
# archetype list comes from the builder's evaluation), so ask again. # archetype list comes from the builder's evaluation), so ask again.
for _ in range(60): for _ in range(60):
status, out = swarm.execute( status, out = swarm.execute(
f"curl --silent --unix-socket {SOCKET} -o /root/create.out -w '%{{http_code}}' " f"{CONTROLLER_CURL} -o /root/create.out -w '%{{http_code}}' "
f"-X POST {API}/api/agents -H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}" f"-X POST {CONTROLLER_URL}/api/agents -H 'Content-Type: application/json' -d {shlex.quote(json.dumps(body))}"
) )
if out.strip().startswith("2"): if out.strip().startswith("2"):
return return
@ -563,7 +563,7 @@ let
with subtest("setup.md steps 8 and 9: two agents, through the endpoint the swarm UI calls"): with subtest("setup.md steps 8 and 9: two agents, through the endpoint the swarm UI calls"):
swarm.wait_until_succeeds( swarm.wait_until_succeeds(
f"curl --fail --silent --unix-socket {SOCKET} {API}/api/permissions >/dev/null", timeout=1800 f"{CONTROLLER_CURL} --fail {CONTROLLER_URL}/api/permissions >/dev/null", timeout=1800
) )
created = int(swarm.succeed("date +%s")) created = int(swarm.succeed("date +%s"))
create_agent({"name": "spawn", "hive": HIVE, "archetype": ARCHETYPE}) create_agent({"name": "spawn", "hive": HIVE, "archetype": ARCHETYPE})
@ -571,7 +571,7 @@ let
with subtest("assert 4: the agents are deployed on the hive, from the cache on heavyduty, and need a login"): with subtest("assert 4: the agents are deployed on the hive, from the cache on heavyduty, and need a login"):
settle_hive_agents( settle_hive_agents(
f"curl --fail --silent --unix-socket {SOCKET} {API}/api/agents/status " f"{CONTROLLER_CURL} --fail {CONTROLLER_URL}/api/agents/status "
"| jq -e '[.[] | select(.hive == \"" + HIVE + "\" and .freshness == \"fresh\" and .needs_login == true)" "| jq -e '[.[] | select(.hive == \"" + HIVE + "\" and .freshness == \"fresh\" and .needs_login == true)"
" | .name] | map(select(. == \"iris\" or . == \"spawn\")) | unique | length == 2'", " | .name] | map(select(. == \"iris\" or . == \"spawn\")) | unique | length == 2'",
1200, 1200,
@ -592,7 +592,14 @@ pkgs.testers.runNixOSTest (
let let
swarmCfg = config.nodes.swarm.services.hyperhive; swarmCfg = config.nodes.swarm.services.hyperhive;
inherit (swarmCfg) swarm; inherit (swarmCfg) swarm;
controllerSocket = swarmCfg.deploy.swarm-controller.socketPath; controller = {
name = swarm.controller.tcp.domain;
inherit (swarm.controller.tcp) port;
service = swarmCfg.deploy.swarm-controller.tcp.serviceHost;
cert = swarmCfg.deploy.swarm-controller.tcp.gatewayClientCertFile;
key = swarmCfg.deploy.swarm-controller.tcp.gatewayClientKeyFile;
root = "${swarmCfg.deploy.hive-controller.tls.stateDir}/swarm-services-root.pem";
};
settingsJson = settingsJson =
config.nodes.swarm.systemd.services.swarm-controller.environment.SWARM_CONTROLLER_META_FLAKE; config.nodes.swarm.systemd.services.swarm-controller.environment.SWARM_CONTROLLER_META_FLAKE;
@ -761,7 +768,7 @@ pkgs.testers.runNixOSTest (
testScript = scriptWith { testScript = scriptWith {
inherit inherit
controllerSocket controller
publicNames publicNames
swarm swarm
nameOf nameOf
@ -773,7 +780,14 @@ pkgs.testers.runNixOSTest (
# What `nix/vm-test-typecheck.nix` checks: the same text with stand-in values. # What `nix/vm-test-typecheck.nix` checks: the same text with stand-in values.
passthru.typecheckScript = scriptWith { passthru.typecheckScript = scriptWith {
controllerSocket = "/stub/socket"; controller = {
name = "controller.stub";
port = 9443;
service = "controller.stub.svc";
cert = "/stub/cert.pem";
key = "/stub/key.pem";
root = "/stub/root.pem";
};
publicNames.forge = "forge.stub"; publicNames.forge = "forge.stub";
swarm = { swarm = {
bao.machine = "stub"; bao.machine = "stub";

View file

@ -133,25 +133,25 @@ it can rebuild.
The job graph lives in memory; hive status and wanted state live in the swarm The job graph lives in memory; hive status and wanted state live in the swarm
queue, so both survive a restart. queue, so both survive a restart.
## Why a unix socket, not a port ## The unix socket and the TCP listener
The hive-gateway's nginx is the only intended client (`swarmctl` runs as root). The daemon binds a unix socket inside its pod, which nothing on the host can reach.
A listener that is never bound to an address cannot be The gateway's nginx reaches the controller through the TCP listener below, and the host's
reached from off-host by mistake. `swarmctl` goes through the gateway as the operator's own SSO account.
The socket path is `services.hyperhive.deploy.swarm-controller.socketPath`, default The socket path is `services.hyperhive.deploy.swarm-controller.socketPath`, default
`/run/swarm-controller/controller.sock`, exported to the process as `/run/swarm-controller/controller.sock`, exported to the process as
`SWARM_CONTROLLER_SOCKET`. `SWARM_CONTROLLER_SOCKET`.
## The optional TCP listener ## The TCP listener
`services.hyperhive.swarm.controller.tcp.enable` (default off) adds a TLS listener beside the `services.hyperhive.swarm.controller.tcp.enable` (default on wherever the swarm has a domain)
socket, for a gateway that reaches the controller over the network. The routes trust their adds a TLS listener beside the socket, and it is the only way the gateway reaches the pod. The routes trust their
transport and check no caller, so the listener finishes a handshake for one client only transport and check no caller, so the listener finishes a handshake for one client only
(`src/tcp_tls.rs`): a certificate that chains to the swarm services root, carries `clientAuth`, (`src/tcp_tls.rs`): a certificate that chains to the swarm services root, carries `clientAuth`,
and names `gateway-client.<swarm.domain>` in a subject alternative name. No certificate, another and names `gateway-client.<swarm.domain>` in a subject alternative name. No certificate, another
name, or the `serverAuth`-only swarm-services leaf is refused during the handshake, before any name, or the `serverAuth`-only swarm-services leaf is refused during the handshake, before any
HTTP. The socket stays and answers exactly as before. HTTP. The socket answers the same routes inside the pod, and checks no caller either.
The daemon takes five variables, all or none (`SWARM_CONTROLLER_TCP_LISTEN`, `_CERT`, `_KEY`, The daemon takes five variables, all or none (`SWARM_CONTROLLER_TCP_LISTEN`, `_CERT`, `_KEY`,
`_CLIENT_CA`, `_CLIENT_NAME`), which the nix module sets from the options. It re-reads the server `_CLIENT_CA`, `_CLIENT_NAME`), which the nix module sets from the options. It re-reads the server
@ -168,9 +168,8 @@ host so blast radius is unchanged."_
What keeps that safe is that the directory is `0750`, owned by the What keeps that safe is that the directory is `0750`, owned by the
`swarm-controller-clients` group, and holds **one** socket. nginx is in that `swarm-controller-clients` group, and holds **one** socket. nginx is in that
group through its unit's `SupplementaryGroups`; root bypasses mode bits. The host's `swarmctl` reaches the controller group through its unit's `SupplementaryGroups`; root bypasses mode bits. The host's `swarmctl` reaches the controller
through the gateway by default (`SWARMCTL_SWARM`), so nginx is the only routine client; through the gateway (`SWARMCTL_SWARM`) and sets no socket, so nginx is the only client
root opens the socket only for a verb run with `SWARMCTL_SWARM` empty. Every other local the module expects. Every other local user gets `EACCES` at the directory. The group is not `swarm-controller`'s own, which also owns the
user gets `EACCES` at the directory. The group is not `swarm-controller`'s own, which also owns the
state directory. So: state directory. So:
> **Never point `socketPath` at a directory that carries anything else.** > **Never point `socketPath` at a directory that carries anything else.**

View file

@ -44,7 +44,7 @@ See `swarm-authelia-bridge/README.md` for what both writers must uphold.
## Configuration ## Configuration
The nix deployment sets every path, each derived from an option it already The nix deployment sets every path, each derived from an option it already
has: `swarm-controller.nix` sets the socket, and `glue-controller-env.nix` sets has: `swarm-controller.nix` sets the swarm and the trust bundle, and `glue-controller-env.nix` sets
`SWARMCTL_AUTHELIA_BIN` and `SWARMCTL_AUTHELIA_USERS_FILE`, only where `SWARMCTL_AUTHELIA_BIN` and `SWARMCTL_AUTHELIA_USERS_FILE`, only where
authelia runs on the same host. It also sets authelia runs on the same host. It also sets
`SWARMCTL_BAO_BOOTSTRAP_TOKEN_FILE` and `SWARMCTL_BAO_BOOTSTRAP_POLICY`, only `SWARMCTL_BAO_BOOTSTRAP_TOKEN_FILE` and `SWARMCTL_BAO_BOOTSTRAP_POLICY`, only
@ -61,7 +61,7 @@ an error.
| `SWARMCTL_AUTHELIA_UNIT` | authelia's unit inside that container | | `SWARMCTL_AUTHELIA_UNIT` | authelia's unit inside that container |
| `SWARMCTL_BAO_BOOTSTRAP_TOKEN_FILE` | where `bao grant-bootstrap` places the 24h grant token | | `SWARMCTL_BAO_BOOTSTRAP_TOKEN_FILE` | where `bao grant-bootstrap` places the 24h grant token |
| `SWARMCTL_BAO_BOOTSTRAP_POLICY` | the `bao-bootstrap` policy file `bao grant-bootstrap` writes | | `SWARMCTL_BAO_BOOTSTRAP_POLICY` | the `bao-bootstrap` policy file `bao grant-bootstrap` writes |
| `SWARM_CONTROLLER_SOCKET` | the controller's unix socket, used when no swarm is named | | `SWARM_CONTROLLER_SOCKET` | a controller socket to use when no swarm is named; the module sets none, as the controller is a pod |
| `SWARMCTL_LOGIN_DEFAULT_SWARM` | `https://<swarm domain>` of this host's swarm, for `login` | | `SWARMCTL_LOGIN_DEFAULT_SWARM` | `https://<swarm domain>` of this host's swarm, for `login` |
| `SWARMCTL_SWARM` | the swarm's domain, bare or `https://`: reach the controller there; the module defaults it to this host's swarm | | `SWARMCTL_SWARM` | the swarm's domain, bare or `https://`: reach the controller there; the module defaults it to this host's swarm |
| `SWARMCTL_CA_FILE` | a PEM CA to trust beside the system roots, for `SWARMCTL_SWARM` | | `SWARMCTL_CA_FILE` | a PEM CA to trust beside the system roots, for `SWARMCTL_SWARM` |
@ -112,9 +112,9 @@ queued: job node 42
agent "agent2" will be deployed to hive "alpha" once the job graph runs; `swarmctl` does not wait for it agent "agent2" will be deployed to hive "alpha" once the job graph runs; `swarmctl` does not wait for it
``` ```
`POST /api/agents` on the swarm-controller, over its unix socket `POST /api/agents` on the swarm-controller, through the swarm's gateway
(`--controller-socket`, else `SWARM_CONTROLLER_SOCKET`, which the nix (`--swarm`, else `SWARMCTL_SWARM`, which the nix module sets to the host's own swarm;
module sets from the daemon's own `socketPath`). It prints the queued see "Reaching the controller" below). It prints the queued
job's node id **and stops there**. job's node id **and stops there**.
It deliberately does not wait. The endpoint queues a DAG — SSO identity, It deliberately does not wait. The endpoint queues a DAG — SSO identity,
@ -187,8 +187,8 @@ as it arrives, with no total-request timeout. The header-state stream
forge: "mara" is now a site admin forge: "mara" is now a site admin
``` ```
`POST /api/forge/users/{name}/admin` on the swarm-controller, over the same `POST /api/forge/users/{name}/admin` on the swarm-controller, through the same
socket as `agent create`. It never creates an account: the forge makes a gateway as `agent create`. It never creates an account: the forge makes a
person's on their first login through authelia, and until then this fails person's on their first login through authelia, and until then this fails
saying so. Running it on a site admin changes nothing, and an agent's name is saying so. Running it on a site admin changes nothing, and an agent's name is
refused. The response body comes from `swarm-controller-api`, imported in refused. The response body comes from `swarm-controller-api`, imported in
@ -204,8 +204,8 @@ refused. The response body comes from `swarm-controller-api`, imported in
# swarmctl schedule rm kqzpmwab # swarmctl schedule rm kqzpmwab
``` ```
The `/api/schedules` routes on the swarm-controller, over the The `/api/schedules` routes on the swarm-controller, through the
same socket as `agent create`; each verb waits for the stored result. What a same gateway as `agent create`; each verb waits for the stored result. What a
schedule does once stored is in schedule does once stored is in
[`docs/2-handbook/swarm/schedules.md`](../docs/2-handbook/swarm/schedules.md). The bodies come [`docs/2-handbook/swarm/schedules.md`](../docs/2-handbook/swarm/schedules.md). The bodies come
from `swarm-controller-api`, imported in `src/schedule.rs`. from `swarm-controller-api`, imported in `src/schedule.rs`.
@ -273,8 +273,8 @@ Read-only, and it needs no token. Where each step is read from:
A check that cannot run gives `unknown` with the reason and the rest still A check that cannot run gives `unknown` with the reason and the rest still
print: `bao` is only on `PATH` on the host running swarm-bao, the users file is print: `bao` is only on `PATH` on the host running swarm-bao, the users file is
only on the authelia host, and the controller socket only on its host (or `--swarm`; on a controller host the only on the authelia host, and the controller only through the gateway, which needs
default swarm needs `swarmctl login` first). The exit code is 0 when every step it can see has finished and 1 `swarmctl login` first (the host's own swarm is the default, so a host that has not logged in reports `unknown (not logged in…)`). The exit code is 0 when every step it can see has finished and 1
otherwise, counting an `unknown` from a failed check; step 10, another agent, otherwise, counting an `unknown` from a failed check; step 10, another agent,
is optional and does not count. is optional and does not count.
@ -295,11 +295,12 @@ $ swarmctl schedule list
`--swarm` (before or after the verb) names the swarm, else `SWARMCTL_SWARM`; either takes the `--swarm` (before or after the verb) names the swarm, else `SWARMCTL_SWARM`; either takes the
bare domain too. On a swarm-controller host the module's wrapper sets `SWARMCTL_SWARM` and bare domain too. On a swarm-controller host the module's wrapper sets `SWARMCTL_SWARM` and
`SWARMCTL_LOGIN_DEFAULT_SWARM` to the host's own swarm, so the host's `swarmctl` uses the gateway `SWARMCTL_LOGIN_DEFAULT_SWARM` to the host's own swarm, so the host's `swarmctl` uses the gateway
too and needs one `swarmctl login`. The gateway names the sender from the SSO session, and the too and needs one `swarmctl login`. The gateway names the sender from the SSO session. Both are defaults, so a value you set wins.
controller's socket serves nginx alone. Both are defaults, so a value you set wins. An empty The controller runs as a pod and has no socket on the host, so the gateway is the only way in. `swarmctl user add`
`SWARMCTL_SWARM` (or `--swarm ""`) puts the verbs back on `SWARM_CONTROLLER_SOCKET` as root. That writes authelia's users file and needs no controller, so `swarmctl login` needs only authelia and your SSO account, both there by step 2.
route sends no `Remote-User`, so the routes that name the sender answer 401. Nothing in setup needs it:
`swarmctl login` needs only authelia and your SSO account, both there by step 2. `--controller-socket` and `SWARM_CONTROLLER_SOCKET` still name a unix socket for a controller reached that way
(none the module sets); with neither a swarm nor a socket the verb stops and says to name the swarm.
`login` finds the swarm's SSO provider itself: the gateway's 401 at `/api/` `login` finds the swarm's SSO provider itself: the gateway's 401 at `/api/`
names a public metadata document (RFC 9728) that names authelia, so `--swarm` names a public metadata document (RFC 9728) that names authelia, so `--swarm`

View file

@ -337,26 +337,40 @@ pub(crate) fn describe_error(status: hyper::StatusCode, body: &[u8]) -> String {
/// Message for a socket that could not be dialled. /// Message for a socket that could not be dialled.
/// ///
/// Worth spelling out because the three ways this fails need three /// The controller runs as a pod, so the host has no socket to dial: the way in
/// different fixes and `No such file or directory (os error 2)` names /// is the swarm's gateway.
/// none of them: the daemon is off, it binds elsewhere, or this host is
/// not the one running it at all. No group-membership case to mention
/// here — `swarmctl` already runs as root.
pub(crate) fn connect_hint(socket: &Path) -> String { pub(crate) fn connect_hint(socket: &Path) -> String {
format!( format!(
"could not connect to swarm-controller at {} — is it running on this host? \ "could not connect to a swarm-controller socket at {} — the controller runs as a pod \
(`systemctl status swarm-controller`). The path comes from \ and has no socket on this host; reach it through the swarm's gateway with \
`--controller-socket` or `SWARM_CONTROLLER_SOCKET`, which the \ `--swarm <domain>` (or `SWARMCTL_SWARM`) after `swarmctl login`",
swarm-controller nix module sets from `socketPath`",
socket.display() socket.display()
) )
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{check_confirmed, describe_error, parse_ident, parse_state}; use super::{check_confirmed, connect_hint, describe_error, parse_ident, parse_state};
use swarm_wire::wanted::AgentState; use swarm_wire::wanted::AgentState;
/// The controller has no socket on the host, so the hint sends the operator to the
/// gateway and the login, not to a unit that is not there.
#[test]
fn the_connect_hint_names_the_gateway_and_the_login() {
let hint = connect_hint(std::path::Path::new(
"/run/swarm-controller/controller.sock",
));
assert!(
hint.contains("/run/swarm-controller/controller.sock"),
"{hint}"
);
assert!(
hint.contains("--swarm <domain>") && hint.contains("swarmctl login"),
"{hint}"
);
assert!(!hint.contains("systemctl"), "{hint}");
}
/// The accepted values are the wire enum's: each spelling it writes /// The accepted values are the wire enum's: each spelling it writes
/// parses back, and an unknown one names the valid ones. /// parses back, and an unknown one names the valid ones.
#[test] #[test]

View file

@ -92,8 +92,9 @@ struct RemoteArgs {
/// socket. Falls back to `SWARMCTL_SWARM`; `login` then falls back to /// socket. Falls back to `SWARMCTL_SWARM`; `login` then falls back to
/// `SWARMCTL_LOGIN_DEFAULT_SWARM`. The swarm-controller nix module sets both /// `SWARMCTL_LOGIN_DEFAULT_SWARM`. The swarm-controller nix module sets both
/// to its host's own swarm, so there the verbs use the gateway and need /// to its host's own swarm, so there the verbs use the gateway and need
/// `swarmctl login` once; an empty `SWARMCTL_SWARM` or `--swarm ""` puts /// `swarmctl login` once. With no swarm, they use the socket that
/// them back on the controller's socket. /// `--controller-socket` or `SWARM_CONTROLLER_SOCKET` names; the module sets
/// neither.
#[arg(long, value_name = "URL", global = true)] #[arg(long, value_name = "URL", global = true)]
swarm: Option<String>, swarm: Option<String>,
/// A PEM CA certificate to trust beside the system roots, for a swarm /// A PEM CA certificate to trust beside the system roots, for a swarm
@ -134,12 +135,19 @@ impl RemoteArgs {
.transpose() .transpose()
} }
/// The swarm when one is named, the controller's socket otherwise. /// The swarm when one is named, else the controller socket the flag or
/// `SWARM_CONTROLLER_SOCKET` names. The controller runs as a pod and has no
/// socket on the host, so a host with neither is told to name the swarm.
fn target(&self, socket: Option<PathBuf>) -> Result<Target> { fn target(&self, socket: Option<PathBuf>) -> Result<Target> {
Ok(match self.swarm()? { if let Some(swarm) = self.swarm()? {
Some(swarm) => Target::Swarm(swarm), return Ok(Target::Swarm(swarm));
None => Target::Socket(path_from(socket, "SWARM_CONTROLLER_SOCKET")?), }
}) let socket =
socket.or_else(|| std::env::var_os("SWARM_CONTROLLER_SOCKET").map(PathBuf::from));
socket.map(Target::Socket).context(
"no swarm is named and no controller socket is given — name the swarm with \
`--swarm <domain>` or `SWARMCTL_SWARM` and run `swarmctl login`",
)
} }
} }
@ -615,9 +623,10 @@ struct AgentCreateArgs {
agents_md: Option<PathBuf>, agents_md: Option<PathBuf>,
/// swarm-controller's unix socket. /// swarm-controller's unix socket.
/// ///
/// Supplied by the nix module that installs this binary, from the same /// Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to
/// `socketPath` option the daemon binds; falls back to
/// `SWARM_CONTROLLER_SOCKET`. /// `SWARM_CONTROLLER_SOCKET`.
/// The controller runs as a pod and has no socket on the host, so name
/// the swarm instead.
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
controller_socket: Option<PathBuf>, controller_socket: Option<PathBuf>,
} }
@ -635,9 +644,10 @@ struct AgentMintForgeTokenArgs {
name: String, name: String,
/// swarm-controller's unix socket. /// swarm-controller's unix socket.
/// ///
/// Supplied by the nix module that installs this binary, from the same /// Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to
/// `socketPath` option the daemon binds; falls back to
/// `SWARM_CONTROLLER_SOCKET`. /// `SWARM_CONTROLLER_SOCKET`.
/// The controller runs as a pod and has no socket on the host, so name
/// the swarm instead.
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
controller_socket: Option<PathBuf>, controller_socket: Option<PathBuf>,
} }
@ -658,9 +668,10 @@ struct ForgeMakeAdminArgs {
name: String, name: String,
/// swarm-controller's unix socket. /// swarm-controller's unix socket.
/// ///
/// Supplied by the nix module that installs this binary, from the same /// Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to
/// `socketPath` option the daemon binds; falls back to
/// `SWARM_CONTROLLER_SOCKET`. /// `SWARM_CONTROLLER_SOCKET`.
/// The controller runs as a pod and has no socket on the host, so name
/// the swarm instead.
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
controller_socket: Option<PathBuf>, controller_socket: Option<PathBuf>,
} }
@ -765,9 +776,10 @@ struct ScheduleIdArgs {
struct ControllerSocketArg { struct ControllerSocketArg {
/// swarm-controller's unix socket. /// swarm-controller's unix socket.
/// ///
/// Supplied by the nix module that installs this binary, from the same /// Used when `--swarm` and `SWARMCTL_SWARM` give no swarm; falls back to
/// `socketPath` option the daemon binds; falls back to
/// `SWARM_CONTROLLER_SOCKET`. /// `SWARM_CONTROLLER_SOCKET`.
/// The controller runs as a pod and has no socket on the host, so name
/// the swarm instead.
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
controller_socket: Option<PathBuf>, controller_socket: Option<PathBuf>,
} }
@ -1553,6 +1565,31 @@ mod tests {
); );
} }
/// A host that names no swarm and gives no socket (the host of a pod-only
/// controller) is told to name the swarm, not to look for a unit.
#[test]
fn with_no_swarm_and_no_socket_the_error_names_the_swarm() {
assert!(
std::env::var_os("SWARMCTL_SWARM").is_none()
&& std::env::var_os("SWARM_CONTROLLER_SOCKET").is_none(),
"this test needs both variables unset"
);
let cli = Cli::try_parse_from(["swarmctl", "schedule", "list"]).expect("parses");
let Verb::Schedule {
command: ScheduleVerb::List(args),
} = cli.command
else {
panic!("expected `schedule list`");
};
let err = args.socket.resolve(&cli.remote).err().expect("no target");
let text = format!("{err:#}");
assert!(
text.contains("--swarm <domain>") && text.contains("swarmctl login"),
"{text}"
);
assert!(!text.contains("systemctl"), "{text}");
}
/// Root on the controller host, with no `--swarm` and no login: the verbs /// Root on the controller host, with no `--swarm` and no login: the verbs
/// still go over the unix socket, unchanged by the remote path. /// still go over the unix socket, unchanged by the remote path.
#[test] #[test]