DEV Community

Cover image for Least privilege on AWS: elevate for the task, not forever
Simone Diaco
Simone Diaco

Posted on AI-assisted

Least privilege on AWS: elevate for the task, not forever

TL;DR: Least privilege breaks down the day someone needs more than their everyday role allows, so teams hand out broad rights "just in case". Keep everyday permissions minimal and grant extra permissions only for the task: requested, approved, time-limited. One trap when you do it on IAM Identity Center: removing an assignment doesn't end the sessions already open. Put the expiry in the policy itself and IAM enforces it on every call. That's what aws-elevate, the open-source tool I built, does.


Least privilege meets real work

Everyone agrees with least privilege. Give people the permissions their job needs, nothing more: read-only on production, write access where they build.

Then real work happens. A migration needs to change a resource only admins can touch. An incident needs someone to restart a service in prod at night. A one-off fix needs write access to a bucket for ten minutes.

If the only way to get those rights is a ticket that takes days, teams do the practical thing: they give broad permissions to everyone who might need them. In IAM Identity Center that usually means an admin permission set assigned permanently, on every account, production included.

That's when least privilege quietly stops being true:

  • Every laptop is a key to production. A stolen session token or a compromised machine reaches prod with full rights, any time of day.
  • Every mistake runs with the widest rights. The wrong profile in a terminal is enough to delete something in the wrong account.
  • Nobody can say why someone had those rights. The audit trail shows who did something, never why they needed it that day.

And if you're in scope for NIS2 or DORA, least privilege and controlled privileged access are requirements, not good intentions.

Just-in-time access

The answer is boring on purpose: everyday permissions stay minimal, and extra permissions are temporary. When a task needs more, you ask for a permission set on one account, for a couple of hours, with a reason. A rule decides whether it's granted at once or needs someone else to approve. When the time is up, the extra access goes away by itself.

It costs a minute when you need it. In exchange, elevated access becomes rare, short and explained.

You can build this yourself, or start from an open-source option, for example: AWS's TEAM sample or aws-elevate, which I built. Either way, there's one detail worth knowing before you start.

The trap: removing access doesn't end the session

When someone uses a permission set, Identity Center gives them credentials for an IAM role in the account. Those are ordinary STS credentials with their own expiry: the permission set's session duration, up to 12 hours.

Removing the assignment stops new sign-ins. It doesn't touch credentials already issued. They keep working until they expire.

So if your just-in-time access "ends" by deleting the assignment, a two-hour access can last twelve.

You can see it yourself in a test account:

  1. Assign yourself a permission set with a session duration of a few hours.
  2. Sign in with the AWS CLI and run aws sts get-caller-identity.
  3. Remove the assignment in the Identity Center console.
  4. Run the same command again with the same profile.

The call still succeeds, and keeps succeeding until the session expires.

AWS documents a way to cut sessions short, and it's an incident-response procedure: a deny policy prepared in advance for the user, removing assignments, deleting active sessions in the console, disabling the user (Revoke active IAM role sessions created by permission sets). Fine for an emergency. Not something you want to run every time temporary access ends.

Put the expiry in the policy

The approach I ended up with: give each grant its own temporary permission set, a copy of the one the rule allows, plus one statement.

{
  "Sid": "JitExpiry",
  "Effect": "Deny",
  "Action": "*",
  "Resource": "*",
  "Condition": {
    "DateGreaterThan": { "aws:CurrentTime": "2026-12-02T15:00:00Z" }
  }
}
Enter fullscreen mode Exit fullscreen mode

IAM evaluates the role's policies on every call, including calls made with credentials issued earlier. Once the clock passes the end time, every call is denied, whatever sessions are open. No cleanup job has to run on time.

Ending access early works the same way: rewrite the expiry to "now" and provision the permission set again. In my tests, calls start failing about 10 seconds later. Removing the assignment and deleting the permission set come after that, as cleanup.

Three details that matter:

  • One permission set per grant. The expiry belongs to one person's access, so it can't live in a shared permission set.
  • An explicit deny wins. It overrides every allow, including the managed policies copied from the source permission set.
  • Cleanup still matters. The deny makes the access useless; deleting the permission set keeps the account tidy and within quota.

How aws-elevate does it

aws-elevate is the open-source (Apache-2.0) tool I built around this approach. You ask for a permission set on an account, for a limited time, with a reason. A rule grants it at once or waits for an approver. The expiry is the policy statement above, so access ends when it should, even in sessions already open.

A user asks for read-only access to production, another approves it, and the user opens the AWS console with the temporary role

It installs as one CloudFormation stack in your delegated administrator account, with a CLI and a local web UI: no web app to host, close to zero cost when idle, and a history of every request you can export. It's an early release: every release goes through end-to-end tests on a real AWS organization, and releases are signed. Start in a test organization. Installation and usage are in the README.

Your turn

How does your team handle the moment someone needs more than their usual permissions? Standing admin, tickets, break-glass accounts, something else? I'd like to hear what works for you in the comments.

And if you try aws-elevate, I'd like to know what's missing: open an issue.

Top comments (0)