简体   繁体   English

如何确保完全保护我的 AWS S3 存储桶?

[英]How can I make sure I fully secured my AWS S3 Bucket?

I am trying to make sure I have my S3 bucket secure.我正在努力确保我的 S3 存储桶安全。 I need to allow some sort of public access due to my website displays the images that are uploaded to my S3 bucket.由于我的网站显示上传到我的 S3 存储桶的图像,我需要允许某种公共访问。

My Public Access settings look sleek this:我的公共访问设置看起来很时尚:

在此处输入图像描述

I then set up my Cross-origin resource sharing (CORS) to look like this:然后我将我的跨域资源共享 (CORS) 设置为如下所示:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST"
        ],
        "AllowedOrigins": [
            "https://example.com",
            "https://www.example.com"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    }
]

And my S3 ACLs look like this:我的 S3 ACL 如下所示:

在此处输入图像描述

After doing this my images are still visible on my website hosted on AWS.这样做之后,我的图像仍然可以在我托管在 AWS 上的网站上看到。 My question here is am I missing anything?我的问题是我错过了什么吗?

I don't think I fully understand the Cross-origin resource sharing (CORS) of this.我不认为我完全理解这个的跨域资源共享(CORS)。 I assumed the AllowedOrigins tag would only allow the images to be viewed on my domain?我假设AllowedOrigins标签只允许在我的域上查看图像? So I took the address to one of my images and threw it in my web browser and it loaded.所以我把地址放到我的一张图片上,然后把它扔到我的 web 浏览器中并加载。 Is this correct behavior or am I misunderstanding this?这是正确的行为还是我误解了这一点?

Any more suggestions on how to secure my S3 bucket?有关如何保护我的 S3 存储桶的更多建议? I basically just want user on my website to be able to view my images and upload images from only my site.我基本上只是希望我网站上的用户能够查看我的图片并仅从我的网站上传图片。 Thanks!谢谢!

Updates更新

For a more full view, my bucket policy is:为了更全面地了解,我的存储桶策略是:

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::example.com.storage/*"
        }
    ]
}

My ACLs in S3 are configured as:我在 S3 中的 ACL 配置为:

在此处输入图像描述

Amazon CloudFront (CF) is often used for serving content from S3 buckets without needing the buckets to be public. Amazon CloudFront (CF) 通常用于提供来自 S3 存储桶的内容,而无需将存储桶公开。 This way your website would server your images from CF, rather than directly from the bucket.这样,您的网站将从 CF 中为您的图像提供服务,而不是直接从存储桶中。 CF would fetch and cache the images from the bucket privately . CF 会私下从存储桶中获取和缓存图像。

The way it works is that in your bucket, you would setup a special bucket policy which would allow a CF user, called origin access identity (OAI), to access your bucket.它的工作方式是,在您的存储桶中,您将设置一个特殊的存储桶策略,该策略将允许称为源访问身份(OAI) 的 CF 用户访问您的存储桶。

The use of CF and OAI to serve your images from your bucket not only keeps your bucket fully private, but also reduces load times as CF caches the images in its edge locations.使用 CF 和 OAI 从存储桶中提供图像不仅可以使存储桶完全私有,而且还可以减少加载时间,因为 CF 会将图像缓存在其边缘位置。

More details on this are in:有关这方面的更多详细信息,请参见:

You asked "how to secure my S3 bucket?"您问“如何保护我的 S3 存储桶?”

Buckets in Amazon S3 are private by default , so they are automatically 'secure'.默认情况下,Amazon S3 中的存储桶是私有的,因此它们自动“安全”。 However, you want to make the objects (eg images) accessible to users on your website, so you need to open sufficient access to permit this (as you have successfully done.).但是,您想让网站上的用户可以访问对象(例如图像),因此您需要打开足够的访问权限以允许这样做(正如您已成功完成的那样。)。

In fact, the only elements you actually needed were:事实上,您真正需要的唯一元素是:

  • On "Block Public Access", allow Bucket Polices (Done!)在“阻止公共访问”上,允许存储桶策略(完成!)
  • Create a Bucket Policy that grants GetObject to anyone (Done!)创建将GetObject授予任何人的存储桶策略(完成!)

You only need the CORS settings if you are experiencing a particular problem, and there is no need to change the Bucket ACLs from their default values.如果您遇到特定问题,您只需要CORS设置,并且无需更改存储桶 ACL的默认值。

The bucket policy is only allowing people to download objects, and only if they know the name of the object.存储桶策略只允许人们下载对象,并且只有在他们知道 object 的名称的情况下。 They are not permitted to upload objects, delete objects or even list the objects in the bucket.他们不允许上传对象、删除对象甚至列出存储桶中的对象。 That's pretty secure!这很安全!

Your settings are fine for publicly-accessible content that you are happy for anyone to access.您的设置适用于您乐于让任何人访问的可公开访问的内容。 If you have any personal or confidential content (eg documents, or items requiring login) then you would need an alternate way of granting access only to appropriately authorized people.如果您有任何个人或机密内容(例如文件或需要登录的项目),那么您将需要另一种方式来仅向适当授权的人员授予访问权限。 However, this doesn't seem to be a requirement in your situation.但是,这似乎不是您的情况的要求。

Bottom line: You are correctly configured for granting public read-only access to anyone, without providing any additional access.底线:您已正确配置为向任何人授予公共只读访问权限,而无需提供任何其他访问权限。 Looks good!看起来不错!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM