AWS Security

Exposed AWS Access Key: Understanding the Blast Radius and Responding Safely

When a long-lived AWS access key leaks, impact follows effective permissions—not admin by default. Identify the principal, contain the key, investigate CloudTrail limits, and replace standing credentials with roles and OIDC.

Illustrative AWS access-key exposure response: committed AKIA key, scanners, effective permissions, CloudTrail, GuardDuty (not guaranteed), deactivate, and prevention with roles/OIDC. Educational example data — not a client incident.

Muted looping landscape animation in eight stages — Committed, Flagged, Used, IAM decides, Logged, Detected, Revoked, Prevented — for an illustrative IAM user ci-uploader in account 111122223333 with masked access key AKIA**************** and source IP 203.0.113.45. Shows that blast radius follows effective permissions, sts GetCallerIdentity is not a permissions test, CloudTrail management versus data events, GuardDuty detection is not guaranteed, and deactivation stops new calls without undoing earlier actions.

A leaked key is not automatically admin

Long-lived IAM user access keys (AKIA…) are still found in public Git history, CI logs, and paste sites. Automated scanners and opportunistic actors often discover public keys quickly. The useful engineering question is not “did someone get a key?” but what that principal can still do—its effective permissions—and how fast you can stop new use while investigating what already happened.

This guide walks an illustrative scenario: IAM user ci-uploader in account 111122223333, access key ID masked as AKIA****************, source IP 203.0.113.45 (documentation range). Outputs and findings are educational examples, not a Cloud9 Solutions customer incident and not attack instructions.

Related prevention context already lives in CI/CD Supply-Chain Security and Building Reliable CI/CD Pipelines with GitHub Actions. This article focuses on exposure response and blast-radius reasoning.

What exposure looks like

A typical path:

  1. A developer or automation commits .env, Terraform state fragments, or a hard-coded AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY.
  2. The commit becomes public (or reachable to scanners) before rotation.
  3. GitHub secret scanning, AWS notifications, or third-party collectors flag the AKIA prefix.
  4. Callers use the key until it is deactivated or its temporary sessions expire.

Identify the compromised principal

Confirm which IAM principal owns the key and whether it has been used:

BASH · identify-key.sh
# Illustrative — run with an approved responder identity, not the leaked key.
aws iam get-access-key-last-used \
  --access-key-id AKIA****************

aws iam generate-credential-report
aws iam get-credential-report \
  --query 'Content' --output text | base64 --decode > credential-report.csv

Useful signals:

  • IAM credential report — which users have active keys and password status (credential report).
  • CloudTrail lookup by userIdentity.accessKeyId — management events attributed to that key (region-scoped Event history limits apply; see below).
  • sts get-caller-identity — only when run by responders in a safe, deliberate context to map account/user ARN. It is not a permissions test (next section).
  • GitHub secret scanning / push protection and AWS abuse or Health-style notifications when present.

AWS may attach a managed quarantine policy such as AWSCompromisedKeyQuarantineV2 (and related quarantine policy versions) and open a support case when it detects exposed credentials. Mention that path when you see the policy attached; do not invent case details. Always follow current AWS guidance for compromised credentials (temporary credential denial patterns, access key rotation).

Effective permissions decide blast radius

Identity-based policies on the user or its groups are only one input. Effective access also depends on:

ControlRole in evaluation
Identity-based policiesWhat the principal’s IAM policies allow/deny
Resource-based policiesWhat the resource itself allows (S3 bucket policy, KMS key policy, etc.)
SCPsOrganization ceilings on what member accounts can allow (SCPs)
RCPsOrganization resource-control filters when used (RCPs)
Permission boundariesMaximum permissions an identity can ever receive (boundaries)
Session policiesExtra filter on temporary credentials
Explicit DenyAlways wins over Allow
Implicit DenyDefault when nothing allows the request

