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
2 changed files with 1420 additions and 12 deletions

View file

@ -102,6 +102,20 @@ bao read -field=public_key ssh-agents/config/ca
- It signs ed25519 user keys only, and the certificate allows a terminal
(`permit-pty`) and nothing else.
## Named connections
Give a machine a short name, so the agent runs `ssh k8s-lab-vm` instead of
`ssh -p 2222 root@muede-pc2`. You declare, per agent, a name, the user, the
host and the port. For example `k8s-lab-vm`, `root`, `muede-pc2`, `2222`.
The agent's ssh config then holds a `Host k8s-lab-vm` block with that host,
user and port, and the connection uses the same certificate as any other. The
block follows a change within ten seconds, and it's empty while the agent's SSH
switch is off, so one switch ends both the certificate and the names. A name
doesn't open the network: see the note under section 1. The routes and the
rules a connection must meet are on
[the SSH CA implementation page](../../4-implementation/swarm/ssh-ca.md#named-connections).
## Revoking access
- **One agent from one machine:** remove its principal (the `authorizedPrincipals`

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