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:
parent
cad1b7cebe
commit
d1554def7a
5 changed files with 720 additions and 69 deletions
|
|
@ -19,11 +19,11 @@ cluster.
|
|||
|
||||
A service gets manifests on the host whose configuration deploys it:
|
||||
|
||||
| service | workload | other objects |
|
||||
| --------------------- | ---------- | -------------------------------------------------------------------------------- |
|
||||
| `swarm-controller` | Deployment | PersistentVolumeClaim `swarm-controller-state`, ConfigMap `swarm-controller-etc` |
|
||||
| `swarm-notify-router` | Deployment | none |
|
||||
| `swarm-ci-metrics` | CronJob | PersistentVolumeClaim `swarm-ci-metrics-state` |
|
||||
| service | workload | other objects |
|
||||
| --------------------- | ---------- | ------------------------------------------------------------------------------------------------ |
|
||||
| `swarm-controller` | Deployment | ServiceAccount, PersistentVolumeClaim `swarm-controller-state`, ConfigMap `swarm-controller-etc` |
|
||||
| `swarm-notify-router` | Deployment | ServiceAccount |
|
||||
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolumeClaim `swarm-ci-metrics-state` |
|
||||
|
||||
`namespace.yaml` holds the Namespace. NATS with its auth responder,
|
||||
`swarm-review-classifier`, `swarm-claude-login` and `swarm-stt` have no
|
||||
|
|
@ -38,7 +38,8 @@ The renderer reads the service's evaluated unit, not a copy of its settings:
|
|||
directory it stands for. On a host with a hive collector, the OTLP endpoint
|
||||
variables point at it ([Pod logs and metrics](telemetry.md)) instead. The
|
||||
renderer fails if the unit's `path` holds anything beyond the NixOS default
|
||||
tools, because the image doesn't carry them.
|
||||
tools, because the image doesn't carry them. The other change is the store
|
||||
login, [below](#the-store-login).
|
||||
- **Files:** the pod mounts each file the unit names at the same path,
|
||||
so the environment carries over unchanged:
|
||||
- credentials at `/run/credentials/<service>.service/<id>`, from the Secret
|
||||
|
|
@ -85,7 +86,8 @@ object.
|
|||
with `fsGroup` its gid so the pod reads its credentials (mode `0440`),
|
||||
read-only root filesystem with an `emptyDir` on `/tmp`, no privilege
|
||||
escalation, every capability dropped, the runtime's default seccomp profile,
|
||||
and no service account token.
|
||||
and no mounted API token. A service that logs in to the store gets a token
|
||||
of its own, [below](#the-store-login).
|
||||
- **Probes:** a service with an opt-in health listener gets its variable set to
|
||||
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
|
||||
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` serves
|
||||
|
|
@ -96,6 +98,31 @@ object.
|
|||
- **Rollout:** each Deployment has one replica and the `Recreate` strategy,
|
||||
because each service runs once per swarm.
|
||||
|
||||
## The store login
|
||||
|
||||
A service that has a role at the store's `jwt-k8s` auth mount
|
||||
(`services.hyperhive.deploy.bao.k8sPrincipals`) logs in with its pod's
|
||||
ServiceAccount token. A unit logs in with the client certificate in its
|
||||
environment, so the pod differs from the unit in these places:
|
||||
|
||||
- **ServiceAccount:** one named like the service, in the rendered namespace,
|
||||
with `automountServiceAccountToken: false`, and the pod runs under it.
|
||||
- **Token:** a projected volume `bao-token` with one `serviceAccountToken`
|
||||
source for the audience `bao`, expiring after 600 seconds (the shortest the
|
||||
API server grants) and mounted read-only at `/var/run/secrets/hyperhive/bao`.
|
||||
The kubelet rewrites the file before it expires, and the client reads it
|
||||
afresh at each login. The store's role for the service accepts this
|
||||
account and this audience only.
|
||||
- **Environment:** the pod sets neither `BAO_CLIENT_CERT` nor
|
||||
`BAO_CLIENT_KEY`, and the credentials they named aren't in the pod's
|
||||
Secret. `BAO_AUTH=jwt`, `BAO_JWT_FILE`, `BAO_JWT_ROLE` (the service's name)
|
||||
and `BAO_JWT_MOUNT` (`jwt-k8s`) take their place, and `BAO_ADDR` names the
|
||||
store's own name at the port of the listener that asks for no client
|
||||
certificate (`deploy.bao.podListenerPort`). `BAO_CACERT` stays.
|
||||
|
||||
[The cluster node](node.md#logging-in-to-the-secret-store) describes the
|
||||
store's side.
|
||||
|
||||
## Not covered yet
|
||||
|
||||
- The pods reach the swarm's host-run services (store, queue, identity
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -26,14 +26,15 @@ file is `services.hyperhive.deploy.bao.bootstrapTokenFile`, which all-local
|
|||
names for you; on a store host that isn't all-local, set it and rebuild first.
|
||||
|
||||
`swarm-bao-granter-role` runs **on the host**. It enables the cert and oidc
|
||||
auth methods (and disables `approle` if an older store still has it mounted),
|
||||
auth methods, and `jwt-k8s` on a host with the cluster node (and disables
|
||||
`approle` if an older store still has it mounted),
|
||||
writes the `bao-granter` policy, and creates the `bao-granter` role, which
|
||||
accepts the leaf `/var/lib/swarm-bao-pki/granter.pem`. Every
|
||||
`swarm-bao-*-policy` unit then logs in with that leaf. The controller's unit
|
||||
mounts the KV and pki engines and writes the `swarm-controller` role, and each
|
||||
sibling unit writes its own principal's policy and role. Every one runs on the
|
||||
host, because every API listener but the loopback UI one demands a client
|
||||
certificate and the host is the side that has one.
|
||||
host, because every API listener but the loopback UI one and the cluster
|
||||
pods' one demands a client certificate and the host is the side that has one.
|
||||
|
||||
Until the granter exists, each `swarm-bao-*-policy` unit **fails** and logs
|
||||
the bootstrap commands. It never skips. `swarm-bao-granter-role` skips while
|
||||
|
|
@ -92,6 +93,17 @@ constrain what a policy says. What bounds it:
|
|||
restarting `swarm-bao-pki` mints a new leaf, but doesn't invalidate the old
|
||||
one.
|
||||
|
||||
## Pods in the cluster
|
||||
|
||||
A service that runs in the k3s cluster (`deploy.k8s.enable`) logs in with its
|
||||
pod's ServiceAccount token instead of a certificate. The store has a `pod`
|
||||
listener for it, on the hive bridge's address at `deploy.bao.podListenerPort`,
|
||||
that asks for no client certificate, and a `jwt-k8s` auth mount with one role
|
||||
per in-cluster service. Only the firewall keeps the port from the agents on
|
||||
the bridge: it admits the port on the pod network's interfaces alone. The
|
||||
roles, the keys they trust and the pods' side are in
|
||||
[the cluster node](../k8s/node.md#logging-in-to-the-secret-store).
|
||||
|
||||
## Sealing
|
||||
|
||||
`services.hyperhive.deploy.bao.seal`:
|
||||
|
|
|
|||
|
|
@ -183,9 +183,9 @@ On the host running
|
|||
the store it's also at
|
||||
`/var/lib/swarm-bao-services-pki/services-root.pem`. That's the file to
|
||||
hand a browser, and reading it needs no store login — which matters,
|
||||
because every store listener but the loopback UI one demands a client
|
||||
certificate, and authelia gates that one to the `admins` group, not
|
||||
open to an anonymous browser fetching a trust anchor.
|
||||
because every store listener but the loopback UI one and the cluster pods'
|
||||
one demands a client certificate, and authelia gates that one to the `admins`
|
||||
group, not open to an anonymous browser fetching a trust anchor.
|
||||
|
||||
**The granting unit generates the root once, and never again.** It asks
|
||||
the mount whether it already has an issuer (`bao list pki/issuers`)
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ pieces fit, and the reasoning behind them, is in [`credentials.md`](../../2-hand
|
|||
| the gateway's client certificate for the controller's TCP listener | `swarm-controller-gateway-client.service` on the host that runs the controller, only where you set `swarm.controller.tcp.enable`. It logs in under the services-issuer identity and issues from the store's `swarm-controller-gateway-client` role: one name, `gateway-client.<swarm.domain>`, `clientAuth` only, so the services leaf can't stand in for it. A daily timer renews it | `<deploy.hive-controller.tls.stateDir>/controller-client.pem` and `controller-client-key.pem`, the key `0640` group `nginx`; the gateway's controller locations name them in `proxy_ssl_certificate`. Until the store answers, a throwaway self-signed pair keeps nginx's config loadable. The listener refuses that pair, so those locations answer 502. Every holder of the services-issuer identity can obtain this leaf: the listener trusts "a gateway of this swarm" | Nothing to place: the services-issuer identity is the one every gateway host already holds |
|
||||
| the secret store's own contents | openbao, on first `bao operator init` — **an operator action, not a unit** | inside the `swarm-bao` container, at its own `/var/lib/openbao`, kept across rebuilds by `ephemeral = false`. ⚠️ **Not a host path**: `nixos-container destroy swarm-bao` takes the raft data with it, so back up the container's tree, not `/var/lib/`. Only the store's TLS material (`/var/lib/swarm-bao-tls`) and its PKCS11 token (`/var/lib/swarm-bao-token`) are host-level | n/a — there is one store; a hive elsewhere is a _client_ of it and holds none of this |
|
||||
| the secret store's unseal material | the HSM/TPM under `deploy.bao.seal = "pkcs11"`; openbao itself under `"shamir"` | in the token; or held by whoever ran `bao operator init`, which is what `"shamir"` means and why it's stated rather than inferred | n/a — only the host running the store seals anything |
|
||||
| a cluster pod's store login token (a ServiceAccount token) | the cluster's API server, which signs it for the pod's account and the audience `bao`. The kubelet projects it into the pod and rewrites it before it expires | `/var/run/secrets/hyperhive/bao/token` in the pod. The store accepts it at its `jwt-k8s` mount, for the role of that account only, against the public halves of the node's signing keys, which `swarm-bao-k8s-jwt-policy` derives from the key files. A node whose signing keys changed needs that unit restarted, and tokens signed with the old key fail to log in meanwhile | Nothing to place: the pods and the store run on the cluster's one host |
|
||||
|
||||
### Hive-level — one of each per hive
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue