Lab 1: IAM Hardening
Create a least-privilege IAM policy
Create a custom policy scoped to EC2/VPC actions in us-east-1 only. This region lock prevents compromised credentials from being used in unmonitored regions.
$ cat > bootcamp-policy.json << 'EOF' { "Version": "2012-10-17", "Statement": [ { "Sid": "EC2VPCAccess", "Effect": "Allow", "Action": [ "ec2:Describe*", "ec2:Create*", "ec2:Delete*", "ec2:AuthorizeSecurityGroupIngress", "ec2:RevokeSecurityGroupIngress" ], "Resource": "*", "Condition": { "StringEquals": {"aws:RequestedRegion": "us-east-1"} } } ] } EOF
IAM misconfigurations are the #1 root cause of AWS breaches. The Capital One breach? Overly permissive IAM role. Getting IAM right is the single most impactful thing you can do.
Create the policy in AWS
Run this command and save the ARN from the output — you'll need it next.
$ aws iam create-policy \ --policy-name BootcampLabPolicy \ --policy-document file://bootcamp-policy.json \ --description 'Scoped policy for Cloud Security Bootcamp labs' # Save the ARN from output: # arn:aws:iam::ACCOUNT_ID:policy/BootcampLabPolicy
Create a dedicated IAM user
Never run labs with admin credentials. Create a scoped user and configure a separate CLI profile.
$ aws iam create-user --user-name bootcamp-student $ aws iam attach-user-policy \ --user-name bootcamp-student \ --policy-arn arn:aws:iam::ACCOUNT_ID:policy/BootcampLabPolicy $ aws iam create-access-key --user-name bootcamp-student # Configure new CLI profile: $ aws configure --profile bootcamp
Enable MFA on root account
Go to IAM > Security credentials > Assign MFA device. Use Google Authenticator or Authy. This is one of the few steps requiring the AWS Console.
If root is compromised without MFA, the attacker owns your entire AWS organization — unlimited access, unlimited charges.
Set up IAM Access Analyzer
Continuously monitors your account for overly permissive access.
$ aws accessanalyzer create-analyzer \ --analyzer-name bootcamp-analyzer \ --type ACCOUNT # List findings: $ aws accessanalyzer list-findings \ --analyzer-arn $(aws accessanalyzer list-analyzers \ --query 'analyzers[0].arn' --output text)
Create a permissions boundary
Prevents privilege escalation — even if someone modifies their own policy, the boundary caps what they can execute.
$ cat > boundary-policy.json << 'EOF' { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["ec2:*", "s3:*", "cloudtrail:*", "guardduty:*", "config:*", "logs:*"], "Resource": "*", "Condition": { "StringEquals": {"aws:RequestedRegion": "us-east-1"} } }, { "Effect": "Deny", "Action": ["iam:CreateUser", "iam:DeleteUser", "iam:AttachUserPolicy", "organizations:*"], "Resource": "*" } ] } EOF $ aws iam create-policy \ --policy-name BootcampBoundary \ --policy-document file://boundary-policy.json $ aws iam put-user-permissions-boundary \ --user-name bootcamp-student \ --permissions-boundary arn:aws:iam::ACCOUNT_ID:policy/BootcampBoundary
Verify — test the boundary
Confirm allowed actions succeed and denied actions fail.
# This should SUCCEED: $ aws ec2 describe-vpcs --profile bootcamp # This should FAIL (boundary blocks it): $ aws iam create-user --user-name test-escalation --profile bootcamp # Expected: AccessDenied