Mount S3 (s3fs) on EC2 with dynamic files - Persistent Public Permission
Asked Answered
F

2

3

Using S3FS and FUSE to mount a S3 bucket to an AWS EC2 instance, I encountered a problem whereby my S3 files are being updated, but the new files doesn't adopt the proper permission.

The ACL rights that the new files had were "---------" instead of "rw-r--r--". I've ensured that the bucket is mounted properly by:

sudo /usr/bin/s3fs -o allow_other -o default_acl="public-read" [bucketname] [mountpoint] 

and creating an automount in /etc/fstab:

s3fs#[bucketname]  [mountpoint]     fuse    defaults,noatime,allow_other,uid=1000,gid=1000,use_cache=/tmp,default_acl=public-read 0 0

and password file in /etc/passwd-s3fs with the right permissions.

My setup is Ubuntu 13.04, PHP5, AWS SDK.

After 2 days of experimenting, I've found a solution (for php) in the provided answer below.

Furtherance answered 7/8, 2013 at 4:12 Comment(0)
F
7

In my php script that PUT files to S3 using AWK SDK for PHP, I had to add in the meta data, as shown below, which did the trick:

$response = $s3->create_object('bucketname', 'mountpoint/'.$filename, array(
    'body'  => $json_data,
    'contentType' => 'application/json',
    'acl' => AmazonS3::ACL_PUBLIC,
    'meta' => array(
        'mode'         => '33188',    // x-amz-meta-mode
    )
));

The mode "33188" defined the permissions "rw-r--r--" instead of "---------" in S3 bucket (but reflected only in the EC2 mounted folder), which was later inherited by the EC2 mounted drive.

Hope this helps someone. Let me know!

Furtherance answered 7/8, 2013 at 4:12 Comment(3)
How can these permissions be changed? I don't understand this numeral for permissions.Nez
It's an old post, so I'll try my best to recollect. I'm guessing you are familiar with permission 0644 (octal) or "rw-r--r--". 33188 is the mode in decimal. Mode contains both file type and its permission, and when you mask off the file type, you get the permissions 0644. See https://mcmap.net/q/463328/-understanding-and-decoding-the-file-mode-value-from-stat-function-output and perlmonks.org/?node_id=985371Furtherance
Is there a way to force Amazon SES create files with this mode?Posterity
M
1

s3fs#[bucketname] [mountpoint] fuse defaults,noatime,allow_other,uid=222,gid=48,use_cache=/tmp,default_acl=public-read 0 0

For me this line work wihtout setting x-amz-meta-mode! take care of : uid=222 is for my server ec2-user and gid=48 is for my server apache group.

All the script php is executed with apache group. That's why i think you need to put the gid to 48.

see also Change user ownership of s3fs mounted buckets

Merri answered 18/12, 2013 at 20:49 Comment(1)
I give up this solution for many years because of data corrpution (web server with data on s3fs). Don't know if s3fs fuse has made progress.Merri

© 2022 - 2024 — McMap. All rights reserved.