Watch
0
0
Fork
You've already forked hyperhive
0

bao: the queue pod's two jwt roles share one ServiceAccount

This commit is contained in:
atlas 2026-11-22 17:31:51 +01:00 • committed by maia
commit 1c8798a3ca
3 changed files with 27 additions and 9 deletions

View file

@ -470,6 +470,9 @@ let
# by spelling it the same way, and is itself named after it. # by spelling it the same way, and is itself named after it.
controllerPolicyName = "swarm-controller"; controllerPolicyName = "swarm-controller";
# The queue's principal: its policy and its cert-auth role carry this name.
natsPolicyName = "swarm-nats";
in in
{ {
inherit inherit
@ -525,6 +528,7 @@ in
listStanza listStanza
openbaoStartSec openbaoStartSec
openbaoStopSec openbaoStopSec
natsPolicyName
readStanza readStanza
refreshConsumer refreshConsumer
servicesPkiRootLabel servicesPkiRootLabel

View file

@ -35,6 +35,7 @@ let
controllerForgeTokenLeaf controllerForgeTokenLeaf
controllerGrafanaTokenLeaf controllerGrafanaTokenLeaf
controllerPolicyName controllerPolicyName
natsPolicyName
createStanza createStanza
credentialMountPath credentialMountPath
grafanaAdminLeaf grafanaAdminLeaf
@ -417,16 +418,27 @@ let
++ reviewClassifierReaders ++ reviewClassifierReaders
++ claudeLoginWriters ++ claudeLoginWriters
++ ciMetricsReaders ++ ciMetricsReaders
++ [ { name = controllerPolicyName; } ]; ++ [ { name = controllerPolicyName; } ]
# The queue's pod holds both of its roles under one ServiceAccount: the
# server's leaf is issued with `swarm-nats`, and the responder reads its
# keys and credentials with `swarm-nats-auth`.
++ map (obj: obj // { serviceAccount = natsPodAccount; }) (
[ { name = natsPolicyName; } ] ++ natsAuthReaders
);
# The jwt role of one principal: the token of exactly its ServiceAccount, for # The ServiceAccount the queue's pod runs under, as ../k8s/render.nix names
# this store's audience. Both the subject and the audience are bound, so a # it: the pod is the service `swarm-nats`.
natsPodAccount = "swarm-nats";
# The jwt role of one principal: the token of exactly its ServiceAccount (the
# one of its name, unless the record names another), for this store's
# audience. Both the subject and the audience are bound, so a
# token of another account, or one minted for the Kubernetes API, is refused. # token of another account, or one minted for the Kubernetes API, is refused.
k8sJwtRoleWrite = obj: '' k8sJwtRoleWrite = obj: ''
bao write auth/${podAuth.mount}/role/${lib.escapeShellArg obj.name} \ bao write auth/${podAuth.mount}/role/${lib.escapeShellArg obj.name} \
role_type=jwt \ role_type=jwt \
user_claim=sub \ user_claim=sub \
bound_subject=${lib.escapeShellArg "system:serviceaccount:${hyperhiveCfg.k8s.namespace}:${obj.name}"} \ bound_subject=${lib.escapeShellArg "system:serviceaccount:${hyperhiveCfg.k8s.namespace}:${obj.serviceAccount or obj.name}"} \
bound_audiences=${lib.escapeShellArg podAuth.audience} \ bound_audiences=${lib.escapeShellArg podAuth.audience} \
token_policies=${lib.escapeShellArg obj.name}${roleTokenArgs obj} token_policies=${lib.escapeShellArg obj.name}${roleTokenArgs obj}
''; '';
@ -450,10 +462,12 @@ in
internal = true; internal = true;
default = map (p: p.name) k8sPrincipals; default = map (p: p.name) k8sPrincipals;
description = '' description = ''
The in-cluster services that log in to the store with a ServiceAccount The principals of the in-cluster services that log in to the store with
token. Each is one principal: its cert-auth role and its jwt role carry a ServiceAccount token. Each is one principal: its cert-auth role and
the same name, policy and token lifetimes, and its pod runs under a its jwt role carry the same name, policy and token lifetimes, and its
ServiceAccount of that name. pod runs under a ServiceAccount of that name. The queue's pod is the
exception: it holds two principals, `swarm-nats` and
`swarm-nats-auth`, under the one ServiceAccount `swarm-nats`.
''; '';
}; };

View file

@ -74,6 +74,7 @@ let
controllerGrafanaTokenLeaf controllerGrafanaTokenLeaf
controllerPolicyName controllerPolicyName
controllerWebhookSecretLeaf controllerWebhookSecretLeaf
natsPolicyName
createStanza createStanza
credentialMountPath credentialMountPath
grafanaAdminLeaf grafanaAdminLeaf
@ -899,7 +900,6 @@ let
# The queue's principal: one `update` on its own role, the shape of the # The queue's principal: one `update` on its own role, the shape of the
# services issuer's grant above, narrowed to one name by the role itself. # services issuer's grant above, narrowed to one name by the role itself.
natsPolicyName = "swarm-nats";
natsCn = baoDeploy.natsCommonName; natsCn = baoDeploy.natsCommonName;
natsPkiRoleName = baoDeploy.natsPkiRoleName; natsPkiRoleName = baoDeploy.natsPkiRoleName;
natsPolicyText = '' natsPolicyText = ''