swarm UI: log an agent into claude from its card; the credentials go to bao and the agent picks them up
A new swarm service, `swarm-claude-login`, in its own container on the host
that sets `deploy.claude-login.enable` (defaulted on by `allSwarmServices`
where the host has the minter's store leaf, like the review classifier).
- swarm-ui: an agent card showing "login needed" gets a "log in" button.
Its dialog starts the login, shows the URL claude printed, and takes the
pasted code.
- swarm-controller: `POST/DELETE /api/agents/{name}/claude-login` and
`POST /api/agents/{name}/claude-login/code`, behind the swarm UI's
authelia-gated `/api/`, relay the steps to the minter as requests on
`$SWARM.claude-login.request`.
- swarm-claude-login: runs `claude auth login` over piped stdio with HOME
and CLAUDE_CONFIG_DIR in a per-login scratch dir, scrapes the first
https URL, writes the code to stdin, and stores the `.credentials.json`
at `swarm/agents/<agent>/claude-credentials` with a KV v2 write, a new
version over any earlier one. The scratch dir goes on every exit path; a
login waits 15 minutes for its code.
- hive-agent: while parked in `wait_for_login`, reads that leaf every 30 s
under the agent's own cert and installs it only when its KV version is
newer than the one recorded in `<harness>/claude-credentials-version`.
An equal or older version is never put back, because claude rotates the
refresh token and the stored copy is stale after the first refresh.
- swarm-secret-client: `claude_login` paths and `SecretStore::read_versioned`.
- Credentials: a `claude-login` store leaf minted by glue-bao-tls, a
`swarm-claude-login` policy (create/update on
`swarm/agents/+/claude-credentials`, read on its own queue client
secret), an authelia machine client, and a `--claude-login-client`
grant in the queue's auth-callout responder. The unit runs as a static
system user.
The hive's own web-UI login is unchanged.
Refs #5268
This commit is contained in:
parent
248df20164
commit
d5de1e4943
48 changed files with 2680 additions and 42 deletions
|
|
@ -47,6 +47,7 @@
|
|||
./glue-nats-wireguard.nix
|
||||
./glue-queue-agent-credential.nix
|
||||
./glue-builder-oidc-client.nix
|
||||
./glue-claude-login-oidc-client.nix
|
||||
./glue-review-classifier-oidc-client.nix
|
||||
./glue-secret-publisher-authelia.nix
|
||||
./glue-secret-publisher-bao-identity.nix
|
||||
|
|
@ -57,6 +58,7 @@
|
|||
./swarm-bao-service.nix
|
||||
./swarm-bao.nix
|
||||
./swarm-builder.nix
|
||||
./swarm-claude-login.nix
|
||||
./swarm-ci-runner.nix
|
||||
./swarm-review-classifier.nix
|
||||
./swarm-secret-publisher.nix
|
||||
|
|
|
|||
|
|
@ -700,6 +700,26 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
claude-login.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Run the claude login minter in a `swarm-claude-login` container on
|
||||
this host. It runs `claude auth login` for the agent an operator logs
|
||||
in from its card in the swarm UI, and writes the credentials to that
|
||||
agent's `secret/swarm/agents/<agent>/claude-credentials`, which the
|
||||
agent's harness installs. Run it on one host: a login in progress
|
||||
lives in the service's memory.
|
||||
|
||||
On by default where
|
||||
{option}`services.hyperhive.deploy.allSwarmServices` is set and this
|
||||
host has the minter's store identity (the pair
|
||||
{option}`services.hyperhive.deploy.bao.claudeLoginClientCertFile`
|
||||
and `claudeLoginClientKeyFile`, minted on the store's host).
|
||||
'';
|
||||
};
|
||||
|
||||
builder.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
|
|
|
|||
|
|
@ -117,6 +117,8 @@ in
|
|||
reviewClassifierClientKeyFile = lib.mkDefault "${pkiDir}/review-classifier-key.pem";
|
||||
builderClientCertFile = lib.mkDefault "${pkiDir}/builder.pem";
|
||||
builderClientKeyFile = lib.mkDefault "${pkiDir}/builder-key.pem";
|
||||
claudeLoginClientCertFile = lib.mkDefault "${pkiDir}/claude-login.pem";
|
||||
claudeLoginClientKeyFile = lib.mkDefault "${pkiDir}/claude-login-key.pem";
|
||||
forgePublisherClientCertFile = lib.mkDefault "${pkiDir}/forge-publisher.pem";
|
||||
forgePublisherClientKeyFile = lib.mkDefault "${pkiDir}/forge-publisher-key.pem";
|
||||
servicesIssuerClientCertFile = lib.mkDefault "${pkiDir}/services-issuer.pem";
|
||||
|
|
@ -303,6 +305,13 @@ in
|
|||
[ -s ${pkiDir}/builder.pem ] || ${signLeaf} ${pkiDir} builder \
|
||||
${lib.escapeShellArg deployCfg.bao.builderCommonName} "" clientAuth
|
||||
|
||||
# The claude login minter's, which writes agents' claude credentials
|
||||
# and reads its queue client secret. Minted here for the matrix-ctl
|
||||
# leaf's reason: the minter is a swarm service, so on a minter host
|
||||
# without the store this is the file an operator copies.
|
||||
[ -s ${pkiDir}/claude-login.pem ] || ${signLeaf} ${pkiDir} claude-login \
|
||||
${lib.escapeShellArg deployCfg.bao.claudeLoginCommonName} "" clientAuth
|
||||
|
||||
# The forge's token publisher. Minted here for the matrix-ctl leaf's
|
||||
# reason: the forge is a swarm singleton, so on a forge host without the
|
||||
# store this is the file an operator copies.
|
||||
|
|
|
|||
35
nix/host-modules/glue-claude-login-oidc-client.nix
Normal file
35
nix/host-modules/glue-claude-login-oidc-client.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Glue: register the claude login minter as an OIDC client wherever authelia
|
||||
# runs.
|
||||
#
|
||||
# ONE PAIRING PER FILE — swarm-claude-login ← authelia, and nothing else.
|
||||
# Deleting this leaves a minter whose token requests authelia answers with a
|
||||
# 401, and no minted secret for swarm-secret-publish to put in the store.
|
||||
#
|
||||
# ⚠️ Gated on authelia being HERE, and NOT on this host running the minter,
|
||||
# for ./glue-controller-oidc-client.nix's reason: a client is a row in THIS
|
||||
# host's provider config. Registered whether or not any host enables the
|
||||
# minter: nothing in `swarm.*` records that, so a swarm without one carries
|
||||
# one unused client and one unused minted secret.
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
hyperhiveCfg = config.services.hyperhive;
|
||||
deployCfg = hyperhiveCfg.deploy;
|
||||
clientId = hyperhiveCfg.swarm.claude-login.clientId;
|
||||
in
|
||||
{
|
||||
config = lib.mkIf deployCfg.authelia.enable {
|
||||
services.hyperhive.swarm.authelia.oidc.clients = [
|
||||
{
|
||||
id = clientId;
|
||||
description = "HyperHive claude login minter";
|
||||
# `client_credentials`: a daemon authenticating as itself.
|
||||
kind = "machine";
|
||||
audience = [ clientId ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
@ -1054,6 +1054,22 @@ let
|
|||
}
|
||||
];
|
||||
|
||||
# The claude login minter: every agent's `claude-credentials` leaf,
|
||||
# create and update so a relogin replaces the last, and nothing else under
|
||||
# an agent; and its own queue client secret, read at start.
|
||||
claudeLoginWriters = [
|
||||
{
|
||||
name = "swarm-claude-login";
|
||||
cn = baoDeploy.claudeLoginCommonName;
|
||||
policyText = ''
|
||||
path "${credentialMountPath}/data/swarm/agents/+/claude-credentials" {
|
||||
capabilities = ["create", "update"]
|
||||
}
|
||||
''
|
||||
+ readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.claude-login.clientId}/oidc/client";
|
||||
}
|
||||
];
|
||||
|
||||
# The forge host's one store identity. `swarm-bao-forge-publisher` writes
|
||||
# the controller's forge token under it, the one writer of that path and
|
||||
# write-only: it copies a file in and never reads one back.
|
||||
|
|
@ -1932,6 +1948,19 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
claudeLoginCommonName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "swarm-claude-login";
|
||||
description = ''
|
||||
Subject the store's `swarm-claude-login` cert-auth role accepts: the
|
||||
identity the claude login minter presents from inside its container.
|
||||
Its grant is create and update on `swarm/agents/+/claude-credentials`
|
||||
and read on its own queue client secret.
|
||||
|
||||
⚠️ Reserved as a hive name by ./swarm.nix, like its siblings.
|
||||
'';
|
||||
};
|
||||
|
||||
forgePublisherCommonName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "swarm-forge-publisher";
|
||||
|
|
@ -2232,6 +2261,31 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
claudeLoginClientCertFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "/var/lib/swarm-bao-pki/claude-login.pem";
|
||||
description = ''
|
||||
Certificate the claude login minter presents to the store. Its subject
|
||||
must be {option}`services.hyperhive.deploy.bao.claudeLoginCommonName`.
|
||||
|
||||
./glue-bao-tls.nix points it at the leaf it mints on the store's host.
|
||||
On a minter host without the store, it is a file the operator copies
|
||||
from the store's host. A path, never a value.
|
||||
'';
|
||||
};
|
||||
|
||||
claudeLoginClientKeyFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "/var/lib/swarm-bao-pki/claude-login-key.pem";
|
||||
description = ''
|
||||
Private key for
|
||||
{option}`services.hyperhive.deploy.bao.claudeLoginClientCertFile`.
|
||||
A path, never a value.
|
||||
'';
|
||||
};
|
||||
|
||||
forgePublisherClientCertFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
|
|
@ -3318,6 +3372,8 @@ in
|
|||
|
||||
systemd.services.swarm-bao-builder-policy = readerPolicyUnit "write the swarm builder's forge-token-reader bao policy and cert-auth role" builderReaders;
|
||||
|
||||
systemd.services.swarm-bao-claude-login-policy = readerPolicyUnit "write the claude login minter's credentials-writer bao policy and cert-auth role" claudeLoginWriters;
|
||||
|
||||
systemd.services.swarm-bao-forge-publisher-policy = readerPolicyUnit "write the forge's controller-token-publisher bao policy and cert-auth role" forgePublisherWriters;
|
||||
|
||||
# A FOURTH sibling, same shape and same reasons as the two above. This
|
||||
|
|
|
|||
203
nix/host-modules/swarm-claude-login.nix
Normal file
203
nix/host-modules/swarm-claude-login.nix
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
# The claude login minter, in a `swarm-claude-login` container on the host
|
||||
# that sets `deploy.claude-login.enable`, which `deploy.allSwarmServices`
|
||||
# defaults on where the host has the minter's store identity. An operator logs
|
||||
# an agent in from its card in the swarm UI: swarm-controller relays the start
|
||||
# and the pasted code over the queue, and the daemon runs `claude auth login`
|
||||
# and writes the credentials to that agent's store leaf.
|
||||
# docs/swarm/claude-login.md has the design.
|
||||
#
|
||||
# Its own network namespace on the bridge, as ./swarm-review-classifier.nix
|
||||
# has: it reaches the swarm services by name and nothing on the host's
|
||||
# loopback.
|
||||
#
|
||||
# The container holds one credential, its own store leaf, which nspawn hands in
|
||||
# as a system credential with no copy on disk. The daemon reads its queue
|
||||
# client secret with it and writes agents' credentials under it.
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
hyperhiveCfg = config.services.hyperhive;
|
||||
cfg = hyperhiveCfg.deploy.claude-login;
|
||||
baoCfg = hyperhiveCfg.swarm.bao;
|
||||
baoDeploy = hyperhiveCfg.deploy.bao;
|
||||
natsCfg = hyperhiveCfg.swarm.nats;
|
||||
autheliaCfg = hyperhiveCfg.swarm.authelia;
|
||||
gatewayCfg = hyperhiveCfg.gateway;
|
||||
networkCfg = hyperhiveCfg.network;
|
||||
tlsCfg = hyperhiveCfg.deploy.hive-controller.tls;
|
||||
|
||||
machine = "swarm-claude-login";
|
||||
unit = "swarm-claude-login";
|
||||
clientId = hyperhiveCfg.swarm.claude-login.clientId;
|
||||
|
||||
# The daemon reaches authelia, the store and the queue by name over TLS, and
|
||||
# in self-signed mode their leaves chain to the hive CA.
|
||||
caTrust = import ./lib/hive-ca-trust.nix { inherit lib tlsCfg gatewayCfg; };
|
||||
caBundleModule = caTrust.trustBundle {
|
||||
inherit pkgs;
|
||||
name = machine;
|
||||
consumers = [ unit ];
|
||||
};
|
||||
|
||||
haveClientIdentity =
|
||||
baoDeploy.claudeLoginClientCertFile != null && baoDeploy.claudeLoginClientKeyFile != null;
|
||||
|
||||
# Credential id → host source, as ./swarm-review-classifier.nix hands its
|
||||
# leaf in.
|
||||
storeFiles = lib.filterAttrs (_: source: source != null) {
|
||||
claude-login-bao-cert = baoDeploy.claudeLoginClientCertFile;
|
||||
claude-login-bao-key = baoDeploy.claudeLoginClientKeyFile;
|
||||
claude-login-bao-server-ca = baoDeploy.serverCaFile;
|
||||
};
|
||||
# nixos-container expands `extraFlags` unquoted, so a source path must be
|
||||
# one word.
|
||||
oneWord = path: builtins.match ".*[[:space:]].*" path == null;
|
||||
credential = id: "/run/credentials/${unit}.service/${id}";
|
||||
|
||||
privateNetwork = true;
|
||||
in
|
||||
{
|
||||
options.services.hyperhive.swarm.claude-login.clientId = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
default = "swarm-claude-login";
|
||||
description = ''
|
||||
The OAuth2 client id the claude login minter presents to the swarm
|
||||
queue. Read-only: the host running authelia registers it, the queue's
|
||||
auth-callout responder grants it the login subject, and the secret
|
||||
publisher carries its secret to the store, all from this one value.
|
||||
'';
|
||||
};
|
||||
|
||||
options.services.hyperhive.deploy.claude-login.package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
defaultText = lib.literalExpression "hyperhive.packages.\${system}.swarm-claude-login";
|
||||
description = "The claude login minter daemon package.";
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = haveClientIdentity;
|
||||
message = ''
|
||||
services.hyperhive.deploy.claude-login.enable requires the minter's
|
||||
swarm-secret-store client identity: set both
|
||||
|
||||
services.hyperhive.deploy.bao.claudeLoginClientCertFile
|
||||
services.hyperhive.deploy.bao.claudeLoginClientKeyFile
|
||||
|
||||
The minter reads its queue client secret and writes agents' claude
|
||||
credentials with it.
|
||||
|
||||
Both default to the pair glue-bao-tls.nix mints when
|
||||
services.hyperhive.deploy.bao.enable is true (the host that runs the
|
||||
store). Otherwise copy claude-login.pem and claude-login-key.pem from
|
||||
the store host's /var/lib/swarm-bao-pki/ and name them in those two
|
||||
options.
|
||||
'';
|
||||
}
|
||||
{
|
||||
assertion = lib.all oneWord (lib.attrValues storeFiles);
|
||||
message = ''
|
||||
The claude login minter's store identity paths must not contain
|
||||
whitespace: nspawn's --load-credential receives them through
|
||||
nixos-container's unquoted extra flags.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
# The container hangs off the bridge, takes its address from the gateway's
|
||||
# DHCP and resolves through its dnsmasq.
|
||||
services.hyperhive.network.enable = lib.mkDefault true;
|
||||
services.hyperhive.gateway.enable = lib.mkDefault true;
|
||||
services.hyperhive.gateway.dns.enable = lib.mkDefault true;
|
||||
|
||||
# nspawn fails to start the container when a credential source is
|
||||
# missing, so where this host mints the leaf the container waits for it.
|
||||
systemd.services."container@${machine}" = lib.mkMerge [
|
||||
caTrust.containerOrdering
|
||||
{ after = [ "swarm-bao-pki.service" ]; }
|
||||
];
|
||||
|
||||
containers.${machine} = {
|
||||
autoStart = true;
|
||||
# The daemon keeps no state; each login's scratch directory is under
|
||||
# PrivateTmp.
|
||||
ephemeral = false;
|
||||
# Journal files on the host, not inside the container: nixpkgs hardcodes
|
||||
# --link-journal=try-guest, and EXTRA_NSPAWN_FLAGS expands after it.
|
||||
extraFlags = [
|
||||
"--link-journal=host"
|
||||
]
|
||||
++ lib.mapAttrsToList (id: source: "--load-credential=${id}:${source}") storeFiles;
|
||||
inherit privateNetwork;
|
||||
hostBridge = networkCfg.bridgeName;
|
||||
bindMounts = caTrust.bindMount;
|
||||
|
||||
config =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
../container-modules/swarm-container.nix
|
||||
caBundleModule
|
||||
];
|
||||
|
||||
services.hyperhive.swarmContainer = {
|
||||
inherit privateNetwork;
|
||||
writesOwnResolvConf = false;
|
||||
};
|
||||
networking.nameservers = [ networkCfg.bridgeIp ];
|
||||
networking.interfaces.eth0.useDHCP = true;
|
||||
|
||||
# `claude-code` is unfree, and this container evaluates its own
|
||||
# nixpkgs, so the host's allowance does not reach here.
|
||||
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "claude-code" ];
|
||||
|
||||
users.users.${unit} = {
|
||||
isSystemUser = true;
|
||||
group = unit;
|
||||
};
|
||||
users.groups.${unit} = { };
|
||||
|
||||
systemd.services.${unit} = {
|
||||
description = "log agents in to claude for the swarm UI";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
environment = {
|
||||
BAO_ADDR = "https://${baoCfg.domain}:${toString baoCfg.port}";
|
||||
BAO_CLIENT_CERT = credential "claude-login-bao-cert";
|
||||
BAO_CLIENT_KEY = credential "claude-login-bao-key";
|
||||
SWARM_CLAUDE_LOGIN_NATS_URL = "tls://${natsCfg.domain}:${toString natsCfg.port}";
|
||||
SWARM_CLAUDE_LOGIN_OIDC_TOKEN_ENDPOINT = "${autheliaCfg.url}/api/oidc/token";
|
||||
SWARM_CLAUDE_LOGIN_OIDC_CLIENT_ID = clientId;
|
||||
SWARM_CLAUDE_LOGIN_CLAUDE = "${pkgs.claude-code}/bin/claude";
|
||||
}
|
||||
// lib.optionalAttrs (storeFiles ? claude-login-bao-server-ca) {
|
||||
BAO_CACERT = credential "claude-login-bao-server-ca";
|
||||
}
|
||||
// lib.optionalAttrs caTrust.useSelfSigned {
|
||||
SWARM_CLAUDE_LOGIN_OIDC_CA_FILE = caTrust.bundlePathFor machine;
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = "${cfg.package}/bin/swarm-claude-login";
|
||||
User = unit;
|
||||
Group = unit;
|
||||
# Each login's scratch directory, gone with the unit.
|
||||
PrivateTmp = true;
|
||||
UMask = "0077";
|
||||
# Bare ids: the system credentials nspawn handed in.
|
||||
LoadCredential = lib.attrNames storeFiles;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
SyslogIdentifier = unit;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -795,6 +795,8 @@ in
|
|||
"--review-classifier-client ${lib.escapeShellArg config.services.hyperhive.swarm.review-classifier.clientId}"
|
||||
# Hears builds and answers each by reply, and nothing else.
|
||||
"--builder-client ${lib.escapeShellArg config.services.hyperhive.swarm.builder.clientId}"
|
||||
# Hears login steps and answers each by reply, and nothing else.
|
||||
"--claude-login-client ${lib.escapeShellArg config.services.hyperhive.swarm.claude-login.clientId}"
|
||||
# What an agent may publish to, keyed on its own name: its
|
||||
# terminal rows and its turn-state header
|
||||
# (`hive-agent::swarm_agent_state`), two subject families so a
|
||||
|
|
|
|||
|
|
@ -126,4 +126,12 @@ in
|
|||
&& deployCfg.bao.builderClientCertFile != null
|
||||
&& deployCfg.bao.builderClientKeyFile != null
|
||||
);
|
||||
|
||||
# The claude login minter, defaulted on the same terms as the review
|
||||
# classifier.
|
||||
config.services.hyperhive.deploy.claude-login.enable = lib.mkDefault (
|
||||
deployCfg.allSwarmServices
|
||||
&& deployCfg.bao.claudeLoginClientCertFile != null
|
||||
&& deployCfg.bao.claudeLoginClientKeyFile != null
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ let
|
|||
hyperhiveCfg.swarm.review-classifier.clientId
|
||||
# The swarm builder, which reads it itself inside its container.
|
||||
hyperhiveCfg.swarm.builder.clientId
|
||||
# The claude login minter, which reads it itself inside its container.
|
||||
hyperhiveCfg.swarm.claude-login.clientId
|
||||
];
|
||||
|
||||
# The swarm controller's OIDC client, which it reads back from the store
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ let
|
|||
deployCfg.bao.metricsAuthCommonName
|
||||
deployCfg.bao.reviewClassifierCommonName
|
||||
deployCfg.bao.builderCommonName
|
||||
deployCfg.bao.claudeLoginCommonName
|
||||
deployCfg.bao.forgePublisherCommonName
|
||||
]
|
||||
# The per-hive subjects, spelled out per hive rather than as the prefix.
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ let
|
|||
_: u: (u.environment.BAO_CLIENT_CERT or null) == granterCertFile
|
||||
) baoGrantWithConsumers.systemd.services;
|
||||
|
||||
# The nineteen units that write a `swarm-*` grant, by name, for the discovery
|
||||
# The twenty units that write a `swarm-*` grant, by name, for the discovery
|
||||
# control below.
|
||||
grantingUnitNames = [
|
||||
"swarm-bao-controller-policy"
|
||||
|
|
@ -191,6 +191,7 @@ let
|
|||
"swarm-bao-forge-publisher-policy"
|
||||
"swarm-bao-review-classifier-policy"
|
||||
"swarm-bao-builder-policy"
|
||||
"swarm-bao-claude-login-policy"
|
||||
];
|
||||
|
||||
# Comment lines dropped first: both the HCL and the scripts explain
|
||||
|
|
@ -976,24 +977,24 @@ let
|
|||
}
|
||||
{
|
||||
# A store host without the granter's pair writes its grants some other
|
||||
# way, so none of the nineteen units may exist. Without this arm
|
||||
# way, so none of the twenty units may exist. Without this arm
|
||||
# `lib.mkIf haveGranter` could be dropped from any of them and every other
|
||||
# case here would still pass.
|
||||
name = "without the granter's pair none of the nineteen granting units render";
|
||||
name = "without the granter's pair none of the twenty granting units render";
|
||||
ok =
|
||||
let
|
||||
s = baoGranterOptOut.systemd.services;
|
||||
in
|
||||
lib.all (unit: !(s ? ${unit})) (grantingUnitNames ++ [ "swarm-bao-granter-role" ])
|
||||
# The control: the same store with the pair renders all nineteen.
|
||||
# The control: the same store with the pair renders all twenty.
|
||||
&& lib.all (unit: baoGrantHere.systemd.services ? ${unit}) grantingUnitNames;
|
||||
}
|
||||
{
|
||||
# 🩸 What replaced the silent skip. With no bootstrap token the nineteen still
|
||||
# 🩸 What replaced the silent skip. With no bootstrap token the twenty still
|
||||
# render, and a refused granter fails them with the step that fixes it.
|
||||
# A store host that never named a token is told to name one, since the
|
||||
# unit that sets the granter up renders only where it has.
|
||||
name = "a store host without a bootstrap token renders the nineteen, each failing loudly with the one-time step";
|
||||
name = "a store host without a bootstrap token renders the twenty, each failing loudly with the one-time step";
|
||||
ok =
|
||||
let
|
||||
s = baoGranterNoToken.systemd.services;
|
||||
|
|
@ -1595,6 +1596,44 @@ let
|
|||
in
|
||||
lib.hasInfix "/builder.pem ]" s && lib.hasInfix "swarm-builder \"\" clientAuth" s;
|
||||
}
|
||||
{
|
||||
# The minter writes one leaf under every agent, create and update so a
|
||||
# relogin replaces the last, and reads its own queue client secret. No
|
||||
# read on the leaf, and nothing else under an agent.
|
||||
name = "the claude login minter's grant is create and update on agents' claude-credentials, and its queue client secret";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-claude-login-policy.script;
|
||||
grants = grantsIn s;
|
||||
in
|
||||
(grantFor grants "secret/data/swarm/agents/+/claude-credentials").caps == [
|
||||
"create"
|
||||
"update"
|
||||
]
|
||||
&& (grantFor grants "secret/data/swarm/services/swarm-claude-login/oidc/client").caps == [ "read" ]
|
||||
&& lib.length grants == 2
|
||||
&& !(lib.hasInfix "secret/data/swarm/agents/*" s)
|
||||
&& lib.hasInfix "auth/cert/certs/swarm-claude-login" s
|
||||
&& lib.hasInfix "allowed_common_names=swarm-claude-login" s
|
||||
&& lib.hasInfix "token_policies=swarm-claude-login" s;
|
||||
}
|
||||
{
|
||||
# The leaf by name: the minter writes it. The agent's own read and the
|
||||
# controller's `swarm/agents/*` reach it without naming it.
|
||||
name = "no granting unit but the claude login minter's names the claude-credentials leaf";
|
||||
ok =
|
||||
lib.filter (
|
||||
u: lib.hasInfix "claude-credentials" baoGrantHere.systemd.services.${u}.script
|
||||
) grantingUnitNames == [ "swarm-bao-claude-login-policy" ];
|
||||
}
|
||||
{
|
||||
name = "the PKI unit signs the claude login minter's leaf under its own subject";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-pki.script;
|
||||
in
|
||||
lib.hasInfix "/claude-login.pem ]" s && lib.hasInfix "swarm-claude-login \"\" clientAuth" s;
|
||||
}
|
||||
{
|
||||
name = "the PKI unit signs the CI runner's leaf under its own subject";
|
||||
ok =
|
||||
|
|
@ -1826,8 +1865,8 @@ let
|
|||
}
|
||||
{
|
||||
# What makes the case above mean something: discovery by the granter's
|
||||
# certificate reaches all nineteen units, and each yields calls.
|
||||
name = "the granter-policy check sees all nineteen granting units, and parses calls from each";
|
||||
# certificate reaches all twenty units, and each yields calls.
|
||||
name = "the granter-policy check sees all twenty granting units, and parses calls from each";
|
||||
ok =
|
||||
lib.sort lib.lessThan (lib.attrNames granterUnits) == lib.sort lib.lessThan grantingUnitNames
|
||||
&& lib.all (u: baoCalls u.script != [ ]) (lib.attrValues granterUnits)
|
||||
|
|
|
|||
|
|
@ -365,6 +365,27 @@ let
|
|||
&& lib.hasInfix socket l."/webhook/forge/".proxyPass
|
||||
&& !(lib.hasInfix "auth_request" l."/webhook/forge/".extraConfig);
|
||||
}
|
||||
{
|
||||
# nginx serves a path from its longest matching prefix location, so that
|
||||
# one must be the gated `/api/`, and no exact location may take a route
|
||||
# out from under it.
|
||||
name = "the claude login routes reach the controller only through a location that asks authelia";
|
||||
ok =
|
||||
let
|
||||
l = allLocal.services.nginx.virtualHosts."t.local".locations;
|
||||
route = "/api/agents/a/claude-login/code";
|
||||
covering = lib.filter (
|
||||
name: !(lib.hasPrefix "~" name) && !(lib.hasPrefix "= " name) && lib.hasPrefix (prefix name) route
|
||||
) (lib.attrNames l);
|
||||
prefix = lib.removePrefix "^~ ";
|
||||
longest = lib.foldl' (
|
||||
a: b: if lib.stringLength (prefix b) > lib.stringLength (prefix a) then b else a
|
||||
) "" covering;
|
||||
in
|
||||
longest == "/api/"
|
||||
&& lib.hasInfix "auth_request /__hive_authelia;" l.${longest}.extraConfig
|
||||
&& !(lib.any (name: lib.hasPrefix "= /api/agents" name) (lib.attrNames l));
|
||||
}
|
||||
{
|
||||
name = "a hive with matrix off serves no matrix discovery endpoint";
|
||||
ok =
|
||||
|
|
|
|||
|
|
@ -163,8 +163,9 @@ let
|
|||
lib.filter (l: swarmServiceLinkDomains ? ${l.label}) cfg.services.hyperhive.swarm.controller.links;
|
||||
|
||||
# Every service container at once: the services-only host plus the CI
|
||||
# runner. The CI runner, the review classifier, the builder, the metrics
|
||||
# store and the homeserver are the five containers on a netns of their own.
|
||||
# runner. The CI runner, the review classifier, the builder, the claude login
|
||||
# minter, the metrics store and the homeserver are the six containers on a
|
||||
# netns of their own.
|
||||
serviceContainersWithCi = hive {
|
||||
deploy.hive-controller.enable = false;
|
||||
deploy.allSwarmServices = true;
|
||||
|
|
@ -247,6 +248,30 @@ let
|
|||
&& !(swarmServicesBaoElsewhere.containers ? swarm-builder)
|
||||
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
|
||||
}
|
||||
{
|
||||
# Static, not `DynamicUser`: the user is declared in the container and
|
||||
# the unit names it. `nats` is the control that the switch is on at all.
|
||||
name = "hosting the swarm's shared services runs the claude login minter in its container as a static user";
|
||||
ok =
|
||||
let
|
||||
c = swarmServicesHere.containers.swarm-claude-login.config;
|
||||
sc = c.systemd.services.swarm-claude-login.serviceConfig;
|
||||
in
|
||||
swarmServicesHere.services.hyperhive.deploy.claude-login.enable
|
||||
&& c.users.users.swarm-claude-login.isSystemUser
|
||||
&& sc.User == "swarm-claude-login"
|
||||
&& !(sc.DynamicUser or false)
|
||||
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
|
||||
}
|
||||
{
|
||||
# The minter's module asserts the store identity the store's host mints,
|
||||
# as the classifier's does.
|
||||
name = "the claude login minter stays off where the shared services are hosted without the store";
|
||||
ok =
|
||||
!swarmServicesBaoElsewhere.services.hyperhive.deploy.claude-login.enable
|
||||
&& !(swarmServicesBaoElsewhere.containers ? swarm-claude-login)
|
||||
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
|
||||
}
|
||||
{
|
||||
# The switch fills in for an operator who has not spoken and yields to
|
||||
# one who has — that is what keeps a shared service placeable on a host
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ in
|
|||
# reason: it runs inside its own container, not on the host.
|
||||
swarm-review-classifier = mkBinPackage "swarm-review-classifier" "hyperhive review classifier try-out daemon";
|
||||
swarm-builder = mkBinPackage "swarm-builder" "hyperhive swarm builder: agent config build checks";
|
||||
swarm-claude-login = mkBinPackage "swarm-claude-login" "hyperhive claude login minter";
|
||||
|
||||
# The only process allowed to write swarm-authelia's users database —
|
||||
# same "runs *inside* a container, not on the host" placement as
|
||||
|
|
|
|||
Loading…
Reference in a new issue