创建仅接受已签名 URL 的无服务器 CloudFront 分配

Create CloudFront distribution that accepts only signed URL’s with serverless

我想创建一个只能使用签名 URL 访问的 Web cloudFront 分配。

在手动创建分发时,默认缓存行为设置下有一个限制查看者访问的选项。

我想使用无服务器框架创建分发,但找不到用于限制查看者访问权限的 CloudFormation 属性 属性。

文档对此完全不清楚。如果签名密钥在您部署 CloudFront 分发包的同一个账户中,您只需要:

    TrustedSigners:
      - self

请注意,在 2020 年底的某个时候,CloudFront 提供了一种创建签名密钥的方法,该方法不涉及使用 AWS 账户根用户。有关详细信息,请参阅这些文档。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#choosing-key-groups-or-AWS-accounts

有点晚了。添加到上面的答案。

通过 CloudFromation 有两种方法。

  1. TrustedKeyGroups - CloudFront 可用于验证签名 URL 或签名 cookie 的密钥组列表。

  2. TrustedSigners - AWS 账户 ID 的列表,其 public 密钥 CloudFront 可用于验证签名 URL 或签名 cookie。

当缓存行为包含 TrustedSigners 或 TrustedKeyGroups 属性 时,CloudFront 要求为匹配缓存行为的所有请求签名 URLs 或签名 cookie。 CloudFront 已经通过这些设置假定了这一点,因此您无需指定任何其他 属性(限制查看者访问 UI)。

根据 AWS,他们建议使用 TrustedKeyGroups 而不是 TrustedSigners。

AWS URL:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-cachebehavior.html#cfn-cloudfront-distribution-cachebehavior-trustedsigners