How to get S3 bucket's full URL for firewall? - amazon-web-services

I am using azcopy (Azure Copy) to copy data from an S3 bucket thru a proxy. We cannot allow *.amazonaws.com or any wildcard. The security team requires a rule for each bucket to prevent exfiltration to other buckets.
We tried [bucketname].s3.amazonaws.com and it failed. The proxy log shows it blocked the URL of the bucket which is [bucketname].s3.dualstack.[region].amazonaws.com
How do I find the full URL of an s3 bucket if all I have is the bucket name and bucket names are unique? I can't find the info in the Amazon S3 console.

The format is:
https://BUCKETNAME.s3-REGION.amazonaws.com/
For example:
https://foo42.s3-ap-southeast-2.amazonaws.com/
It is also possible for buckets to use s3.amazonaws.com, which will normally result in a redirect to the region-specific path.
URLs with dualstack relate to IPv6.

Related

Error in object URL of static website in S3 bucket: Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature

I have created a static website in an S3 bucket AWS. I have created two files in bucket one in index.html and 2nd is error.html. When I open index.html and click on object URL in AWS it gives below error:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>InvalidArgument</Code>
<Message>Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4.</Message>
<ArgumentName>Authorization</ArgumentName>
<ArgumentValue>null</ArgumentValue>
<RequestId>R69TKNDJTYZ8E0SW</RequestId>
<HostId>OAOZKRsA6ATOgH6jBr5jO1fS0zi+GSh4at34nLq8V/Ug8Icvuy8c6NOlCoNqqjpBcORg8bDlzJ0=</HostId>
</Error>
I have checked every possible solution but nothing works. My bucket has public access like below my bucket name it is written in red Publicly accessible. But still I could not find what is issue.

S3 Redirect with Cloudfront getting "Access Denied" error Message

I am trying to use an S3 bucket to redirect from one website to another. The redirect from "http://example.com" works, but I can't get the redirect from "https://example.com", "http://www.example.com" or "https://www.example.com" to work.
I have an S3 bucket called "example.com". I then created a Cloudfront distribution, attached the custom SSL certificate, and added "example.com" and "www.example.com" as Alternate Domain Names.
I'm getting this access denied message:
I'm assuming that I am not doing something correctly on the policy settings for the S3 bucket. Any guidance?
I am using the following bucket policy:
I am not currently using the "Access Control List".
For the Cloudfront Distribution redirection to https, it is necessary to configure ACM SSL certificates. provision a certificate exactly for the subdomain.example.com and use the same alternate domain name subdomain.example.com unless there would be an SSL handshake error.
Select your Origin domain and path
In the origin access -> use Origin access control settings (recommended) -> Origin access control -> Create Control Settings -> Copy the bucket policy from this screen and update it to your s3 bucket policy.
Follow the behavior settings as follows: specify your Origin and origin groups
Basically, there are 2 approaches that you can setup CloudFront with S3.
Your S3 bucket is public accessible and CloudFront origin with S3 is public
Ensure your S3 bucket does not having enabled Block Public Access
Ensure your S3 bucket policy is having Public Read Access
Ensure you can access your S3 bucket object publicly via your web-browser
Ensure you have configured your CloudFront origin with S3 using Public mode
Your S3 bucket is private and CloudFront origin must be configured with access control
Ensure your S3 bucket is having enabled Block Public Access
Ensure your S3 bucket policy is added with correct policy.
Ensure you have configured your CloudFront origin with S3 using one of Access control mode, such as OAC
For testing, you can try the Public approach, but for better secure, you can follow the approach from Zeeshan comment.

Sharing S3 Bucket between Accounts for CloudFront

I have two AWS accounts. Each account has an S3 bucket and CloudFront which exposes the contents of the S3 bucket.
I would like to get rid of a CORS issue.
For that I I need to serve all content using one CloudFront.
How I can grant permissions to the S3 bucket from account2 to CloudFront in account1?
This is possible if the bucket is publicly accessible , the bucket won't come in the drop down when you're creating origin but you can use the name as bucket.s3.region.amazonaws.com.
It is also possible using origin access identity. Use first your own bucket to create the bucket policy automatically by CloudFront, you should be able to see IAM identity in CloudTrail, you can copy the same policy on the other account S3 bucket and OAI should work.

AWS Get Pre-Signed URL with custom domain

Following is what I'm doing. I'm generating a pre-signed URL using a custom domain for my s3 bucket resources which are not public.
https://files.customdomain.com/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
Also to add the certificate I've created a cloudfront distribution for the bucket having following origin settings
Origin Domain Name: bucket-name.s3.amazonaws.com
Origin Id : s3.bucket-name
Restrict Bucket Access: No
Yet I'm unable to access my resources. Throws access denied error. Any help would be appreciated.
There are two cases:
If your bucket has regular name.
In this case you should use CloudFront to access your bucket.
And like mentioned above URL looks like in this answer:
https://cloudfront-url/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
If your bucket has s3 static website name.
In this case your bucket name looks like files.customdomain.com and you can generate pre-signed url for this bucket:
https://files.customdomain.com/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
In your DNS you will have CNAME files.customdomain.com points to files.customdomain.com.s3.[bucket-region].amazonaws.com.
NOTICE
When I generate pre-signed URL via aws-cli:
aws s3 presign s3://files.customdomain.com/file123 --endpoint-url https://files.customdomain.com
I get URL with duplicate bucket name in the path:
https://files.customdomain.com/files.customdomain.com/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
instead of:
https://files.customdomain.com/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
I don't know if it has the same behavior via SDK.
Have you tried initializing S3 with the custom url var S3 = new AWS.S3({endpoint: 'media.domain.com', s3BucketEndpoint: true});
More info https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
Also, make sure signature is correct as well https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html#specify-signature-version
Ref : https://github.com/aws/aws-sdk-js/issues/891
When using S3 with CloudFront, you don't want an S3 signed URL... you want a CloudFront signed URL.
Read Configuring Security and Limiting Access to Content in the CloudFront developer guide.
I found a solution for this question. The signed url needs to be generated for cloudfront url endpoint from s3 bucket. Therefore instead of
https://files.customdomain.com/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
it needs to be
https://cloudfront-url/file123?AWSAccessKeyId=XXX&Expires=1541220685&Signature=XXXX
and DNS records had to resolve custom domain to cloudfront url.

how to access cloudfront to s3 bucket object simple url

i am trying to access cloudfront to s3 bucket object response "AccessDenied".
xxxxxxxxxxxxx.cloudfront.net/bucket_name/35.jpg
inside bucket i can access url this is "public" url.
https://s3.ap-south-1.amazonaws.com/bucket_name/35.jpg
I am also try another bucket with another cloudfront ID with signed URL result is same. Please view code here =>
amazon cloudfront Error "AccessDenied"
You should:
Configure your CloudFront distribution with an Origin to point to your S3 bucket
Access the content via: xxxx.cloudfront.net/35.jpg
See:
Using Amazon S3 Origins and Custom Origins for Web Distributions
Using CloudFront with Amazon S3
Task List for Creating a Web Distribution