在我们的 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.
这是有道理的,因为实例角色会生成供外部用户使用的预签名帖子 url。
我是否真的面临外部用户可以获得与我的实例角色相同的访问权限的风险?
如果是这样,是否值得创建一个单独的角色,只有可以访问我特定存储桶中的 s3:PutObject,然后在生成预签名的帖子 url 之前担任该角色?这样一来,如果以某种方式遭到破坏,它就不会拥有与实例角色一样多的特权?
基于Boto3 docs ,该网址应该仅授予将特定对象发布到特定存储桶的访问权限,但这个 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 被篡改或已过期。
