Least privilege principle in AWS - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the effort to manage permissions grows as we add more users or resources.
How does the number of permission checks or policy updates change when the system grows?
Analyze the time complexity of applying least privilege policies to multiple users.
// Example: Assigning least privilege policies
for each user in users:
create policy with minimal permissions
attach policy to user
verify access only to allowed resources
This sequence creates and attaches a minimal permission policy for each user, ensuring they only access what they need.
Look at what repeats as users increase.
- Primary operation: Creating and attaching a policy per user.
- How many times: Once for each user.
Each new user requires a new policy and attachment.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 10 policy creations and attachments |
| 100 | About 100 policy creations and attachments |
| 1000 | About 1000 policy creations and attachments |
Pattern observation: The work grows directly with the number of users.
Time Complexity: O(n)
This means the effort grows in a straight line as you add more users.
[X] Wrong: "One policy can cover all users without extra work as users grow."
[OK] Correct: Using one policy for all users often gives too many permissions, breaking least privilege and risking security.
Understanding how permission management scales helps you design secure and manageable systems, a key skill in cloud roles.
"What if we grouped users by role and assigned one policy per role instead of per user? How would the time complexity change?"
Practice
least privilege principle mean in AWS security?Solution
Step 1: Understand the principle meaning
The least privilege principle means giving users only the minimum permissions they need.Step 2: Compare options to principle
Only Users get only the permissions they need to do their job matches this by limiting permissions to what is needed.Final Answer:
Users get only the permissions they need to do their job -> Option AQuick Check:
Least privilege = minimal needed access [OK]
- Thinking least privilege means full access
- Confusing least privilege with no access
- Assuming password sharing is secure
my-bucket?Solution
Step 1: Identify required permissions for read-only S3 access
Read-only means allowing onlys3:GetObjecton the specific bucket's objects.Step 2: Match policy actions and resources
{\"Effect\": \"Allow\", \"Action\": [\"s3:GetObject\"], \"Resource\": \"arn:aws:s3:::my-bucket/*\"} allows onlys3:GetObjectonmy-bucketobjects, following least privilege.Final Answer:
Policy allowing only s3:GetObject on my-bucket objects -> Option CQuick Check:
Least privilege = specific action + resource [OK]
- Using wildcard * for all actions or resources
- Allowing delete or write actions unnecessarily
- Granting permissions for unrelated services
{
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject"],
"Resource": "arn:aws:s3:::example-bucket/*"
}Solution
Step 1: Analyze actions in the policy
The policy allowss3:PutObject(upload) ands3:GetObject(download) actions.Step 2: Check resource scope
The resource is limited to objects insideexample-bucket, so permissions apply only there.Final Answer:
Allows uploading and downloading objects only in example-bucket -> Option BQuick Check:
Actions + resource = upload/download in example-bucket [OK]
- Assuming delete permission is included
- Thinking permissions apply to all buckets
- Confusing allow with deny
Solution
Step 1: Understand the reported behavior
Users can stop instances, which is not intended by the new policy.Step 2: Identify possible causes
If the policy only allows starting, but users can stop, they likely have another policy granting stop permissions.Final Answer:
Users have an additional policy granting stop permissions -> Option AQuick Check:
Multiple policies combine permissions [OK]
- Assuming one policy overrides others
- Not checking group or role policies
- Ignoring policy wildcards
dev-environment. Which approach is best?Solution
Step 1: Identify the scope of access needed
The developer needs to manage Lambda functions only in thedev-environment.Step 2: Apply least privilege by limiting actions and resources
Create an IAM policy allowing only Lambda actions on functions with resource ARN containingdev-environmentrestricts Lambda actions to only functions indev-environment, minimizing risk.Step 3: Evaluate other options
Options B, C, and D grant broader access than needed, violating least privilege.Final Answer:
Create an IAM policy allowing only Lambda actions on functions with resource ARN containing dev-environment -> Option DQuick Check:
Least privilege = limit actions + resource scope [OK]
- Using broad AWS managed policies
- Granting admin or full access unnecessarily
- Ignoring resource-level restrictions
