Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I avoid specifying ACLs when uploading files to S3? #2664

Closed
emuesuenu opened this issue May 12, 2023 · 3 comments
Closed

How can I avoid specifying ACLs when uploading files to S3? #2664

emuesuenu opened this issue May 12, 2023 · 3 comments

Comments

@emuesuenu
Copy link

I am trying to upload a file to an S3 Bucket.
We are using fog-aws as the storage engine,
The object ACL setting for the bucket is disabled.

In this state, it is not possible to specify ACLs when uploading files,
I would like fog-aws to work without setting the x-amz-acl header.

CarrierWave's default implementation is to set some value regardless of the fog_public specification.

def acl_header
case fog_provider
when 'AWS'
{ 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' }
when "Google"
@uploader.fog_public ? { destination_predefined_acl: "publicRead" } : {}
else
{}
end
end

How can I work around this?
I tried overriding acl_header when inheriting from CarrierWave::Uploader::Base, but it did not work as expected.

@mshibuya
Copy link
Member

mshibuya commented Jan 8, 2024

Setting

CarrierWave.configure do |config|
  config.fog_attributes = { 'x-amz-acl' => 'bucket-owner-full-control' }
end

should work, could you check? @emuesuenu @jalkoby @stormsilver

@stormsilver
Copy link
Contributor

When ACLs are disabled on the bucket, S3 will throw an error for any request that specifies an ACL regardless of what the ACL is.

@mshibuya
Copy link
Member

mshibuya commented Jan 9, 2024

That's not correct, according to the AWS documentation:

https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html

After you disable ACLs, your bucket accepts only PUT requests that do not specify an ACL or PUT requests with bucket owner full control ACLs, such as the bucket-owner-full-control canned ACL

It's working for me and I want you to actually use that configuration with your app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants