Watch
0
0
Fork
You've already forked hyperhive
0

swarm-archive: back up every agent's state to an append-only restic repository per agent

swarm-archive serves restic repositories with rclone, append-only, one login
and one repository per agent. swarm-controller writes each placed agent's
login and restic password to the store, replaces them on a move and removes
them when the agent is destroyed. Every hive backs its agents up hourly under
its own store identity. The archive host prunes by retention.
This commit is contained in:
atlas 2026-11-10 07:49:49 +01:00
commit 306aae0378

View file

@ -518,7 +518,39 @@ let
capabilities = ["create", "read", "update"]
}
'') atticHiveFactNames}
path "${credentialMountPath}/data/${ciRunnerTokenLeaf}" {
# The archive credentials of the agents each hive places
# (swarm-controller's archive_access.rs): the hive's copy and the archive's
# hash and restic password, listed to find what no placement justifies and
# deleted when a move or a destroy revokes it.
path "${credentialMountPath}/data/swarm/hives/+/archive/*" {
capabilities = ["create", "read", "update"]
}
path "${credentialMountPath}/metadata/swarm/hives/+/archive/" {
capabilities = ["list"]
}
path "${credentialMountPath}/metadata/swarm/hives/+/archive/+" {
capabilities = ["delete"]
}
path "${credentialMountPath}/data/swarm/services/archive/users/*" {
capabilities = ["create", "read", "update"]
}
path "${credentialMountPath}/data/swarm/services/archive/restic/*" {
capabilities = ["create", "read"]
}
path "${credentialMountPath}/metadata/swarm/services/archive/users/" {
capabilities = ["list"]
}
path "${credentialMountPath}/metadata/swarm/services/archive/users/+" {
capabilities = ["delete"]
}
path "${credentialMountPath}/data/${ciRunnerTokenLeaf}" {
capabilities = ["create", "update"]
}
@ -998,7 +1030,11 @@ let
"public-key"
"pull-token"
]
+ readStanza "${credentialMountPath}/data/swarm/hives/${obj.hiveName}/squid-selfcheck";
+ readStanza "${credentialMountPath}/data/swarm/hives/${obj.hiveName}/squid-selfcheck"
# The archive credentials swarm-controller writes for the agents this hive
# places: the backup unit (./hive-archive-backup.nix) lists them and reads each.
+ readStanza "${credentialMountPath}/data/swarm/hives/${obj.hiveName}/archive/*"
+ listStanza "${credentialMountPath}/metadata/swarm/hives/${obj.hiveName}/archive/";
# The PKI mount agent client certificates are issued from. Its root is
# generated inside the store, so the agent CA's key never exists outside it.
@ -1103,6 +1139,12 @@ let
}
'';
listStanza = path: ''
path "${path}" {
capabilities = ["list"]
}
'';
# Singletons, so a list of one rather than a second shape: the granting unit
# below takes a list either way and the units stay identical apart from
# the objects they write.
@ -1339,6 +1381,20 @@ let
}
];
# The backup archive: the users file is rendered from one leaf per agent, and
# the prune reads each agent's restic password. Read and list only; the
# controller writes both.
archiveReaders = [
{
name = "swarm-archive";
cn = baoDeploy.archiveCommonName;
policyText =
readStanza "${credentialMountPath}/data/swarm/services/archive/users/*"
+ readStanza "${credentialMountPath}/data/swarm/services/archive/restic/*"
+ listStanza "${credentialMountPath}/metadata/swarm/services/archive/users/";
}
];
# The CI run poller: its forge token and its own OIDC client secret, both
# read once per pass by the host unit.
ciMetricsReaders = [
@ -2611,6 +2667,42 @@ in
'';
};
archiveCommonName = lib.mkOption {
type = lib.types.str;
default = "swarm-archive";
description = ''
Subject the store's `swarm-archive` cert-auth role accepts: the identity
the backup archive's host units present. Its grant is read on
`swarm/services/archive/users/*` and `restic/*`, and list on `users`.
⚠️ Reserved as a hive name by ./swarm.nix, like its siblings.
'';
};
archiveClientCertFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/var/lib/swarm-bao-pki/archive.pem";
description = ''
Certificate the backup archive's host units present to the store. Its
subject must be {option}`services.hyperhive.deploy.bao.archiveCommonName`.
./glue-bao-tls.nix points it at the leaf it mints on the store's host.
On an archive host without the store, it is a file the operator copies
from the store's host. A path, never a value.
'';
};
archiveClientKeyFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/var/lib/swarm-bao-pki/archive-key.pem";
description = ''
Private key for {option}`services.hyperhive.deploy.bao.archiveClientCertFile`.
A path, never a value.
'';
};
atticClientCertFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
@ -3847,6 +3939,8 @@ in
systemd.services.swarm-bao-attic-policy = readerPolicyUnit "write the in-swarm cache's secret-creator bao policy and cert-auth role" atticWriters;
systemd.services.swarm-bao-archive-policy = readerPolicyUnit "write the backup archive's user and password reader bao policy and cert-auth role" archiveReaders;
systemd.services.swarm-bao-notify-router-policy = readerPolicyUnit "write the notification router's client-secret-reader bao policy and cert-auth role" notifyRouterReaders;
systemd.services.swarm-bao-forge-publisher-policy = readerPolicyUnit "write the forge's controller-token-publisher bao policy and cert-auth role" forgePublisherWriters;