Watch
0
0
Fork
You've already forked hyperhive
0

default the host's swarmctl to the gateway; login takes a callback port

This commit is contained in:
atlas 2026-11-22 15:00:54 +01:00
commit 58236e1b7f
4 changed files with 183 additions and 67 deletions

View file

@ -154,11 +154,14 @@ let
storeRetry = import ./lib/store-retry.nix { };
tcpOn = deployCfg.swarm-controller.enable && tcpCfg.enable;
# Which swarm `swarmctl login` logs in to when given none: this host's own.
# Read by `login` alone. `SWARMCTL_SWARM` would also move every socket verb
# onto the gateway, where each needs a login. A default, so an operator's
# own value still wins.
loginDefaultEnv = lib.optionalAttrs (swarmDomain != null) {
# 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
# controller socket then serves the gateway alone, which always sets
# `Remote-User`. Both are defaults, so an operator's own value wins: an
# empty `SWARMCTL_SWARM` puts the socket verbs back on the socket for
# root.
swarmDefaultEnv = lib.optionalAttrs (swarmDomain != null) {
SWARMCTL_SWARM = "https://${swarmDomain}";
SWARMCTL_LOGIN_DEFAULT_SWARM = "https://${swarmDomain}";
};
@ -339,7 +342,7 @@ let
)
++ lib.mapAttrsToList (
name: value: "--set-default ${name} ${lib.escapeShellArg value}"
) loginDefaultEnv
) swarmDefaultEnv
)
}
'';
@ -633,8 +636,10 @@ in
the socket itself is `0666`, exactly as hive-c0re publishes the
per-agent sockets, and the directory is `0750` owned by the
`${clientsGroup}` group. Members of that group (the gateway's
nginx, for `/api/` and `/webhook/forge/`) and root (`swarmctl`,
which bypasses mode bits) can reach the socket; every other local
nginx, for `/api/` and `/webhook/forge/`) and root (which bypasses mode
bits) can reach the socket. The host's `swarmctl` goes through the
gateway by default, so only a root-run verb with an empty
`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.
Moving this path under a directory that carries anything else —

View file

@ -154,14 +154,16 @@ let
or null == "https://matrix.hive.t.local";
}
{
# Login-only: `SWARMCTL_SWARM` would move every socket verb onto the
# gateway. The socket variable is the control that the wrapper text was
# found at all.
name = "the host's swarmctl logs in to its own swarm by default, and its other verbs stay on the socket";
# The host's swarmctl reaches the gateway by default and the socket only when
# the operator empties `SWARMCTL_SWARM`: `--set-default` lets that empty value
# through, `--set` would not. The socket variable is the control that the
# wrapper text was found at all.
name = "the host's swarmctl defaults to its own swarm's gateway, and an operator's own value wins";
ok =
lib.hasInfix "--set SWARM_CONTROLLER_SOCKET " 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 "SWARMCTL_SWARM" swarmctlWrapperCmd);
&& !(lib.hasInfix "--set SWARMCTL_SWARM" swarmctlWrapperCmd);
}
{
# The gateway's leaf chains to the store's root, which no system store

View file

@ -142,6 +142,7 @@ test.overrideTestDerivation (old: {
env = (old.env or { }) // {
FULL_SETUP_SOCKET = deploy.swarm-controller.socketPath;
FULL_SETUP_FORGE_DOMAIN = swarm.forge.domain;
FULL_SETUP_SWARM_DOMAIN = swarm.domain;
FULL_SETUP_HIVE = hive;
FULL_SETUP_TOPLEVELS = builtins.toJSON (map toString (toplevels settingsJson));
FULL_SETUP_META_SETTINGS = settingsJson;

View file

@ -10,6 +10,11 @@ TOPLEVELS = json.loads(os.environ["FULL_SETUP_TOPLEVELS"])
REPO = os.environ["FULL_SETUP_HYPERHIVE_REPO"]
CONTROL_NIX = os.environ["FULL_SETUP_CONTROL_NIX"]
INIT = "/root/bao-init.json"
# The host's swarmctl defaults to the swarm's gateway, where each controller verb needs a
# `swarmctl login`, which a VM without a browser cannot do. An empty `SWARMCTL_SWARM` puts a
# verb on the controller socket.
VIA_SOCKET = "SWARMCTL_SWARM="
SWARM_URL = "https://" + os.environ["FULL_SETUP_SWARM_DOMAIN"]
FORGE_AUTH = "/root/forge-auth.header"
NIX = "nix --extra-experimental-features nix-command"
ARCHETYPE = {"source": "hyperhive", "name": "reviewer"}
@ -297,7 +302,7 @@ with subtest("swarmctl setup status reports the steps done so far"):
"✅ 10 another agent [optional]",
]
for _ in range(60):
lines = machine.execute("swarmctl setup status")[1].splitlines()
lines = machine.execute(f"{VIA_SOCKET} swarmctl setup status")[1].splitlines()
if all(any(line.startswith(prefix) for line in lines) for prefix in reported):
break
machine.sleep(10)
@ -306,7 +311,16 @@ with subtest("swarmctl setup status reports the steps done so far"):
"swarmctl setup status did not report the steps done so far:\n"
+ "\n".join(lines)
)
assert machine.execute("swarmctl setup status >/dev/null")[0] == 1
assert machine.execute(f"{VIA_SOCKET} swarmctl setup status >/dev/null")[0] == 1
with subtest(
"the host's swarmctl reaches the controller through the gateway by default"
):
# No login exists in the VM, so a verb that names the controller stops at the login, and
# says which swarm it went to. Over the socket the same verb needs none.
status, out = machine.execute("swarmctl schedule list 2>&1")
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("the agents are deployed and need a login"):
settle(