full-setup and the host swarmctl reach the controller as a pod, not through a host socket
This commit is contained in:
parent
df4058d2f7
commit
ee6b5f69f6
3 changed files with 222 additions and 157 deletions
|
|
@ -44,7 +44,7 @@ See `swarm-authelia-bridge/README.md` for what both writers must uphold.
|
|||
## Configuration
|
||||
|
||||
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
|
||||
authelia runs on the same host. It also sets
|
||||
`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_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 |
|
||||
| `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_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` |
|
||||
|
|
@ -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
|
||||
```
|
||||
|
||||
`POST /api/agents` on the swarm-controller, over its unix socket
|
||||
(`--controller-socket`, else `SWARM_CONTROLLER_SOCKET`, which the nix
|
||||
module sets from the daemon's own `socketPath`). It prints the queued
|
||||
`POST /api/agents` on the swarm-controller, through the swarm's gateway
|
||||
(`--swarm`, else `SWARMCTL_SWARM`, which the nix module sets to the host's own swarm;
|
||||
see "Reaching the controller" below). It prints the queued
|
||||
job's node id **and stops there**.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
`POST /api/forge/users/{name}/admin` on the swarm-controller, over the same
|
||||
socket as `agent create`. It never creates an account: the forge makes a
|
||||
`POST /api/forge/users/{name}/admin` on the swarm-controller, through the same
|
||||
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
|
||||
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
|
||||
|
|
@ -204,8 +204,8 @@ refused. The response body comes from `swarm-controller-api`, imported in
|
|||
# swarmctl schedule rm kqzpmwab
|
||||
```
|
||||
|
||||
The `/api/schedules` routes on the swarm-controller, over the
|
||||
same socket as `agent create`; each verb waits for the stored result. What a
|
||||
The `/api/schedules` routes on the swarm-controller, through the
|
||||
same gateway as `agent create`; each verb waits for the stored result. What a
|
||||
schedule does once stored is in
|
||||
[`docs/2-handbook/swarm/schedules.md`](../docs/2-handbook/swarm/schedules.md). The bodies come
|
||||
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
|
||||
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
|
||||
default swarm needs `swarmctl login` first). The exit code is 0 when every step it can see has finished and 1
|
||||
only on the authelia host, and the controller only through the gateway, which needs
|
||||
`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,
|
||||
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
|
||||
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
|
||||
too and needs one `swarmctl login`. The gateway names the sender from the SSO session, and the
|
||||
controller's socket serves nginx alone. Both are defaults, so a value you set wins. An empty
|
||||
`SWARMCTL_SWARM` (or `--swarm ""`) puts the verbs back on `SWARM_CONTROLLER_SOCKET` as root. That
|
||||
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.
|
||||
too and needs one `swarmctl login`. The gateway names the sender from the SSO session. Both are defaults, so a value you set wins.
|
||||
The controller runs as a pod and has no socket on the host, so the gateway is the only way in. `swarmctl user add`
|
||||
writes authelia's users file and needs no controller, so `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/`
|
||||
names a public metadata document (RFC 9728) that names authelia, so `--swarm`
|
||||
|
|
|
|||
|
|
@ -337,26 +337,40 @@ pub(crate) fn describe_error(status: hyper::StatusCode, body: &[u8]) -> String {
|
|||
|
||||
/// Message for a socket that could not be dialled.
|
||||
///
|
||||
/// Worth spelling out because the three ways this fails need three
|
||||
/// different fixes and `No such file or directory (os error 2)` names
|
||||
/// 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.
|
||||
/// The controller runs as a pod, so the host has no socket to dial: the way in
|
||||
/// is the swarm's gateway.
|
||||
pub(crate) fn connect_hint(socket: &Path) -> String {
|
||||
format!(
|
||||
"could not connect to swarm-controller at {} — is it running on this host? \
|
||||
(`systemctl status swarm-controller`). The path comes from \
|
||||
`--controller-socket` or `SWARM_CONTROLLER_SOCKET`, which the \
|
||||
swarm-controller nix module sets from `socketPath`",
|
||||
"could not connect to a swarm-controller socket at {} — the controller runs as a pod \
|
||||
and has no socket on this host; reach it through the swarm's gateway with \
|
||||
`--swarm <domain>` (or `SWARMCTL_SWARM`) after `swarmctl login`",
|
||||
socket.display()
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
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;
|
||||
|
||||
/// 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
|
||||
/// parses back, and an unknown one names the valid ones.
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -92,8 +92,9 @@ struct RemoteArgs {
|
|||
/// 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.
|
||||
/// `swarmctl login` once. With no swarm, they use the socket that
|
||||
/// `--controller-socket` or `SWARM_CONTROLLER_SOCKET` names; the module sets
|
||||
/// neither.
|
||||
#[arg(long, value_name = "URL", global = true)]
|
||||
swarm: Option<String>,
|
||||
/// A PEM CA certificate to trust beside the system roots, for a swarm
|
||||
|
|
@ -134,12 +135,19 @@ impl RemoteArgs {
|
|||
.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> {
|
||||
Ok(match self.swarm()? {
|
||||
Some(swarm) => Target::Swarm(swarm),
|
||||
None => Target::Socket(path_from(socket, "SWARM_CONTROLLER_SOCKET")?),
|
||||
})
|
||||
if let Some(swarm) = self.swarm()? {
|
||||
return Ok(Target::Swarm(swarm));
|
||||
}
|
||||
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>,
|
||||
/// 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
|
||||
/// 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.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
controller_socket: Option<PathBuf>,
|
||||
}
|
||||
|
|
@ -635,9 +644,10 @@ struct AgentMintForgeTokenArgs {
|
|||
name: String,
|
||||
/// 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
|
||||
/// 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.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
controller_socket: Option<PathBuf>,
|
||||
}
|
||||
|
|
@ -658,9 +668,10 @@ struct ForgeMakeAdminArgs {
|
|||
name: String,
|
||||
/// 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
|
||||
/// 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.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
controller_socket: Option<PathBuf>,
|
||||
}
|
||||
|
|
@ -765,9 +776,10 @@ struct ScheduleIdArgs {
|
|||
struct ControllerSocketArg {
|
||||
/// 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
|
||||
/// 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.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
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
|
||||
/// still go over the unix socket, unchanged by the remote path.
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue