IAM Best Practices

Difficulty: Beginner

Question

Name three or more IAM best practices you would follow in a production AWS account, and explain why each matters.

Answer

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.

1. Protect the root user

  • Enable MFA on root (AWS now requires it for root users), preferably a phishing-resistant passkey or hardware key.
  • Delete any root access keys; there is almost never a reason to have them.
  • Use root only for the handful of tasks that require it, such as changing account settings or closing the account.
  • In an AWS Organization, member accounts can have root credentials removed entirely using centralized root access management.

2. Use temporary credentials, not access keys

  • Humans: sign in through IAM Identity Center or your identity provider (Google Workspace, Okta, Entra ID). Developers get short-lived credentials via aws sso login instead of keys in ~/.aws/credentials.
  • Workloads: EC2 instance profiles, Lambda execution roles, ECS task roles, and EKS Pod Identity or IRSA. The SDK picks up rotating credentials automatically.
  • CI/CD: GitHub Actions and GitLab can assume a role through OIDC federation, so no AWS secret is stored in the CI system at all.

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.

3. Least privilege, enforced and measured

  • Start from narrow policies scoped to specific actions and resource ARNs, not "Action": "" and "Resource": "".
  • Prefer customer-managed policies over broad AWS-managed ones like AdministratorAccess for workloads.
  • Use IAM Access Analyzer to generate policies from CloudTrail activity, find unused roles and permissions, and flag resources shared outside your account.
  • Add conditions: require MFA for sensitive actions, restrict by aws:SourceIp, aws:RequestedRegion, or tags.

4. Guardrails above individual policies

ToolScopeUse
Service Control Policies (SCPs)Organization, OU, or accountHard limits, e.g. deny leaving the org or using unapproved Regions
Permissions boundariesA user or roleCap what a delegated admin can grant
Resource policiesS3 bucket, KMS key, SQS queueControl who can access a resource, including cross-account

An explicit deny anywhere wins over any allow.

Common mistakes

  • One shared IAM user for the whole team, so CloudTrail cannot tell who did what.
  • Wildcard policies "just for now" that never get tightened.
  • Ignoring unused users and keys; review with the credential report and Access Analyzer.

Code examples

Least-privilege policy scoped to one bucket prefix

{
  "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.

Trust policy letting GitHub Actions assume a role via OIDC

{
  "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.

Key points

  • Root: MFA on, no access keys, used only for root-only tasks
  • Humans use IAM Identity Center or federation; workloads use roles; CI uses OIDC
  • Least privilege with specific actions, resource ARNs, and conditions
  • IAM Access Analyzer finds unused access and generates policies from activity
  • SCPs and permissions boundaries set guardrails; explicit deny always wins

Common follow-up questions

  • What is the difference between an IAM user, a group, and a role?
  • How does IAM evaluate a request when there is an allow in one policy and a deny in another?
  • What is a permissions boundary and when would you use one?
  • How would you give a Lambda function access to one DynamoDB table only?

Interview tips

  • Go beyond the classic three (MFA, least privilege, roles) and mention Identity Center, OIDC for CI, and Access Analyzer; it shows current knowledge
  • Explain why each practice matters with a real failure mode, such as leaked keys on GitHub
  • Mention that explicit deny always overrides allow; it is a common follow-up

Concepts covered

IAM, Least Privilege, IAM Roles, MFA, IAM Identity Center

More AWS & Cloud Fundamentals questions