DEV Community

kawasaki031677
kawasaki031677

Posted on

IAM Policies vs S3 Bucket Policies: Which Should You Use?

Introduction

S3 access control offers two options: IAM policies and S3 bucket policies. Since you can configure access permissions using either one, you might wonder: "Which one should I actually use?"

In real-world environments, you often see the same Allow permissions configured in both IAM policies and bucket policies, making it unclear where access is actually being managed.

This article clarifies the differences between the two and provides practical guidelines on how to choose.

Quick Summary

Here's a simple way to organize your thinking:

What you want to do Consider this policy
Define what this Role can do IAM Policy
Define who can access this bucket Bucket Policy
Prevent access under certain conditions Bucket Policy
Share resources with another AWS account IAM Policy + Bucket Policy

In particular, if you're simply granting S3 access to an application Role within a single account, designing around IAM policies makes it easier to centralize permission management.

Note: This doesn't mean "always use IAM policies for S3." The key is deciding where your permission management responsibility belongs, not which policy type is universally correct.

Differences Between IAM Policies and Bucket Policies

The fundamental difference is which starting point you use to define permissions.

IAM Policy

IAM policies are Identity-based policies. They define "what this Role is allowed to do":

AppRole
  ↓
s3:GetObject
  ↓
Bucket
Enter fullscreen mode Exit fullscreen mode

Bucket Policy

Bucket policies are Resource-based policies. They define "who can access this S3 bucket":

Bucket
  ↓
Allow access from AppRole
Enter fullscreen mode Exit fullscreen mode

What if both IAM Policy and Bucket Policy have Allow?

For example, suppose you have this configuration within the same account:

IAM Policy
  └─ s3:GetObject Allow

Bucket Policy
  └─ s3:GetObject Allow
Enter fullscreen mode Exit fullscreen mode

Having Allow in both places doesn't double the permissions. For simple same-account access, duplicate Allow settings become redundant.

Important: The real problem is managing permissions in multiple places, which makes access control harder to maintain.

When to Use Bucket Policies

1. Cross-Account Access

Consider this architecture:

Account A
  AppRole
     ↓
Account B
  S3 Bucket
Enter fullscreen mode Exit fullscreen mode

Here, IAM policies alone in Account A aren't enough. You need:

  • Account A: IAM policy granting the Role S3 access
  • Account B: Bucket policy allowing that Role to access the bucket

So cross-account access requires: "Source IAM Policy" + "Destination Bucket Policy"


2. Setting Guardrails at the S3 Level

For example, you might want to enforce:

"Only allow HTTPS connections to this bucket"

Here, you can set an explicit Deny in the bucket policy:

{
  "Effect": "Deny",
  "Principal": "*",
  "Action": "s3:*",
  "Resource": [
    "arn:aws:s3:::example-bucket",
    "arn:aws:s3:::example-bucket/*"
  ],
  "Condition": {
    "Bool": {
      "aws:SecureTransport": "false"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Even if IAM policy has Allow, an explicit Deny will block access.

Common Anti-Patterns

Duplicating the Same Allow in Both IAM and Bucket Policies

For example:

IAM Policy
  Allow s3:GetObject
      +
Bucket Policy
  Allow s3:GetObject
Enter fullscreen mode Exit fullscreen mode

Question: For same-account, simple access scenarios, ask yourself: "Why do I need both?"

Putting Many Principals in Bucket Policy

For example:

Bucket Policy
 ├─ RoleA
 ├─ RoleB
 ├─ RoleC
 ├─ RoleD
 ├─ RoleE
 └─ RoleF
Enter fullscreen mode Exit fullscreen mode

This turns the bucket policy into a Principal management registry.

Reconsider: If you're just consolidating all Role access permissions into the bucket policy, your design might need revision.

Summary

IAM policies and S3 bucket policies aren't about "which is correct." Use them this way:

Requirement Primarily use
Grant S3 permissions to an application Role IAM Policy
Cross-account access IAM Policy + Bucket Policy
Prohibit non-HTTPS access Bucket Policy
Prohibit access outside specific VPC Endpoints Bucket Policy

Don't default to bucket policies just because you're dealing with S3. Instead, ask: "Where should permission management naturally live?" This perspective helps you avoid policy duplication and unnecessary complexity.

References

AWS Security Blog: IAM Policies and Bucket Policies and ACLs! Oh, My!

Top comments (0)