Watch
0
0
Fork
You've already forked hyperhive
0

sign ssh certificates on demand from ssh itself, warn before setup, say what to do when a host key changes

This commit is contained in:
atlas 2026-11-16 19:42:44 +01:00 • committed by mara
commit 3d7541c0af
3 changed files with 521 additions and 67 deletions

View file

@ -19,6 +19,7 @@ import { Hint } from "../../ui/hint/Hint.js";
import { Preformatted } from "../../ui/preformatted/Preformatted.js";
import type { GrantState } from "./AgentPermissions.js";
import {
forgetHostKeyCommand,
sshBody,
sshSummary,
targetSnippet,
@ -77,19 +78,27 @@ export function AgentSsh({ agent, g }: { agent: string; g: GrantState }) {
title={`whether ${agent} may get SSH certificates from the swarm`}
popoverLabel={`${agent} SSH access`}
>
<p class="ui-badge-popover-help" role="note">
<strong>Warning:</strong> SSH access with no constraints on the
machine makes {agent} unconstrained there. Whatever {agent}'s own
sandbox stops it doing, it can do on a machine it can log in to. Only
allow this for machines you would let {agent} control completely.
</p>
<p class="ui-badge-popover-help">
Lets {agent} log in over SSH to machines that trust the swarm's SSH
certificate authority. With this on, {agent} gets a certificate that
names it and lasts one hour, and renews it every 20 minutes; its key
lives in memory only. The change reaches {agent} within about 25
minutes. A certificate already signed stays valid until it expires, at
most three hours. A machine has to trust the authority before anything
works: see "on the target" below.
certificate authority. With this on, {agent} signs its own key for a
certificate that names it, on its first <code>ssh</code> after the
swarm has updated its login, which takes seconds. The certificate
lasts one hour, and the key lives in memory only. Switching off stops
new certificates within seconds; one already signed stays valid until
it expires, an hour after signing. A machine has to trust the
authority before anything works: see "on the target" below.
</p>
<p class="ui-badge-popover-help" role="note">
{agent} accepts the key a machine shows on the first connection and
refuses a changed one afterwards (trust on first use). It does not
check the key against anything you registered.
refuses a changed one afterwards (trust on first use). If a host's key
really changed, check the new key out of band, then forget the old one
with <code>{forgetHostKeyCommand(agent)}</code> on the hive host.
</p>
<CheckboxField
id={`ssh-${agent}`}

View file

@ -73,3 +73,12 @@ export function targetSnippet(
return `# in ~<user>/.ssh/authorized_keys on the target\n${authorizedKeysLine(agent, ca)}`;
}
}
/**
* The command that makes the agent forget a host's recorded key, run as root on
* the hive host after the operator has checked the new key out of band. The
* agent's pins live in its state directory.
*/
export function forgetHostKeyCommand(agent: string): string {
return `ssh-keygen -R <host> -f /agents/${agent}/state/ssh_known_hosts`;
}

View file

@ -4,6 +4,7 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import {
authorizedKeysLine,
forgetHostKeyCommand,
sshBody,
sshSummary,
targetSnippet,
@ -37,6 +38,14 @@ test("the authorized_keys line trusts the CA for one principal only", () => {
);
});
test("the forget command names the agent's pin file and leaves the host to the operator", () => {
assert.equal(
forgetHostKeyCommand("atlas"),
"ssh-keygen -R <host> -f /agents/atlas/state/ssh_known_hosts",
);
assert.ok(forgetHostKeyCommand("maia").includes("/agents/maia/"));
});
test("each target form names the agent and the CA key, and keeps <user> for the operator", () => {
for (const form of ["nixos", "home-manager", "ssh"]) {
const text = targetSnippet(form, "atlas", ca);