Watch
0
0
Fork
You've already forked hyperhive
0

agent ssh connections: declare per agent, render into the agent's ssh config

This commit is contained in:
atlas 2026-11-20 01:38:49 +01:00
commit 934da6f31f

View file

@ -119,6 +119,46 @@ and attaches it to the agent's cert-auth role `hive-agent-<name>` as a second
NixOS then writes `/etc/ssh/authorized_principals.d/<user>` and sets
`AuthorizedPrincipalsFile` to it.
## Named connections
The operator's named connections are the `ssh_connections` list of the same
record (`swarm_wire::ssh_connection::SshConnection`: `name`, `user`, `host`,
`port`). They have their own routes in
`swarm-controller/src/ssh_connections.rs`, and a write changes only that
field; a `PUT` or `DELETE` on `/permissions` keeps them:
```text
GET /api/agents/<agent>/ssh-connections
PUT /api/agents/<agent>/ssh-connections/<name> {"user":"root","host":"muede-pc2","port":2222}
DELETE /api/agents/<agent>/ssh-connections/<name>
```
`SshConnection::checked` is the one validation, run by the controller before it
stores a connection and by the agent before it renders one:
- **Name:** lower-case letters, digits and hyphens, up to 63, not starting with
a hyphen. A name is unique per agent, and an agent has at most 32.
- **User:** letters, digits, `_`, `.` and `-`, up to 32, not starting with `-`
or `.`.
- **Host:** a DNS name (one label is fine) or an IPv4 address. The swarm refuses
IPv6 addresses, `localhost`, and loopback, link-local, multicast and reserved
addresses.
- **Port:** 1 to 65535, except 80 and 443. The hive sends those two ports to
its own proxy, so no direct connection there can exist.
The swarm doesn't check the hive's own bridge subnet, because each hive sets its
own and an agent can move between hives.
`hive-agent`'s `ssh_connections.rs` renders the list each time the harness reads
the record (every ten seconds) into `/run/hive-agent-ssh-connections/config`:
one `Host` block each with `HostName`, `User` and `Port`, and an empty file
while `ssh` is off. The block carries no identity lines: ssh takes the
identity from the `Host *` block below the `Include` in `ssh.nix`, which
gives the swarm CA certificate to every connection. The file belongs to the
agent user, because ssh refuses an included file that another user owns.
A controller older than the field drops the list when it next writes the
record through `PUT /permissions`.
## Not covered
Egress. The default `egress.forward = "log"` lets a direct connection from an