【问题标题】:Grant access to an S3 bucket for a specific user only, no public access仅为特定用户授予对 S3 存储桶的访问权限,不授予公共访问权限
【发布时间】:2019-11-28 22:29:40
【问题描述】:

我正在尝试配置一个 S3 存储桶,使其仅可供特定用户访问,而不是公众访问。

我创建了一个名为 s3-injury-log 的用户和以下存储桶策略

{
    "Id": "Policy1542998309644",
    "Version": "2012-10-17",
    "Statement": [{
        "Sid": "Stmt1542998308012",
        "Action": "s3:*",
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::injury-log",
        "Principal": {
            "AWS": ["arn:aws:iam::058842494618:user/s3-injury-log"]
        }
    }]
}

我的“阻止所有公共访问”选项卡如下

Block all public access - Off
Block public access to buckets and objects granted through new access control lists (ACLs) - On
Block public access to buckets and objects granted through any access control lists (ACLs) - On
Block public access to buckets and objects granted through new public bucket policies - Off
Block public and cross-account access to buckets and objects through any public bucket policies - Off

但是当尝试将对象放入存储桶时(使用 aws java 库),我收到以下错误消息

Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: CC71A7EFAFC9BBDB; S3 Extended Request ID: klrwopIIJK3PsJzEw

知道我做错了什么吗?

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-iam


    【解决方案1】:

    您的政策似乎不正确,它只允许存储桶级别的操作。因此,PutObject 操作被拒绝,这是对象级别的。

    只需更新您的政策以允许对象级操作:

    {
        "Id": "Policy1542998309644",
        "Version": "2012-10-17",
        "Statement": [{
            "Sid": "Stmt1542998308012",
            "Action": "s3:*",
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::injury-log",
                "arn:aws:s3:::injury-log/*"
            ]
            "Principal": {
                "AWS": ["arn:aws:iam::058842494618:user/s3-injury-log"]
            }
        }]
    }
    

    【讨论】:

    • 这个策略应该有效。只需确保您使用正确的凭据,例如尝试使用 AWS CLI 上传文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    相关资源
    最近更新 更多