Cheat Sheets / Security & Identity

Identity & Zero Trust for Platform Engineers cheat sheet

80 commands from every lesson of Identity & Zero Trust for Platform Engineers, on one page.

01 · Zero trust, layer by layer

Quick checks: how much implicit trust is left?

kubectl get networkpolicy -ANamespaces with no policy are flat: every pod can reach them
kubectl get peerauthentication -AMesh mTLS mode per namespace (PERMISSIVE still accepts plaintext)
kubectl get ns -L pod-security.kubernetes.io/enforcePod Security level enforced per namespace
kubectl get clusterrolebindings -o wide | grep cluster-adminWho holds cluster-admin
kubectl auth can-i --list --as=system:serviceaccount:<ns>:defaultWhat a namespace's default ServiceAccount can do

02 · From TLS to mTLS

Inspect TLS from the command line

openssl s_client -connect host:443 -servername host -tls1_3 </dev/nullHandshake details, chain and negotiated cipher
openssl s_client -connect host:443 -showcerts </dev/nullPrint every certificate the server sends
openssl x509 -in cert.pem -noout -subject -issuer -dates -ext subjectAltNameWho, issued by whom, validity, SAN names
curl -v --cert client.crt --key client.key --cacert ca.crt https://api.internalCall an mTLS endpoint with a client certificate
openssl s_server -accept 8443 -cert srv.crt -key srv.key -CAfile ca.crt -Verify 1Test server that requires a client certificate

03 · PKI for a whole platform

Inventory and expiry

kubectl get certificates -Acert-manager certificates and their Ready state
kubectl get certificaterequests -A --sort-by=.metadata.creationTimestampRecent issuance attempts (look for failures)
kubeadm certs check-expirationControl-plane certificate expiry on a kubeadm node
openssl x509 -in cert.pem -noout -enddateExpiry of one certificate
echo | openssl s_client -connect host:443 -servername host 2>/dev/null | openssl x509 -noout -enddateExpiry as a client actually sees it

Trust bundles

cat old-root.pem new-root.pem > bundle.pemA bundle that trusts both roots during rotation
openssl verify -CAfile bundle.pem -untrusted intermediate.pem leaf.pemCheck a leaf chains to a root in the bundle

04 · Workload identity with SPIFFE

Look at identities

istioctl proxy-config secret deploy/orders -n shopCertificates the proxy holds (identity, expiry)
istioctl proxy-config secret deploy/orders -n shop -o json | jq -r '..|.inlineBytes?' | grep -v null | head -1 | base64 -d | openssl x509 -noout -text | grep URIThe SPIFFE ID inside the workload certificate
linkerd viz edges deploy -n shopWhich identities talk to which (Linkerd)
kubectl exec -n spire spire-server-0 -- /opt/spire/bin/spire-server entry showRegistration entries in SPIRE

05 · Cloud workload identity

AWS

kubectl annotate sa orders -n shop eks.amazonaws.com/role-arn=arn:aws:iam::111122223333:role/ordersIRSA: link a ServiceAccount to an IAM role
aws eks create-pod-identity-association --cluster-name prod --namespace shop --service-account orders --role-arn <role-arn>EKS Pod Identity association
kubectl exec -n shop deploy/orders -- aws sts get-caller-identityWhich role the pod actually assumed
aws ec2 modify-instance-metadata-options --instance-id <id> --http-tokens required --http-put-response-hop-limit 1IMDSv2 only, unreachable from pod network namespaces

Azure and GCP

az identity federated-credential create --name orders --identity-name orders-id --resource-group rg --issuer <aks-oidc-issuer> --subject system:serviceaccount:shop:orders --audience api://AzureADTokenExchangeAzure: trust one ServiceAccount
kubectl annotate sa orders -n shop azure.workload.identity/client-id=<client-id>Azure: link the ServiceAccount (pods also need label azure.workload.identity/use=true)
kubectl annotate sa orders -n shop iam.gke.io/gcp-service-account=orders@proj.iam.gserviceaccount.comGKE: link to a Google service account

06 · Service-to-service authorization

Check what is allowed

kubectl get networkpolicy -n shop -o yamlAll network rules in a namespace
kubectl get authorizationpolicy -AIstio identity-based policies
istioctl x authz check <payments-pod> -n shopEffective authorisation rules on one workload's proxy
hubble observe --namespace shop --verdict DROPPEDCilium: flows that policy dropped, with identities
kubectl -n shop exec deploy/orders -- curl -s -o /dev/null -w '%{http_code}' http://payments:8080/chargeTest a call: 403 means L7 policy, timeout means network policy

07 · OAuth 2.0, OIDC, SAML and SCIM

Explore an OIDC provider

curl -s https://issuer.example.com/.well-known/openid-configuration | jqDiscovery: endpoints, supported flows, JWKS URL
curl -s <jwks_uri> | jq '.keys[] | {kid, alg, kty}'The public keys used to verify tokens
cut -d. -f2 <<< "$TOKEN" | tr '_-' '/+' | base64 -d 2>/dev/null | jqRead a JWT's claims (reading is not validating)