In the illustrative ci-uploader scenario, effective access is only s3:ListBucket on app-uploads and s3:GetObject on app-uploads/*. Calls such as iam:CreateUser or ec2:RunInstances are denied. Impact tracks that wedge—not “full admin because a key leaked.”

Tools that help reason about Allow/Deny before or during response:

ILLUSTRATIVEIAM policy evaluation (simplified)
  1. Request arrives

    A principal (here an IAM user access key) calls an AWS API. Evaluation asks whether that request is allowed for that action, resource, and context.

  2. Any explicit Deny?

    Identity policies, resource policies, SCPs, RCPs, permission boundaries, and session policies can all carry Deny. One explicit Deny ends evaluation with DENY.

  3. Organization filters

    If the account is in AWS Organizations, Service Control Policies (SCPs) and Resource Control Policies (RCPs) can prevent an Allow even when the account’s own policies would permit the action.

  4. Permission boundary & session policy

    If a permission boundary or session policy is present, the request must also be allowed by that filter. Missing Allow there is a Deny for this request.

  5. Identity or resource Allow?

    In the common same-account case, an Allow from identity-based policy or resource-based policy can authorize the request after earlier filters pass. Cross-account access has additional trust and resource-policy requirements.

  6. Default: implicit Deny

    If nothing explicitly allows the request after Deny and filter checks, the result is Deny. Effective permissions are the intersection of what is allowed—not “admin because a key exists.”

Focus: Any explicit Deny?. Identity policies, resource policies, SCPs, RCPs, permission boundaries, and session policies can all carry Deny. One explicit Deny ends evaluation with DENY.

Illustrative decision order aligned with AWS IAM policy evaluation logic. Explicit Deny always wins; Organizations SCPs/RCPs and permission boundaries/session policies can filter Allows; otherwise identity or resource Allow may authorize; default is implicit Deny. Cross-account requests add trust-policy and resource-policy nuance.

Cross-account access adds trust-policy and resource-policy requirements beyond this same-account sketch. See the official policy evaluation logic.

Why sts:GetCallerIdentity is not a meaningful permissions test

GetCallerIdentity returns the account and principal for the credentials in use. It does not require IAM permissions. It can succeed even when every meaningful API is denied—including when an explicit Deny is present for other actions. An explicit Deny cannot “block” GetCallerIdentity the way it blocks s3:GetObject.

Treat a successful GetCallerIdentity as evidence that the key material is valid and active, not that the principal is powerful.

Investigation signals—and their limits

CloudTrail

  • Event history in the console covers management events, roughly 90 days, per Region.
  • Data events (for example S3 object-level API calls, Lambda invoke) are not recorded unless you configure them on a trail or CloudTrail Lake event data store (data events).
  • Longer retention and multi-Region aggregation need a trail (or Lake) and durable storage.
  • Delivery is near-real-time but not instantaneous; expect short delay.

Illustrative management-event lookups (responder identity):

BASH · cloudtrail-lookup.sh
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIA**************** \
  --max-results 50

GuardDuty and neighbors

GuardDuty only helps if enabled. Finding families such as UnauthorizedAccess:IAMUser, CredentialAccess, Stealth:IAMUser, or PenTest:IAMUser (see the active finding types list) may fire on unusual API use—detection is not guaranteed. Also review IAM Access Analyzer, AWS Config, Security Hub, billing / Cost Anomaly Detection, and AWS Health / abuse notifications when available.

Containment: deactivate, replace, then delete

AWS’s practical order for exposed IAM user keys:

  1. Deactivate the access key (Inactive) so new signed requests fail.
  2. Investigate what the key already did (CloudTrail, resources created, data APIs if logged).
  3. Replace workloads with role-based temporary credentials where possible.
  4. Delete the compromised key after you understand impact and replacements work.
  5. Rotate anything the key could have read (secrets, tokens, downstream credentials).
BASH · deactivate-key.sh
aws iam update-access-key \
  --user-name ci-uploader \
  --access-key-id AKIA**************** \
  --status Inactive

Temporary sessions already issued

  • For IAM users, deny continued use of previously issued temporary credentials with a policy conditioned on aws:TokenIssueTime (issue time before containment).
  • For roles, use revoke active sessions (role session invalidation patterns in the IAM guide) in addition to rotating any leaked role credentials or trust abuse.

Illustrative deny-for-old-sessions sketch (educational; tailor and review before use):

JSON · deny-old-sessions.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenySessionsIssuedBeforeContainment",
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "DateLessThan": {
          "aws:TokenIssueTime": "2026-11-18T10:15:00Z"
        }
      }
    }
  ]
}

Assess impact across Regions

After containment, enumerate what the principal could do and what did happen:

Data access (if logged)

  • S3 data events (GetObject, ListBucket, …) when data-event logging exists
  • secretsmanager:GetSecretValue, ssm:GetParameter / GetParametersByPath

Resource creation

  • ec2:RunInstances in every Region, Lambda functions, other compute or data stores

Persistence and privilege expansion

  • iam:CreateUser, CreateAccessKey, CreateLoginProfile
  • AttachUserPolicy, PutUserPolicy, PutRolePolicy, UpdateAssumeRolePolicy
  • New roles, instance profiles, OIDC identity providers, scheduled or hidden backdoors

Deactivation does not remove users, keys, instances, or policies already created. Find and remove them deliberately, then verify with CloudTrail and inventory across Regions.

Prevention that actually reduces blast radius

YAML · github-oidc-aws.yml
# Educational fragment. Pin actions by digest in high-risk repos.
permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::111122223333:role/github-deploy
          aws-region: eu-central-1

Illustrative trust-policy conditions for the role (scope tightly):

JSON · github-oidc-trust.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
        },
        "StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:example-org/example-repo:ref:refs/heads/main"
        }
      }
    }
  ]
}
  • Enforce least privilege, permission boundaries, and SCP/RCP guardrails.
  • Enable secret scanning and push protection (about secret scanning, push protection).
  • Add pre-commit / CI secret scanning so keys never reach the default branch.
  • Alert on unusual API use (GuardDuty when enabled, CloudTrail metrics/alarms, Cost Anomaly Detection).

Incident-response checklist

  1. Declare the incident and use an approved responder identity (not the leaked key).
  2. Identify the IAM user/role and access key ID; pull credential report and last-used data.
  3. Deactivate the access key; apply temporary-session denial / role session revocation as needed.
  4. Search CloudTrail (all relevant Regions) for the AccessKeyId; note management vs data-event coverage gaps.
  5. Inventory created or modified IAM principals, compute, data stores, and secrets access.
  6. Remove persistence; rotate secrets the key could read; replace standing keys with roles/OIDC.
  7. Delete the deactivated key after replacement is verified.
  8. Review SCP/boundary/OIDC posture so the same class of key cannot return.
  9. Write the timeline: exposure window, first use, containment time, residual risk.

Official references

Need help hardening AWS identity, delivery pipelines, or incident readiness? Explore Cloud9 Solutions.

Related technical guides

LET’S BUILD WHAT’S NEXT

Good engineering starts with a conversation.

Let’s connect