简体   繁体   English

AWS CloudFront访问控制允许来源和签名Cookie /网址

[英]AWS CloudFront Access-Control-Allow-Origin and Signed Cookie/Urls

I'm stuck with a CORS at S3+Cloudfront+Signed Urls. 我在S3 + Cloudfront + Signed Urls遇到了CORS。

My use cases is: 我的用例是:

First story (successful): 第一个故事(成功):

  1. I have an Amazon S3 bucket with a Cloudfront. 我有一个带Cloudfront的Amazon S3存储桶。 Files are accessible by the DOMAIN1/file link 可以通过DOMAIN1/file链接访问DOMAIN1/file

  2. I write a simple test JS script to get file from DOMAIN1 and put it at the DOMAIN2/test.html 我编写了一个简单的测试JS脚本来从DOMAIN1中获取文件,并将其放在DOMAIN2/test.html

  3. I'm able to get file successfully. 我能够成功获取文件。 CORS is fine . CORS很好

Second case (successful too): 第二种情况(也成功):

  1. I restrict Cloud Front distribution by using Signed Url. 我通过使用签名网址来限制Cloud Front分发。
  2. At first I tried is to access a file at DOMAIN1 without Signature. 最初,我尝试的是访问DOMAIN1上没有签名的文件。 Got an Access denied. 得到了拒绝访问。 It's ok, since request is not signed. 没关系,因为请求未签名。
  3. I've created a signed URL and able to download the file successfully. 我已经创建了一个签名的URL,并且能够成功下载文件。

Third case (failed) 第三种情况(失败)

  1. I put signed url (from 2nd case) to the DOMAIN2/test.html test script 我将签名的URL(从DOMAIN2/test.html情况开始)放到DOMAIN2/test.html测试脚本中
  2. And always got a No 'Access-Control-Allow-Origin' header error. 并始终No 'Access-Control-Allow-Origin' header错误。

So Cloudfront is not sending a header in case of restricted distribution. 因此,在分配受限的情况下,Cloudfront不会发送标头。

CORS xml is: CORS xml是:

<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>http://*</AllowedOrigin>
    <AllowedOrigin>https://*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>10</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>

It must be some issue in the CloudFront/S3/IAM settings. CloudFront / S3 / IAM设置中一定有问题。 How I can fix it? 我该如何解决?

Seems like a solution was to setup a correct access rights to the S3 bucket. 似乎一种解决方案是为S3存储桶设置正确的访问权限。 Instead the "Everyone" access, need an "Any AWS authenticated user" or "Cloudfront appropriate user". 取而代之的是“所有人”访问,需要“任何经AWS身份验证的用户”或“适合Cloudfront的用户”。

I went to Cloudfront Distributions -> MYPRIVATECLOUDFRONTID -> Behaviors and added the Following: 我去了Cloudfront Distributions -> MYPRIVATECLOUDFRONTID -> Behaviors并添加了以下内容:

Path Pattern = path/to/my/file.ext

Forward Headers = Whitelist

And added to Whitelist Header: Origin 并添加到Whitelist Header: Origin

Don't forget to uncheck the option Restrict Viewer Access (Use Signed URLs or Signed Cookies) - for me, it was marked to not restrict even though I have marked the whole cache to be restricted. 不要忘记取消选中“ Restrict Viewer Access (Use Signed URLs or Signed Cookies) -对我来说,即使我已将整个缓存标记为受限,它也被标记为不受限。

My next step is to automatically set this whitelist on demand. 我的下一步是根据需要自动设置此白名单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cloudfront 使用签名 URL 获取 S3 对象的间歇性 403 CORS 错误(访问控制允许来源) - Intermittent 403 CORS Errors (Access-Control-Allow-Origin) With Cloudfront Using Signed URLs To GET S3 Objects AWS javascript sdk getSignedUrl操作上的access-control-allow-origin吗? - Access-control-allow-origin on aws javascript sdk getSignedUrl operation? Chrome S3 Cloudfront:初始和加载请求中没有“ Access-Control-Allow-Origin”标头 - Chrome S3 Cloudfront: No 'Access-Control-Allow-Origin' header on initial and load request Video.js - HLS =&gt; 没有“Access-Control-Allow-Origin”标头 [S3、CloudFront] - Video.js - HLS => No 'Access-Control-Allow-Origin' header [S3, CloudFront] CloudFront 未正确传回来自 S3 的 Access-Control-Allow-Origin 标头 - CloudFront is not correctly passing back the Access-Control-Allow-Origin header from S3 S3 访问控制允许来源 - S3 Access-Control-Allow-Origin 从签名的 S3 URL 获取数据给出:`No 'Access-Control-Allow-Origin' header is present` - Getting data from signed S3 URL giving: `No 'Access-Control-Allow-Origin' header is present` 当请求的 Origin 标头存在时,AWS S3 不发送 Access-Control-Allow-Origin 标头 - AWS S3 Not Sending Access-Control-Allow-Origin header when Origin header on request is present AWS S3不将Origin返回为Access-Control-Allow-Origin值 - AWS S3 not returning Origin as Access-Control-Allow-Origin value 源访问身份 (OAI) 和 CloudFront 签名 URL 之间的关系 - Relationship between Origin Access Identities (OAIs) and CloudFront Signed URLs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM