Cloud Computing Tutorial · Identity and Security · Lesson 8 of 24
Least Privilege and Temporary Credentials
Grant only what's needed, use roles and federation instead of keys, and find unused permissions.
Why least privilege matters
If an application with AdministratorAccess is compromised (a vulnerable dependency, an SSRF bug), the attacker
gets the whole account. With least privilege, they get only what that application could do.
In practice
- Start from what the workload does: "read objects under
uploads/in one bucket, write to one queue". - Scope resources by ARN and use conditions, not
"Resource": "*". - Use temporary credentials everywhere:
- people: SSO (IAM Identity Center, Entra ID, Google Workspace/Cloud Identity) with MFA;
- CI/CD: OIDC federation (GitHub Actions to an IAM role, Azure workload identity federation, Google Workload Identity Federation);
- workloads: roles and managed identities.
- Remove unused permissions: IAM Access Analyzer can generate policies from actual CloudTrail activity and report unused access; Azure and Google Cloud have similar recommenders.
granted = {"s3:*", "dynamodb:*", "sqs:*", "iam:PassRole", "ec2:*"}
used_last_90_days = ["s3:GetObject", "s3:PutObject", "sqs:SendMessage", "s3:GetObject", "sqs:SendMessage"]
used = sorted(set(used_last_90_days))
unused_services = sorted({g.split(":")[0] for g in granted} - {u.split(":")[0] for u in used})
print("actions actually used:", used)
print("services granted but never used:", unused_services)
print("suggested policy actions:", used)
Output
actions actually used: ['s3:GetObject', 's3:PutObject', 'sqs:SendMessage'] services granted but never used: ['dynamodb', 'ec2', 'iam'] suggested policy actions: ['s3:GetObject', 's3:PutObject', 'sqs:SendMessage']
Break-glass access
Keep a tightly controlled emergency role, protected by MFA, monitored, and tested, for when SSO is down.
Test yourself
What's the best way for a GitHub Actions workflow to deploy to AWS?
OIDC federation to an IAM roleAn IAM user's access key in repository secretsThe root userA shared admin password
Show answer
Answer: OIDC federation to an IAM role
Federation issues short-lived credentials per run, scoped by repository and branch.