Difficulty: Beginner
Name three or more IAM best practices you would follow in a production AWS account, and explain why each matters.
The core IAM best practices are: lock down the root user with MFA and never use it day to day, give humans temporary credentials through IAM Identity Center (or federation) and workloads IAM roles instead of long-lived access keys, and grant least privilege by starting narrow and tightening with data from IAM Access Analyzer. Around those sit guardrails such as Service Control Policies, permissions boundaries, and conditions in policies. Leaked long-lived keys and over-broad permissions cause most real AWS security incidents.
aws sso login instead of keys in ~/.aws/credentials.Access keys committed to a public GitHub repository are found by bots within minutes and used to mine crypto. Roles remove that whole class of problem.
"Action": "" and "Resource": "".AdministratorAccess for workloads.aws:SourceIp, aws:RequestedRegion, or tags.| Tool | Scope | Use |
|---|---|---|
| Service Control Policies (SCPs) | Organization, OU, or account | Hard limits, e.g. deny leaving the org or using unapproved Regions |
| Permissions boundaries | A user or role | Cap what a delegated admin can grant |
| Resource policies | S3 bucket, KMS key, SQS queue | Control who can access a resource, including cross-account |
An explicit deny anywhere wins over any allow.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteInvoices",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::acme-billing/invoices/*"
},
{
"Sid": "ListOnlyInvoicesPrefix",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::acme-billing",
"Condition": { "StringLike": { "s3:prefix": ["invoices/*"] } }
}
]
}
The role can only read, write, and list objects under invoices/ in one bucket, instead of having s3:* on every bucket.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
"StringLike": { "token.actions.githubusercontent.com:sub": "repo:acme/payments-api:ref:refs/heads/main" }
}
}]
}
Only workflows from the main branch of one repository can assume this deploy role, and no AWS access key is stored in GitHub.
IAM, Least Privilege, IAM Roles, MFA, IAM Identity Center