Stage 6, Part 7 of 9 · p. 53, RBAC, ServiceAccounts & Security

PART 7: INCIDENT MANAGEMENT

35. Security Incident Post-Mortem Template

text
INCIDENT: ServiceAccount Token Leaked - Unauthorized API Access
DATE: 2024-01-15
DURATION: 3 hours
SEVERITY: SEV-1
IMPACT: Attacker accessed production configmaps and secrets.

TIMELINE:
  14:00 - Anomaly detection alert: unusual API calls from unknown IP
  14:03 - Security team acknowledged
  14:05 - Identified compromised ServiceAccount "backup-sa"
  14:08 - Token was leaked in a public GitHub commit
  14:15 - Revoked SA, recreated with new name
  14:20 - Rotated all secrets the SA could access
  14:30 - Audited all actions taken by the SA
  16:00 - Verified no data exfiltration
  17:00 - Incident closed

ROOT CAUSE:
  Developer accidentally committed a ServiceAccount token to a public
  GitHub repository. The token had broad permissions (list/get on
  configmaps and secrets cluster-wide).

LESSONS LEARNED:
  1. ServiceAccount tokens must never be committed to Git.
  2. Tokens should be short-lived (projected tokens).
  3. RBAC should be least-privilege (not cluster-wide).

ACTION ITEMS:
  [ ] Enable Secret scanning in GitHub (Owner: Dev, Due: 2024-01-16)
  [ ] Audit all ServiceAccounts for excessive permissions (Owner: Security, Due: 2024-01-20)
  [ ] Enforce short-lived projected tokens (Owner: Platform, Due: 2024-01-22)
  [ ] Add pre-commit hooks to prevent token commits (Owner: Dev, Due: 2024-01-25)

36. On-Call Runbook: Suspected RBAC Breach

text
SYMPTOM: Audit log alert, unexpected RBAC usage, or over-privileged identity detected.

STEP 1: Identify the compromised identity
  $ kubectl get events -A | grep -i "forbidden\|unauthorized"

  # Check audit logs
  $ grep "system:serviceaccount:namespace:sa-name" /var/log/kubernetes/audit.log | tail -50

STEP 2: Determine blast radius
  # What permissions does the identity have?
  $ kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa-name>
  $ kubectl get rolebindings,clusterrolebindings -A -o json | \
    jq '.items[] | select(.subjects[]?.name=="<sa-name>")'

STEP 3: Isolate
  # Delete the compromised SA
  $ kubectl delete sa <sa-name> -n <ns>

  # Or remove the RoleBinding
  $ kubectl delete rolebinding <binding-name> -n <ns>

STEP 4: Check what the identity did
  # Review audit logs for all actions by the SA
  $ grep "<sa-name>" /var/log/kubernetes/audit.log | \
    jq -r '. | "\(.timestamp) \(.verb) \(.resource.resource)/\(.resource.name) in \(.resource.namespace)"'

STEP 5: Rotate credentials
  # Rotate all secrets the SA had access to
  # Rotate any API keys, DB passwords, etc.

STEP 6: Fix RBAC
  # Apply least-privilege
  # Remove over-privileged bindings
  # Add policy to prevent recurrence

STEP 7: Verify remediation
  # Check that the SA is gone
  # Verify no new suspicious activity

STEP 8: Escalate
  # Security team, management, possibly legal

37. Escalation Matrix

SeverityImpactResponse TimeEscalation
SEV-1Confirmed breach / cluster-admin compromise5 minSecurity + Platform + Management + Legal
SEV-2Suspected RBAC abuse / policy violation15 minSecurity + Platform
SEV-3Compliance finding / misconfiguration1 hourSecurity
SEV-4Policy warning / drift4 hoursTicket

1:1 copy of the class Google Doc, code in code blocks.