Skip to content
Workload and AI agent identity · Chapter 18 of 20 Appendix A: Cheat sheet

Appendix A: Cheat sheet

What this appendix is for: looking things up when you know what you want to do but have forgotten the syntax. It explains nothing new. The days in parentheses lead to the chapters where each command appears with all its options and a real output. kcadm.sh is short for /opt/keycloak/bin/kcadm.sh, spire-server for sudo -u spire /opt/spire/bin/spire-server … -socketPath /run/spire-server/api.sock. In the course, <realm> is gebaeude, and <ns> is usually laden.

Which badge for which door

Who Badge Issued by Checked by Day
Pod towards the API server projected ServiceAccount token API server (TokenRequest) API server 2
Pod towards its own service projected token with its own audience API server service via TokenReview or offline via JWKS 2, 3
Pod towards Keycloak ServiceAccount token as client assertion API server Keycloak (identity provider kubernetes, offline) 4
Pod towards pod X.509 SVID SPIRE server via the agent the other side (mTLS, ghostunnel) 5–7
Human access token from device login Keycloak service (aud, scope) 9
Agent on behalf of a human token from token exchange Keycloak service (aud, scope, azp) 11, 12
MCP client access token with aud = MCP server Keycloak MCP server, which exchanges it again itself 13

Reading and verifying a token

Command What for Day
step crypto jwt inspect --insecure < <datei> read a token without verifying it 0
date -u -d @<sekunden> turn iat, exp, nbf into a time of day 0
kubectl get --raw /.well-known/openid-configuration the cluster’s discovery document 0, 3
kubectl get --raw /openid/v1/jwks the cluster’s public keys 3
step crypto jwt verify --jwks <datei> --iss <iss> --aud <aud> < <token> verify a token offline 3
kubectl create -f review.json -o yaml TokenReview: is the token valid for Kubernetes? 2, 14
curl … /protocol/openid-connect/userinfo -H @kopf.txt ask Keycloak who a token belongs to 9
jq -r '"Authorization: Bearer " + .access_token' <antwort> > kopf.txt header line for curl -H @kopf.txt 9

What you look at first in every token: iss (who issued it), aud (for which door), sub (who), azp (through which client), scope (which rights), exp (until when), sid and jti (which session, which pass).

Kubernetes

Command What for Day
kubectl create token <sa> -n <ns> --audience <aud> --duration 10m token for one audience, short lifetime 2
kubectl auth can-i --list -n <ns> --as system:serviceaccount:<ns>:<sa> all rights of a ServiceAccount 1
kubectl auth can-i create tokenreviews --as <sa> may a service have tokens reviewed? 2
automountServiceAccountToken: false switch off the default token 2
projected.sources.serviceAccountToken with audience and expirationSeconds token with its own audience in the pod 2
sudo journalctl -u k3s --grep "Unable to authenticate" reason for a rejected token 2
kubectl delete serviceaccount <sa> -n <ns> delete a service account – only blocks with online checkers 14
sudo k3s secrets-encrypt status are Secrets encrypted at rest? 1

Keycloak with kcadm.sh

Command What for Day
kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin log in (prompts for the password) 4
kcadm.sh create identity-provider/instances -r <realm> -s providerId=kubernetes -s config.issuer=<iss> trust the cluster 4
kcadm.sh create clients -r <realm> -s clientId=<id> -s clientAuthenticatorType=federated-jwt -s 'attributes."jwt.credential.issuer"=<idp>' -s 'attributes."jwt.credential.sub"=system:serviceaccount:<ns>:<sa>' client without a secret 4, 10
kcadm.sh get clients -r <realm> -q clientId=<id> find a client by its name 4, 16
kcadm.sh create clients/<id>/protocol-mappers/models … -s protocolMapper=oidc-audience-mapper -s 'config."included.custom.audience"=<tür>' write the door into aud 10
… -s 'config."included.client.audience"=<client>' write a client into aud (for exchange) 11, 13
kcadm.sh update clients/<id>/default-client-scopes/<scope-id> scope always in the token 10
kcadm.sh update clients/<id>/optional-client-scopes/<scope-id> scope only on request 9, 12
kcadm.sh delete clients/<id>/default-client-scopes/<scope-id> remove a scope from the default list 12, 16
kcadm.sh create client-scopes/<id>/scope-mappings/realm -b '[{"id":…,"name":…}]' scope only with a role 11
kcadm.sh add-roles / remove-roles -r <realm> --uusername <name> --rolename <rolle> grant / revoke a role 11, 16
kcadm.sh update clients/<id> -s 'attributes."standard.token.exchange.enabled"=true' client may exchange tokens 11
kcadm.sh update clients/<id> -s 'attributes."access.token.lifespan"=60' token lifetime per client 12
kcadm.sh create clients/<id>/client-secret new client secret 16

