在生成 presgined s3 之前承担一个角色 url

Assume a role before generating presgined s3 url

在我们的django应用中,我们允许用户直接上传文件到S3。

我们使用 generate_presigned_post 来做到这一点。

一切正常,但我们现在在 Macie 中收到可疑访问警报,因为它发现 EC2 凭据正在外部使用。

Macie 的描述是

This alert is created by temporary EC2 instance credentials being used outside of Amazon IP space. EC2 instance profile credentials are expected to most commonly be used on EC2 instances where they have been made available by the EC2 metadata service. This technique is used by open source exploitation frameworks such as Metasploit, and observing their usage from outside of AWS network may indicate their potential leakage. Please consider reaching out to user to confirm whether they were intentially using EC2 credentials outside of AWS. If so, whitelist valid users or consider resetting IAM user credentials.

这是有道理的,因为实例角色会生成预签名的 post url,供外部用户使用。

我是否真的面临外部用户可以获得与我的实例角色相同的访问权限的风险?

如果是这样,是否值得创建一个单独的角色,让 只有 可以访问我特定存储桶中的 s3:PutObject,然后在生成预签名 posturl?这样一来,如果以某种方式遭到破坏,它就不会拥有与实例角色一样多的特权?

基于 Boto3 docs,url 应该 授予对 post 特定对象到特定存储桶的访问权限,但这Macie 警报让我紧张。

谢谢!

除了将文件上传到您的存储桶之外,您不必担心外部用户可以访问任何其他内容。

htt ps://s3.amazonaws.com/bucket/foo.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256& X-Amz-Expires=3600&X-Amz-Credential=AKIAJRZXXXXXXXXus-east-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20171021T190750Z&X-Amz-Signature=8b84ae9b59e9f8a8d7066ecc39e797c8dc29848abcdef61717

AWS 所做的只是获取与您的 access_key (AKIAJRZXXXXXXXX) 关联的 secret_key,计算基于对象url、过期时间等的签名,并检查是否与url中的签名匹配。只有您和 AWS 知道 secret_key,没有其他人知道。如果签名匹配,用户可以上传文件,否则访问将被拒绝,因为 URL 被篡改或已过期。