Opscraft
AWS IAM & multi-account security · Lesson 6 of 7 · 4 min read

Detection, audit and incident response

The detective stack

Service Role
CloudTrail API call history — organisation trail to the log-archive account, log file validation, S3 Object Lock; data events (S3 object-level, Lambda) selectively; CloudTrail Lake for SQL queries
AWS Config Resource configuration history and compliance rules (e.g. s3-bucket-public-read-prohibited); conformance packs; aggregators
GuardDuty Threat detection from CloudTrail, VPC Flow Logs, DNS logs, EKS audit logs, runtime monitoring — e.g. credentials used from unusual IPs, crypto-mining
Security Hub Aggregates findings and runs standards (CIS, AWS Foundational Security Best Practices) across accounts
IAM Access Analyzer External/unused access, policy validation
Detective / Security Lake Investigation and centralised security data
Macie Sensitive data discovery in S3
Enlarge diagramCloudTrailGuardDutyConfigSecurity HubAccess Analyzerevery API call, org-wide, to the log-archive accountthreats: odd API use, crypto-mining, leaked keysresource history and compliance rulesone place for findings and standardsexternal and unused access
Figure 1. The detective stack: record everything, watch for threats, and check configuration continuously.
Swipe sideways to see all of it, or tap to open it full screen.

Leaked access key — the runbook

  1. Contain: deactivate the key immediately (don't just delete — you lose the reference); if a role session was stolen, revoke active sessions (IAM console "Revoke active sessions" adds a deny for tokens issued before now).
  2. Investigate: CloudTrail for the key ID — what was called, from where, which resources created (often EC2 for crypto-mining in many regions, new IAM users/keys for persistence).
  3. Eradicate: delete attacker-created resources, users, keys, roles, Lambda functions; check all regions.
  4. Recover: rotate any secrets the key could read; review billing.
  5. Learn: why a long-lived key existed and how it leaked (committed to Git → secret scanning / push protection); replace with roles/OIDC; add GuardDuty alerts and SCPs denying key creation.
Enlarge diagramContaindeactivate thekey; revokesessionsInvestigateCloudTrail, everyregionEradicatedelete attackerresources andusersRecoverrotate secrets itcould read;check billingLearnreplace keyswith roles andOIDC; secretscanning12345
Figure 2. A leaked access key: contain first, then find out what it did, clean up, and remove the reason it existed.
Swipe sideways to see all of it, or tap to open it full screen.

Debugging AccessDenied

  1. aws sts get-caller-identity — are you who you think you are (right role, right account)?
  2. Read the error: modern AccessDenied messages state which policy type denied (...with an explicit deny in a service control policy, ...because no identity-based policy allows the ...).
  3. Check: identity policy action/resource ARNs (bucket vs object ARN), conditions (region, tags, source VPC endpoint), permissions boundary, SCPs/RCPs, resource policies (S3 bucket policy, KMS key policy — encrypted objects need kms:Decrypt too), session policies.
  4. Cross-account: both sides must allow; for S3 objects uploaded by another account, Object Ownership matters.
  5. IAM Policy Simulator and CloudTrail event (errorCode, errorMessage) to confirm.
Enlarge diagramget-caller-identityright role, rightaccount?Read the messageit names the policytype that deniedCheck that layerARNs, conditions,boundary, SCP,resource policyConfirmPolicy Simulator,CloudTrailerrorMessage1234
Figure 3. Debugging AccessDenied: confirm who you are, read which policy type denied you, then check that layer.
Swipe sideways to see all of it, or tap to open it full screen.