AWS S3
Bucket Policy
Access Denied
Root User
Cloud Storage

Access denied when put bucket policy on aws s3 bucket with root user bucket owner

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Amazon Simple Storage Service (S3) is a scalable object storage service widely used for storing and protecting any amount of data. AWS S3 employs a sophisticated security model that incorporates Identity and Access Management (IAM) policies, bucket policies, and Access Control Lists (ACLs) to control access to S3 buckets and objects. It's not uncommon for AWS users, even root users who own the S3 buckets, to encounter "Access Denied" errors when they attempt to apply or modify bucket policies. This article delves into the reasons behind these errors, even for root users who are bucket owners, and explores solutions to mitigate such access issues.

Understanding AWS S3 Bucket Policies

Bucket Policies

A bucket policy is a resource-based policy that specifies access permission and defines who has access to an S3 bucket and its objects. Policies are JSON documents composed of one or more statements, each defining an action, effect, resources, and principal.

Root User and Ownership

In AWS, the root user is the account owner and has full access to all AWS resources, meaning it can read, write, manage, and apply policies on AWS services. However, access issues with the root user can arise because S3 implements early security checks to ensure safe access.

Causes of "Access Denied" for Root User

1. Explicit Deny in a Policy

AWS follows a rule where explicit denies always override allows. If there's an explicit deny in a bucket policy, it would restrict access irrespective of permissions granted in any other policy.

2. Block Public Access Settings

AWS offers Block Public Access settings, which may block public access to buckets and objects. These settings can override permissions that would otherwise allow access.

3. MFA Delete Enabled

Multifactor Authentication (MFA) Delete adds an extra layer of protection by requiring MFA for change requests. If enabled, without the required MFA token, even root users may face access issues.

4. Other Security Mechanisms

AWS may incorporate additional service controls to protect sensitive resources. These include SCPs (Service Control Policies) within AWS Organizations that could impose restrictions.

Technical Example

Consider the following JSON policy for an S3 bucket named "example-bucket":

  • Description: This policy explicitly denies any principal from applying a bucket policy if an attempt is made from an IP address in the range 203.0.113.0/24.
  • Impact on Root User: Any attempt by the bucket owner to modify the bucket policy from the specified IP range will be met with an "Access Denied" error, regardless of any broader IAM permissions since explicit deny rules take precedence.
  • IAM Policy Permissions: Verify the root user has the necessary IAM policy permissions, such as `s3:PutBucketPolicy`.
  • Bucket Policy Configuration: Review your existing bucket policies for explicit deny statements that might contradict intended allow policies.
  • Block Public Access: Check and temporarily adjust the Block Public Access settings if they interfere with policy actions.
  • MFA Configuration: Ensure MFA is configured correctly if MFA Delete is enabled on the bucket.
  • Review Service Control Policies (SCPs): Assess any down-the-line restrictions imposed by SCPs in your AWS organization structure that may hinder access.

Course illustration
Course illustration

All Rights Reserved.