通过 HTTP 从 Cloudfront 访问 Amazon S3

Amazon S3 access from Cloudfront through HTTP

我想我可以通过添加主体来做到这一点:arn:iam:cloudfront ....

但这允许直接 S3 访问,而不是 HTTP 端点访问。

当我将 Cloudfront 配置为直接为 S3 存储桶提供服务时,它不显示子目录 index.htmls。为了访问 mysite.com/blog/,我必须输入 mysite.com/blog/index.html

出于这个原因,我必须使用 S3 的 HTTP 端点,就好像该站点不在 S3 上而是在 Apache 服务器上一样。

现在我无法通过 arn:iam:cloudfront 限制访问。由于 Cloudfront 成为另一个网络爬虫,S3 成为另一个网络服务器。

他们建议添加自定义 headers 以便服务器了解它是云端。但是S3不支持自定义headers.

将用户代理限制到 CloudFront 并将委托人限制到 AWS:* 做了一个简短的工作,但它不会阻止 UserAgent 欺骗。

我该如何解决这个问题?

你试过这个方法吗?

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

To ensure that your users access your objects using only CloudFront URLs, regardless of whether the URLs are signed, perform the following tasks:

Create an origin access identity, which is a special CloudFront user, and associate the origin access identity with your distribution. (For web distributions, you associate the origin access identity with origins, so you can secure all or just some of your Amazon S3 content.) You can also create an origin access identity and add it to your distribution when you create the distribution.

Change the permissions either on your Amazon S3 bucket or on the objects in your bucket so only the origin access identity has read permission (or read and download permission). When your users access your Amazon S3 objects through CloudFront, the CloudFront origin access identity gets the objects on your users' behalf. If your users request objects directly by using Amazon S3 URLs, they're denied access. The origin access identity has permission to access objects in your Amazon S3 bucket, but users don't.

根本不要将源配置为 S3——将其配置为自定义源,然后使用存储桶的网站端点主机名作为源服务器主机名。

到那时,您应该能够配置 CloudFront 将发送到源的 Origin Custom Header -- 这恰好是存储桶的网站端点。

User-Agent 不在 list of custom headers that CloudFront won't forward 上,因此您应该能够在从 CloudFront 到 S3 的请求中发送自定义用户代理字符串——有点像静态密码,并将您的存储桶配置为仅允许该自定义用户代理。

它在理论上仍然可以被欺骗,但由于它是您组成的随机字符串,除了您、S3 和 CloudFront 之外没有人知道该值,并且有人欺骗未知值将非常棘手,尤其是因为 S3 只是拒绝访问,没有解释。