AWS IAM: Identity-Based vs. Resource-Based Policies Explained
Understand the difference between permissions attached to IAM identities and permissions attached directly to AWS resources, using a simple Amazon S3 example.
Imagine a developer needs to download files from an Amazon S3 bucket. You can grant permission through an IAM policy attached to the developer's role, or through a policy attached directly to the S3 bucket.
Both approaches control access, but they work differently.
Understanding this difference is important when designing secure AWS environments.
1. Identity-Based Policies
Identity-based policies are attached to IAM users, groups, or roles.
They answer one main question:
What can this identity do?
For example, suppose a developer has an IAM role that needs permission to read objects from an S3 bucket.
You can attach an identity-based policy to that role granting the
s3:GetObject action on the required bucket objects.These policies come in three forms:
- AWS Managed Policies: Created and maintained by AWS.
- Customer Managed Policies: Created and maintained by you, and reusable across identities.
- Inline Policies: Attached directly to one IAM identity.
2. Resource-Based Policies
Resource-based policies are attached directly to AWS resources, such as S3 buckets, SQS queues, and KMS keys.
They answer a different question:
Who can access this resource, and what can they do?
For example, an S3 bucket policy can grant a particular IAM role permission to read objects from that bucket.
Unlike identity-based policies, resource-based policies specify the principal receiving access through the
Principal element.3. Understanding the difference through an example
Suppose you have two AWS accounts:
- Account A contains an application.
- Account B contains an S3 bucket with important files.
The application in Account A needs to read files from the bucket in Account B.
You generally need two permissions:
- An identity-based policy in Account A allowing the application's IAM role to perform
s3:GetObject.
- A resource-based bucket policy in Account B allowing that role to access the bucket objects.
Both sides must permit the cross-account access.
This is a useful example of why understanding both policy types matters.
4. What beginners often miss
Attaching an Allow policy does not always mean access will succeed.
AWS evaluates applicable policies and controls when processing requests. An explicit Deny overrides an Allow.
Also, identity-based and resource-based policies can work together. For same-account access, an applicable resource-based policy may independently grant access to a principal, depending on the principal type and authorization rules.
Therefore, never assume that every AWS access request requires exactly the same combination of policies.
Security takeaway
Before designing IAM permissions, understand where access is being granted.
- Use identity-based policies to define what users and roles can do.
- Use resource-based policies to control access directly at supported resources.
- Review cross-account permissions carefully.
- Follow the principle of least privilege.
I have been studying AWS IAM policies, and understanding these two policy types has helped me better understand how access control works across AWS resources and accounts.
Question for the AWS community: When managing access to S3 buckets, do you prefer using identity-based policies, bucket policies, or a combination of both? What factors influence your decision?
Official AWS documentation
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article