Least privilege on AWS, one denied request at a time
Nobody writes a least-privilege policy on the first attempt. The approach that works is to start slightly too broad, watch what the role actually does, and then cut the policy down to that.
Start from what is actually used
IAM Access Analyzer can generate a policy from the CloudTrail activity of a role, and the IAM console shows when each service was last accessed. Both turn "what might this need?" into "what did it do over the last 30 or 90 days?", which is a far easier question to answer.
Scope resources and add conditions
An action on * is rarely what you mean. Name the resources, and add conditions where they make the policy tighter, for example requiring TLS:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::example-reports/exports/*",
"Condition": { "Bool": { "aws:SecureTransport": "true" } }
}]
}
Put guardrails above the roles
Individual policies drift. Service control policies and permission boundaries set a ceiling that no role in the account can exceed, whatever its own policy says. Use them for the rules that must always hold, such as blocking regions you do not use or preventing CloudTrail from being switched off.
Make it a loop
- Review last-accessed data on a schedule and remove what is unused.
- Alert on repeated
AccessDeniedevents in CloudTrail: they show either a missing permission or someone probing. - Prefer short-lived role sessions to long-lived access keys.