PC-002CRITICALSecrets & API Keys

AWS IAM Access Key ID Hardcoded

Identifies hardcoded Amazon Web Services IAM access key prefixes (AKIA, ASIA, AROA, and related 20-character identifiers) committed in source code, scripts, or infrastructure templates.

Rule Slug
aws-access-key-id
Affected Files
*
Detection Method
Regex + Entropy (>= 3.1)
Live Rule Tester100% Browser-Local
CRITICAL: Detected 1 violation
Line 7:AKIAQ••••••••••••1W3(entropy: 4.122)

Vulnerable Pattern vs. Hardened Fix

Vulnerable Pattern
// storage/s3Upload.ts
import { S3Client } from '@aws-sdk/client-s3';

export const s3 = new S3Client({
  region: 'us-east-1',
  credentials: {
    accessKeyId: 'AKIAQ7X9M2K4P8R6T1W3',
    secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCY9xK2L8pQ4m',
  },
});
Recommended Fix
// storage/s3Upload.ts
import { S3Client } from '@aws-sdk/client-s3';

// Uses default AWS credential provider chain (IAM Role, SSO, or runtime env)
export const s3 = new S3Client({
  region: process.env.AWS_REGION ?? 'us-east-1',
});

Why This Fails in Production

Hardcoded AWS IAM Access Key IDs (especially long-lived user credentials prefixed with AKIA) represent one of the highest-impact cloud security vulnerabilities in modern software engineering. Whenever an AKIA access key ID appears in a codebase, its paired 40-character AWS Secret Access Key is almost always located on an adjacent line, in a nearby configuration object, or in the same commit diff. Attackers running continuous GitHub scanners harvest these pairs within minutes and immediately invoke sts:GetCallerIdentity to enumerate account privileges.

Once validated, compromised AWS credentials are commonly weaponized in two ways: rapid resource abuse and stealth data exfiltration. Resource abuse includes spinning up dozens of high-cost GPU EC2 instances across rarely monitored regions for cryptocurrency mining or abusing Amazon SES quotas for phishing campaigns, easily generating tens of thousands of dollars in unexpected billing within hours. Stealthier intrusions enumerate S3 buckets, dump RDS snapshots, read Secrets Manager vaults, or create persistent backdoor IAM users and secondary access keys.

Even temporary STS session keys prefixed with ASIA pose immediate danger if pushed while still within their validity window, and role or group identifiers such as AROA or AIDA leak internal cloud account topology and naming conventions that assist targeted reconnaissance. When AWS Trust & Safety detects an exposed key publicly, it automatically attaches the AWSCompromisedKeyQuarantine policy, which can abruptly block legitimate production workloads relying on that IAM identity.

Modern cloud workloads should avoid static IAM access keys altogether by adopting short-lived IAM Roles (EC2 instance profiles, ECS task roles, Lambda execution roles, or GitHub Actions OIDC federation). Running a client-side pre-push audit prevents static development credentials from ever escaping your workstation.

Remediation Steps

  1. 1Deactivate and delete the compromised access key immediately in the AWS IAM Console (Users -> Security credentials) or via aws iam delete-access-key.
  2. 2Inspect AWS CloudTrail event history across all regions for unauthorized CreateUser, PutUserPolicy, RunInstances, GetSecretValue, or S3 GetObject activity.
  3. 3Replace static AKIA keys with IAM Roles, AWS SSO (IAM Identity Center) for local CLI work, and OIDC federation for CI/CD deployments.
  4. 4Remove the credential from source files and scrub Git history with git-filter-repo before rotating any downstream secrets stored inside the affected AWS account.

Frequently Asked Questions

Why does PushCheck flag the Access Key ID even without the Secret Access Key?
An AWS Access Key ID has a deterministic, high-confidence 20-character signature, whereas the 40-character Secret Access Key looks like arbitrary base64 text. Flagging the ID guarantees zero missed leaks while avoiding massive false positives across unrelated hashes.
Should I use IAM access keys in local development?
Prefer AWS IAM Identity Center (aws sso login) which issues short-lived credentials automatically. If a legacy tool requires access keys, store them only in ~/.aws/credentials outside your project directory.
What is the difference between AKIA and ASIA keys?
AKIA indicates a long-term IAM user access key that never expires until manually rotated. ASIA indicates a temporary STS security credential that requires a matching session token and expires automatically, though leaking an active session is still dangerous.

Related Secrets & API Keys Rules

Scan local project folder →