Watch
0
0
Fork
You've already forked hyperhive
0

k8s: pods log in to the secret store with their ServiceAccount token

The store gets a listener for the pods that asks for no client certificate,
open on the pod network's interfaces only, and a jwt auth mount with one
role per in-cluster service. The rendered pods run under a ServiceAccount
with a projected token in place of their client certificate.
This commit is contained in:
atlas 2026-11-21 14:03:28 +01:00 • committed by maia
commit 2a6b0ee00a

View file

@ -28,6 +28,9 @@ service images loaded and no service's objects applied.
bridge's default subnet.
- **Firewall:** the pod network's interfaces, `cni0` and `flannel.1`, are
trusted, so the node reaches its pods.
- **Secret store:** the store gets a second listener and an auth mount for the
pods' ServiceAccount tokens, described under
[Logging in to the secret store](#logging-in-to-the-secret-store).
## What it leaves alone
@ -58,12 +61,53 @@ address to answer with, so it gets no ConfigMap.
The firewall trusts the pod network's interfaces, so a pod reaches
these listeners without a firewall rule per port. Each service still
authenticates its callers: the secret store refuses a connection without a
client certificate.
authenticates its callers: every listener of the secret store but its pods'
one refuses a connection without a client certificate.
## Logging in to the secret store
A pod holds no client certificate. It logs in to the secret store with a
ServiceAccount token the kubelet projects into it, and the store checks that
token against the node's own signing keys.
- **Listener:** the store binds a listener on the hive bridge's address at
`deploy.bao.podListenerPort` (default `8208`). It serves the store's server
certificate and asks for no client certificate. A pod dials it by the name it
dials the store by, `bao.<swarm domain>`, which CoreDNS answers with the
bridge's address.
- **Firewall:** that port is open on `cni0` and `flannel.1` and on no other
interface. The bridge's firewall refuses it, so an agent on the bridge can't
connect. Binding an address doesn't isolate a port, because the kernel
accepts a packet for any local address on any interface, so the firewall
rule does. Every other listener of the store keeps its client certificate
requirement.
- **Auth mount:** `jwt-k8s`. `swarm-bao-granter-role` enables it with the
bootstrap token, and `swarm-bao-k8s-jwt-policy` writes its config: the
public halves of the keys k3s signs ServiceAccount tokens with, derived from
the key files under `/var/lib/rancher/k3s/server/tls`, and the issuer the
node gives its API server, `https://kubernetes.default.svc.cluster.local`.
The unit runs after k3s and needs no manual step. Restart it after a rotation
of the node's signing keys.
- **Roles:** one per in-cluster service, named like the service and its cert
role (`swarm-controller`, `swarm-notify-router`, `swarm-ci-metrics`). A role
accepts the token of the ServiceAccount of that name in the services'
namespace (`system:serviceaccount:<namespace>:<service>`), and only with the
audience `bao`, so a token meant for the Kubernetes API is no use to the
store. It hands out the policy and token lifetimes of the service's cert role.
- **Pod:** the [rendered manifest](manifests.md#the-store-login) runs the pod
under that ServiceAccount, with a token projected for the audience `bao` and
`BAO_AUTH=jwt` in its environment.
The bootstrap policy that `swarmctl bao grant-bootstrap` applies carries
`sys/auth/jwt-k8s`, so a store set up before the node existed needs that step
once more.
## Validation
`module-eval-k8s` compares an all-local host with the option on against the
same host with it off, and checks the address ranges and the CoreDNS
ConfigMap. The VM test `k8s-node` boots a node through the module and runs a
pod against it.
pod against it. The VM test `k8s-bao-login` runs the node and the secret store
together: a pod under a service's ServiceAccount logs in and reads a value, a
pod under another account gets no token, and a client on the hive bridge can't
connect to the pods' port.