Guide
AWS IAM Least Privilege: How to Get There and Keep It
How to apply least privilege in AWS IAM: find broad policies, cut them down with last accessed data and policy generation, cap them, and keep them small.
Part of the guide User Access Review: How to Run One, Step by Step
Least privilege is easy to agree with and hard to do in AWS. Policies are long, a single * can allow every action in a service, and the quick fix during an incident is often more access. This guide is for the engineer who has been asked to “tighten up IAM” before an audit, and for the compliance lead who wants to know what that work involves. It covers what least privilege means in IAM, the tools AWS gives you, the steps to cut a broad policy down, and how to stop it growing back.
AWS IAM least privilege means each person and workload gets only the actions, on the specific resources, under the conditions its work needs, and nothing more. You start from what exists, use last accessed data and CloudTrail activity to cut broad policies down, cap what remains with permissions boundaries and SCPs, and review access regularly.
A few AWS words come up on this page:
- IAM (Identity and Access Management) is the part of AWS that decides who can do what.
- A policy is a JSON document that lists what is allowed or denied. An identity-based policy is attached to an IAM user, group or role. A resource-based policy sits on a resource, such as a storage bucket.
- An IAM role is a set of permissions that a person or a program takes on for a while, with temporary credentials.
- CloudTrail is the AWS service that logs API calls made in your account. A trail is the setting that keeps those logs in a storage bucket.
- AWS Organizations groups several AWS accounts. The management account runs the organization, and the others are member accounts.
What least privilege means in AWS IAM
AWS lists “Apply least-privilege permissions” among its IAM security best practices. It defines it as granting only the permissions required to perform a task, by “defining the actions that can be taken on specific resources under specific conditions.” That gives you three things to narrow in every policy, and a fourth for roles:
- Actions.
s3:GetObjectinstead ofs3:*, ands3:*instead of*. - Resources. One bucket’s ARN (its full AWS name) instead of every bucket.
- Conditions. Limits on when a statement applies, such as only over an encrypted connection or only from your organization.
- Who may take on a role. Each role has a trust policy, which names the principals (people, services or accounts) allowed to assume it. A small permissions policy on a role that anyone in another account can assume is not least privilege.
The same page is practical about it. You might start with broad permissions while you learn what a workload needs, then reduce them as it matures. AWS managed policies are a fine place to start, but AWS warns they “might not grant least-privilege permissions for your specific use cases because they are available for use by all AWS customers,” and recommends your own customer managed policies instead.
Least privilege covers programs as well as people. NIST’s control AC-6 in SP 800-53 Rev. 5 speaks of users “or processes acting on behalf of users.” In AWS, that means the roles your build pipeline, Lambda functions and servers use. They can hold more than any person. The least privilege glossary entry has the general definition.
The AWS tools for least privilege
AWS has several features that help. Each one answers a different question, and none of them does the whole job.
| Feature | What it tells you or does | What it does not do |
|---|---|---|
| Last accessed information | Which services a user, group, role or policy is allowed, and when each was last used. For many services, which management actions too (create, change, delete), but not reads and writes of data such as S3 objects. | Count access allowed by resource-based policies, boundaries or SCPs, or tell a successful call from a denied one: it counts attempts. |
| Access Analyzer policy generation | Writes a draft policy from up to 90 days of a user or role's CloudTrail activity. | Name resources for you. It leaves placeholders, and it misses iam:PassRole and data events (actions on the data inside a resource, such as reading an S3 object). |
| Access Analyzer policy validation | Runs more than 100 checks on a policy, AWS says, and flags errors and access it considers too broad. | Know what your workload needs. A valid policy can still allow too much. |
| Unused access analyzer | Reports unused roles, access keys, passwords and permissions, continuously, across an account or organization. Paid. | Say whether access that is used is still needed. |
| Permissions boundary | Sets the most a single IAM user or role can ever be allowed. | Grant anything. It only caps. |
| Service control policy (SCP) | Sets the most any IAM user or role in a member account can do, including the account's root user (the login created with the account, which can do anything in it). | Grant anything, or affect the management account or service-linked roles (roles AWS services create and manage for themselves). |
The sources are AWS’s pages on last accessed information, policy generation, policy validation (the count of checks is on the best practices page), permissions boundaries and service control policies. The unused access analyzer has its own guide: AWS IAM Access Analyzer for access reviews.
How to cut an IAM policy down to least privilege
Most teams do not start from zero. They have roles and groups that grew over years. The work is to find the broadest access, shrink it one identity at a time, and keep a record of why each permission is there.
- Find the broadest grants first. Start with whoever holds the AWS managed AdministratorAccess policy, which allows every action on every resource, then any customer managed or inline policy whose
ActionorResourceis*, then role trust policies that let many principals in. These carry the most risk, so they are worth your time first. - See what each identity really uses. Open the user or role in the IAM console and choose the Last Accessed tab, or use the AWS CLI commands below. Services that were never used, or not in many months, are the first to remove.
- Draft a smaller policy. For a role with steady work, such as a deploy role, let IAM Access Analyzer generate a policy from its CloudTrail activity. In the IAM console, open the role, and on the Permissions tab choose Generate policy. You pick up to 90 days of activity, the trail to read, and a service role that lets Access Analyzer read that trail (the console can create it). You need a CloudTrail trail for the account, and AWS says generation does not support trails that AWS Control Tower creates.
- Name the resources and add conditions. Replace the placeholder ARNs in the draft with your real buckets, tables or keys. Use
*only for actions that do not support resource-level permissions. Add back what the draft cannot see, such asiam:PassRoleand S3 object reads and writes, if the role needs them. - Validate it. Run IAM Access Analyzer policy validation on the draft and fix its errors and security warnings.
- Test before you switch. While the broad policy is still attached, every call succeeds, so a test then shows nothing. Try the new policy on its own: on a copy of the role, or in a non-production account, with the broad policy not attached. Run the work the role does and look for access denied errors in CloudTrail. Calls on data, such as S3 object reads, show in CloudTrail only if you turned on data events, so also watch the application’s own errors. Then swap the policies in production and keep the old one ready to put back. AWS’s advice is to test each generated policy before you deploy it to production.
- Write down the owner and the reason. For each role, note who owns it and what it is for. That note is what a reviewer reads at the next review.
People who come in through IAM Identity Center are a special case. A permission set is a bundle of policies that Identity Center gives to people in one or more accounts. When you assign one in an account, Identity Center creates a matching role there, with a name that starts with AWSReservedSSO_. Identity Center manages that role, so change the permission set in Identity Center, or move people to a smaller one, rather than the role in IAM. Everyone assigned the permission set in that account uses the same role, so its last accessed data shows their combined use, not one person’s.
Commands to run
These use the AWS CLI. The account ID and role name are examples. First, list who holds AdministratorAccess directly or through a group:
aws iam list-entities-for-policy \
--policy-arn arn:aws:iam::aws:policy/AdministratorAccess \
--query '{Users: PolicyUsers[].UserName, Groups: PolicyGroups[].GroupName, Roles: PolicyRoles[].RoleName}'
The result does not show who is in each group. Run aws iam get-group --group-name <name> for each group it lists. It also finds only this one AWS managed policy. It misses customer managed and inline policies with *, and does not say who may assume each role it lists. For those, get-account-authorization-details returns one snapshot of every user, group and role with their inline policies and trust policies, and every customer managed policy. The AWS CLI returns the policy documents as plain JSON. If you call the API directly, they come back URL-encoded, so decode them before you search for wildcards.
Next, ask IAM which allowed services a role never used. The generate command starts a report and returns a job ID. The get command reads it, and must be run by the same user or role session that started it.
JOB_ID=$(aws iam generate-service-last-accessed-details \
--arn arn:aws:iam::123456789012:role/example-deploy-role \
--query JobId --output text)
# Run this until JobStatus says COMPLETED (or FAILED).
aws iam get-service-last-accessed-details --job-id "$JOB_ID" --query JobStatus
aws iam get-service-last-accessed-details --job-id "$JOB_ID" --max-items 1000 \
--query 'ServicesLastAccessed[?LastAuthenticated==null].ServiceNamespace' --output text
LastAuthenticated is empty when nothing used the service in the tracking period, which AWS says is at least 400 days for services, or less in a Region that started tracking more recently. Recent activity appears within four hours. AWS also warns that some actions are not tracked yet, and action-level data covers management actions only, not data calls such as S3 object reads. So do not remove a permission only because it has no tracking data. Check what the role is for. Add --granularity ACTION_LEVEL to the first command, and the report also gives TrackedActionsLastAccessed for each service AWS tracks at that level: when each tracked action was last used.
Last, validate the smaller policy before you attach it. Here is a short example of a policy narrowed on actions, resources and conditions: two actions, one bucket, and a condition that requires an encrypted connection. Save your own policy as deploy-role-policy.json to use the command below as written.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-build-artifacts/*",
"Condition": { "Bool": { "aws:SecureTransport": "true" } }
}
]
}
aws accessanalyzer validate-policy \
--policy-type IDENTITY_POLICY \
--policy-document file://deploy-role-policy.json \
--query 'findings[].[findingType, issueCode]' --output text
An empty result means no findings. You need permission for access-analyzer:ValidatePolicy, and the command runs in your default Region. Each finding has a type: ERROR (part of the policy does not work), SECURITY_WARNING (access AWS considers too broad), WARNING or SUGGESTION. The validate-policy reference lists the options.
Guardrails: permissions boundaries and SCPs
Cutting policies down fixes today. Guardrails stop the worst from coming back. Both kinds set a ceiling, and AWS is clear that neither one grants a permission. For access granted by identity-based policies, a request is allowed only if the identity’s own policy allows it and every ceiling above it allows it too. An explicit deny anywhere wins. One exception matters: in the same account, a resource-based policy, such as a bucket policy, can grant access directly to an IAM user or a role session, and an implicit deny in a boundary does not block that.
Permissions boundaries are for delegating. Say your developers may create roles for their own services. You set a boundary, a managed policy, and require that every role they create carries it. The roles they create can then use what their policies allow inside the boundary, and nothing outside it, even with a broad policy attached. AWS’s boundaries page shows how to enforce this with the iam:PermissionsBoundary condition key. A boundary applies to one IAM user or role, not to a group.
Service control policies are for the whole organization. An SCP attached to an organizational unit (a folder of accounts in AWS Organizations) limits every IAM user and role in the member accounts under it, including each account’s root user. One example from AWS’s best practices for the management account is an SCP at the root that stops member accounts from leaving the organization or closing themselves. AWS says organizations created in the console after July 10, 2026 get it automatically. Older organizations, and ones created with the CLI, SDKs or CloudFormation, must add it by hand. Two limits matter. SCPs do not affect the management account, which is why AWS recommends keeping your resources and workloads in other accounts. And they do not affect service-linked roles. AWS recommends testing an SCP on a few accounts before attaching it to the root of the organization, because a wrong one can lock people out.
How to keep least privilege once you have it
Permissions creep back. A role gets a new statement for an incident and keeps it. Someone moves teams and keeps their old group. This slow growth has a name, privilege creep, and the fix is to look again on a schedule.
AWS’s own best practice is to regularly review and remove unused users, roles, permissions, policies and credentials. In practice that means:
- Review people’s access in your user access review. Each manager confirms that their people still need the AWS groups, roles or permission sets they hold. The user access review guide covers the whole process, and the privileged user access review guide covers admin access, which deserves a closer look.
- Review workload roles with their owners. The team that runs a service confirms what its role needs. Last accessed data shows what went unused since the last review. If PCI DSS applies, requirement 7.2.5.1 asks for periodic reviews of application and system accounts, at an interval set by your own targeted risk analysis.
- Check credentials. Long-lived access keys are easy to forget. The IAM credential report guide shows how to list every key and when it was last used.
- Look at broad grants each time. Re-run the commands above and compare the results with last time. A new name on that list should have a ticket behind it.
Last accessed data helps a reviewer decide. It does not decide for them: an emergency admin role should go unused, and someone who moved teams but still uses an old role never shows up as unused. The Access Analyzer guide covers both cases.
What auditors and frameworks say
No framework names IAM. They ask for access that matches the job, and evidence that you check it.
- SOC 2. The AICPA trust services criteria, in CC6.3, ask you to authorize, change and remove access with least privilege and segregation of duties in mind.
- ISO/IEC 27001:2022. Annex A control 5.15 asks for access control rules based on business and security needs. Control 8.2 asks you to restrict and manage privileged access rights, which in AWS means admin policies and roles.
- PCI DSS v4.0.1. Requirements 7.2.1 and 7.2.2 ask for access based on job classification and function, with the least privileges needed. Requirement 7.2.5 asks that application and system accounts get the least privileges needed for the system or application to work. Requirement 7.2.4 says user accounts and access privileges are reviewed at least once every six months. The PCI DSS standard has the full text.
- NIST SP 800-53. AC-6 sets the principle, and AC-6(7) asks you to review the privileges assigned to roles or classes of users, at a frequency you define, and to reassign or remove them if needed.
SOC 2 and ISO 27001 do not set a review frequency. Your own policy sets it, and the auditor tests that you followed it. Auditors commonly ask for the list of who had access, who reviewed it, what they decided, and that the removals happened.
Common mistakes
- Treating AWS managed policies as the end state. They are a start. AWS says so itself.
- Trusting a generated policy as-is. It has placeholders, it misses
iam:PassRoleand data events, and AWS says not to use policy generation for auditing. Use CloudTrail for that. - Reading last accessed data as the whole picture. It only counts identity-based policies. Access granted by a bucket policy or a key policy does not show there.
- Working in the management account. SCPs do not apply there, so no SCP caps a broad role in it.
- Fixing it once. Without a regular review, broad grants come back.
Where Acciew fits
Acciew runs the review part of least privilege for AWS. It reads IAM users, groups and roles, the policies attached to each, who may assume each role, and when each user and role was last used. It shows each manager the access of their people, with how they got it, such as a policy that comes through a group, and asks for a yes or no from an email link. At the end it builds the evidence pack. It names the policy someone holds, not what that policy allows, and it does not read permissions boundaries, SCPs or IAM Identity Center. It only reads, and your admins make every change. It is in early access, with design partners first.
Have an access review coming up?
Acciew is in early access. We are looking for design partners: teams with a user access review ahead of them.
Apply as a design partnerQuestions and answers
What is least privilege in AWS IAM?
It means each IAM user, role and workload is allowed only the actions, on the specific resources, under the conditions its work needs. AWS lists it as an IAM security best practice. It also accepts that you may start broad while you learn what a workload needs, and then reduce the permissions.
How do I find unused permissions in AWS?
Use IAM last accessed information. In the IAM console it is on the Last Accessed tab of a user, group, role or policy, and the AWS CLI command is generate-service-last-accessed-details. It lists the services a policy allows and when each was last used, going back at least 400 days. IAM Access Analyzer's unused access analyzer reports the same kind of gap continuously, for a fee.
Can AWS write a least-privilege policy for me?
Partly. IAM Access Analyzer can generate a policy from up to 90 days of a user's or role's activity in your CloudTrail trail. For some services it lists the exact actions, for others only the service, and it leaves placeholders where you name the resources. You still review it, fill it in and test it before you attach it.
What is the difference between a permissions boundary and an SCP?
Both set a ceiling and neither grants anything. A permissions boundary is a managed policy set on one IAM user or role. A service control policy (SCP) is set in AWS Organizations on the root, an organizational unit or an account, and applies to the IAM users and roles in member accounts, but not to the management account.
Is least privilege required for SOC 2 or ISO 27001?
Neither names AWS. The SOC 2 criterion CC6.3 asks you to consider least privilege when you grant, change and remove access. ISO/IEC 27001:2022 asks for access control rules based on business and security needs in control 5.15, and asks you to restrict and manage privileged access rights in control 8.2. Neither sets how often you review access. Your own policy does.
This guide is part of User Access Review: How to Run One, Step by Step. Read the whole guide there.