Opscraft
AWS IAM & multi-account security · Lesson 4 of 7 · 3 min read

Least privilege in practice

Getting to least privilege

  1. Start from job function needs, not *.
  2. Use IAM Access Analyzer: policy validation (lint), policy generation from CloudTrail activity, unused access findings (unused roles, keys, permissions), and external access findings (resources shared outside the org/account).
  3. Last accessed information (service/action level) to trim permissions.
  4. Scope by resource ARNs and conditions (aws:RequestedRegion, aws:ResourceTag, aws:SourceVpce, aws:PrincipalOrgID).
  5. Review regularly; automate via IaC with policy checks in CI (Checkov, cfn-guard, tfsec/Trivy, Access Analyzer ValidatePolicy/CheckNoNewAccess).
Enlarge diagramStart narrowjob needs, not *GenerateAccess Analyzerfrom CloudTrailactivityScoperesource ARNsand conditionsCheck in CIpolicy linting onevery PRTrimlast-accesseddata, unusedfindings12345
Figure 1. Getting to least privilege is a loop, not a one-off.
Swipe sideways to see all of it, or tap to open it full screen.

ABAC (attribute-based access control)

Use tags instead of listing resources:

{
  "Effect": "Allow",
  "Action": ["ec2:StartInstances", "ec2:StopInstances"],
  "Resource": "*",
  "Condition": {
    "StringEquals": { "aws:ResourceTag/team": "${aws:PrincipalTag/team}" }
  }
}

Scales well with many teams — but tag-modification permissions must be controlled (otherwise users retag resources to gain access): restrict ec2:CreateTags/DeleteTags via aws:RequestTag/aws:TagKeys conditions.

Enlarge diagramrole taggedteam=paymentsinstance taggedteam=paymentsallowedinstance taggedteam=ordersdeniedtags matchtags don't match
Figure 2. Attribute-based access: grant by matching tags instead of listing every resource. Protect the tags themselves, or people can retag their way in.
Swipe sideways to see all of it, or tap to open it full screen.

Permissions boundaries for delegation

Let developers create roles for their Lambdas without escalating privileges: allow iam:CreateRole only with a specific boundary (iam:PermissionsBoundary condition), and deny removing it. Anything they create can never exceed the boundary.

Enlarge diagramrole's policy: what it asks forboundary: the most it may haveeffectivethe overlapEffective permissions = only what the policy AND the boundary (AND any SCPs) all allow.
Figure 3. A permissions boundary caps what a role can ever do. Developers may create roles, but only with the boundary attached, so they cannot escalate.
Swipe sideways to see all of it, or tap to open it full screen.

Privilege escalation paths to know

iam:PassRole with * (pass an admin role to a new EC2/Lambda), iam:CreatePolicyVersion/SetDefaultPolicyVersion, iam:AttachRolePolicy/PutRolePolicy on your own role, iam:UpdateAssumeRolePolicy, lambda:UpdateFunctionCode on a privileged function, sts:AssumeRole on broad role ARNs. Scope iam:PassRole to specific role ARNs and iam:PassedToService.

Enlarge diagramiam:PassRole on *iam:CreatePolicyVersioniam:AttachRolePolicylambda:UpdateFunctionCodestart an EC2 or Lambda with an admin rolerewrite a policy you are attached toattach AdministratorAccess to yourselfrun code as a more powerful function's role
Figure 4. Common privilege-escalation paths. Each lets someone with limited rights give themselves more.
Swipe sideways to see all of it, or tap to open it full screen.