Configuring Security for an S3 for Presigned Post? - amazon-web-services

Continuing my adventure in AWS, Uploading The File, I am just going to come out and ask it. What is the proper way to configure the security settings for an S3 bucket intended to be the endpoint for a presigned post file upload?
Currently I have created an IAM user with full S3 permissions which can generate the presigned post in response to a get request via an AWS Lambda function. However if I have the block all privacy setting enabled when I use the post I get access denied. If I turn off block all it works but I am worried about security.
So I will just ask, what is the proper way to configure the security settings for an S3 bucket intended to be the endpoint for a presigned post file upload?

Related

AWS S3 PreSigned URL Permissions at the Creation Level & Usage Level

Is there a way to restrict the permissions of my Users so that, they should not be able to create/generate a presigned URL for the S3 objects that they have access to. ?? My users should not be able to generate a pre-signed URL even if they have access to the S3 objects.
Either restricting their ability of generating presigned URL or atleast detecting an action in real-time when its created is also fine with me.
It looks like there is no cloudtrail API call for generating presigned URL or also there is no cloudtrail API call whenever the generated presigned URL is used for accessing the S3 object.
So, I am stuck at this point and we as a platform team need to stop our App users from being able to generate presigned URLs and give them out to unauthorized users.

AWS: Does my S3 bucket need a policy for files to be readable from my application?

I have a Laravel application that is hosted on AWS. I am using an S3 bucket to store files. I know that I have successfully connected to this bucket because when I upload files, they appear as I would expect inside the bucket's directories.
However, when I try to use the URL attached to the uploaded file to display it, I receive a 403 Forbidden error.
I have an IAM user set up named laravel which has the permission AmazonS3FullAccess applied to it, and I am using that key/secret.
I have the Object URL like so:
https://<BUCKET NAME>.s3.eu-west-1.amazonaws.com/<DIR>/<FILENAME>.webm
But if I try to access that either in my app (fed into an audio player) or just via the link directly, I get a 403. None of the tutorials I've followed to get this working involve Bucket Policies, but when I've googled the problems I'm having, Bucket Policy seems to come up.
Is there a single source of truth on how I am to do this? My AWS knowledge is very limited, but I am trying to get better!
When you request a URL of the form https://bucket.s3.amazonaws.com/dog/snoopy.png, that request is unauthenticated. Your S3 bucket policy does not allow unauthenticated access to the contents of the bucket so that request is denied with 403.
If you want your files to be downloadable by an unauthenticated/anonymous client then create an S3 bucket policy to allow that.
Alternatively, your server can create signed URLs and share those with the client.
Otherwise, your client's requests need to be authenticated, which means having correctly-permissioned credentials and using an AWS SDK.
Typically, back-end applications that you write that need access to data in S3 (or other AWS resources) would be given AWS credentials allowing the necessary access. If your back-end application runs in AWS then you would do that by launching the compute with an IAM role.
Typically, front-end applications would not have AWS credentials. Instead they would either authenticate to a back-end that then does work with AWS resources on their behalf. There are other options, however, such as AWS Amplify apps.

Restrict S3 objects URL only to logged in users on a website

My website has some files hosted on AWS S3 buckets, but I need to restrict access to the s3 objects URL to only logged in users of the website. Something similar to how google drive works. which means that anyone trying to access the urls to any of the files on our S3 bucket needs to be logged into the website before he or she would be able to.
Is this possible?
Thanks
If you want to restrict access to the S3 objects, don't make the objects public and don't use the public URLs shown on AWS S3 console.
S3 provides an option to generate pre-signed URLs to download S3 objects. So once your users log in to your website and when they request to download the S3 object, make a request to S3 to generate this pre-signed URL. Clicking on the pre-signed URL will download the object.
With pre-signed URLs, you can configure additional options like expiry time, so that these URLs are more secure.
You can find more info about pre-signed URLs and their implementation here.
If you happen to use AWS Cognito for log in/out functionality, you can assign IAM roles to logged in users.
This way when trying to access the s3 bucket, you can restrict access using IAM roles.
AWS Amplify would be a good fit for this use-case.

How to track AWS S3 Pre-sign urls

We provide REST api to upload user files, on backend we use S3 Bucket to store the user uploads.
As our REST api has timeout of 30sec, user may get timeouts based on filesize and his network.
So we thought of providing him a S3 Pre-Sign URLs for uploads, through which user can upload his large files using AJAX calls from frontend or using backend scheduled script.
Everything looks OK but we don't have any clue about provided s3 Pre-Signs:
- whether he attempted to upload or not:
if attempted whether the upload is success or not
if failed, what was the error (url expired or something other..)
We can know about success case by searching the object key in our bucket. But in case of failures we don't have any clue.
Please let me know if there is anyway to track the S3 pre-sign access/uploads.
You will not know when a pre-signed URL is used, but another couple of options are:
You can configure an Amazon S3 Event to trigger when a new file is uploaded to a bucket. This could trigger an AWS Lambda function that can process the file or, at least, make a log that the file was uploaded.
You can use Amazon S3 Server Access Logging to track access to the bucket.

How to create session token for my file on AWS S3 if it connected to other CDN provider?

I have some video file stored on AWS S3 and I want to secure these files by adding session token with specific expiry time on the video URLs for preventing unauthorized access.
I know the s3 SDK can generate temporary credentials with Cloudfront to achieve this.
However, if I connected S3 to other CDN provider such as cloudflare. Will these temporary credentials work perfectly?
For example, my video file is stored on s3 -> http://files.video.com.s3.amazonaws.com/video.mp4
The cloudflare cdn url is -> http://files.video.com/video.mp4
If i generated temporary credentials for the file and access the url -> http://files.video.com/video.mp4?token=4180da90a6973bc8bd801bfe49f04a&expirey=1526231040535
Will it work?
It sounds like you're referring to S3 Presigned URLs. No, if your S3 bucket is private, CloudFlare will not be able to generate presigned URLs to access your files. AWS CloudFront uses an Origin Access Identity to resolve this issue. However with 3rd party CDNs, this is not possible.
There are 2 ways you could achieve better security (source).
Make your bucket public but restrict the allowed IPs for your S3 bucket to only CloudFlare IPs.
Make your bucket private and use CloudFlare workers to authorize its GET requests