Designing Least-Privilege Policies
Least privilege means granting only the permissions needed to perform a task. It limits the damage from mistakes and compromised credentials, but achieving it across hundreds of roles requires understanding how policies combine and using tools that show what access is actually needed. This lesson explains the IAM policy types, the evaluation logic, and techniques for designing, refining and delegating least-privilege permissions.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the IAM policy types and where each applies.
- Explain the policy evaluation logic within an account and across accounts.
- Describe how IAM Access Analyzer policy generation, unused access findings and last accessed information refine permissions.
- Explain how permissions boundaries allow safe delegation of role creation.
Policy Types
Several kinds of policy can affect a request. Each has a different purpose and position in the evaluation.
- Identity-based policies
- Attached to users, groups or roles; grant permissions to the identity. Managed policies (AWS managed or customer managed) are reusable; inline policies belong to one identity.
- Resource-based policies
- Attached to resources such as S3 buckets, KMS keys, SQS queues, Lambda functions and role trust policies; name the principals allowed to access the resource, including other accounts.
- Permissions boundaries
- A managed policy set as the maximum permissions an identity-based policy can grant to a user or role; does not grant anything itself.
- SCPs and RCPs
- Organisation guardrails that set maximum permissions for principals and resources in member accounts, as described in the Multi-Account Governance module.
- Session policies
- Passed when assuming a role or federating, further limiting that session.
- VPC endpoint policies
- Limit what can be done through a VPC endpoint.
- ACLs
- Legacy cross-account permissions on some services such as S3; generally disabled.
Evaluation Logic
For a request within one account, AWS evaluates all applicable policies as follows. An explicit Deny in any policy ends evaluation with a denial. Otherwise, the request must be allowed by an identity-based or resource-based policy, and it must also be within every applicable limit: SCPs and RCPs, the permissions boundary if one is set, and the session policy if one is used. If nothing allows the request, it is implicitly denied.
For a cross-account request, both sides must allow it: the identity-based policy in the requester's account and the resource-based policy (or role trust policy) in the resource's account. This is why cross-account access to an S3 bucket needs both a bucket policy and an IAM policy, and why cross-account role assumption needs both a trust policy and sts:AssumeRole permission.
| Situation | Result |
|---|---|
| Any explicit Deny applies | Denied |
| Allowed by identity policy, outside permissions boundary | Denied |
| Allowed by identity policy, denied by SCP | Denied |
| Same account, allowed only by resource policy naming the role | Allowed (if no limits deny it) |
| Cross-account, resource policy allows, identity policy does not | Denied |
| No policy allows | Denied (implicit) |
The following diagram shows the order in which a request is evaluated.

Writing Narrow Policies
Least-privilege policies are narrow in actions, resources and conditions. Specific actions replace wildcards such as s3:*; resource ARNs replace "*" where the action supports resource-level permissions; and conditions restrict context, for example aws:SourceVpce to require a VPC endpoint, aws:RequestedRegion to limit Regions, aws:ResourceTag to limit to tagged resources, aws:CalledVia to allow an action only when called through a specific service such as CloudFormation, and iam:PassedToService to limit which service a role may be passed to.
iam:PassRole deserves particular care: a principal that can pass a powerful role to a service such as EC2 or Lambda can effectively obtain that role's permissions. Policies should allow passing only specific roles to specific services.
{
"Version": "2012-10-17",
"Statement": [
{"Sid": "PassOnlyTheFunctionRole", "Effect": "Allow", "Action": "iam:PassRole",
"Resource": "arn:aws:iam::111122223333:role/orders-function-role",
"Condition": {"StringEquals": {"iam:PassedToService": "lambda.amazonaws.com"}}},
{"Sid": "ManageOnlyOrdersFunctions", "Effect": "Allow",
"Action": ["lambda:UpdateFunctionCode", "lambda:UpdateFunctionConfiguration", "lambda:PublishVersion"],
"Resource": "arn:aws:lambda:eu-west-1:111122223333:function:orders-*"}
]
}Refining Permissions with IAM Access Analyzer
Initial policies are often broader than needed. IAM provides data to tighten them.
- Last accessed information shows when each service, and for some services each action, was last used by a role, user or policy, and at the organisation level for SCP planning.
- Policy generation in IAM Access Analyzer reviews a role's CloudTrail activity over a period and generates a policy containing only the actions and resources actually used, which can replace a broad starting policy after a trial period.
- Unused access findings report unused roles, unused access keys and passwords, and unused permissions within roles across an account or organisation, continuously, with recommendations to remove them.
- External access findings report resources, such as buckets, keys and roles, that are shared outside the zone of trust (the account or organisation), and internal access findings show which principals in the organisation can reach critical resources.
- Policy validation and custom policy checks, described in the policy-as-code lesson, catch problems before deployment.
Which Access Analyzer feature?
Delegating Safely with Permissions Boundaries
Developers often need to create IAM roles, for example for Lambda functions in their stacks, but allowing role creation without limits lets them create roles more powerful than themselves. A permissions boundary solves this. The administrator creates a boundary policy, such as allowing only the services the team uses, and grants developers permission to create roles only if they attach that boundary, using the iam:PermissionsBoundary condition key. The developers' own policy also denies changing or removing the boundary. Any role they create can then never exceed the boundary, whatever policies they attach to it.
{
"Sid": "CreateRolesOnlyWithBoundary",
"Effect": "Allow",
"Action": ["iam:CreateRole", "iam:PutRolePolicy", "iam:AttachRolePolicy"],
"Resource": "arn:aws:iam::111122223333:role/app/*",
"Condition": {"StringEquals": {"iam:PermissionsBoundary": "arn:aws:iam::111122223333:policy/AppTeamBoundary"}}
}Boundaries in exam scenarios
When a scenario requires that developers can create IAM roles for their applications but must not be able to escalate privileges, the answer is a permissions boundary enforced through the iam:PermissionsBoundary condition. SCPs limit whole accounts, not individual developers' creations.
Delegate safely
Tightening a Pipeline Role
A deployment pipeline's CodeBuild role has the AdministratorAccess policy because the team was unsure which permissions it needed. Security requires least privilege without breaking deployments.
-
Generate
Use IAM Access Analyzer policy generation on the role's CloudTrail activity over the last 90 days, covering several releases.
-
Review and scope
Edit the generated policy to restrict resources to the application's ARNs and add iam:PassedToService conditions on iam:PassRole.
-
Validate
Run policy validation and a CheckAccessNotGranted check for sensitive actions such as iam:CreateUser.
-
Monitor
Replace AdministratorAccess, then watch unused access findings and AccessDenied errors in CloudTrail during the next releases.
A role's identity policy allows s3:PutObject on a bucket, and the role has a permissions boundary that allows only DynamoDB actions. Can the role write to the bucket?
Show answer
No. Effective permissions are the intersection of the identity policy and the permissions boundary, and the boundary does not include S3.
Exam Tips
Remember for the exam
- Explicit deny always wins; an action needs an allow and must be within SCPs, RCPs, permissions boundaries and session policies.
- Cross-account access needs both the identity policy and the resource policy (or trust policy).
- Restrict iam:PassRole to specific roles and iam:PassedToService values.
- IAM Access Analyzer generates policies from CloudTrail activity, reports unused access and external access, and validates policies.
- Permissions boundaries with the iam:PermissionsBoundary condition let developers create roles without privilege escalation.