14:05. GitHub secret scanning alerts: an AWS access key pair belonging to the IAM user ci-deployer was pushed to a public repository 40 minutes ago inside a terraform.tfvars file. That key is used by a legacy Jenkins job to push images to ECR and update an ECS service. Jenkins has a production deploy scheduled at 15:00.
Step 1. What do you do first?
- Query CloudTrail first to see whether the key was actually used before deciding anything. The investigation is essential and comes next, but it does not shorten the exposure window; mitigate, then investigate.
- Deactivate the exposed access key in IAM now (delete it once Jenkins is updated), create a replacement, and accept that the 15:00 deploy may fail until Jenkins has the new credential. Public exposure means assume compromise — scrapers harvest public commits within minutes. Revocation is cheap and reversible; every minute the key stays active is not.
- Force-push to rewrite history and remove the file so nobody else sees it. It has already been seen; forks, caches and scrapers keep it, and rewriting history does nothing to the credential itself.
- Wait until after the 15:00 deploy so the release is not disrupted, then rotate. Trading a confirmed credential exposure for schedule convenience is a decision nobody will defend in the postmortem.
Step 2. The key is deactivated. CloudTrail shows, from an unfamiliar IP twelve minutes after the push: sts:GetCallerIdentity, s3:ListAllMyBuckets, secretsmanager:ListSecrets, then an AccessDenied on secretsmanager:GetSecretValue. What next?
- Treat it as an active intrusion: enumerate what the key was permitted to do, check for persistence (new users, keys, roles, trust-policy or Lambda changes), rotate any secret the key could have read, and open an incident with a written timeline. Reconnaissance calls followed by a denied read are an attacker probing; the denial shows least privilege held on that call, but you must verify nothing was left behind and rotate whatever was reachable.
- Delete the ci-deployer IAM user immediately. Deactivating the key already stopped the attacker; deleting the user before the investigation destroys evidence such as last-used data and breaks Jenkins for no additional safety.
- The AccessDenied proves the attacker failed; close the incident and write it up as a near miss. You saw the calls logged in this region by this trail; 'denied once' is not 'failed everywhere', and reconnaissance often precedes a second attempt with another key.
- Rotate every secret in the account right now. Rotate what the key could reach, prioritised by evidence; blanket rotation of hundreds of secrets mid-incident causes its own outages and buries the timeline.
Step 3. The postmortem is next week. What is the action item that removes this class of failure, rather than a reminder?
- Add a written rule that developers must never commit tfvars files. A rule is a reminder; the next paste lands in a README or a shell history.
- Replace the static IAM user with a role assumed through short-lived credentials (OIDC or an instance role for Jenkins), turn on push protection and secret scanning across the organisation, add pre-commit scanning as defence in depth, and alert on credential use from unexpected IPs or regions. It removes long-lived keys — the thing that leaked — and adds detection for the next leak; the class of failure, not the instance, is addressed.
- Make all repositories private. Private repositories leak too — through contractors, tokens, mirrors and laptops; the credential's lifetime is the root problem.
- Encrypt tfvars with git-crypt and document the decryption key in the repository README. A key stored next to the ciphertext is obfuscation, not encryption.
Deactivate the leaked key at once, then read CloudTrail and check for persistence, then replace the static key with short-lived OIDC credentials.
The scored shape is mitigate, investigate, then mechanise. Revoking first accepts a possible broken deploy in exchange for closing the window; the CloudTrail read afterwards is what turns "a key leaked" into "here is exactly what the attacker tried and what least privilege prevented". Persistence checks matter because credential theft is usually a foothold, not the goal. The durable fix is to make the leaked thing impossible to leak — credentials that expire in an hour are worthless in a public commit found tomorrow — and to add detection for the leaks that will still happen.
Starting with 'check CloudTrail to see whether it was used' or with rewriting git history. Both leave the credential live; scrapers harvest public commits within minutes and forks keep the file.