Day 5: SPIFFE and SPIRE – the HR department and its gatekeepers
Goal: run a SPIRE server outside the cluster, log SPIRE agents in the cluster in with their ServiceAccount token, and see how an agent recognizes a pod without believing anything it says · Duration: about 120 min · Prerequisite: Day 4 completed
Where we start
# on id1
systemctl is-active keycloakExpected:
active
# on id1
kubectl get --raw /.well-known/openid-configurationExpected:
"issuer":"https://172.16.0.126:6443". In addition, the
cluster’s CA has been in ~/cluster-ca.crt since Day 1.
Introduction
Until yesterday every identity in the building had the same origin: the Kubernetes API server. That is enough as long as everything runs in one cluster. But a service on a VM, a job in a second cluster, a program on a laptop – none of them get a building badge from this cluster.
SPIFFE is an open standard for the identities of programs, regardless of where they run. SPIRE is the software that implements it. It issues every program a short-lived staff badge – an X.509 certificate or a JWT – and keeps renewing it, without the program having to bring a single secret.
How does SPIRE do that without a secret? It does not ask “Who are you?”, but determines it itself: from properties a program cannot forge. This is called attestation, and that is what today is about. You issue the first staff badge tomorrow.
Today you will learn:
- what a SPIFFE ID, trust domain, SVID and bundle are,
- how to install a SPIRE server as a service on id1,
- why the server itself needs a badge from the cluster – and how you keep it small,
- how to start SPIRE agents as a DaemonSet that identify themselves
with a projected token (node attestation
k8s_psat), - how an agent finds out via the kubelet which pod is talking to it (workload attestation),
- where a node attestation with the wrong audience fails.
Background
The picture for today: the HR department and the gatekeepers on each floor
Your office building gets an HR department. It keeps the personnel files and issues photo staff badges that are valid everywhere on the campus – not just in this building.
The HR department does not sit on every floor. A gatekeeper sits there. Anyone who needs a staff badge goes to their gatekeeper, not to the HR department. The gatekeeper believes no one who says “I am the accountant”. They check for themselves: which desk, which employment contract, which face? Only then do they look in the personnel files to see whether there is a badge for such a person.
But how does the HR department know that the gatekeeper is genuine? When starting their shift, the gatekeeper presents their building badge – issued by the cluster’s badge office, for the door “HR department”. The HR department calls the badge office and has it checked. For that it needs a phone number of its own and a permission at the badge office.
The terms
| Term | Meaning | in the picture |
|---|---|---|
| Trust domain | namespace in which a SPIRE installation assigns identities, here
gebaeude.test |
the company campus |
| SPIFFE ID | URI of the form
spiffe://<domäne>/<pfad> |
personnel number |
| SVID | SPIFFE Verifiable Identity Document: X.509 certificate or JWT with the SPIFFE ID | photo staff badge |
| Bundle | the CA certificates of a trust domain | specimen card of the HR department |
| SPIRE server | issues SVIDs, keeps the registration entries | HR department |
| SPIRE agent | runs on every node, accepts requests from programs | gatekeeper on the floor |
| Node attestation | the agent proves to the server which node it runs on | gatekeeper presents their building badge when starting their shift |
| Workload attestation | the agent determines which program is talking to it | gatekeeper compares the face |
| Selector | a determined property, for example
k8s:sa:werkstatt |
feature in the personnel file |
| Workload API | the agent’s Unix socket through which programs fetch their SVID | the gatekeeper’s counter |
Remember: SPIRE does not believe anything a program says about itself. It determines the identity itself – for the node via a badge the cluster issued, for the program via what the kernel and the kubelet know.
What runs where today
| Part | Where | Why there |
|---|---|---|
| SPIRE server | id1, as a systemd service | outside the cluster; it should also issue identities for things that do not run in the cluster |
| SPIRE agent | DaemonSet, one pod per node | it must see the processes of its node |
| Workload API | socket /run/spire/agent-sockets/agent.sock on every
node |
pods mount it via hostPath |
Drill 1: Unpacking SPIRE
Where you are: on id1.
What you have afterwards: SPIRE 1.16.0 with a verified checksum under
/opt/spireand a system userspire.
Step 1 – working folder and architecture.
# on id1
mkdir -p ~/kurs/05# on id1
dpkg --print-architectureExpected:
amd64
If yours says arm64, replace amd64 with
arm64 in the following commands.
Step 2 – download the archive and checksum file.
# on id1
cd ~/kurs/05# on id1
curl -sLO https://github.com/spiffe/spire/releases/download/v1.16.0/spire-1.16.0-linux-amd64-musl.tar.gz# on id1
curl -sLO https://github.com/spiffe/spire/releases/download/v1.16.0/spire-1.16.0-linux-amd64-musl_sha256sum.txtmusl means: the programs are statically built and need
no libraries from the system.
Step 3 – verify. Unlike with Keycloak, this file
also contains the file name. That way sha256sum can do the
comparison itself:
# on id1
cat spire-1.16.0-linux-amd64-musl_sha256sum.txtExpected:
7bcf5e167151a1fc58293768462b44e155ba8784214582aefa6adf18c633d1d5 spire-1.16.0-linux-amd64-musl.tar.gz
# on id1
sha256sum -c spire-1.16.0-linux-amd64-musl_sha256sum.txt-c– read the file as a list of “checksum file name” and compare each file against it.
Expected:
spire-1.16.0-linux-amd64-musl.tar.gz: OK
Step 4 – user, unpack, link. The same pattern as with Keycloak:
# on id1
sudo useradd --system --home-dir /var/lib/spire --shell /usr/sbin/nologin spire# on id1
sudo tar -xzf ~/kurs/05/spire-1.16.0-linux-amd64-musl.tar.gz -C /opt# on id1
sudo ln -s /opt/spire-1.16.0 /opt/spire# on id1
/opt/spire/bin/spire-server --versionExpected:
1.16.0
# on id1
ls -l /opt/spire/binExpected:
total 251776
-rwxr-xr-x 1 root root 78437656 Nov 5 18:28 spire-agent
-rwxr-xr-x 1 root root 179378008 Nov 5 18:28 spire-server
What you see: Two programs. You run the server on
id1; a container image will bring the agent in a moment. The files
belong to root and stay that way – the user
spire should not be able to modify its own programs.
Remember: Two programs, two roles:
spire-serveris the HR department,spire-agentthe gatekeeper. Both come from the same verified archive.
Save your progress? Sign up for free
Drill 2: Who checks the HR department?
Where you are: on id1.
What you have afterwards: a ServiceAccount
spire-serverwith exactly the permissions the server needs, and a kubeconfig for it under/etc/spire.
The server will have the agents’ building badges checked with a TokenReview – just like on Day 2. For that it needs access to the API server itself. This is the old chicken-and-egg problem of every identity solution: someone has to have a first badge. You make it as small as possible.
Step 1 – ServiceAccount and permissions.
# on id1
nano ~/kurs/05/server-zugang.yamlapiVersion: v1
kind: Namespace
metadata:
name: spire
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: spire-server
namespace: spire
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: spire-server-prueft-ausweise
rules:
- apiGroups: ["authentication.k8s.io"]
resources: ["tokenreviews"]
verbs: ["create"]
- apiGroups: [""]
resources: ["pods", "nodes"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: spire-server-prueft-ausweise
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: spire-server-prueft-ausweise
subjects:
- kind: ServiceAccount
name: spire-server
namespace: spire| Rule | What the server needs it for |
|---|---|
tokenreviews create |
have an agent’s building badge checked |
pods get |
look up the pod the badge is bound to |
nodes get |
read the node’s UID; it becomes part of the agent’s SPIFFE ID |
# on id1
kubectl apply -f ~/kurs/05/server-zugang.yamlExpected:
namespace/spire created
serviceaccount/spire-server created
clusterrole.rbac.authorization.k8s.io/spire-server-prueft-ausweise created
clusterrolebinding.rbac.authorization.k8s.io/spire-server-prueft-ausweise created
Step 2 – may it do what it should, and no more?
# on id1
kubectl auth can-i create tokenreviews --as system:serviceaccount:spire:spire-serverExpected:
Warning: resource 'tokenreviews' is not namespace scoped in group 'authentication.k8s.io'
yes
# on id1
kubectl auth can-i list secrets -n laden --as system:serviceaccount:spire:spire-serverExpected:
no
Step 3 – a badge for 30 days. The server runs outside the cluster; no kubelet puts a badge there for it. You order it yourself:
# on id1
kubectl create token spire-server -n spire --duration 720h > ~/kurs/05/spire-server.jwt# on id1
step crypto jwt inspect --insecure < ~/kurs/05/spire-server.jwtExpected (excerpt):
"exp": 1798714590,
"iat": 1796122590,
"iss": "https://172.16.0.126:6443",
"sub": "system:serviceaccount:spire:spire-server"
What you see: exp - iat = 2 592 000
seconds, 30 days. That is the longest badge in the whole course, and
that is intentional: it shows you where the chicken-and-egg problem
sits. It is not bound to any pod, and after 30 days you have to renew
it, otherwise SPIRE accepts no new agents. In return it can only create
TokenReviews and read pods and nodes.
Step 4 – the kubeconfig. kubectl config
builds the file piece by piece. The token does not go into it; the
kubeconfig only points to a file:
# on id1
kubectl config set-cluster labor --server=https://172.16.0.126:6443 --certificate-authority=/etc/spire/cluster-ca.crt --kubeconfig=$HOME/kurs/05/spire-kubeconfigExpected:
Cluster "labor" set.
# on id1
kubectl config set users.spire-server.tokenFile /etc/spire/spire-server.jwt --kubeconfig=$HOME/kurs/05/spire-kubeconfigExpected:
Property "users.spire-server.tokenFile" set.
# on id1
kubectl config set-context labor --cluster=labor --user=spire-server --kubeconfig=$HOME/kurs/05/spire-kubeconfig# on id1
kubectl config use-context labor --kubeconfig=$HOME/kurs/05/spire-kubeconfigExpected:
Switched to context "labor".
# on id1
cat ~/kurs/05/spire-kubeconfigExpected:
apiVersion: v1
clusters:
- cluster:
certificate-authority: /etc/spire/cluster-ca.crt
server: https://172.16.0.126:6443
name: labor
contexts:
- context:
cluster: labor
user: spire-server
name: labor
current-context: labor
kind: Config
users:
- name: spire-server
user:
tokenFile: /etc/spire/spire-server.jwt
What you see: The paths already point to
/etc/spire, where the files will live in a moment.
tokenFile instead of token has two advantages:
the token is not in a file that people like to pass around, and you can
renew it by replacing only the token file.
Step 5 – everything in its place.
install copies and sets owner and permissions in one
step:
# on id1
sudo install -d -o spire -g spire -m 750 /etc/spire# on id1
sudo install -o spire -g spire -m 644 ~/cluster-ca.crt /etc/spire/cluster-ca.crt# on id1
sudo install -o spire -g spire -m 600 ~/kurs/05/spire-server.jwt /etc/spire/spire-server.jwt# on id1
sudo install -o spire -g spire -m 600 ~/kurs/05/spire-kubeconfig /etc/spire/kubeconfig| Option | Meaning |
|---|---|
-d |
create a directory instead of copying a file |
-o spire -g spire |
owner and group |
-m 600 |
only the owner may read and write |
You no longer need the copy of the token in your working folder:
# on id1
rm ~/kurs/05/spire-server.jwt# on id1
sudo ls -l /etc/spireExpected:
total 12
-rw-r--r-- 1 spire spire 570 Dec 1 10:56 cluster-ca.crt
-rw------- 1 spire spire 333 Dec 1 10:56 kubeconfig
-rw------- 1 spire spire 921 Dec 1 10:56 spire-server.jwt
Step 6 – try it as the server.
# on id1
sudo -u spire kubectl --kubeconfig /etc/spire/kubeconfig auth can-i create tokenreviewsExpected (last line):
yes
# on id1
sudo -u spire kubectl --kubeconfig /etc/spire/kubeconfig get secrets -n ladenExpected:
Error from server (Forbidden): secrets is forbidden: User "system:serviceaccount:spire:spire-server" cannot list resource "secrets" in API group "" in the namespace "laden"
Remember: Every identity solution needs a first badge. You cannot abolish it, only make it small: tightly limited permissions, an expiry date, a file readable only by the service.
Save your progress? Sign up for free
Drill 3: Opening the HR department
Where you are: on id1.
What you have afterwards: a running SPIRE server for the trust domain
gebaeude.testand its bundle as a file.
Step 1 – the configuration. SPIRE uses the HCL format, which you may know from Terraform:
# on id1
sudo nano /etc/spire/server.confserver {
bind_address = "0.0.0.0"
bind_port = "8081"
socket_path = "/run/spire-server/api.sock"
trust_domain = "gebaeude.test"
data_dir = "/var/lib/spire/server"
log_level = "INFO"
ca_ttl = "24h"
default_x509_svid_ttl = "1h"
default_jwt_svid_ttl = "5m"
}
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
connection_string = "/var/lib/spire/server/datastore.sqlite3"
}
}
KeyManager "disk" {
plugin_data {
keys_path = "/var/lib/spire/server/keys.json"
}
}
NodeAttestor "k8s_psat" {
plugin_data {
clusters = {
"labor" = {
service_account_allow_list = ["spire:spire-agent"]
kube_config_file = "/etc/spire/kubeconfig"
}
}
}
}
}| Option | Value | Meaning |
|---|---|---|
bind_address, bind_port |
0.0.0.0, 8081 |
the agents connect here over the network |
socket_path |
/run/spire-server/api.sock |
administration socket, local only; you create entries through it |
trust_domain |
gebaeude.test |
trust domain; .test is reserved for testing and belongs
to nobody |
ca_ttl |
24h |
lifetime of the server’s CA |
default_x509_svid_ttl |
1h |
lifetime of an X.509 staff badge |
default_jwt_svid_ttl |
5m |
lifetime of a JWT staff badge |
DataStore "sql" |
SQLite file | registration entries and attested agents |
KeyManager "disk" |
keys.json |
where the CA’s private key is stored |
NodeAttestor "k8s_psat" |
cluster labor |
agents identify themselves with a projected ServiceAccount token |
service_account_allow_list |
spire:spire-agent |
only this ServiceAccount may become a gatekeeper |
kube_config_file |
/etc/spire/kubeconfig |
the server uses this to call the badge office |
# on id1
sudo chown spire:spire /etc/spire/server.confStep 2 – the service.
# on id1
sudo nano /etc/systemd/system/spire-server.service[Unit]
Description=SPIRE-Server – Personalabteilung des Bürogebäudes (Labor)
After=network-online.target
Wants=network-online.target
[Service]
User=spire
Group=spire
RuntimeDirectory=spire-server
StateDirectory=spire/server
ExecStart=/opt/spire/bin/spire-server run -config /etc/spire/server.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target| Option | Meaning |
|---|---|
RuntimeDirectory=spire-server |
systemd creates /run/spire-server for the socket, owned
by spire |
StateDirectory=spire/server |
systemd creates /var/lib/spire/server for the data |
# on id1
sudo systemctl daemon-reload# on id1
sudo systemctl enable --now spire-serverExpected:
Created symlink /etc/systemd/system/multi-user.target.wants/spire-server.service → /etc/systemd/system/spire-server.service.
Step 3 – is it alive?
# on id1
sudo -u spire /opt/spire/bin/spire-server healthcheck -socketPath /run/spire-server/api.sockExpected:
Server is healthy.
Only the user spire may open the administration socket.
Hence sudo -u spire – you will see that a lot over the next
days.
Step 4 – what happened at startup.
# on id1
sudo journalctl -u spire-server --no-pager -o catExpected (excerpt, lines shortened at the front and
in the middle – look for X509 CA activated,
JWT key activated and
Starting Server APIs):
level=info msg="X509 CA activated" expiration="2026-12-02 10:56:59 +0000 UTC" issued_at="2026-12-01 10:56:59.963590667 +0000 UTC" … self_signed=true …
level=info msg="JWT key activated" expiration="2026-12-02 10:56:59.979117934 +0000 UTC" …
level=info msg="Starting Server APIs" address=/run/spire-server/api.sock network=unix subsystem_name=endpoints
level=info msg="Starting Server APIs" address="[::]:8081" network=tcp subsystem_name=endpoints
What you see: The server built its own CA
(self_signed=true), valid for 24 hours, and its own key for
JWT badges. It listens on the socket and on port 8081.
# on id1
sudo ls -l /var/lib/spire/serverExpected:
total 252
-rw-r----- 1 spire spire 4096 Dec 1 10:56 datastore.sqlite3
-rw-r----- 1 spire spire 32768 Dec 1 10:56 datastore.sqlite3-shm
-rw-r----- 1 spire spire 214272 Dec 1 10:56 datastore.sqlite3-wal
-rw------- 1 spire spire 425 Dec 1 10:56 keys.json
What you see: keys.json is the HR
department’s stamp – the CA’s private key. Whoever has these 425 bytes
can issue staff badges for any SPIFFE ID in
gebaeude.test.
Step 5 – the HR department’s specimen card. The bundle is the CA certificates. Anyone who wants to verify a staff badge needs it:
# on id1
sudo -u spire /opt/spire/bin/spire-server bundle show -socketPath /run/spire-server/api.sock > ~/kurs/05/bundle.crt# on id1
step certificate inspect --short ~/kurs/05/bundle.crtExpected:
X.509v3 Root CA Certificate (ECDSA P-256) [Serial: 3343...9314]
Subject: spiffe://gebaeude.test
Issuer:
Valid from: 2026-12-01T10:56:49Z
to: 2026-12-02T10:56:59Z
What you see: A root CA whose name is the trust domain. Valid from ten seconds before startup – SPIRE leaves some leeway for clocks that run slow.
Remember: The HR department has a stamp (
keys.json) and a specimen card (bundle). The stamp never leaves id1; everyone gets the specimen card.
Save your progress? Sign up for free
Drill 4: The gatekeepers start their shift
Where you are: on id1.
What you have afterwards: a SPIRE agent on every node that has logged in to the server with its building badge and carries its own SPIFFE ID.
Step 1 – ServiceAccount and permissions for the
gatekeepers. The agent will ask the kubelet of its node which
pods run there. The kubelet only lets in those who are allowed
nodes/proxy:
# on id1
nano ~/kurs/05/agent-zugang.yamlapiVersion: v1
kind: ServiceAccount
metadata:
name: spire-agent
namespace: spire
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: spire-agent-fragt-kubelet
rules:
- apiGroups: [""]
resources: ["pods", "nodes", "nodes/proxy"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: spire-agent-fragt-kubelet
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: spire-agent-fragt-kubelet
subjects:
- kind: ServiceAccount
name: spire-agent
namespace: spire# on id1
kubectl apply -f ~/kurs/05/agent-zugang.yamlExpected:
serviceaccount/spire-agent created
clusterrole.rbac.authorization.k8s.io/spire-agent-fragt-kubelet created
clusterrolebinding.rbac.authorization.k8s.io/spire-agent-fragt-kubelet created
Step 2 – the specimen card for the gatekeepers. When an agent calls the server for the first time, it must be able to verify that it is talking to the genuine HR department. For that it gets the bundle:
# on id1
kubectl create configmap spire-bundle -n spire --from-file=bundle.crt=$HOME/kurs/05/bundle.crtExpected:
configmap/spire-bundle created
A ConfigMap is enough: the bundle is public, not a secret.
Step 3 – the gatekeeper’s standing orders.
# on id1
nano ~/kurs/05/agent-config.yamlapiVersion: v1
kind: ConfigMap
metadata:
name: spire-agent
namespace: spire
data:
agent.conf: |
agent {
data_dir = "/run/spire/agent"
log_level = "DEBUG"
server_address = "172.16.0.126"
server_port = "8081"
socket_path = "/run/spire/agent-sockets/agent.sock"
trust_bundle_path = "/run/spire/bundle/bundle.crt"
trust_domain = "gebaeude.test"
}
plugins {
NodeAttestor "k8s_psat" {
plugin_data {
cluster = "labor"
}
}
KeyManager "memory" {
plugin_data {}
}
WorkloadAttestor "k8s" {
plugin_data {
node_name_env = "MY_NODE_NAME"
kubelet_ca_path = "/run/spire/kubelet-ca/server-ca.crt"
}
}
}| Option | Value | Meaning |
|---|---|---|
log_level |
DEBUG |
today you want to see what the gatekeeper determines;
INFO in production |
server_address, server_port |
id1, 8081 | where the HR department sits |
socket_path |
/run/spire/agent-sockets/agent.sock |
counter for the programs on this node |
trust_bundle_path |
bundle from Step 2 | only for the first connection; after that the server supplies new bundles itself |
NodeAttestor "k8s_psat" |
cluster = "labor" |
same name as in server.conf |
KeyManager "memory" |
the agent’s keys only in memory; after a restart it logs in again | |
WorkloadAttestor "k8s" |
recognize pods via the kubelet | |
node_name_env |
MY_NODE_NAME |
the node’s name from this environment variable; it addresses the kubelet under this name |
kubelet_ca_path |
CA of the node | the agent uses it to verify the kubelet’s certificate |
With k3s the kubelet’s certificate is issued by the CA from
/var/lib/rancher/k3s/agent/server-ca.crt, and it names the
node (DNS:id1 or DNS:id2). That is why
verification works without switching it off.
# on id1
kubectl apply -f ~/kurs/05/agent-config.yamlExpected:
configmap/spire-agent created
Step 4 – the DaemonSet.
# on id1
nano ~/kurs/05/agent.yamlapiVersion: apps/v1
kind: DaemonSet
metadata:
name: spire-agent
namespace: spire
spec:
selector:
matchLabels:
app: spire-agent
template:
metadata:
labels:
app: spire-agent
spec:
serviceAccountName: spire-agent
automountServiceAccountToken: true
hostPID: true
containers:
- name: spire-agent
image: ghcr.io/spiffe/spire-agent:1.16.0
args: ["-config", "/run/spire/config/agent.conf"]
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: config
mountPath: /run/spire/config
readOnly: true
- name: bundle
mountPath: /run/spire/bundle
readOnly: true
- name: agent-ausweis
mountPath: /var/run/secrets/tokens
readOnly: true
- name: kubelet-ca
mountPath: /run/spire/kubelet-ca/server-ca.crt
readOnly: true
- name: sockets
mountPath: /run/spire/agent-sockets
volumes:
- name: config
configMap:
name: spire-agent
- name: bundle
configMap:
name: spire-bundle
- name: agent-ausweis
projected:
sources:
- serviceAccountToken:
audience: spire-server
expirationSeconds: 600
path: spire-agent
- name: kubelet-ca
hostPath:
path: /var/lib/rancher/k3s/agent/server-ca.crt
type: File
- name: sockets
hostPath:
path: /run/spire/agent-sockets
type: DirectoryOrCreate| Option | Meaning |
|---|---|
kind: DaemonSet |
exactly one pod per node – one gatekeeper per floor |
automountServiceAccountToken: true |
normal badge for the questions to the kubelet (Step 1) |
hostPID: true |
the agent sees the processes of all pods on the node; only then can it map a request to a process ID |
agent-ausweis |
projected token with audience spire-server – the
building badge for node attestation; the agent looks for it under
/var/run/secrets/tokens/spire-agent |
kubelet-ca |
the node’s CA as a single file |
sockets |
folder on the node; the agent puts its socket there, and other pods mount it |
# on id1
kubectl apply -f ~/kurs/05/agent.yaml# on id1
kubectl rollout status daemonset/spire-agent -n spire --timeout=120sExpected:
Waiting for daemon set "spire-agent" rollout to finish: 0 of 2 updated pods are available...
Waiting for daemon set "spire-agent" rollout to finish: 1 of 2 updated pods are available...
daemon set "spire-agent" successfully rolled out
# on id1
kubectl get pods -n spire -o wideExpected (your names will be different):
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
spire-agent-5rddc 1/1 Running 0 10s 10.42.0.9 id1 <none> <none>
spire-agent-qsd4m 1/1 Running 0 10s 10.42.1.10 id2 <none> <none>
Step 5 – what the gatekeeper on id2 went through. Take the name of the pod on id2 from the output:
# on id1
kubectl logs -n spire spire-agent-qsd4mExpected (excerpt – look for
Node attestation was successful and
Starting agent APIs):
time="2026-12-01T10:58:01Z" level=info msg="SVID is not found. Starting node attestation" subsystem_name=attestor trust_domain_id="spiffe://gebaeude.test"
time="2026-12-01T10:58:02Z" level=info msg="Node attestation was successful" reattestable=true spiffe_id="spiffe://gebaeude.test/spire/agent/k8s_psat/labor/52aba4e0-1660-4c14-a9a5-209b4671bd08" subsystem_name=attestor trust_domain_id="spiffe://gebaeude.test"
time="2026-12-01T10:58:02Z" level=info msg="Starting agent APIs" address=/run/spire/agent-sockets/agent.sock apis="Workload and SDS APIs" network=unix subsystem_name=endpoints
What you see: The agent did not have a badge yet,
presented its building badge and got a SPIFFE ID. You know the long
number at the end: it is the UID of the node id2, the same as
node.uid in the tokens from Day 2.
Step 6 – the HR department’s list.
# on id1
sudo -u spire /opt/spire/bin/spire-server agent list -socketPath /run/spire-server/api.sockExpected:
Found 2 attested agents:
SPIFFE ID : spiffe://gebaeude.test/spire/agent/k8s_psat/labor/4bee6d80-8467-4725-92f0-65fcf0151197
Attestation type : k8s_psat
Expiration time : 2026-12-01 11:58:00 +0000 UTC
Serial number : 285608448633470380483031929771468856538
Can re-attest : true
Agent version : 1.16.0
SPIFFE ID : spiffe://gebaeude.test/spire/agent/k8s_psat/labor/52aba4e0-1660-4c14-a9a5-209b4671bd08
Attestation type : k8s_psat
Expiration time : 2026-12-01 11:58:02 +0000 UTC
Serial number : 178516960658550117146823408055946995170
Can re-attest : true
Agent version : 1.16.0
| Field | Meaning |
|---|---|
SPIFFE ID |
…/spire/agent/<attestor>/<cluster>/<node-uid>
– the gatekeeper’s personnel number |
Expiration time |
one hour after login (default_x509_svid_ttl); the agent
renews before that |
Can re-attest |
the agent may log in again with a new building badge, for example after a restart |
Step 7 – the call to the badge office.
# on id1
sudo journalctl -u spire-server --no-pager -o cat --since "-3min" --grep "attestation"Expected (excerpt, one line wrapped):
level=info msg="Agent attestation request completed" address="172.16.0.228:36301"
agent_id="spiffe://gebaeude.test/spire/agent/k8s_psat/labor/52aba4e0-1660-4c14-a9a5-209b4671bd08"
… method=AttestAgent node_attestor_type=k8s_psat …
What you see: The server checked the agent’s building badge via TokenReview – with the permissions from Drill 2 – and accepted it.
Remember: The gatekeeper proves their floor with a building badge that only the kubelet of this node receives. The HR department checks it with the badge office and assigns a personnel number made of cluster and node.
Save your progress? Sign up for free
Drill 5: The gatekeeper takes a close look
Where you are: on id1.
What you have afterwards: a pod
werkstattthat asks the gatekeeper for a staff badge, and the list of features the gatekeeper determines in the process.
Step 1 – an employee without a personnel file. The
pod uses the agent image because it contains the program
spire-agent. However, it is not started as an agent but as
a client: api watch asks for a staff badge via the socket
and waits until one arrives.
# on id1
nano ~/kurs/05/werkstatt.yamlapiVersion: v1
kind: ServiceAccount
metadata:
name: werkstatt
namespace: laden
---
apiVersion: v1
kind: Pod
metadata:
name: werkstatt
namespace: laden
labels:
app: werkstatt
spec:
serviceAccountName: werkstatt
automountServiceAccountToken: false
nodeName: id2
containers:
- name: werkstatt
image: ghcr.io/spiffe/spire-agent:1.16.0
command: ["/opt/spire/bin/spire-agent"]
args: ["api", "watch", "-socketPath", "/run/spire/sockets/agent.sock"]
volumeMounts:
- name: spire-sockel
mountPath: /run/spire/sockets
readOnly: true
volumes:
- name: spire-sockel
hostPath:
path: /run/spire/agent-sockets
type: Directory| Option | Meaning |
|---|---|
automountServiceAccountToken: false |
the pod gets no building badge; it should get its identity only from SPIRE |
nodeName: id2 |
pinned to id2, so you know which gatekeeper is responsible |
spire-sockel |
the folder with the agent’s socket, read-only |
# on id1
kubectl apply -f ~/kurs/05/werkstatt.yaml# on id1
kubectl wait --for=condition=Ready pod/werkstatt -n laden --timeout=60sExpected:
pod/werkstatt condition met
Step 2 – what does the gatekeeper say?
# on id1
kubectl logs -n laden werkstattExpected:
rpc error: code = PermissionDenied desc = no identity issued
# on id1
kubectl exec -n laden werkstatt -- /opt/spire/bin/spire-agent api fetch x509 -socketPath /run/spire/sockets/agent.sockExpected:
rpc error: code = PermissionDenied desc = no identity issued
command terminated with exit code 1
What you see: The gatekeeper accepted the request but issued no badge. They know the pod – there is just no personnel file that matches it.
Step 3 – what the gatekeeper determined. Because of
log_level = "DEBUG", the agent writes down what it found
out about the caller. Take the agent pod on id2:
# on id1
kubectl logs -n spire spire-agent-qsd4m --since=3mExpected (excerpt – look for
PID attested to have selectors; the list is wrapped line by
line here):
level=debug msg="PID attested to have selectors" pid=54271 selectors="[
type:\"k8s\" value:\"sa:werkstatt\"
type:\"k8s\" value:\"ns:laden\"
type:\"k8s\" value:\"node-name:id2\"
type:\"k8s\" value:\"pod-uid:ca5dc7a1-e01c-4aba-9c80-db3d5141887b\"
type:\"k8s\" value:\"pod-name:werkstatt\"
type:\"k8s\" value:\"pod-image-count:1\"
type:\"k8s\" value:\"pod-init-image-count:0\"
type:\"k8s\" value:\"pod-image:ghcr.io/spiffe/spire-agent@sha256:ab3a8ce70435374cc5d84c81eabf0278dc046ddbc0a736d59694ba9e5975b1b6\"
type:\"k8s\" value:\"pod-image:ghcr.io/spiffe/spire-agent:1.16.0\"
type:\"k8s\" value:\"pod-label:app:werkstatt\"
type:\"k8s\" value:\"container-name:werkstatt\"
type:\"k8s\" value:\"container-image:ghcr.io/spiffe/spire-agent@sha256:ab3a8ce70435374cc5d84c81eabf0278dc046ddbc0a736d59694ba9e5975b1b6\"
type:\"k8s\" value:\"container-image:ghcr.io/spiffe/spire-agent:1.16.0\"]" subsystem_name=workload_attestor
level=error msg="No identity issued" method=FetchX509SVID pid=54271 registered=false service=WorkloadAPI subsystem_name=endpoints
| Selector | How the gatekeeper knows it |
|---|---|
sa:werkstatt, ns:laden |
from the pod description at the kubelet |
node-name:id2 |
from the pod description; matches its own node |
pod-uid:…, pod-name:werkstatt |
from the pod description |
pod-image:…@sha256:… |
from the pod’s status: which image is actually running |
pod-label:app:werkstatt |
from the labels |
container-name:werkstatt |
which container in the pod made the request |
What you see: How the gatekeeper gets to the pod:
the call arrives over a Unix socket, and the kernel tells the agent
which process (pid) sits at the other end. Because of
hostPID the agent can read its cgroup, and the cgroup
contains the pod UID. With the UID it asks the kubelet about the pod.
None of this comes from the pod itself – it only made the call. Tomorrow
you write a personnel file whose features match these selectors.
Remember: Workload attestation means: the gatekeeper does not ask “Who are you?” but checks – process, cgroup, kubelet. The selectors are the result; a personnel file (Day 6) is the rule for who gets which badge with them.
Save your progress? Sign up for free
Diagnosis task
A colleague tidied up the DaemonSet and changed the audience of the
agent badge from spire-server to the shorter
spire. The agent pods are running;
kubectl get pods -n spire shows 1/1 Running.
Nevertheless the workshop now reports something different than
before:
# on id1
kubectl exec -n laden werkstatt -- /opt/spire/bin/spire-agent api fetch x509 -socketPath /run/spire/sockets/agent.sockExpected:
rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial unix /run/spire/sockets/agent.sock: connect: no such file or directory"
command terminated with exit code 1
What is going on?
Solution path:
no such file or directory: the socket is missing. The agent only creates it once it has a badge itself. So look at the agent’s logs:# on id1 kubectl logs -n spire daemonset/spire-agent --tail=8Expected (excerpt, wrapped):
level=warning msg="Failed to retrieve attestation result" error="failed to receive attestation response: rpc error: code = Internal desc = nodeattestor(k8s_psat): unable to validate token with TokenReview API for cluster \"labor\": token review API response contains an error: [invalid bearer token, token audiences [\"spire\"] is invalid for the target audiences [\"spire-server\"]]" retry_interval=8.112214662s level=warning msg="Health check failed" check=agent … error="subsystem is not ready"The message is unambiguous: the building badge is for the door
spire, the server expectsspire-server. That is the default audience of thek8s_psatplugin (settingaudienceinserver.conf).The pod is
Runninganyway because the DaemonSet has no probe. The agent waits and retries every few seconds. The server’s journal shows the same error for every attempt.Solution: Set
audience: spire-serverback in the DaemonSet and runkubectl apply -f ~/kurs/05/agent.yaml. After thatspire-server agent listshows two agents again – with new serial numbers, but the same SPIFFE IDs, because the ID depends on the node UID, not on the pod.
The lesson from Day 2 applies here too: the audience is a contract. Whoever changes it on one side must change it on the other as well. And: a liveness or readiness probe on the agent’s health endpoint would have made the problem visible immediately.
Challenge
Is there really a separate gatekeeper for each node? Start a second workshop, this time on id1, and show that a different agent recognizes it. Write down the steps before you read the solution.
Solution: A copy of werkstatt.yaml with
a different name and nodeName: id1. The ServiceAccount
already exists, so the pod is enough:
# on id1
nano ~/kurs/05/werkstatt-id1.yamlapiVersion: v1
kind: Pod
metadata:
name: werkstatt-id1
namespace: laden
labels:
app: werkstatt
spec:
serviceAccountName: werkstatt
automountServiceAccountToken: false
nodeName: id1
containers:
- name: werkstatt-id1
image: ghcr.io/spiffe/spire-agent:1.16.0
command: ["/opt/spire/bin/spire-agent"]
args: ["api", "watch", "-socketPath", "/run/spire/sockets/agent.sock"]
volumeMounts:
- name: spire-sockel
mountPath: /run/spire/sockets
readOnly: true
volumes:
- name: spire-sockel
hostPath:
path: /run/spire/agent-sockets
type: Directory# on id1
kubectl apply -f ~/kurs/05/werkstatt-id1.yaml# on id1
kubectl get pods -n spire -o wideExpected (excerpt):
spire-agent-5c4sd 1/1 Running 0 19s 10.42.0.11 id1 <none> <none>
# on id1
kubectl logs -n spire spire-agent-5c4sd --since=1mExpected (excerpt – start of the selector list):
level=debug msg="PID attested to have selectors" pid=135002 selectors="[type:\"k8s\" value:\"sa:werkstatt\" type:\"k8s\" value:\"ns:laden\" type:\"k8s\" value:\"node-name:id1\" type:\"k8s\" value:\"pod-uid:2eded228-df42-427d-a76f-5682754f897f\" type:\"k8s\" value:\"pod-name:werkstatt-id1\" …
Same ServiceAccount, same namespace, same image – but
node-name:id1, a different pod-uid and a
request to the agent on id1. Each gatekeeper only answers requests from
their own floor, because the socket lives in the node’s file system.
Save your progress? Sign up for free
Checkpoint
# on id1
sudo -u spire /opt/spire/bin/spire-server healthcheck -socketPath /run/spire-server/api.sockExpected:
Server is healthy.
# on id1
sudo -u spire /opt/spire/bin/spire-server agent list -socketPath /run/spire-server/api.sockExpected: Found 2 attested agents: with
two SPIFFE IDs of the form
spiffe://gebaeude.test/spire/agent/k8s_psat/labor/<node-uid>.
# on id1
kubectl exec -n laden werkstatt -- /opt/spire/bin/spire-agent api fetch x509 -socketPath /run/spire/sockets/agent.sockExpected: no identity issued – the
gatekeeper answers, but there is no personnel file yet.
Test yourself
- What is the difference between SPIFFE and SPIRE?
- Why does the SPIRE server need a kubeconfig, even though the agents come to it?
- How does the agent know which pod is talking to it via the socket – and why can the pod not lie in the process?
- What is in
keys.json, and what could someone do with it? - An agent pod is running (
1/1 Running), but programs on the node get “no such file or directory” for the socket. Where do you look first? - Why does
werkstattnot get a normal ServiceAccount token mounted?
Answers:
- SPIFFE is the standard: the format of the IDs
(
spiffe://…), of the badges (SVID) and of the Workload API. SPIRE is a piece of software that implements it – server and agents. - The server does not check the agent’s building badge itself, but has the API server check it via TokenReview and looks up pod and node. For that it needs access of its own – the first badge, which you can only keep small but never abolish.
- Through the Unix socket the agent learns the caller’s process ID
from the kernel. With
hostPIDit reads its cgroup and finds the pod UID, then it asks the kubelet. The pod supplies not a single piece of information about itself. - The private key of the trust domain’s CA. Whoever has it can issue
staff badges for any SPIFFE ID in
gebaeude.test– like a stolen stamp. - In the agent’s logs. It only creates the socket once node attestation has succeeded; the reason for the failure is spelled out there in plain text.
- Because today its identity is supposed to come from SPIRE. A mounted building badge would be a second, unused badge – and every unused badge is one that can be stolen.
Interview note
“How does SPIRE work in Kubernetes?” – Good answer: a SPIRE server
holds the trust domain’s CA and the registration entries. An agent runs
on every node as a DaemonSet. The agent identifies itself via node
attestation, in Kubernetes typically with k8s_psat: a
projected ServiceAccount token with its own audience, which the server
checks via TokenReview. Programs fetch their SVID via the Workload API,
a Unix socket. The agent recognizes them via the process ID, the cgroup
and the kubelet and derives selectors from that. If a registration entry
matches, there is an SVID – without the program ever having had a
secret. If they dig deeper: the server itself needs access to the API
server, and workload attestation does not protect against someone with
root on the node.
Enterprise note
In production the SPIRE server usually runs highly available with
PostgreSQL instead of SQLite, and the CA key is not in
keys.json but in an HSM or cloud KMS (KeyManager plugins),
or SPIRE hangs as a sub-CA under an existing PKI
(UpstreamAuthority). The server’s access to the API server
should not be a 30-day token that someone renews by hand, but an
automatically renewed token or – if the server runs in the cluster – its
own projected token.
The bundle in the ConfigMap is only for the first connection. The
server’s CA expires here after 24 hours; an agent that starts for the
first time after that cannot connect with the old bundle. That is why in
production you distribute the bundle automatically, for example with the
k8sbundle notifier or via a bundle endpoint. You will see
how rotation works on Day 8.
And a limit the SPIRE documentation itself names: workload
attestation via cgroups is only reliable against unprivileged programs.
Anyone with root on the node can obtain any identity of the pods running
there. Privileged pods and hostPID therefore belong to the
agent alone.
Summary
- SPIFFE describes identities (
spiffe://gebaeude.test/…) and badges (SVIDs); SPIRE issues them. - The SPIRE server runs on id1 as a service under the user
spire, with its own CA (24 h) and an SQLite database.keys.jsonis its stamp. - The server has tightly limited access to the cluster: create
TokenReviews, read pods and nodes, via a 30-day token as
tokenFile. - The agents run as a DaemonSet and log in via
k8s_psat: a projected token with audiencespire-server, only for the ServiceAccountspire:spire-agent. - An agent’s SPIFFE ID contains the cluster and the node UID.
- When a pod makes a request via the socket, the agent determines its selectors via process ID, cgroup and kubelet. Without a registration entry the result is “no identity issued”.
Commands at a glance
| Command | What for |
|---|---|
sha256sum -c <datei> |
verify checksums from a list |
kubectl create token <sa> -n <ns> --duration 720h |
token for a service outside the cluster |
kubectl config set users.<name>.tokenFile <pfad> --kubeconfig=<datei> |
kubeconfig that reads the token from a file |
sudo install -o <u> -g <g> -m 600 <quelle> <ziel> |
copy with owner and permissions |
spire-server healthcheck -socketPath <sock> |
is the server alive? |
spire-server bundle show -socketPath <sock> |
CA certificates of the trust domain |
spire-server agent list -socketPath <sock> |
attested agents |
kubectl rollout status daemonset/<name> -n <ns> |
wait until a pod runs on every node |
spire-agent api fetch x509 -socketPath <sock> |
request an X.509 SVID as a program |
spire-agent api watch -socketPath <sock> |
wait for an SVID and show renewals |