|
| 1 | +--- |
| 2 | +name: workload-identity |
| 3 | +description: Workload identity playbook (SPIFFE/SPIRE, cloud IAM, OIDC federation). Workflows for picking SPIFFE vs cloud IAM, deploying SPIRE on EKS, federating trust domains, bridging to AWS/GCP/Azure via OIDC, and migrating off long-lived workload secrets. Use when designing or hardening service-to-service auth for k8s, multi-cloud, or AI agents. |
| 4 | +--- |
| 5 | + |
| 6 | +# Workload Identity - Playbook |
| 7 | + |
| 8 | +**Companion rule:** `318-workload-identity.mdc`. This skill turns the principles into end-to-end workflows. |
| 9 | + |
| 10 | +**Scope:** the *infrastructure* layer of identity. For the *application* layer (cross-app, agent-on-behalf-of-user), use `skills/okta` (XAA / ID-JAG) and `skills/zero-trust` (HITL gates, threat models). |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## When to invoke |
| 15 | + |
| 16 | +Use when the user is: |
| 17 | + |
| 18 | +- Designing service-to-service auth for a Kubernetes platform |
| 19 | +- Choosing between SPIFFE/SPIRE and cloud IAM (IRSA, GCP Workload Identity, Azure Managed Identity) |
| 20 | +- Deploying SPIRE on EKS / GKE / AKS (or evaluating Red Hat ZTWIM on OpenShift) |
| 21 | +- Federating SPIFFE trust domains (multi-cluster, multi-cloud, or cross-org) |
| 22 | +- Bridging SPIRE to cloud IAM via OIDC (AssumeRoleWithWebIdentity, GCP WIF, Azure federated credentials) |
| 23 | +- Migrating workloads off long-lived secrets, instance profiles, or shared service accounts |
| 24 | +- Sizing the operational SLOs for a workload-identity rollout |
| 25 | +- Picking between SPIRE topologies (single-cluster, nested, federated, HA) |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Golden Rules (anchor every decision) |
| 30 | + |
| 31 | +1. **Attestation, not credentials.** If the design ships a long-lived workload secret, restart. |
| 32 | +2. **Trust domain per environment.** `prod`, `staging`, `dev` are separate roots of authority. |
| 33 | +3. **Image-digest selectors** beat image-tag selectors. Always. |
| 34 | +4. **mTLS proves *who*. Authorization is separate.** Pair with Istio AuthorizationPolicy / OPA / Lattice auth policy. |
| 35 | +5. **TTL in hours for X.509-SVIDs, minutes for JWT-SVIDs.** SDK auto-rotates. |
| 36 | +6. **One substrate per workload, but the platform mixes both.** SPIFFE for portable / k8s east-west; cloud IAM for cloud-native single-cloud. |
| 37 | +7. **OIDC bridge collapses "give pods cloud creds" to "trust my SPIFFE issuer".** |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## Workflow 1 - Pick SPIFFE vs Cloud IAM |
| 42 | + |
| 43 | +The most common architecture decision in this space. |
| 44 | + |
| 45 | +### Steps |
| 46 | + |
| 47 | +1. **Scope** the choice: which workload, which trust boundaries, which clouds, which platforms. |
| 48 | +2. **Score against the dimensions** in [references/spiffe-vs-cloud-iam.md](references/spiffe-vs-cloud-iam.md): |
| 49 | + - Portability needed? |
| 50 | + - Attestation granularity required (image digest vs cloud role)? |
| 51 | + - Operational capacity for SPIRE (HA, CA, observability)? |
| 52 | + - Cloud-team IAM depth? |
| 53 | + - Service-mesh strategy? |
| 54 | +3. **Default rules:** |
| 55 | + - Inside one cloud, IAM-deep team, no portability need → cloud IAM (IRSA / VPC Lattice for AWS; Workload Identity for GCP; Managed Identity for Azure) |
| 56 | + - Multi-cloud, k8s-heavy, ISV / portable platform → SPIFFE |
| 57 | + - Most enterprises: **both**, segmented by workload class |
| 58 | +4. **Decide and document** in an ADR (don't fold this into a generic "design doc" - it's worth its own). |
| 59 | +5. **Plan the OIDC bridge** (Workflow 4) if SPIFFE is on one side and cloud creds on the other. |
| 60 | + |
| 61 | +**Deliverable:** ADR with decision, scope, alternatives considered, and the boundary between SPIFFE and cloud-IAM-managed workloads. |
| 62 | + |
| 63 | +See [references/spiffe-vs-cloud-iam.md](references/spiffe-vs-cloud-iam.md). |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Workflow 2 - Deploy SPIRE on EKS |
| 68 | + |
| 69 | +Production-ready SPIRE on EKS with image-digest selectors and Vault PKI as upstream CA. |
| 70 | + |
| 71 | +### Steps |
| 72 | + |
| 73 | +1. **Trust domain decision.** One per environment (`prod.example.com`, `staging.example.com`, `dev.example.com`). Hard to change later. |
| 74 | +2. **SPIRE Server topology.** |
| 75 | + - HA: at least 2 replicas behind an internal NLB. |
| 76 | + - Datastore: RDS Postgres (Multi-AZ), encrypted at rest, in a private subnet. |
| 77 | + - UpstreamAuthority: Vault PKI (or AWS Private CA). SPIRE Server becomes an intermediate CA. |
| 78 | +3. **SPIRE Agent.** |
| 79 | + - DaemonSet, runs as privileged for `/proc` and CRI socket access. |
| 80 | + - Node attestor: `aws_iid` (EC2 instance identity document) with the cluster's OIDC issuer. |
| 81 | +4. **Workload attestor.** |
| 82 | + - `k8s` plugin with namespace, service-account, and **container image digest** selectors. |
| 83 | + - `unix` plugin as backup for non-k8s workloads on the node. |
| 84 | +5. **Registration entries.** |
| 85 | + - Author via Terraform (`spire-controller-manager` CRDs) or `spire-server entry create` in CI. |
| 86 | + - Selectors include `k8s:ns:<ns>`, `k8s:sa:<sa>`, `k8s:container-image:<image>@sha256:...`. |
| 87 | +6. **Workload integration.** |
| 88 | + - Sidecar (Envoy + SDS) for polyglot workloads. |
| 89 | + - Library (`go-spiffe`, `java-spiffe`) for high-perf services. |
| 90 | + - Ambient mesh (Cilium / Istio Ambient) for encrypt-everything-east-west cases. |
| 91 | +7. **Authorization on top.** |
| 92 | + - Istio AuthorizationPolicy with `source.principal` matching SPIFFE IDs. |
| 93 | + - Or Envoy ext_authz to OPA with Rego policy. |
| 94 | + - Default-deny per service. |
| 95 | +8. **Audit and monitoring.** |
| 96 | + - SPIRE Server audit log → SIEM. |
| 97 | + - Metrics: SVID issuance latency, renewal failures, registration entry counts. |
| 98 | + - Alerts: handshake failure spikes, agent attestation failures. |
| 99 | +9. **Cutover plan.** |
| 100 | + - Phase 1: SPIRE deployed but not enforced; shadow-mode logging. |
| 101 | + - Phase 2: Enforce per service (start with non-critical), measure error budget. |
| 102 | + - Phase 3: Default-deny across the mesh. |
| 103 | +10. **Disaster recovery.** |
| 104 | + - Datastore backup, restore runbook. |
| 105 | + - Trust-bundle export for cross-region recovery. |
| 106 | + - Rotation of upstream CA documented. |
| 107 | + |
| 108 | +**Deliverable:** Terraform modules (SPIRE Server, Agent DaemonSet, registration), runbooks, dashboards, error-budget policy. |
| 109 | + |
| 110 | +See [references/spire-on-eks.md](references/spire-on-eks.md). |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Workflow 3 - Federate Trust Domains |
| 115 | + |
| 116 | +Multi-cluster, multi-cloud, or cross-org. Two trust domains exchange bundles so workloads on each side can verify the other's SVIDs. |
| 117 | + |
| 118 | +### Steps |
| 119 | + |
| 120 | +1. **Define the federation graph.** Which trust domains federate with which? Federation is bilateral; consider a hub-and-spoke vs full-mesh. |
| 121 | +2. **Bundle endpoint setup.** Each SPIRE Server exposes its bundle at an HTTPS endpoint, signed by a known certificate. Use a stable URL with rotation in mind. |
| 122 | +3. **Bundle endpoint authentication.** |
| 123 | + - `https_spiffe` - peer authenticates the endpoint via a SPIFFE ID (best for mature deployments). |
| 124 | + - `https_web` - peer trusts the bundle endpoint cert via Web PKI (simpler bootstrap). |
| 125 | +4. **Configure remote bundle on each Server.** `spire-server bundle set -id spiffe://other.example.com -path ...`. |
| 126 | +5. **Federation policy.** Mark registration entries as federated so SPIRE issues SVIDs that include the federated trust bundle. |
| 127 | +6. **Authorization across federation.** Istio / OPA policies must allow remote SPIFFE IDs explicitly. Don't trust by federation alone. |
| 128 | +7. **Rotation and revocation.** Bundles are fetched periodically (default 5 min). Plan for partial unavailability of the remote endpoint. |
| 129 | +8. **Audit.** Log federation events; alert on bundle fetch failures. |
| 130 | + |
| 131 | +**Deliverable:** Federation topology diagram, bundle endpoint config, cross-domain authorization policies, runbook for adding/removing a federated peer. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## Workflow 4 - OIDC Bridge to Cloud IAM |
| 136 | + |
| 137 | +Trade a JWT-SVID for cloud creds. No static cloud key. |
| 138 | + |
| 139 | +### Steps |
| 140 | + |
| 141 | +1. **Enable the SPIRE OIDC Discovery Provider.** Exposes `.well-known/openid-configuration` and the JWKS over HTTPS at a stable URL. |
| 142 | +2. **Per cloud:** |
| 143 | + - **AWS** - register the SPIRE OIDC provider in IAM (Identity Provider). Define a trust policy on the target role with `sub` matching the specific SPIFFE ID. Workload calls `AssumeRoleWithWebIdentity`. |
| 144 | + - **GCP** - configure Workload Identity Federation: workload identity pool + provider pointing to the SPIRE OIDC endpoint; pool member maps to a service account; workload calls the STS endpoint. |
| 145 | + - **Azure** - federated credential on the User-Assigned Managed Identity referencing the SPIRE issuer + subject; workload calls the Azure AD token endpoint. |
| 146 | + - **Vault** - `auth/jwt` method with the SPIRE issuer; role binds bound claims to a Vault policy. |
| 147 | +3. **Trust-policy hardening.** Always pin the `sub` claim to a specific SPIFFE ID. Never trust the issuer alone. |
| 148 | +4. **Token TTLs.** Cloud creds inherit the issuing service's defaults; tune to minutes. |
| 149 | +5. **Audit.** Log token exchanges on both sides; the cloud audit log is your record of who got what when. |
| 150 | +6. **Rotation.** SPIRE auto-rotates the JWT-SVID; cloud trust policy doesn't need rotation as long as the issuer URL and JWKS are stable. |
| 151 | + |
| 152 | +**Deliverable:** OIDC provider config per cloud, trust policies pinned to SPIFFE IDs, audit dashboards, key rotation runbook. |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## Workflow 5 - Migrate Off Long-Lived Workload Secrets |
| 157 | + |
| 158 | +The most-requested operational workflow. |
| 159 | + |
| 160 | +### Steps |
| 161 | + |
| 162 | +1. **Inventory.** Every workload secret in production. Sources: secrets manager, k8s Secrets, Helm values, env vars, mounted files, code. |
| 163 | +2. **Classify by replacement substrate:** |
| 164 | + - Cloud-resource access from a cloud workload → **cloud IAM** (IRSA / Pod Identity / Workload Identity / Managed Identity). Eliminates the secret entirely. |
| 165 | + - Service-to-service inside a cluster → **SPIFFE SVIDs** + mTLS, replace bearer tokens. |
| 166 | + - Cloud access from outside the cloud (CI, on-prem) → **OIDC federation** (GitHub OIDC → cloud STS; SPIRE → cloud STS). |
| 167 | + - Vendor / SaaS → **OAuth client credentials** with short-lived access tokens; rotate the client secret in vault. |
| 168 | +3. **Migration order.** Highest blast radius first (admin-scoped, multi-tenant, internet-exposed). Lowest second (analytics workloads, dev tools). |
| 169 | +4. **For each workload:** |
| 170 | + - Provision the new identity primitive. |
| 171 | + - Deploy code change to fetch creds from the new substrate. |
| 172 | + - Verify in shadow mode (both old and new working). |
| 173 | + - Cut over. |
| 174 | + - Revoke the old secret. |
| 175 | + - Confirm via audit that no caller is using the old secret. |
| 176 | +5. **Decommission.** Revoke unused secrets after a grace period; delete the secret store entries. |
| 177 | +6. **Prevent regression.** |
| 178 | + - CI: pre-commit secret scanning (Gitleaks / TruffleHog / GitGuardian). |
| 179 | + - PR template asks "is a new long-lived secret introduced?". |
| 180 | + - SCPs / OPA policies block the creation of static IAM users in prod accounts. |
| 181 | + |
| 182 | +**Deliverable:** Inventory + status board, per-workload migration runbook, decommission audit, regression prevention controls. |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## Workflow 6 - Cloudflare Access / AOP / Worker JWT Layering |
| 187 | + |
| 188 | +Decision matrix for HTTP-edge identity. (Lifted from the broader Cloudflare context; see also `400-cloudflare.mdc`.) |
| 189 | + |
| 190 | +| Layer | Usually redundant | Still useful | |
| 191 | +|---|---|---| |
| 192 | +| **Cloudflare Access** | Re-validating the same IdP token, same issuer/audience/group already enforced by Access | Centralized edge authorization for coarse route access | |
| 193 | +| **Worker JWT validation** | Repeating Access policy checks with no new claims | API-specific checks: audience, scope, tenant, route, method, fine-grained claim conditions | |
| 194 | +| **Origin validation** | A second full interactive login after Access | Lightweight verification of `Cf-Access-Jwt-Assertion`, AOP/mTLS, service-specific authorization | |
| 195 | + |
| 196 | +**Rule of thumb:** do not duplicate the same authentication decision. Add another layer only when it enforces a different boundary or finer-grained authorization. |
| 197 | + |
| 198 | +For internal workloads (not internet-origin HTTP), this rule is the same: each layer must answer a *different* question, or it's not pulling its weight. |
| 199 | + |
| 200 | +--- |
| 201 | + |
| 202 | +## Anti-patterns (reviewers call these out) |
| 203 | + |
| 204 | +1. EC2 instance profile as the identity for high-density shared compute. |
| 205 | +2. One trust domain across environments. |
| 206 | +3. Long-lived JWT-SVIDs (defeats rotation). |
| 207 | +4. mTLS without an authorization layer ("we have mTLS so we're done"). |
| 208 | +5. Identity in the cert CN instead of the URI SAN. |
| 209 | +6. Hand-distributed trust bundles instead of Workload API. |
| 210 | +7. Treating SPIFFE and cloud IAM as complements *for the same workload*. |
| 211 | +8. Self-signed SPIRE root in prod (no UpstreamAuthority). |
| 212 | +9. Image-tag selectors instead of digest. |
| 213 | +10. Assuming TTL is sufficient when sub-second revocation is required. |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## Review Output Format |
| 218 | + |
| 219 | +``` |
| 220 | +[BLOCKER] <one-line summary> |
| 221 | +Principle: <which golden rule> |
| 222 | +Evidence: <file:line, ADR ref, or runtime evidence> |
| 223 | +Why it matters: <blast radius / attack path> |
| 224 | +Fix: <specific, actionable> |
| 225 | +
|
| 226 | +[IMPORTANT] <...> |
| 227 | +[SUGGESTION] <...> |
| 228 | +``` |
| 229 | + |
| 230 | +BLOCKER = violates a golden rule (e.g., long-lived workload secret introduced; mTLS without authz; selector without image digest). |
| 231 | +IMPORTANT = misalignment with `318-workload-identity.mdc`. |
| 232 | +SUGGESTION = tightens posture / improves operability. |
| 233 | + |
| 234 | +--- |
| 235 | + |
| 236 | +## References |
| 237 | + |
| 238 | +- [references/spiffe-vs-cloud-iam.md](references/spiffe-vs-cloud-iam.md) - the decision matrix in depth |
| 239 | +- [references/spire-on-eks.md](references/spire-on-eks.md) - SPIRE Server + Agent on EKS, Vault PKI upstream |
| 240 | +- [references/oidc-federation-bridges.md](references/oidc-federation-bridges.md) - SPIRE → AWS / GCP / Azure / Vault |
| 241 | + |
| 242 | +## Related |
| 243 | + |
| 244 | +- Rule: `318-workload-identity.mdc` (the principles) |
| 245 | +- Rule: `316-zero-trust.mdc` (always-on) |
| 246 | +- Rule: `317-okta.mdc` (Okta + XAA at the application layer) |
| 247 | +- Rule: `412-aws-iam.mdc` (IRSA, Pod Identity, VPC Lattice) |
| 248 | +- Rule: `450-kubernetes.mdc` (mesh patterns) |
| 249 | +- Skill: `zero-trust` (threat models, HITL, MCP hardening) |
| 250 | +- Skill: `aws-iam` (AWS IAM operational patterns) |
| 251 | +- Skill: `okta` (Okta operations, XAA workflows) |
0 commit comments