Q&A-8Respond to a cloud credential printed in a public build log.
Answer
First, I'd clarify: is the log still public, and is the credential still active? I'll assume it's an AWS IAM access key that appeared in a public GitHub Actions log, and it's still active. Automated scanners harvest these within minutes, so the first 60 seconds matter.
Immediate containment: deactivate the key, don't delete it yet. Deactivating stops all API calls but preserves the key for CloudTrail correlation. Run:
aws iam update-access-key --access-key-id AKIA... --status InactiveIf it's a role session, you can't revoke a single session. Attach a deny-all policy to the role or use an SCP. Then preserve evidence: export the build log, snapshot CloudTrail logs. Don't delete the log yet: deleting it doesn't revoke the credential, and the attacker may have already copied it.
Investigation: use CloudTrail to see what the attacker did. aws cloudtrail lookup-events --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIA.... Look for calls from unusual IPs, regions, user agents. Check GuardDuty findings. A typical attack trace: get-caller-identity to check permissions, then s3 ls to list buckets, then iam create-user to create a backdoor, then ec2 run-instances to mine crypto. Each leaves a CloudTrail event with the access key ID. Also look for AccessDenied errors, which show what the attacker tried but couldn't do. CloudTrail's default event history retains 90 days of management events; for data events you need a trail.
Remediation: rotate any dependent credentials. If the key was used to access a database, rotate that password. Fix the leak: remove the secret from the log, but also from git history if it was committed. Use git filter-repo or BFG. Enable secret scanning and push protection. Move to short-lived credentials: OIDC for CI/CD, so no long-lived keys exist.
Tradeoffs: deactivate vs delete. Deactivate preserves evidence; delete removes it. Always deactivate first. For role sessions, you can't revoke a specific session, so you must attach a deny policy or rotate the role's trust policy. That's slower but necessary.
| Option | Stops attacker? | Preserves evidence? | When to use |
|---|---|---|---|
| Deactivate key | Yes | Yes | First step, always |
| Delete key | Yes | No | After investigation |
| Rotate key | No | Yes | Only after deactivating old key |
| Deny policy on role | Yes | Yes | For role sessions |
Failure modes: deleting the log before preserving evidence; rotating the key without deactivating the old one; assuming the key was only used for the build. If the key had admin permissions, the attacker could have created backdoor users, so audit IAM for new users, roles, and policies. Also check for other secrets in the same log and rotate them.
Prevention: use OIDC, secret scanning, log redaction, least privilege.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.