Rino Bino
Rino Bino

Reputation: 457

S3 Website Cross Account Permissions Not Working

Quick Summary:

If objects are put into a bucket owned by "Account A" from a different account ("Account B"), you cannot access files via S3 static website (http) from "Account A" (bucket owner).

This is true regardless of the bucket policy granting GetObject on all objects, and regardless of if bucket-owner-full-control ACL is enabled on the object.

PROBLEM OVERVIEW

I have a unique setup where I need to publish files to an S3 bucket from an account that does not own the bucket.

The upload actions work fine. My problem is that I cannot access files from the bucket-owner account over the S3 static website if the files were published from another account (403 Forbidden response).

The problem only exists if the files were pushed to S3 FROM a different account. Because the issue is only for those files, the problem seems like it would be in the Object Ownership ACL configuration. I've confirmed I can access other files (that weren't uploaded by the other acct) in the bucket through the S3 static website endpoint, so I know my bucket policy and VPC endpoint config is correct.

If I completely disable Object ACL's completely it works fine, however I cannot do that because of two issues:

Because of these above constraints, I must use Object ACL's enabled on the bucket. I've tried both settings "Object Writer" and "Bucket owner preferred", neither are working. All files are uploaded with the bucket-owner-full-control object ACL.

enter image description here

As mentioned, disabling ACL fixes everything, but since my client tools (Ansible and Aptly) cannot upload to S3 without an ACL set, ACL's must remain enabled. (Disabling ACL is a relatively new S3 feature, added late 2021)

enter image description here

ENVIRONMENT EXPLAINED:

Here is an example of how this file is uploaded using Ansible:

Reminder: the role doing the uploading is NOT part of the bucket owner account.

- name: "publish gpg pubkey to s3 from Account B"
  aws_s3:
    bucket: "test-bucket-a"
    object: "/files/pubkey.gpg"
    src: "/home/file/pubkey.gpg"
    mode: "put"
    permission: "bucket-owner-full-control"

I am using VPC Endpoint to access, and this is added to the bucket policy. All the needed routes and endpoint config are in-place. I know my policy config is good because if I disable the Object ACL everything works perfectly.

{
    "Sid": "AllowGetThroughVPCEndpoint",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::test-bucket-a/*",
    "Condition": {
      "StringEquals": {
        "aws:sourceVpce": "vpce-0bfb94<scrubbed>"
      }
    }
},

Some key troubleshooting notes:

enter image description here

Upvotes: 1

Views: 707

Answers (1)

Rino Bino
Rino Bino

Reputation: 457

This problem was Ansible's fault the whole time.

Even though permission: "bucket-owner-full-control" was set during upload, the setting wasn't working properly. I believe as a side effect of this issue: https://github.com/ansible-collections/amazon.aws/issues/219

Fix:

I ended up doing an ansible-galaxy collection install --upgrade amazon.aws and tried re-uploading the file and everything worked as expected.

Upvotes: 0

Related Questions