Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 38 ยท Identity and Access

Least Privilege and Policy Design

Learn to write least-privilege cloud policies: scope actions and resources, use conditions, permission boundaries and RBAC, and find unused permissions with a runnable analyzer.

Least privilege sounds simple, give people and programs only the access they need, but it is hard in practice. Deadlines push teams towards wildcards, and nobody remembers which permissions a role really uses a year later. This lesson shows how to design policies that are tight enough to matter and manageable enough to maintain, and how to use access data to shrink permissions safely.

The three dimensions of a permission

Every allow statement can be narrowed in three ways. Wide in all three is administrator.

  1. Actions. storage:* allows reading, writing, deleting and changing sharing. storage:GetObject allows reading objects.
  2. Resources. * means every resource in the account. bucket/invoices/* is one path in one bucket.
  3. Conditions. Only from a particular network, only with MFA, only for resources carrying a matching tag, only before an expiry time.
flowchart LR
    W["Wide policy<br/>actions: *<br/>resources: *"] --> N1["Narrow actions"] --> N2["Narrow resources"] --> N3["Add conditions"] --> L["Least privilege"]

Tighten one dimension at a time and test after each step.

Examples from broad to narrow

Broad (avoid):

JSON
{ "effect": "Allow", "actions": ["*"], "resources": ["*"] }

Better:

JSON
{ "effect": "Allow", "actions": ["storage:*"], "resources": ["bucket/invoices/*"] }

Best for a job that only reads last month's invoices:

JSON
{
  "effect": "Allow",
  "actions": ["storage:GetObject"],
  "resources": ["bucket/invoices/2026-10/*"],
  "condition": { "source_network": "10.0.0.0/16" }
}

Note that listing a bucket and reading objects are different actions, and some workflows need both. Start with the minimum, run the workload, and add only what a clear error message shows is missing.

Design patterns

  • Role-based access control (RBAC). Define roles for job functions (billing-reader, deployer, incident-responder) and grant roles, not individual permissions, to people. Review roles, not people, most of the time.
  • Attribute-based access control (ABAC). Compare tags: "a user may manage resources whose team tag equals the user's team tag". One policy then scales to many teams.
  • Permission boundaries. A maximum-permissions policy attached to a role or user. Even if someone attaches an admin policy, the boundary caps the effective access. Useful when you let developers create their own roles.
  • Organization guardrails. Policies applied to whole groups of accounts that deny dangerous things outright: disabling logging, using unapproved regions, making storage public.
  • Separation of duties. The person who administers keys cannot use them to decrypt data, and the person who deploys cannot approve their own change.
  • Break-glass access. A rarely used, heavily monitored emergency path for outages, with approval and alerts.
  • Just-in-time access. Elevated rights are granted for a limited time on request and then expire.

Finding unused permissions

You do not have to guess what a role needs. Providers record the last time each permission was used, and activity logs show actual API calls. Compare the granted permissions with the used ones, remove or review the unused ones, and keep a safety net such as testing in staging first.

Runnable example: policy shrinker

The program compares the actions a role is granted with the actions seen in 90 days of (made-up) logs, then proposes a smaller policy and a "needs review" list. Real tools do this at far larger scale; the logic is the same.

Python Propose a smaller policy from usage

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Four of the unused permissions are marked dangerous: they let a compromised role change bucket policies, delete a queue or create new encryption keys. Removing them shrinks the blast radius at no cost to the workload.

Conditions in practice

A condition can turn a broad permission into a safe one. This second example evaluates conditions on requests: required MFA, an allowed source network and a matching team tag (ABAC).

Python Conditions and tag-based access

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

One rule now serves every team, because the tag comparison replaces a separate policy per team.

A practical workflow

  1. Start from a job description: what must this identity do, on which resources?
  2. Write the narrowest policy you can, in code, with comments for why each statement exists.
  3. Test with the real workload in a non-production account.
  4. Review access analyzer findings and last-used data every quarter.
  5. Use code review for every policy change, and scan policies for wildcards in the pipeline.

Start strict, loosen on evidence. It is much easier to add one missing permission after an "access denied" message than to discover a year later that a role could delete everything.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which policy best follows least privilege for a job that reads one folder of one bucket?

    It limits both the action and the resource to exactly what the job needs.
  2. 2. What does a permission boundary do?

    Even if broader policies are attached, effective access cannot exceed the boundary.
  3. 3. What is the advantage of attribute-based access control with tags?

    ABAC compares attributes such as team tags, so rules scale without per-team policies.
  4. 4. How can you find permissions a role does not need?

    Usage data shows which granted actions are never exercised, and those are candidates for removal.

Summary

  • Narrow permissions along three dimensions: actions, resources and conditions.
  • Use RBAC for job functions, ABAC for scale, permission boundaries and organization guardrails for hard limits.
  • Use usage data to remove unused permissions, starting with the dangerous ones.
  • Keep policies in code, reviewed and tested, and revisit them regularly.

Next: Authentication, MFA and Federation