Cloud Security

IAM Least Privilege Tutorial: Build Policies That Hold

Watson for Cyber Security
Photo: IBM España. (PDM 1.0)
In this article4 sections

The short answer

Least privilege in IAM means giving every identity — a user, a role, or a service account — exactly the permissions its job requires and nothing more, then enforcing that minimum in code and reviewing it on a schedule. This tutorial shows you how to take an over-permissioned identity, work out what it genuinely needs, and rebuild its policy so that a compromise of that identity stops being a compromise of the whole environment.

If you take one rule from this tutorial, make it this: start from nothing, add only what the job needs, and prove that everything else can be removed. Every step below serves that rule.

How it works

To apply least privilege, you need to know the machinery you are constraining. Cloud IAM systems differ in vocabulary — AWS IAM has users, roles, and policies; Azure uses roles and assignments; Google Cloud uses principals and bindings — but they all share four moving parts:

  • Who — the principal making the request: a person, an application, or an automated job.
  • What — the action being attempted: read a file, create a server, delete a database.
  • Which — the resource the action targets: one bucket, one key vault, one project.
  • When — the conditions under which the action is allowed: from the office network, with multi-factor authentication, during business hours.

Least privilege is mostly about the last three. The platform already knows who is calling; your job is to constrain the what, which, and when so tightly that the identity can still do its work and nothing else.

Policy evaluation follows simple logic worth memorizing. By default, everything is denied. An explicit allow grants a specific action on a specific resource. An explicit deny always wins, even over an allow. Two mistakes therefore dominate real-world IAM: granting too broad an action (a wildcard) and granting an action on too broad a resource (all storage in the account). Fixing those two mistakes is most of the discipline.

Here is a concrete example. A nightly job on a virtual machine copies database dumps into an object-storage bucket. When the job was built, the team attached the platform’s built-in administrator policy “temporarily” and moved on. Today that VM can read, modify, and delete every file in every bucket in the account, create new servers, and change its own permissions. If the VM is ever compromised, the attacker inherits an administrator’s reach.

The overly broad policy looks like this:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "*"
    }
  ]
}

The job actually does three things: it lists the backup bucket, writes new dump files, and decrypts the key the bucket uses. That job — and nothing else — is what the replacement policy allows:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::db-backups",
        "arn:aws:s3:::db-backups/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "kms:Decrypt",
      "Resource": "arn:aws:kms:us-east-1:111122223333:key/backup-key-id"
    }
  ]
}

Three changes do the work. The wildcard action became three named actions — exactly the verbs the script uses. The wildcard resource became the single bucket that holds backups, so the job cannot touch customer data, logs, or any other bucket in the account. And a second statement allows decrypting only the specific encryption key the bucket uses, because the platform encrypts buckets by default and the script would fail without it. The pattern generalizes: name the job, list its real actions, narrow the resources to the ones it touches, and add a condition — a specific network or a required tag — where the job allows one. The finished policy documents the job, which makes future changes and future audits easier.

Why it matters operationally

Least privilege is often filed under compliance hygiene, but its real value is operational. Every permission an identity holds but does not need is a capability an attacker can reach through that identity. The chain is short: a phished employee, a leaked service-account key, a compromised vendor tool, or an unpatched application server — and now the attacker can do whatever the over-privileged identity could do.

Scope controls the outcome. In the example above, a compromised backup VM can read and write one bucket. With the old policy, the same compromise could delete every bucket in the account or spin up expensive infrastructure. The incident is identical; the blast radius is not.

Least privilege also protects you from your own organization:

  • Accidents. A script that can only write to the backup bucket cannot delete the production bucket when a variable is mistyped.
  • Audits. Frameworks such as ISO 27001 and SOC 2 expect access granted on a need-to-know basis and reviewed regularly. Policies that document the job make that evidence nearly free.
  • Investigations. During an incident, a well-scoped policy tells responders exactly what the compromised identity could and could not do, which shrinks the forensic work.
  • Offboarding. Tightly scoped, job-shaped roles are easier to reassign and retire than shared administrator accounts that accumulate permissions for years.

There is a cultural benefit too. When granting access means writing down what the job is and why each permission is needed, reviewers start asking the right question — “what does this actually need?” — instead of approving administrator access to unblock a deadline.

What to do about it

Least privilege is a loop, not a one-time project: inventory, scope, test, review. Work through the four steps below on one high-risk identity first — a service account, a build server, or any user with administrator access — and use that win to build the habit.

Step 1: Inventory what exists. List every identity in the environment and flag the ones that are over-permissioned, unused, or long-lived. Find users, roles, and service accounts with administrator-level policies attached. Use the platform’s own tooling to surface excess: IAM Access Analyzer in AWS, access reviews and role-assignment reports in Microsoft Entra, and Policy Intelligence with the IAM recommender in Google Cloud. Check last-used timestamps: identities that have not authenticated in months, and access keys nobody uses, are candidates for deletion — not for more permissions.

Step 2: Write the minimal policy. For each identity, write the job down in one sentence, then build the policy from that sentence using the pattern above: named actions instead of wildcards, named resources instead of “everything,” and a condition where one applies. Where the platform supports it, prefer short-lived credentials and roles over static access keys — a credential that expires limits how long a leak stays useful.

Step 3: Test before you enforce. Never swap a working administrator policy for a minimal one in production without proof. Simulate the new policy with the platform’s policy simulator, or apply it in a staging account and run the job there. Watch the access logs for denials; each denied action tells you something the job genuinely needs, and you add exactly that — nothing more. A few iterations of “run, observe a denial, add one permission” produce a policy that fits the job precisely.

Step 4: Review on a schedule. Put access review on the calendar — quarterly is a common cadence — and make it a working session, not a rubber stamp. Delete identities and access keys that are no longer used. Re-check every administrator-level grant; each one needs a current owner and a written justification. Compare policies against access logs again, because permissions the logs show unused are removal candidates. Keep policies in version control and require review on every change, the way you treat infrastructure code.

Before declaring an identity “least privilege,” run this checklist:

  • The identity’s job is documented in one sentence.
  • Actions are named; no wildcard actions without a compensating condition.
  • Resources are narrowed to the specific ones the job touches.
  • Conditions cover network, MFA, or time where the job allows.
  • The policy was tested, and the job runs cleanly.
  • No unused credentials remain, and the next review is scheduled.

Every permission you remove today is attack surface you no longer have to defend tomorrow.

Derek Zacharias

Founder & principal consultant, Dominion Cyber

Derek Zacharias is a cybersecurity practitioner and the primary author at Dominion Cyber, a Virginia-based security consultancy. He writes the technical guides on securenetworks.cloud: wireless network auditing, reconnaissance and endpoint tooling, Linux and container lab builds, digital forensics, and the threat-actor profiles in the Threat Intelligence library. His work runs from hands-on methodology through to the operational decisions behind it — what to test, what to fix first, and what evidence to keep.

Get the weekly security brief

One email a week: what is worth patching, what is worth watching, and what is worth reading. No spam, unsubscribe any time.