Get tokens (test IdP)

curl -s -d grant_type=client_credentials -d client_id=svc -d client_secret=… <token_endpoint>Client Credentials: a service gets a token for itself
kubectl oidc-login get-token --oidc-issuer-url=<issuer> --oidc-client-id=kubectlkubelogin: browser login, token for kubectl

08 · Validating tokens and propagating identity

Gateway / mesh token checks (Istio)

kubectl apply -f requestauthentication.yamlValidate JWTs from an issuer (signature, iss, aud) at the proxy
kubectl get requestauthentication,authorizationpolicy -n shopWhich token rules apply in a namespace

Debugging tokens

cut -d. -f1 <<< "$TOKEN" | base64 -d 2>/dev/nullHeader: alg and kid
cut -d. -f2 <<< "$TOKEN" | tr '_-' '/+' | base64 -d 2>/dev/null | jq '{iss,aud,sub,exp,scope}'Claims that every check uses
date -d @<exp>Human-readable expiry

09 · Human access: least privilege, JIT and reviews

Who can do what

kubectl auth can-i --list --as=alice@example.com --as-group=team-shopEffective permissions of a user and group
kubectl get clusterrolebindings,rolebindings -A -o wide | grep -i <group>Where a group is bound
kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.roleRef.name=="cluster-admin") | .metadata.name, .subjects'Everyone with cluster-admin

Audit

jq 'select(.verb=="create" and .objectRef.subresource=="exec")' audit.logWho exec'd into pods
jq 'select(.objectRef.resource=="secrets" and .user.username | test("@"))' audit.logHumans reading Secrets

10 · Tenant isolation in a multi-tenant SaaS

PostgreSQL row-level security

ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;Turn on RLS for a table
ALTER TABLE accounts FORCE ROW LEVEL SECURITY;Apply RLS to the table owner too
CREATE POLICY tenant_isolation ON accounts USING (tenant_id = current_setting('app.tenant_id')::uuid);Only rows for the session's tenant
SET app.tenant_id = '…';Set the tenant for this connection or transaction (from the verified token)

Quick isolation tests

curl -H "Authorization: Bearer $TENANT_A_TOKEN" https://api.example.com/tenants/B/usersMust be 403/404, never data
kubectl get resourcequota,limitrange -n <tenant-ns>Compute limits for a dedicated namespace

11 · Compliance as code

Evidence you can pull from the platform

kubectl get policyreport,clusterpolicyreport -AKyverno policy results per namespace (pass/fail)
kube-bench run --targets node,policies --jsonCIS Kubernetes Benchmark results
trivy image --format cyclonedx --output sbom.json <image>SBOM for an image
cosign verify --key cosign.pub <image>@<digest>Proof an image was signed by your pipeline
git log --merges --format='%h %an %s' -- clusters/prodReviewed, merged changes to production config

12 · Threat modelling a platform

STRIDE at a glance

S: SpoofingPretending to be someone else → strong authentication, mTLS, MFA
T: TamperingChanging data or code → signing, integrity checks, GitOps
R: RepudiationDenying an action → audit logs, signed commits, tamper-resistant logs
I: Information disclosureLeaking data → encryption, tenant isolation, least privilege
D: Denial of serviceExhausting resources → rate limits, quotas, cells
E: Elevation of privilegeGaining more rights → least privilege, Pod Security, admission control

13 · Responding to a compromised workload

Contain

kubectl label pod <pod> -n shop quarantine=true app-Remove from Service endpoints (stop new traffic) and mark it
kubectl apply -f quarantine-netpol.yamlDeny all ingress and egress for quarantine=true pods
kubectl cordon <node>No new pods on the affected node

Preserve and scope

kubectl get pod <pod> -n shop -o yaml > pod.yamlSpec, image digest, ServiceAccount, node
kubectl logs <pod> -n shop --all-containers --timestamps > logs.txtContainer logs before anything restarts
kubectl debug node/<node> -it --image=busyboxInspect the node from a debug pod (host filesystem under /host)
kubectl auth can-i --list --as=system:serviceaccount:shop:<sa>What the workload's identity could do in the cluster
kubectl get clusterrolebindings,mutatingwebhookconfigurations,daemonsets -A --sort-by=.metadata.creationTimestampRecently created high-risk objects (persistence)

14 · Capstone: zero-trust design review

Review questions per layer

HumansSSO + MFA everywhere? Standing admin? JIT? Reviews?
WorkloadsOne identity per service? Static cloud keys anywhere?
Service to serviceDefault deny? Strict mTLS? Identity-based L7 policy?
Edge and usersToken checks complete (aud, alg, tenant)? Identity headers stripped?
DataTenant enforced in the database? Per-tenant keys where needed?
DeliverySigned images verified at admission? Pipeline credentials short-lived?
Detect and respondRuntime detection? Audit logs central? Quarantine runbook?