The token endpoint

All requests go to http://172.16.0.126:8080/realms/gebaeude/protocol/openid-connect/token.

grant_type Further fields Who Day
client_credentials client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer, client_assertion@<ausweis> workload with a Kubernetes badge 4, 10
client_credentials client_id, client_secret workload with a secret (avoid) 16
urn:ietf:params:oauth:grant-type:device_code client_id, device_code@<datei> human after the device login (…/auth/device) 9
urn:ietf:params:oauth:grant-type:token-exchange client assertion, subject_token@<datei>, subject_token_type=urn:ietf:params:oauth:token-type:access_token, scope=<bereich> agent on behalf of someone 11, 12

SPIFFE and SPIRE

Command What for Day
spire-server healthcheck is the server alive? 5
spire-server agent list registered agents 5
spire-server entry create -node -spiffeID <id> -selector k8s_psat:cluster:<name> node alias 6
spire-server entry create -parentID <alias> -spiffeID <id> -selector k8s:ns:<ns> -selector k8s:sa:<sa> entry for a ServiceAccount 6
spire-server entry show / update -entryID <id> … / delete -entryID <id> maintain entries 6
spire-agent api fetch x509 -socketPath <sock> fetch an X.509 SVID 5, 6
spire-agent api fetch jwt -audience <aud> -socketPath <sock> fetch a JWT SVID 6
spire-server localauthority x509 show / prepare / activate / taint / revoke rotate the CA 8
ghostunnel server … --allow-uri=<id> / ghostunnel client … --verify-uri=<id> mTLS in front of a plaintext service 7

The selectors of the k8s plugin are called ns:, sa:, pod-name:, node-name: – not serviceaccount: (Day 6).

MCP server

Command or setting What for Day
curl -s <server>/.well-known/oauth-protected-resource/<pfad> Protected Resource Metadata (RFC 9728) 13
curl -s <host>/.well-known/oauth-authorization-server/realms/<realm> the issuer’s metadata (RFC 8414) 13
-H "MCP-Protocol-Version: 2026-07-28" and _meta with io.modelcontextprotocol/protocolVersion in every request (stateless) 13
401 with WWW-Authenticate: Bearer resource_metadata="…" missing or invalid token 13
403 with error="insufficient_scope", scope="…" token without the required scope 13
Never pass a token through; exchange it for the downstream service no token passthrough 13

Emergency: order of revocation

No. What Affects Day
1 Determine the remaining lifetime: access.token.lifespan on the client, last fetch from kcadm.sh get events decision 14, 16
2 Disable the client: kcadm.sh update clients/<id> -s enabled=false new tokens of this client 14
3 End sessions: kcadm.sh create users/<id>/logout exchange with the human’s tokens 14
4 Rotate the secret or rebind the workload (jwt.credential.sub) new tokens with the old access 14, 16
5 Cut rights and lifetime only future tokens 16
6 Issued tokens: wait out the remaining lifetime or have the service block them specifically running tokens 14, 16

Deleting the ServiceAccount alone is not enough: Keycloak checks Kubernetes badges offline (Day 14).

Audit

Command What for Day
kcadm.sh update realms/<realm> -s eventsEnabled=true -s eventsExpiration=604800 -s adminEventsEnabled=true -s adminEventsDetailsEnabled=true store events 15
kcadm.sh get events -r <realm> [-q client=<id>] [-q type=<typ>] [-q dateFrom=<datum>] [-q max=<n>] user events 15, 16
kcadm.sh get admin-events -r <realm> [-q 'resourcePath=*<id>*'] admin events 15, 16
jq '.[] \| select(.details.token_id == "<jti>")' events.json the event for a token 15
jq '.[] \| select(.sessionId == "<sid>")' events.json all events of a session 15
date -d @<sekunden> +%T make Keycloak time readable (first ten digits) 16
journalctl -u lagerdienst --since <zeit> --no-pager the warehouse’s visitor log 10, 15, 16
sudo journalctl -u keycloak --grep "CLIENT_LOGIN_ERROR\|TOKEN_EXCHANGE_ERROR" error events with a reason 4, 11, 14

Following the trail backwards: jti in the warehouse → token_id of a TOKEN_EXCHANGE → sessionId → LOGIN with IP. Without a session (sid=None): token_id → CLIENT_LOGIN → client_assertion_id (Kubernetes badge) or client_auth_method=client-secret (secret) and ipAddress (Day 15, 16).

Contents

More