Skip to content

AWS IAM security: best practices to reduce excessive permissions

IAM is where cloud incidents most often begin. See how to apply least privilege, control credentials, and review access in a way your team can sustain.

Reading time
9 min
Published

In the cloud, the perimeter that matters most is identity, and AWS is no exception: most relevant attack paths go through permissions that are too broad. For example, think of an application that uses a role with administrative access, an old access key leaked in a repository, or a user who kept piling up policies without anyone reviewing them. With loose IAM, a single entry point is enough to compromise the whole account.

You can structure IAM around least privilege without stalling operations, as long as you start with the basics of credentials and MFA and know the privilege escalation paths, the ones where a harmless-looking permission turns into full access. Then comes the periodic review, which has to fit the team routine or it will be abandoned. The goal is to shrink the blast radius of any compromised credential and keep access auditable. Chasing the perfect configuration usually goes wrong, because it becomes impossible to maintain.

Least privilege in practice

Least privilege means granting only the permissions a specific task requires, and nothing beyond that. The first step is taking policies like AdministratorAccess out of everyday use and replacing long-lived credentials with temporary roles. Applications running on EC2, ECS, or Lambda should assume roles and never carry embedded access keys.

Conditions let you restrict the context in which a permission applies. You can require MFA for sensitive actions, for example, or limit a role to a network source or a specific tag. A stolen credential then loses much of its value, because it only works inside the expected context. A condition snippet that requires MFA looks like this:

Policy snippet that denies sensitive actions without MFA (the combination AWS recommends)
"Effect": "Deny","Condition": {  "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }}

For actions that should never happen, use an explicit deny. A Deny always wins over an Allow, so a policy that denies disabling audit trails, deleting KMS keys, or changing organization controls keeps protecting the environment even when another policy grants the permission by mistake.

Privilege escalation paths

With least privilege, taking AdministratorAccess out of circulation is only the beginning. Some permissions look harmless on their own but let a limited identity turn itself into an administrator. A policy can look restricted and still contain one of these paths, so it pays to know them. The goal here is defensive: knowing where they are so you can close them.

  • Anyone who can attach policies to themselves, with iam:AttachUserPolicy or iam:PutUserPolicy, can grant themselves any permission
  • With iam:CreatePolicyVersion and SetDefaultPolicyVersion, an identity can rewrite a policy that is already attached
  • iam:PassRole combined with permission to create resources (Lambda, EC2, ECS) lets an identity inherit a more powerful role
  • iam:CreateAccessKey on another user generates credentials for an identity with more access
  • Anyone who can change the trust policy of an administrative role can assume it from an identity they control

Note that all these cases have something in common: the identity can change its own authorization or pass along a privileged role. The fix follows the same logic. Restrict the actions in the iam namespace and put conditions on iam:PassRole, so that only the expected roles can be passed. IAM Access Analyzer helps on both ends: it validates policies and generates new ones from actual usage, which lets you find overly broad grants before they become an escalation path.

Credentials, MFA, and federation

Long-lived access keys are the most dangerous asset in IAM. They leak in repositories, logs, and container images, and they do not expire on their own: a leaked key keeps working until someone deactivates it. For human access, prefer federation through IAM Identity Center, with temporary sessions. For machine access, use roles. When an access key is unavoidable, rotate it periodically and keep an eye on its last-used date.

MFA should be mandatory on the root account and on all privileged human access. The root account should have no access keys and should only come into play for the tasks that require root, always with strong MFA and with the credentials stored in a safe place.

Continuous permission review

Without review, permissions only grow: every project adds something and nobody takes anything away. IAM Access Analyzer flags unintended external access, and last accessed information shows permissions that were granted and never used. Policies that have never been exercised are natural candidates for removal.

  • Prefer policies managed by the organization over inline policies scattered across identities
  • Use permission boundaries to set a ceiling for whoever creates roles
  • Apply SCPs to block dangerous actions in every account of the organization
  • Treat wildcards in Action and Resource as exceptions, with the justification on record

Detecting abuse as well as preventing it

Prevention and detection go together. Set up alerts for the CloudTrail events that often signal escalation or preparation for persistent access, such as access key creation, policy attachment, changes to the trust policy of a role, root account use, and repeated AssumeRole failures. Ideally, the escalation path is already closed. When something gets through anyway, a fast alert is what shortens the response time.

Practical checklist

  • Enable MFA on the root account and remove the root access keys
  • Require MFA for all privileged human access
  • Replace users with access keys by federation through IAM Identity Center
  • Have applications assume roles instead of carrying access keys
  • Take AdministratorAccess out of everyday use
  • Restrict the actions in the iam namespace and limit iam:PassRole to the expected roles
  • Explicitly deny the actions that should never happen, such as disabling auditing
  • Apply permission boundaries to whoever creates identities
  • Define SCPs that block dangerous actions across the organization
  • Review permissions with last accessed data and remove what was never used
  • Run IAM Access Analyzer to find unintended external access
  • Create alerts for key creation and policy changes recorded in CloudTrail
  • Rotate and monitor the use of any access keys that still exist

Best practices

  • Model access by role and job function, not person by person
  • Use conditions (MFA, source, tag) to restrict the context of roles
  • Prefer temporary sessions over long-lived credentials
  • Document the reason for any broad permission that has to exist
  • Keep policies versioned as code and apply only changes that were reviewed and approved
  • Watch CloudTrail for user and key creation and for policy changes

Common mistakes

Applications with embedded access keys
The key ends up leaking in a repository or an image and gives persistent access that is hard to detect.
AdministratorAccess for day-to-day tasks
Any compromise turns into full control of the account.
Root account with active access keys
It exposes the highest level of privilege, which cannot be limited by policy.
Wildcards in Action and Resource by default
They grant much more than necessary and make auditing harder.
Permissions that are never reviewed
Forgotten access piles up and widens the blast radius of any incident.

Authorship and review

Cesar Gargiulo

CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.

Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.

Frequently asked questions

What is IAM in AWS, and why is it critical for security?
IAM (Identity and Access Management) is the service that controls who can do what in your AWS account, through users, groups, roles, and policies. It weighs so heavily on security because most serious cloud incidents go through identity. A leaked credential or an overly broad permission opens the way to unauthorized access and privilege escalation. That is why applying least privilege in IAM is among the measures that reduce risk the most on AWS.
What is the difference between an IAM user and an IAM role?
An IAM user is a fixed identity with long-lived credentials. A role has no permanent credentials: it is assumed for a limited time and generates short-lived credentials. For machine access and federated human access, roles are safer because they shorten the window in which a credential can be used.
Do I need IAM Identity Center even with a single account?
It pays off most when there are several accounts and several users, because it offers federated access with temporary sessions and a central point of management. For a single small account it may be overkill. Once several people and accounts are involved, though, it greatly reduces the use of long-lived credentials.
How do I start applying least privilege without breaking operations?
Before cutting anything, look at actual usage with last accessed information and Access Analyzer, so you are not removing permissions in the dark. Tackle the most dangerous cases first, such as AdministratorAccess and root access keys, then move forward gradually, role by role, and check that each adjustment did not interrupt a legitimate workflow.
Do SCPs replace IAM policies?
No. SCPs set the maximum permissions for the accounts in an organization, but on their own they grant no access at all. IAM policies are still needed to grant the permissions within that ceiling. In other words, the SCP restricts and IAM grants.
What is iam:PassRole, and why does it require care?
iam:PassRole is the permission to hand a role to an AWS service, such as attaching a role to a Lambda function or an EC2 instance. The problem is that if an identity can pass a more powerful role and also create the resource that will use it, the identity inherits that role's access. It is a classic escalation path. The defense is to put conditions on PassRole so it allows only the expected roles for each service, instead of leaving it open with a wildcard.
How do I identify privilege escalation paths in IAM?
Review the permissions in the iam namespace and on sts:AssumeRole, and look for anyone who can change their own authorization or pass privileged roles. IAM Access Analyzer helps validate policies and flags overly broad grants, and last accessed information shows what was never used. In larger environments, a structured review that maps these paths usually yields more than analyzing each policy in isolation.

When to bring in specialist help

Reviewing IAM in an organization with many accounts and accumulated roles takes method and knowledge of the context. GUARDIASEC does this review as part of its AWS and cloud security service. We map the privilege escalation paths and rank the fixes by how much each one reduces risk.