diff --git a/nix/host-modules/default.nix b/nix/host-modules/default.nix index 1044c61ec..9d34cc4d4 100644 --- a/nix/host-modules/default.nix +++ b/nix/host-modules/default.nix @@ -75,6 +75,7 @@ ./swarm-bao-service.nix ./swarm-bao.nix ./swarm-bao-operator-viewer.nix + ./swarm-bao-readers.nix ./swarm-builder.nix ./swarm-claude-login.nix ./swarm-notify-router.nix diff --git a/nix/host-modules/lib/swarm-bao-shared.nix b/nix/host-modules/lib/swarm-bao-shared.nix index e6a286499..6b7f9089c 100644 --- a/nix/host-modules/lib/swarm-bao-shared.nix +++ b/nix/host-modules/lib/swarm-bao-shared.nix @@ -265,6 +265,119 @@ let gatewayCfg = hyperhiveCfg.gateway; }; + # The swarm appservice token's leaf, the nix half of + # `swarm_secret_client::matrix::swarm_appservice_token_path`. Under + # `controller/`, the one kind no hive's policy reads: its sender is the + # homeserver's admin. + swarmAppserviceTokenLeaf = "swarm/controller/swarm-controller/matrix/appservice-token"; + + # The swarm appservice registration's leaf, the nix half of + # `swarm_secret_client::matrix::swarm_appservice_registration_path`. Only + # matrix-ctl reaches it; the controller reads the token above, not this. + swarmAppserviceRegistrationLeaf = "swarm/controller/swarm-controller/matrix/appservice-registration"; + + # The controller's own OIDC client secret, the nix half of + # `swarm_secret_client::queue::controller_client_path`. Authelia's mint writes + # it; the controller reads it and holds no other copy. + controllerClientLeaf = "swarm/controller/swarm-controller/oidc/client"; + + # The controller's own forge token, the nix half of + # `swarm_secret_client::forge::controller_token_path`. The forge's host writes + # it; the controller reads it and holds no other copy. + controllerForgeTokenLeaf = "swarm/controller/swarm-controller/forge/token"; + + # The controller's Viewer token for Grafana's API, the nix half of + # `swarm_secret_client::grafana::controller_token_path`. Grafana's host + # writes it; the controller reads it and holds no other copy. + controllerGrafanaTokenLeaf = "swarm/controller/swarm-controller/grafana/token"; + + # The HMAC secret of the swarm-wide forge webhooks, the nix half of + # `swarm_secret_client::forge::controller_webhook_secret_path`. The controller + # creates it, seeded from its old state-directory file, and reads it; `create` + # without `update`, so the first value stored is the one every start reads. + controllerWebhookSecretLeaf = "swarm/controller/swarm-controller/forge/webhook-secret"; + + # The forge's runner registration token, the nix half of + # `swarm_secret_client::ci::registration_token_path`. The controller writes + # it and cannot read it back (`forge::runner_token` keeps the value it last + # wrote in memory); the CI runner's fetch unit is its one reader. + ciRunnerTokenLeaf = "swarm/services/ci-runner/registration-token"; + + # The review classifier's forge token, the nix half of + # `swarm_secret_client::review_classifier::forge_token_path`. The controller + # mints it, reads it back before deciding whether to re-mint, and posts the + # classifier's reviews with it; no other principal's policy reaches it. + classifierForgeTokenLeaf = "swarm/services/review-classifier/forge/token"; + + # The swarm builder's forge token, the nix half of + # `swarm_secret_client::builder::forge_token_path`. The controller mints it + # and reads it back before deciding whether to re-mint; the builder reads it + # to fetch config repos. + builderForgeTokenLeaf = "swarm/services/builder/forge/token"; + + # The CI run poller's forge token, the nix half of + # `swarm_secret_client::ci_metrics::forge_token_path`. The controller mints it + # and reads it back before deciding whether to re-mint; the poller reads it + # to list runs. + ciMetricsForgeTokenLeaf = "swarm/services/ci-metrics/forge/token"; + + readStanza = path: '' + path "${path}" { + capabilities = ["read"] + } + ''; + + listStanza = path: '' + path "${path}" { + capabilities = ["list"] + } + ''; + + # The callout's keys, the nix half of `swarm-nats-auth`'s `xkey::SEED_PATH` + # and `xkey::PUBLIC_PATH`, and of the `seed_path` and `public_path` of + # `nkey::ISSUER` and `nkey::USER`. All are readable by the `swarm-nats-auth` + # role alone: `swarm/public/` marks the halves that are no secret, and no + # policy opens them to every token. + xkeySeedLeaf = "swarm/services/swarm-nats/callout/xkey-seed"; + xkeyPublicLeaf = "swarm/public/swarm-nats/callout-xkey"; + issuerSeedLeaf = "swarm/services/swarm-nats/callout/issuer-seed"; + issuerPublicLeaf = "swarm/public/swarm-nats/callout-issuer"; + userSeedLeaf = "swarm/services/swarm-nats/callout/user-seed"; + userPublicLeaf = "swarm/public/swarm-nats/callout-user"; + + # Grafana's admin password, which only Grafana's leaf creates. The nix half + # of `adminPasswordStorePath` in ./swarm-grafana.nix. + grafanaAdminLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/admin/password"; + + # The bearer Grafana's datasources present at the metrics and log stores. + # Grafana's leaf creates it, the stores' responders read it. The nix half of + # `metricsBearerStorePath` in ./swarm-grafana.nix and of `--store-path` in + # ./swarm-victoriametrics.nix and ./swarm-victorialogs.nix. + grafanaMetricsBearerLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/metrics/bearer"; + + # Grafana's datasource-encryption key, which only Grafana's leaf creates. The + # nix half of `secretKeyStorePath` in ./swarm-grafana.nix. + grafanaSecretKeyLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/secret-key"; + + # authelia's jwt, session, storage-encryption, OIDC HMAC and OIDC issuer keys, + # which only `authelia-swarm-secrets` in authelia's container creates and reads. + # The nix half of `keyLeaf` in ./swarm-authelia.nix. `create` without + # `update`, so a stored key is never replaced: the storage-encryption key + # encrypts authelia's database and the issuer key signs every id token. + autheliaKeyLeaves = map (name: "swarm/services/${autheliaCfg.machine}/keys/${name}") [ + "jwt" + "session" + "storage-encryption" + "oidc-hmac" + "oidc-issuer" + ]; + + createStanza = path: '' + path "${path}" { + capabilities = ["create", "read"] + } + ''; + in { inherit @@ -276,14 +389,27 @@ in atticPushTokenLeaf atticUrlLeaf autheliaCfg + autheliaKeyLeaves baoCli baoStoreUp baoUiClientLeaf + builderForgeTokenLeaf caTrust certRoleTokenTtl + ciMetricsForgeTokenLeaf + ciRunnerTokenLeaf classifierAcpKeyLeaf classifierApiKeyLeaf + classifierForgeTokenLeaf + controllerClientLeaf + controllerForgeTokenLeaf + controllerGrafanaTokenLeaf + controllerWebhookSecretLeaf + createStanza credentialMountPath + grafanaAdminLeaf + grafanaMetricsBearerLeaf + grafanaSecretKeyLeaf granterAfter granterCn granterEnv @@ -294,6 +420,16 @@ in haveBootstrapToken haveGranter haveServerTls + issuerPublicLeaf + issuerSeedLeaf + listStanza + readStanza + swarmAppserviceRegistrationLeaf + swarmAppserviceTokenLeaf tlsDir + userPublicLeaf + userSeedLeaf + xkeyPublicLeaf + xkeySeedLeaf ; } diff --git a/nix/host-modules/swarm-bao-readers.nix b/nix/host-modules/swarm-bao-readers.nix new file mode 100644 index 000000000..3d271e8e4 --- /dev/null +++ b/nix/host-modules/swarm-bao-readers.nix @@ -0,0 +1,446 @@ +# The store's per-principal grants for the services that each read or write a +# few leaves with a leaf of their own: one policy and one cert-auth role per +# principal, written by the granter. Split out of ./swarm-bao.nix; the unit +# shape, the leaves and the stanzas it shares with the other grants are in +# ./lib/swarm-bao-shared.nix. +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.services.hyperhive.swarm.bao; + hyperhiveCfg = config.services.hyperhive; + deployCfg = hyperhiveCfg.deploy; + baoDeploy = deployCfg.bao; + shared = import ./lib/swarm-bao-shared.nix { inherit config lib pkgs; }; + inherit (shared) + atticFactLeaves + atticJwtLeaf + atticPublicKeyLeaf + atticPushTokenLeaf + builderForgeTokenLeaf + certRoleTokenTtl + ciMetricsForgeTokenLeaf + ciRunnerTokenLeaf + classifierAcpKeyLeaf + classifierApiKeyLeaf + controllerForgeTokenLeaf + controllerGrafanaTokenLeaf + createStanza + credentialMountPath + grafanaAdminLeaf + grafanaMetricsBearerLeaf + grafanaSecretKeyLeaf + granterPolicyUnit + haveServerTls + issuerPublicLeaf + issuerSeedLeaf + listStanza + readStanza + tlsDir + userPublicLeaf + userSeedLeaf + xkeyPublicLeaf + xkeySeedLeaf + ; + + # ── the principals that each hold a leaf of their own ────────────────────── + # + # 🩸 Each of these reads exactly ONE path in the store, and does it holding + # its own leaf rather than `deploy.bao.clientCertFile` — the hive's own leaf, + # whose policy (`swarm-secret-client`'s `policy::render_shared_hives`) grants read on + # `swarm/agents/*` AND `swarm/hives//*`, and nothing under + # `swarm/services/`. + # Principals presenting one certificate are ONE principal to bao, so sharing + # the hive's leaf would give each of them everything that leaf reads: a unit + # that fetches a service's OIDC client secret could fetch every agent + # credential in the swarm, and could not fetch its own secret at all, as + # that path is not the hive's to read. + # + # Each gets its own leaf, its own cert-auth role and a policy holding the + # one `secret/data/…` path that principal's script actually names — spelled + # to the LEAF rather than to a prefix, for the reason `matrixCtlPolicyText` + # above gives for doing the same. + createReadStanza = path: '' + path "${path}" { + capabilities = ["create", "read"] + } + ''; + + # 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. + # + # Grafana's leaf also creates its admin password (`swarm-bao-grafana-admin` + # in ./swarm-grafana.nix) and the bearer its metrics datasource presents + # (`swarm-bao-grafana-metrics-bearer`) and its datasource-encryption key + # (`swarm-bao-grafana-secret-key`). `create` without `update`, so a stored + # value is never replaced. + # + # The controller's Grafana token is the one it may replace: + # `swarm-bao-grafana-controller-token` mints a new one when Grafana refuses + # the stored one, as it does after its database is recreated. + grafanaOidcReaders = [ + { + name = "swarm-grafana-oidc"; + cn = baoDeploy.grafanaOidcCommonName; + policyText = + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/oidc/client" + # The journal forwarder in its container, under this same leaf. + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.grafana.otel.clientId}/oidc/client" + + createStanza "${credentialMountPath}/data/${grafanaAdminLeaf}" + + createStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" + + createStanza "${credentialMountPath}/data/${grafanaSecretKeyLeaf}" + + '' + path "${credentialMountPath}/data/${controllerGrafanaTokenLeaf}" { + capabilities = ["create", "read", "update"] + } + ''; + } + ]; + + otelOidcReaders = [ + { + name = "swarm-otel-oidc"; + cn = baoDeploy.otelOidcCommonName; + policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.otel.clientId}/oidc/client"; + } + ]; + + # The store's own forwarder. Its path is `forwarderStoreSecretPath` below with + # KV v2's `data/` inserted. + forwarderOidcReaders = [ + { + name = "swarm-forwarder-oidc"; + cn = baoDeploy.forwarderOidcCommonName; + policyText = readStanza "${credentialMountPath}/data/swarm/services/${cfg.otel.clientId}/oidc/client"; + } + ]; + + # The queue's auth-callout responder, which checks the secret an agent + # presents against the one stored for it. One leaf under every agent: `+` is + # one path segment, where `*` globs only at the end and would reach every + # other credential an agent holds. Plus the responder's own OIDC client + # secret, which it reads as it starts and again when the IdP refuses it. + # + # And the two leaves of each callout key, which `ensure-callout-keys` + # creates when the store holds no seed. `create` without `update`, so a + # stored pair is never replaced; `read` because creating is + # read-then-create, and the responder loads the seeds as it starts. + natsAuthReaders = [ + { + name = "swarm-nats-auth"; + cn = baoDeploy.natsAuthCommonName; + batchToken = true; + policyText = + readStanza "${credentialMountPath}/data/swarm/agents/+/queue" + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.nats.clientId}/oidc/client" + + lib.concatMapStrings (leaf: createStanza "${credentialMountPath}/data/${leaf}") [ + xkeySeedLeaf + xkeyPublicLeaf + issuerSeedLeaf + issuerPublicLeaf + userSeedLeaf + userPublicLeaf + ]; + } + ]; + + # The log store's auth responders: the agent one checks the secret an agent + # presents against the one stored for it (the same `+` leaf as the queue + # responder's) and reads the agent's mirrored `logs`/`metrics` grant, the other checks the bearer Grafana presents against + # Grafana's metrics bearer; and the store container's journal forwarder + # reads its own client secret under the same leaf. Nothing else. + logsAuthReaders = [ + { + name = "swarm-logs-auth"; + cn = baoDeploy.logsAuthCommonName; + batchToken = true; + policyText = + readStanza "${credentialMountPath}/data/swarm/agents/+/queue" + + readStanza "${credentialMountPath}/data/swarm/agents/+/observability" + + readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" + # The journal forwarder in the store's container, under this same leaf. + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victorialogs.otel.clientId}/oidc/client"; + } + ]; + + # The metrics store's responders under one leaf: the agent one checks the + # secret an agent presents against the one stored for it (the same `+` leaf + # as the log store's) and reads the agent's mirrored grant, the other checks the bearer Grafana presents; and the + # host unit that fetches the store container's journal forwarder secret. + # Nothing else. + metricsAuthReaders = [ + { + name = "swarm-metrics-auth"; + cn = baoDeploy.metricsAuthCommonName; + batchToken = true; + policyText = + readStanza "${credentialMountPath}/data/swarm/agents/+/queue" + + readStanza "${credentialMountPath}/data/swarm/agents/+/observability" + + readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" + # The metrics store container's journal forwarder, fetched on its host. + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victoriametrics.otel.clientId}/oidc/client"; + } + ]; + + # The CI runner's token fetch. The one reader of the path, which the + # controller writes and cannot read back. + ciRunnerReaders = [ + { + name = "swarm-ci-runner"; + cn = baoDeploy.ciRunnerCommonName; + policyText = + readStanza "${credentialMountPath}/data/${ciRunnerTokenLeaf}" + # The journal forwarder in the runner's container, under this same leaf. + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.ci-runner.otel.clientId}/oidc/client"; + } + ]; + + # The review classifier: the API key and the ACP provider key the operator + # writes, the one its run's runtime needs read once per run, and its own + # queue client secret, read at start. All by the daemon inside its + # container. + reviewClassifierReaders = [ + { + name = "swarm-review-classifier"; + cn = baoDeploy.reviewClassifierCommonName; + policyText = + readStanza "${credentialMountPath}/data/${classifierApiKeyLeaf}" + + readStanza "${credentialMountPath}/data/${classifierAcpKeyLeaf}" + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.review-classifier.clientId}/oidc/client"; + } + ]; + + # The swarm builder: its forge token, read once per build, the cache push token, + # read once per push, and its own queue client secret, read at start. All by the + # daemon inside its container. + builderReaders = [ + { + name = "swarm-builder"; + cn = baoDeploy.builderCommonName; + policyText = + readStanza "${credentialMountPath}/data/${builderForgeTokenLeaf}" + + readStanza "${credentialMountPath}/data/${atticPushTokenLeaf}" + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.builder.clientId}/oidc/client"; + } + ]; + + # The in-swarm cache's six secrets: create and read, so a rewrite of a signing + # key or a token an operator holds is refused. The public key also gets + # `update`: the cache's host unit replaces it when a re-created cache signs + # with another. The cache container's journal forwarder reads its client + # secret under the same leaf. + atticWriters = [ + { + name = "swarm-attic"; + cn = baoDeploy.atticCommonName; + policyText = + lib.concatMapStrings + (leaf: '' + path "${credentialMountPath}/data/${leaf}" { + capabilities = ["create", "read"] + } + '') + ( + [ + atticJwtLeaf + atticPushTokenLeaf + ] + ++ lib.remove atticPublicKeyLeaf atticFactLeaves + ) + + '' + path "${credentialMountPath}/data/${atticPublicKeyLeaf}" { + capabilities = ["create", "read", "update"] + } + '' + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.attic.otel.clientId}/oidc/client"; + } + ]; + + # 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. It also creates the marker that tells the + # controller an archive exists. With an external S3 backend it reads the + # provider key, which the operator writes. + archiveReaders = [ + { + name = "swarm-archive"; + cn = baoDeploy.archiveCommonName; + policyText = + readStanza "${credentialMountPath}/data/swarm/services/archive/users/*" + + readStanza "${credentialMountPath}/data/swarm/services/archive/restic/*" + + readStanza "${credentialMountPath}/data/swarm/services/archive/s3/*" + + listStanza "${credentialMountPath}/metadata/swarm/services/archive/users/" + + createReadStanza "${credentialMountPath}/data/swarm/services/archive/ready"; + } + ]; + + # The CI run poller: its forge token and its own OIDC client secret, both + # read once per pass by the host unit. + ciMetricsReaders = [ + { + name = "swarm-ci-metrics"; + cn = baoDeploy.ciMetricsCommonName; + policyText = + readStanza "${credentialMountPath}/data/${ciMetricsForgeTokenLeaf}" + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.ci-metrics.clientId}/oidc/client"; + } + ]; + + # 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; the leaf's metadata, to say when it was written (`read`) and to + # delete every version of it (`delete`; the `data/` path's delete would leave + # the older versions, each a live session), never the credential itself; 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"] + } + path "${credentialMountPath}/metadata/swarm/agents/+/claude-credentials" { + capabilities = ["read", "delete"] + } + '' + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.claude-login.clientId}/oidc/client"; + } + ]; + + # The notification router: its own queue client secret, read at start by the + # daemon inside its container, and nothing else. + notifyRouterReaders = [ + { + name = "swarm-notify-router"; + cn = baoDeploy.notifyRouterCommonName; + policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.notify-router.clientId}/oidc/client"; + } + ]; + + # The speech-to-text service: its own queue client secret, read at start by + # the daemon inside its container, and nothing else. + sttReaders = [ + { + name = "swarm-stt"; + cn = baoDeploy.sttCommonName; + policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.stt.clientId}/oidc/client"; + } + ]; + + # The forge host's one store identity. The forge's + # `forgejo-swarm-controller-account`, in its container, writes the + # controller's forge token under it, the one writer of that path and + # write-only: it puts the token it mints and never reads one back. + # `swarm-bao-forge-oidc` reads the forge's own OIDC client secret, and the + # journal forwarder in its container its own, those two leaves and no other + # service's. + forgePublisherWriters = [ + { + name = "swarm-forge-publisher"; + cn = baoDeploy.forgePublisherCommonName; + policyText = '' + path "${credentialMountPath}/data/${controllerForgeTokenLeaf}" { + capabilities = ["create", "update"] + } + '' + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.forge.sso.clientId}/oidc/client" + # The journal forwarder in the forge's container, under this same leaf. + + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.forge.otel.clientId}/oidc/client"; + } + ]; + + # The role name IS the policy name, as for the three service principals + # above: the role attaches the policy by spelling it identically, and one + # string for both objects removes the way they drift apart. + readerPolicyWrite = obj: '' + printf '%s' ${lib.escapeShellArg obj.policyText} | + bao policy write ${lib.escapeShellArg obj.name} - + ''; + + # ⚠️ Names are `swarm-[-]`, outside the `hive-*` namespace the + # controller may rewrite, for the reason the three service principals above + # state. A per-hive CN cannot collide with a hive's own leaf either — a hive's + # CN is its bare name and ../reserved-hive-fragments.nix forbids the substring + # `swarm` in one — and ./swarm.nix reserves the concrete per-hive spellings + # anyway, because the prefixes are operator-settable and an operator may spell + # one without that substring. + # + # `batchToken = true` on an object makes its logins batch tokens, which the + # store does not persist and cannot renew or revoke. Only for a principal + # that logs in, reads and drops the token within one call: the five + # minutes outlast that read, and a leaked token dies as fast. A principal + # that holds a handle longer must not set it. + readerRoleWrite = + obj: + let + ttlArgs = + if obj.batchToken or false then + " \\\n token_type=batch \\\n token_ttl=5m" + else + " \\\n token_ttl=${certRoleTokenTtl} \\\n token_max_ttl=${certRoleTokenTtl}"; + in + '' + bao write auth/cert/certs/${lib.escapeShellArg obj.name} \ + certificate=@${tlsDir}/client-ca.pem \ + allowed_common_names=${lib.escapeShellArg obj.cn} \ + token_policies=${lib.escapeShellArg obj.name} \ + display_name=${lib.escapeShellArg obj.cn}${ttlArgs} + ''; + + # One unit per PRINCIPAL, not one unit for all of them: these names are + # operator-facing strings, the same reason `swarm-bao-secret-publisher-policy` + # below gives for not being more script inside the controller's unit. A + # reader whose secret never arrives is diagnosed by the state of the unit + # named after it. + readerPolicyUnit = + description: objects: + granterPolicyUnit description ( + lib.concatMapStrings readerPolicyWrite objects + "\n" + lib.concatMapStrings readerRoleWrite objects + ); + +in +{ + config = lib.mkIf (deployCfg.bao.enable && haveServerTls) { + # 🩸 The principals that each log in with a leaf of their own, not as the + # hive. See the lists in this file for what each grant is; the + # units are identical apart from the objects they write, so the shape + # lives in `readerPolicyUnit` and the difference is visible here in one + # line each. + systemd.services.swarm-bao-grafana-oidc-policy = readerPolicyUnit "write Grafana's OIDC-secret-reader bao policy and cert-auth role" grafanaOidcReaders; + + systemd.services.swarm-bao-otel-oidc-policy = readerPolicyUnit "write the collector's OIDC-secret-reader bao policy and cert-auth role" otelOidcReaders; + + systemd.services.swarm-bao-forwarder-oidc-policy = readerPolicyUnit "write the store forwarder's OIDC-secret-reader bao policy and cert-auth role" forwarderOidcReaders; + + systemd.services.swarm-bao-nats-auth-policy = readerPolicyUnit "write the queue responder's agent-credential-reader bao policy and cert-auth role" natsAuthReaders; + + systemd.services.swarm-bao-logs-auth-policy = readerPolicyUnit "write the log store responder's agent-credential-reader bao policy and cert-auth role" logsAuthReaders; + + systemd.services.swarm-bao-metrics-auth-policy = readerPolicyUnit "write the metrics store responder's Grafana-bearer-reader bao policy and cert-auth role" metricsAuthReaders; + + systemd.services.swarm-bao-ci-runner-policy = readerPolicyUnit "write the CI runner's registration-token-reader bao policy and cert-auth role" ciRunnerReaders; + + systemd.services.swarm-bao-review-classifier-policy = readerPolicyUnit "write the review classifier's API-key-reader bao policy and cert-auth role" reviewClassifierReaders; + + 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-ci-metrics-policy = readerPolicyUnit "write the CI run poller's forge-token-reader bao policy and cert-auth role" ciMetricsReaders; + + 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-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-stt-policy = readerPolicyUnit "write the speech-to-text service's client-secret-reader bao policy and cert-auth role" sttReaders; + + systemd.services.swarm-bao-forge-publisher-policy = readerPolicyUnit "write the forge's controller-token-publisher bao policy and cert-auth role" forgePublisherWriters; + }; +} diff --git a/nix/host-modules/swarm-bao.nix b/nix/host-modules/swarm-bao.nix index 29ea1e895..9ad05ce64 100644 --- a/nix/host-modules/swarm-bao.nix +++ b/nix/host-modules/swarm-bao.nix @@ -48,14 +48,26 @@ let atticPublicKeyLeaf atticPushTokenLeaf autheliaCfg + autheliaKeyLeaves baoCli baoStoreUp baoUiClientLeaf + builderForgeTokenLeaf caTrust certRoleTokenTtl + ciMetricsForgeTokenLeaf + ciRunnerTokenLeaf classifierAcpKeyLeaf classifierApiKeyLeaf + classifierForgeTokenLeaf + controllerClientLeaf + controllerForgeTokenLeaf + controllerGrafanaTokenLeaf + controllerWebhookSecretLeaf + createStanza credentialMountPath + grafanaAdminLeaf + grafanaSecretKeyLeaf granterAfter granterCn granterEnv @@ -66,7 +78,14 @@ let haveBootstrapToken haveGranter haveServerTls + issuerSeedLeaf + listStanza + readStanza + swarmAppserviceRegistrationLeaf + swarmAppserviceTokenLeaf tlsDir + userSeedLeaf + xkeySeedLeaf ; # What this container's own collector stamps as `service.name` on every @@ -735,56 +754,6 @@ let + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.matrix.sso.clientId}/oidc/client" + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.matrix.otel.clientId}/oidc/client"; - # The swarm appservice token's leaf, the nix half of - # `swarm_secret_client::matrix::swarm_appservice_token_path`. Under - # `controller/`, the one kind no hive's policy reads: its sender is the - # homeserver's admin. - swarmAppserviceTokenLeaf = "swarm/controller/swarm-controller/matrix/appservice-token"; - - # The swarm appservice registration's leaf, the nix half of - # `swarm_secret_client::matrix::swarm_appservice_registration_path`. Only - # matrix-ctl reaches it; the controller reads the token above, not this. - swarmAppserviceRegistrationLeaf = "swarm/controller/swarm-controller/matrix/appservice-registration"; - - # The controller's own OIDC client secret, the nix half of - # `swarm_secret_client::queue::controller_client_path`. Authelia's mint writes - # it; the controller reads it and holds no other copy. - controllerClientLeaf = "swarm/controller/swarm-controller/oidc/client"; - - # The controller's own forge token, the nix half of - # `swarm_secret_client::forge::controller_token_path`. The forge's host writes - # it; the controller reads it and holds no other copy. - controllerForgeTokenLeaf = "swarm/controller/swarm-controller/forge/token"; - - # The controller's Viewer token for Grafana's API, the nix half of - # `swarm_secret_client::grafana::controller_token_path`. Grafana's host - # writes it; the controller reads it and holds no other copy. - controllerGrafanaTokenLeaf = "swarm/controller/swarm-controller/grafana/token"; - - # The HMAC secret of the swarm-wide forge webhooks, the nix half of - # `swarm_secret_client::forge::controller_webhook_secret_path`. The controller - # creates it, seeded from its old state-directory file, and reads it; `create` - # without `update`, so the first value stored is the one every start reads. - controllerWebhookSecretLeaf = "swarm/controller/swarm-controller/forge/webhook-secret"; - - # The forge's runner registration token, the nix half of - # `swarm_secret_client::ci::registration_token_path`. The controller writes - # it and cannot read it back (`forge::runner_token` keeps the value it last - # wrote in memory); the CI runner's fetch unit is its one reader. - ciRunnerTokenLeaf = "swarm/services/ci-runner/registration-token"; - - # The review classifier's forge token, the nix half of - # `swarm_secret_client::review_classifier::forge_token_path`. The controller - # mints it, reads it back before deciding whether to re-mint, and posts the - # classifier's reviews with it; no other principal's policy reaches it. - classifierForgeTokenLeaf = "swarm/services/review-classifier/forge/token"; - - # The swarm builder's forge token, the nix half of - # `swarm_secret_client::builder::forge_token_path`. The controller mints it - # and reads it back before deciding whether to re-mint; the builder reads it - # to fetch config repos. - builderForgeTokenLeaf = "swarm/services/builder/forge/token"; - atticHiveFactNames = [ "pull-token" "url" @@ -792,12 +761,6 @@ let "public-key" ]; - # The CI run poller's forge token, the nix half of - # `swarm_secret_client::ci_metrics::forge_token_path`. The controller mints it - # and reads it back before deciding whether to re-mint; the poller reads it - # to list runs. - ciMetricsForgeTokenLeaf = "swarm/services/ci-metrics/forge/token"; - # The PKI engine the swarm's *service* certificates are to be issued from, # named once for the same reason `credentialMountPath` is: the role below, # the grant that points at `pki/issue/`, and the `secrets enable` in the @@ -1091,420 +1054,6 @@ let } ''; - # ── the principals that each hold a leaf of their own ────────────────────── - # - # 🩸 Each of these reads exactly ONE path in the store, and does it holding - # its own leaf rather than `deploy.bao.clientCertFile` — the hive's own leaf, - # whose policy (`swarm-secret-client`'s `policy::render_shared_hives`) grants read on - # `swarm/agents/*` AND `swarm/hives//*`, and nothing under - # `swarm/services/`. - # Principals presenting one certificate are ONE principal to bao, so sharing - # the hive's leaf would give each of them everything that leaf reads: a unit - # that fetches a service's OIDC client secret could fetch every agent - # credential in the swarm, and could not fetch its own secret at all, as - # that path is not the hive's to read. - # - # Each gets its own leaf, its own cert-auth role and a policy holding the - # one `secret/data/…` path that principal's script actually names — spelled - # to the LEAF rather than to a prefix, for the reason `matrixCtlPolicyText` - # above gives for doing the same. - readStanza = path: '' - path "${path}" { - capabilities = ["read"] - } - ''; - - createReadStanza = path: '' - path "${path}" { - capabilities = ["create", "read"] - } - ''; - - 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. - # - # Grafana's leaf also creates its admin password (`swarm-bao-grafana-admin` - # in ./swarm-grafana.nix) and the bearer its metrics datasource presents - # (`swarm-bao-grafana-metrics-bearer`) and its datasource-encryption key - # (`swarm-bao-grafana-secret-key`). `create` without `update`, so a stored - # value is never replaced. - # - # The controller's Grafana token is the one it may replace: - # `swarm-bao-grafana-controller-token` mints a new one when Grafana refuses - # the stored one, as it does after its database is recreated. - grafanaOidcReaders = [ - { - name = "swarm-grafana-oidc"; - cn = baoDeploy.grafanaOidcCommonName; - policyText = - readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/oidc/client" - # The journal forwarder in its container, under this same leaf. - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.grafana.otel.clientId}/oidc/client" - + createStanza "${credentialMountPath}/data/${grafanaAdminLeaf}" - + createStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" - + createStanza "${credentialMountPath}/data/${grafanaSecretKeyLeaf}" - + '' - path "${credentialMountPath}/data/${controllerGrafanaTokenLeaf}" { - capabilities = ["create", "read", "update"] - } - ''; - } - ]; - - otelOidcReaders = [ - { - name = "swarm-otel-oidc"; - cn = baoDeploy.otelOidcCommonName; - policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.otel.clientId}/oidc/client"; - } - ]; - - # The store's own forwarder. Its path is `forwarderStoreSecretPath` below with - # KV v2's `data/` inserted. - forwarderOidcReaders = [ - { - name = "swarm-forwarder-oidc"; - cn = baoDeploy.forwarderOidcCommonName; - policyText = readStanza "${credentialMountPath}/data/swarm/services/${cfg.otel.clientId}/oidc/client"; - } - ]; - - # The queue's auth-callout responder, which checks the secret an agent - # presents against the one stored for it. One leaf under every agent: `+` is - # one path segment, where `*` globs only at the end and would reach every - # other credential an agent holds. Plus the responder's own OIDC client - # secret, which it reads as it starts and again when the IdP refuses it. - # - # And the two leaves of each callout key, which `ensure-callout-keys` - # creates when the store holds no seed. `create` without `update`, so a - # stored pair is never replaced; `read` because creating is - # read-then-create, and the responder loads the seeds as it starts. - natsAuthReaders = [ - { - name = "swarm-nats-auth"; - cn = baoDeploy.natsAuthCommonName; - batchToken = true; - policyText = - readStanza "${credentialMountPath}/data/swarm/agents/+/queue" - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.nats.clientId}/oidc/client" - + lib.concatMapStrings (leaf: createStanza "${credentialMountPath}/data/${leaf}") [ - xkeySeedLeaf - xkeyPublicLeaf - issuerSeedLeaf - issuerPublicLeaf - userSeedLeaf - userPublicLeaf - ]; - } - ]; - - # The callout's keys, the nix half of `swarm-nats-auth`'s `xkey::SEED_PATH` - # and `xkey::PUBLIC_PATH`, and of the `seed_path` and `public_path` of - # `nkey::ISSUER` and `nkey::USER`. All are readable by the `swarm-nats-auth` - # role alone: `swarm/public/` marks the halves that are no secret, and no - # policy opens them to every token. - xkeySeedLeaf = "swarm/services/swarm-nats/callout/xkey-seed"; - xkeyPublicLeaf = "swarm/public/swarm-nats/callout-xkey"; - issuerSeedLeaf = "swarm/services/swarm-nats/callout/issuer-seed"; - issuerPublicLeaf = "swarm/public/swarm-nats/callout-issuer"; - userSeedLeaf = "swarm/services/swarm-nats/callout/user-seed"; - userPublicLeaf = "swarm/public/swarm-nats/callout-user"; - - # Grafana's admin password, which only Grafana's leaf creates. The nix half - # of `adminPasswordStorePath` in ./swarm-grafana.nix. - grafanaAdminLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/admin/password"; - - # The bearer Grafana's datasources present at the metrics and log stores. - # Grafana's leaf creates it, the stores' responders read it. The nix half of - # `metricsBearerStorePath` in ./swarm-grafana.nix and of `--store-path` in - # ./swarm-victoriametrics.nix and ./swarm-victorialogs.nix. - grafanaMetricsBearerLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/metrics/bearer"; - - # Grafana's datasource-encryption key, which only Grafana's leaf creates. The - # nix half of `secretKeyStorePath` in ./swarm-grafana.nix. - grafanaSecretKeyLeaf = "swarm/services/${hyperhiveCfg.swarm.grafana.oidc.clientId}/secret-key"; - - # authelia's jwt, session, storage-encryption, OIDC HMAC and OIDC issuer keys, - # which only `authelia-swarm-secrets` in authelia's container creates and reads. - # The nix half of `keyLeaf` in ./swarm-authelia.nix. `create` without - # `update`, so a stored key is never replaced: the storage-encryption key - # encrypts authelia's database and the issuer key signs every id token. - autheliaKeyLeaves = map (name: "swarm/services/${autheliaCfg.machine}/keys/${name}") [ - "jwt" - "session" - "storage-encryption" - "oidc-hmac" - "oidc-issuer" - ]; - - createStanza = path: '' - path "${path}" { - capabilities = ["create", "read"] - } - ''; - - # The log store's auth responders: the agent one checks the secret an agent - # presents against the one stored for it (the same `+` leaf as the queue - # responder's) and reads the agent's mirrored `logs`/`metrics` grant, the other checks the bearer Grafana presents against - # Grafana's metrics bearer; and the store container's journal forwarder - # reads its own client secret under the same leaf. Nothing else. - logsAuthReaders = [ - { - name = "swarm-logs-auth"; - cn = baoDeploy.logsAuthCommonName; - batchToken = true; - policyText = - readStanza "${credentialMountPath}/data/swarm/agents/+/queue" - + readStanza "${credentialMountPath}/data/swarm/agents/+/observability" - + readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" - # The journal forwarder in the store's container, under this same leaf. - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victorialogs.otel.clientId}/oidc/client"; - } - ]; - - # The metrics store's responders under one leaf: the agent one checks the - # secret an agent presents against the one stored for it (the same `+` leaf - # as the log store's) and reads the agent's mirrored grant, the other checks the bearer Grafana presents; and the - # host unit that fetches the store container's journal forwarder secret. - # Nothing else. - metricsAuthReaders = [ - { - name = "swarm-metrics-auth"; - cn = baoDeploy.metricsAuthCommonName; - batchToken = true; - policyText = - readStanza "${credentialMountPath}/data/swarm/agents/+/queue" - + readStanza "${credentialMountPath}/data/swarm/agents/+/observability" - + readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}" - # The metrics store container's journal forwarder, fetched on its host. - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victoriametrics.otel.clientId}/oidc/client"; - } - ]; - - # The CI runner's token fetch. The one reader of the path, which the - # controller writes and cannot read back. - ciRunnerReaders = [ - { - name = "swarm-ci-runner"; - cn = baoDeploy.ciRunnerCommonName; - policyText = - readStanza "${credentialMountPath}/data/${ciRunnerTokenLeaf}" - # The journal forwarder in the runner's container, under this same leaf. - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.ci-runner.otel.clientId}/oidc/client"; - } - ]; - - # The review classifier: the API key and the ACP provider key the operator - # writes, the one its run's runtime needs read once per run, and its own - # queue client secret, read at start. All by the daemon inside its - # container. - reviewClassifierReaders = [ - { - name = "swarm-review-classifier"; - cn = baoDeploy.reviewClassifierCommonName; - policyText = - readStanza "${credentialMountPath}/data/${classifierApiKeyLeaf}" - + readStanza "${credentialMountPath}/data/${classifierAcpKeyLeaf}" - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.review-classifier.clientId}/oidc/client"; - } - ]; - - # The swarm builder: its forge token, read once per build, the cache push token, - # read once per push, and its own queue client secret, read at start. All by the - # daemon inside its container. - builderReaders = [ - { - name = "swarm-builder"; - cn = baoDeploy.builderCommonName; - policyText = - readStanza "${credentialMountPath}/data/${builderForgeTokenLeaf}" - + readStanza "${credentialMountPath}/data/${atticPushTokenLeaf}" - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.builder.clientId}/oidc/client"; - } - ]; - - # The in-swarm cache's six secrets: create and read, so a rewrite of a signing - # key or a token an operator holds is refused. The public key also gets - # `update`: the cache's host unit replaces it when a re-created cache signs - # with another. The cache container's journal forwarder reads its client - # secret under the same leaf. - atticWriters = [ - { - name = "swarm-attic"; - cn = baoDeploy.atticCommonName; - policyText = - lib.concatMapStrings - (leaf: '' - path "${credentialMountPath}/data/${leaf}" { - capabilities = ["create", "read"] - } - '') - ( - [ - atticJwtLeaf - atticPushTokenLeaf - ] - ++ lib.remove atticPublicKeyLeaf atticFactLeaves - ) - + '' - path "${credentialMountPath}/data/${atticPublicKeyLeaf}" { - capabilities = ["create", "read", "update"] - } - '' - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.attic.otel.clientId}/oidc/client"; - } - ]; - - # 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. It also creates the marker that tells the - # controller an archive exists. With an external S3 backend it reads the - # provider key, which the operator writes. - archiveReaders = [ - { - name = "swarm-archive"; - cn = baoDeploy.archiveCommonName; - policyText = - readStanza "${credentialMountPath}/data/swarm/services/archive/users/*" - + readStanza "${credentialMountPath}/data/swarm/services/archive/restic/*" - + readStanza "${credentialMountPath}/data/swarm/services/archive/s3/*" - + listStanza "${credentialMountPath}/metadata/swarm/services/archive/users/" - + createReadStanza "${credentialMountPath}/data/swarm/services/archive/ready"; - } - ]; - - # The CI run poller: its forge token and its own OIDC client secret, both - # read once per pass by the host unit. - ciMetricsReaders = [ - { - name = "swarm-ci-metrics"; - cn = baoDeploy.ciMetricsCommonName; - policyText = - readStanza "${credentialMountPath}/data/${ciMetricsForgeTokenLeaf}" - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.ci-metrics.clientId}/oidc/client"; - } - ]; - - # 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; the leaf's metadata, to say when it was written (`read`) and to - # delete every version of it (`delete`; the `data/` path's delete would leave - # the older versions, each a live session), never the credential itself; 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"] - } - path "${credentialMountPath}/metadata/swarm/agents/+/claude-credentials" { - capabilities = ["read", "delete"] - } - '' - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.claude-login.clientId}/oidc/client"; - } - ]; - - # The notification router: its own queue client secret, read at start by the - # daemon inside its container, and nothing else. - notifyRouterReaders = [ - { - name = "swarm-notify-router"; - cn = baoDeploy.notifyRouterCommonName; - policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.notify-router.clientId}/oidc/client"; - } - ]; - - # The speech-to-text service: its own queue client secret, read at start by - # the daemon inside its container, and nothing else. - sttReaders = [ - { - name = "swarm-stt"; - cn = baoDeploy.sttCommonName; - policyText = readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.stt.clientId}/oidc/client"; - } - ]; - - # The forge host's one store identity. The forge's - # `forgejo-swarm-controller-account`, in its container, writes the - # controller's forge token under it, the one writer of that path and - # write-only: it puts the token it mints and never reads one back. - # `swarm-bao-forge-oidc` reads the forge's own OIDC client secret, and the - # journal forwarder in its container its own, those two leaves and no other - # service's. - forgePublisherWriters = [ - { - name = "swarm-forge-publisher"; - cn = baoDeploy.forgePublisherCommonName; - policyText = '' - path "${credentialMountPath}/data/${controllerForgeTokenLeaf}" { - capabilities = ["create", "update"] - } - '' - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.forge.sso.clientId}/oidc/client" - # The journal forwarder in the forge's container, under this same leaf. - + readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.forge.otel.clientId}/oidc/client"; - } - ]; - - # The role name IS the policy name, as for the three service principals - # above: the role attaches the policy by spelling it identically, and one - # string for both objects removes the way they drift apart. - readerPolicyWrite = obj: '' - printf '%s' ${lib.escapeShellArg obj.policyText} | - bao policy write ${lib.escapeShellArg obj.name} - - ''; - - # ⚠️ Names are `swarm-[-]`, outside the `hive-*` namespace the - # controller may rewrite, for the reason the three service principals above - # state. A per-hive CN cannot collide with a hive's own leaf either — a hive's - # CN is its bare name and ../reserved-hive-fragments.nix forbids the substring - # `swarm` in one — and ./swarm.nix reserves the concrete per-hive spellings - # anyway, because the prefixes are operator-settable and an operator may spell - # one without that substring. - # - # `batchToken = true` on an object makes its logins batch tokens, which the - # store does not persist and cannot renew or revoke. Only for a principal - # that logs in, reads and drops the token within one call: the five - # minutes outlast that read, and a leaked token dies as fast. A principal - # that holds a handle longer must not set it. - readerRoleWrite = - obj: - let - ttlArgs = - if obj.batchToken or false then - " \\\n token_type=batch \\\n token_ttl=5m" - else - " \\\n token_ttl=${certRoleTokenTtl} \\\n token_max_ttl=${certRoleTokenTtl}"; - in - '' - bao write auth/cert/certs/${lib.escapeShellArg obj.name} \ - certificate=@${tlsDir}/client-ca.pem \ - allowed_common_names=${lib.escapeShellArg obj.cn} \ - token_policies=${lib.escapeShellArg obj.name} \ - display_name=${lib.escapeShellArg obj.cn}${ttlArgs} - ''; - - # One unit per PRINCIPAL, not one unit for all of them: these names are - # operator-facing strings, the same reason `swarm-bao-secret-publisher-policy` - # below gives for not being more script inside the controller's unit. A - # reader whose secret never arrives is diagnosed by the state of the unit - # named after it. - readerPolicyUnit = - description: objects: - granterPolicyUnit description ( - lib.concatMapStrings readerPolicyWrite objects + "\n" + lib.concatMapStrings readerRoleWrite objects - ); - # Every listener serves the same identity: they differ in which address # they answer on, not in who they are. Client verification is separate and # optional — a store with no `clientCaFile` still serves TLS, it just does @@ -3896,43 +3445,6 @@ in token_max_ttl=${certRoleTokenTtl} ''; - # 🩸 The principals that each log in with a leaf of their own, not as the - # hive. See the block around `readStanza` for what each grant is; the - # units are identical apart from the objects they write, so the shape - # lives in `readerPolicyUnit` and the difference is visible here in one - # line each. - systemd.services.swarm-bao-grafana-oidc-policy = readerPolicyUnit "write Grafana's OIDC-secret-reader bao policy and cert-auth role" grafanaOidcReaders; - - systemd.services.swarm-bao-otel-oidc-policy = readerPolicyUnit "write the collector's OIDC-secret-reader bao policy and cert-auth role" otelOidcReaders; - - systemd.services.swarm-bao-forwarder-oidc-policy = readerPolicyUnit "write the store forwarder's OIDC-secret-reader bao policy and cert-auth role" forwarderOidcReaders; - - systemd.services.swarm-bao-nats-auth-policy = readerPolicyUnit "write the queue responder's agent-credential-reader bao policy and cert-auth role" natsAuthReaders; - - systemd.services.swarm-bao-logs-auth-policy = readerPolicyUnit "write the log store responder's agent-credential-reader bao policy and cert-auth role" logsAuthReaders; - - systemd.services.swarm-bao-metrics-auth-policy = readerPolicyUnit "write the metrics store responder's Grafana-bearer-reader bao policy and cert-auth role" metricsAuthReaders; - - systemd.services.swarm-bao-ci-runner-policy = readerPolicyUnit "write the CI runner's registration-token-reader bao policy and cert-auth role" ciRunnerReaders; - - systemd.services.swarm-bao-review-classifier-policy = readerPolicyUnit "write the review classifier's API-key-reader bao policy and cert-auth role" reviewClassifierReaders; - - 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-ci-metrics-policy = readerPolicyUnit "write the CI run poller's forge-token-reader bao policy and cert-auth role" ciMetricsReaders; - - 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-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-stt-policy = readerPolicyUnit "write the speech-to-text service's client-secret-reader bao policy and cert-auth role" sttReaders; - - 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 # one is what turns `swarm-services-issuer` from a declaration into a # grant: a bao policy reaches nothing until a login role hands it to a