Least privilege in practice
Getting to least privilege
- Start from job function needs, not
*. - 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).
- Last accessed information (service/action level) to trim permissions.
- Scope by resource ARNs and conditions (
aws:RequestedRegion,aws:ResourceTag,aws:SourceVpce,aws:PrincipalOrgID). - Review regularly; automate via IaC with policy checks in CI (Checkov, cfn-guard, tfsec/Trivy, Access Analyzer
ValidatePolicy/CheckNoNewAccess).
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.
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.
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.