I have a Rails 6 app, where registered users(Owner) can upload files - images/videos on S3 and then the the owner can provide access to other users(invitations) to view their uploaded content.
Is there a way I can restrict file access so that only the owner can download his uploaded files(images/videos), thereby putting restrictions in place to other non-owner/invited users.. Videos/images should not get downloaded by just right-clicking and saving/downloading them so easily.
Note - the uploaded files also include large videos(both mp4 and HLS streaming), so other invited users can view them but cannot download it unless they are the owners/uploaders as the files are coming from AWS Cloudfront for videos and S3, if they are images.
Associations are setup like -
User has one role
User has many images/videos, each residing in his own folder on s3(`bucket/user_id/image_slug/` or `bucket/user_id/video_slug/`)
User has many invitations(must be view only access to owners file)
Not sure,what is the right approach, can be -
- update the ACL for the file if its accessed by non-owner and make it read-only?
- Make all uploaded files public and disable public access for non-owners but this will also restrict any access to the file directly.
Let me know what is the best suited logic for this approach.
What you are trying to achieve needs groundwork on multiple levels:
Based on S3 security best practices, you should keep the permission level to a minimum just enough on the S3 side for the app to provide the expected behavior.
S3 allows you to grant access to user specific folders.
You should look into the access granted gem to cover server side restrictions. You should also look into client side restrictions. A common technique is to disable right mouse click.
Related:
How to download files without showing S3 URls
Top 7 security features for video streaming platforms
How Netflix protects its content