`swarm-bao-k8s-jwt-policy` exits 0 when the bootstrap token lacks `sys/auth/jwt-k8s`, so a store set up before the node looked fine in `swarmctl setup status`: the unit is active and nothing marks the root-only `swarmctl bao grant-bootstrap` re-run as pending. The unit now keeps /run/swarm-bao-k8s-jwt-pending while it stays off and removes it before it writes the mount's config. `setup status` reads the file and shows step 3, "granter bootstrapped", as not done, naming the verb. `module-eval-k8s` pins the order of the touch, the exit and the removal.
9.5 KiB
The cluster node
services.hyperhive.deploy.k8s.enable (default false) makes the host run a
single-node k3s server for the swarm services that run in the cluster. It's
the Kubernetes counterpart of services.hyperhive.deploy.singleHostSwarm: set
it on the host that runs the swarm's services, and the cluster comes up with the
service images loaded and no service's objects applied.
What the host gets
- k3s: one server, which also runs the workloads. traefik and
metrics-server are off, and the cluster encrypts its Secrets at rest
(
--secrets-encryption). CoreDNS and the local-path provisioner stay on, so pods have cluster DNS and PersistentVolumeClaims. - Images: the node holds k3s's own images and the image of each service
that renders manifests on this host, in containerd before k3s
starts. No registry exists, and the pods name their images with
imagePullPolicy: Never. - Manifests:
services.hyperhive.k8s.enableis on, so the host buildssystem.build.k8sManifestsandsystem.build.k8sImages. Setting it tofalseexplicitly fails the evaluation. - Addresses: pods take their addresses from
deploy.k8s.podCidr(default10.200.0.0/16) and services fromdeploy.k8s.serviceCidr(default10.201.0.0/16). Neither may overlap the hive bridge's subnet (network.bridgeIp, default10.42.0.0/24) or the other, and the evaluation fails when one does: the bridge and the cluster would route the same addresses. k3s's own default pod range,10.42.0.0/16, contains the bridge's default subnet. - Firewall: the pod network's interfaces,
cni0andflannel.1, are trusted, so the node reaches its pods. - NetworkPolicy: k3s's own controller (kube-router, iptables) enforces NetworkPolicy objects; the node doesn't turn it off. A pod no policy selects reaches whatever it can route to. The manifests say which pods have one.
- 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.
What it leaves alone
The cluster starts with no hyperhive workload. Each service keeps running as
its systemd unit, and nothing applies the services' manifests: two copies of
swarm-notify-router, swarm-ci-metrics or swarm-controller would share one
queue consumer, one cursor or one swarm. A service's objects go into the
cluster when its runtime is "k8s" (the runtime switch).
With the option off, the host's configuration is the one it has without the module.
Reaching host-run services
A pod reaches a service that runs on the host by the service's swarm name. The
cluster's CoreDNS answers each such name with the hive bridge's address
(network.bridgeIp), the address the agents' resolver gives, so a pod reaches
the same listeners an agent does: the gateway's vhosts, the secret store's TLS
port, the queue and the hive's OTLP collector. The names are the hive domain
and every name a host module contributes to gateway.localNames because the
host runs that service. services.hyperhive.deploy.k8s.hostServices is that
table, and it holds the only host address the cluster knows.
The node applies the table to k3s as a coredns-custom ConfigMap, which is a
node object and not a service manifest. A name outside the table, and every
cluster name, resolves as before. A host without the hive bridge has no
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: every listener of the secret store but its pods' one refuses a connection without a client certificate.
Reaching the cluster from the host
The host's resolver, the hive's dnsmasq (the host's own /etc/resolv.conf
names it), forwards the cluster's domain to CoreDNS. deploy.k8s.clusterDomain
is cluster.local and deploy.k8s.clusterDns, the tenth address of
deploy.k8s.serviceCidr, is the address k3s gives CoreDNS: the node passes
both as flags (--cluster-domain, --cluster-dns) and the resolver's
server=/cluster.local/<address> line reads the same values. A process on the
host, nginx included, so reaches a Service as
<name>.<namespace>.svc.cluster.local. The node doesn't set the line without
gateway.dns.enable, the option that runs that resolver.
A ClusterIP answers the host because kube-proxy (k3s runs it in iptables
mode) rewrites a host process's connection to the Service's address into the
pod's, and the firewall trusts the pod network's interfaces. The bridge's
agents ask the same resolver, so they get the same names. A name is no route:
the hive's egress rules decide whether the host forwards their traffic to the
cluster's addresses, and a pod's NetworkPolicy refuses what it forwards.
A pod that serves the host, such as the controller or the queue's exporter, has
a NetworkPolicy that selects it for ingress and allows no more than the port it
serves everyone, if it has one. kube-router, the policy engine, adds a rule at
the top of every pod's chain that admits traffic from any address of the node
(-m addrtype --src-type LOCAL, commented "from local node"), so the host
reaches the pod and no other pod does.
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(default8208). 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
cni0andflannel.1and 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-roleenables it with the bootstrap token, andswarm-bao-k8s-jwt-policywrites 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 audiencebao, 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 runs the pod
under that ServiceAccount, with a token projected for the audience
baoandBAO_AUTH=jwtin 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.
Turning the node on for a swarm that already runs
The first activation with deploy.k8s.enable restarts the store's container,
container@swarm-bao. The node adds a pod listener to the store's
configuration, and a changed container configuration restarts the container.
What comes next depends on the store's seal:
-
With the default
pkcs11seal the store unseals itself. Skip the unseal below. -
With
deploy.bao.seal = "shamir"the store comes back sealed. Every unit that reads it fails until an operator unseals it, andswarmctl bao grant-bootstrapcan't log in either. Unseal first, with the saved keys, as setup does:bao operator unseal # repeat with different keys until the store reports unsealed
Then, on either seal, as root on the host that runs swarm-bao:
swarmctl bao grant-bootstrap # prompts for the root token, input hidden
systemctl reset-failed 'swarm-bao-*-policy.service' swarm-bao-agent-pki.service
systemctl restart 'swarm-bao-*-policy.service' swarm-bao-agent-pki.service
The grant adds sys/auth/jwt-k8s to the bootstrap policy, and the restart lets
swarm-bao-granter-role enable the mount and swarm-bao-k8s-jwt-policy write
the pods' login. Until both have run, the pods can't log in.
Until the grant runs, swarmctl setup status shows step 3, "granter
bootstrapped", as not done. swarm-bao-k8s-jwt-policy exits 0 and keeps
/run/swarm-bao-k8s-jwt-pending while the bootstrap token lacks the grant, and
the status reads that file.
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. 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.