Q: An IAM user has `ec2:RunInstances` permissions, but they do NOT have permissions to read S3 buckets. However, they also have the `iam:PassRole` permission for an existing `S3Admin` EC2 Role. Explain how this user can escalate their privileges to steal S3 data.
This is a classic IAM privilege escalation path.
Master cloud-native security and container runtime defense: Prepare with KodeKloud's CKS course with live browser-based terminal sandboxes.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "When an interviewer asks how I respond to this security vulnerability, I emphasize immediate blast-radius containment. The interviewer is testing: IAM PassRole abuse, privilege escalation vectors.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
This is a classic IAM privilege escalation path.
- Launch a new EC2 instance via the CLI.
- During the launch, they "pass" the
S3Adminrole to the instance, effectively attaching it. - Once the instance boots, they SSH into it (or execute commands via User Data).
Remediation & Permanent Safeguards
The user cannot read the S3 bucket directly. However, because they possess iam:PassRole along with ec2:RunInstances, they can:
- From inside the instance, they execute
aws s3 cpcommands. The command succeeds because the instance is using the temporary credentials of the highly privilegedS3Adminrole. The user bypasses their own restrictions and steals the data via the machine's identity.
- Launch a new EC2 instance via the CLI.
- During the launch, they "pass" the S3Admin role to the instance, effectively attaching it.
- Once the instance boots, they SSH into it (or execute commands via User Data).
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Relying on legacy bucket ACLs instead of modern S3 Block Public Access and IAM bucket policies when configuring Security user ec2RunInstances AWS recommends disabling ACLs (Bucket Owner Enforced) in favor of centralized declarative bucket policies and account-level Block Public Access controls.
-
Confusing SSE-S3 encryption with KMS customer-managed key (SSE-KMS) authorization policies when configuring Security user ec2RunInstances
Accessing SSE-KMS encrypted objects requires both
s3:GetObjectandkms:Decryptpermissions; neglecting KMS key policies causes silent 403 Forbidden errors. - Using sequential timestamps or predictable prefixes for high-throughput S3 read and write keys when configuring Security user ec2RunInstances Sequential key prefixes limit S3 horizontal partitioning; randomized hash prefixes distribute workloads across partitions to achieve 3,500 PUT and 5,500 GET requests/sec.
- Failing to audit S3 object delete markers when troubleshooting missing versioned objects when configuring Security user ec2RunInstances Issuing a DELETE on a versioned bucket only adds a delete marker; engineers must retrieve previous versions or purge markers to restore data.