保护 Amazon S3 中的私有数据

Protect Private Data in Amazon S3

我想在 Amazon S3 上上传一些图片,并根据用户的订阅授予他们查看这些图片某些部分的权限。阅读 Amazon S3 文档后,我想到了这些解决方案:

  1. 将我的应用程序中的每个用户分配给 Amazon S3 中的一个 IAM 用户,然后定义用户策略或存储桶策略来管理谁有权访问什么。但是有两个缺点:首先,用户或存储桶策略对其大小有限制,并且由于用户和图像的数量非常大,我很可能需要超过该限制。其次,每个 AWS 账户的 IAM 用户数量限制为 5000,我的应用程序中会有更多用户。

  2. Amazon S3 可以定义一些与 IAM 用户作用相同的临时安全凭证。我可以要求客户端向我的服务器发出请求,然后我使用特殊策略为他们创建一个临时 IAM 用户并将他们的凭据传递给他们,然后他们可以使用他们的凭据直接向 S3 发送请求并可以访问他们的资源。但问题是这些用户将持续 15 分钟到 1 小时,因此客户需要至少每 1 小时请求我的服务器为他们创建一个临时 IAM 用户。

  3. 因为我想提供一些图像,所以最好结合使用 Amazon Cloudfront 和 S3 来尽快提供内容。我还阅读了提供私有内容的 Cloudfront 文档,我发现他们的解决方案使用签名 URLs 或签名 cookie。我将拒绝对 S3 资源的任何访问,云端将是唯一有权从 S3 读取数据的人,每次用户登录我的应用程序时,我都会向他们发送他们进行签名所需的凭据URL 或者我会向他们发送必要的 cookie。他们可以使用他们拥有的信息请求所需的资源,并且此信息将持续到他们登录我的应用程序为止。但我有一些安全问题。由于几乎所有关于访问控制的信息都发送给客户端(例如在 cookie 中),他们可以轻松修改它并授予自己更多权限。然而,这是一个大问题,但我认为我必须使用 cloudfront 来减少加载资源时间。

我想知道您认为这些解决方案中哪一个比其他解决方案更合理、更好,以及是否有其他解决方案可能使用其他亚马逊网络服务。

我自己在 S3 上提供私有内容的方法是将 CloudFront 与 签名 URL 签名 cookies(有时,两者都使用)一起使用).您不应使用 IAM 用户或大量用户的临时凭证,就像您的情况一样。

您可以在此处阅读有关此主题的更多信息: Serving Private Content through CloudFront

您选择使用签名 URL 还是签名 cookie 取决于以下因素。

Choosing Between Signed URLs and Signed Cookies

CloudFront signed URLs and signed cookies provide the same basic functionality: they allow you to control who can access your content. If you want to serve private content through CloudFront and you're trying to decide whether to use signed URLs or signed cookies, consider the following.

Use signed URLs in the following cases:

  • You want to use an RTMP distribution. Signed cookies aren't supported for RTMP distributions.
  • You want to restrict access to individual files, for example, an installation download for your application.
  • Your users are using a client (for example, a custom HTTP client) that doesn't support cookies.

Use signed cookies in the following cases:

  • You want to provide access to multiple restricted files, for example, all of the files for a video in HLS format or all of the files in the subscribers' area of a website.
  • You don't want to change your current URLs.

关于您的安全问题,CloudFront 使用 public 密钥来验证签名 cookie 中的签名并确认 cookie 未被篡改。如果签名无效,请求将被拒绝。

您还可以遵循 this page 末尾的指南,以防止滥用已签名的 cookie。