【问题标题】:Remove specific permissions for the s3 bucket owner删除 s3 存储桶所有者的特定权限
【发布时间】:2021-06-22 12:51:27
【问题描述】:

我创建了一个 s3 存储桶,同时我向存储桶添加了一个策略,表示拒绝对规范用户执行 ListBucket 操作。这里的规范用户就是我。下面是我的代码..

s3_client.create_bucket(Bucket=bucket_name)
bucket_policy = {
    'Version': '2012-10-17',
    'Statement': [{
        'Sid': 'AddPerm',
        'Effect': 'Deny',
        'Principal': 
#I am denying ListBucket access to this canonical user id.
{"CanonicalUser":"1234567777777777777777544444444466666ac73d5bc7cd43619"},
        'Action': ['s3:ListBucket'],
        'Resource': f'arn:aws:s3:::{bucket_name}',
    }]
}
# Convert the policy from JSON dict to string
bucket_policy = json.dumps(bucket_policy)
s3_client.put_bucket_policy(Bucket=bucket_name, Policy=bucket_policy)
s3_client.put_object(Bucket=bucket_name, Key="a/b/c/abc.txt")
#Still i am getting response for this list_objects operation.
response = s3_client.list_objects(Bucket=bucket_name) 
print(response)

如何删除 root 用户的特定 s3 存储桶权限?

谢谢

【问题讨论】:

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


    【解决方案1】:

    基于cmets,问题是拒绝root用户访问同一账户内的资源,也不推荐这样做。

    您只能使用 AWS Organizations 服务控制策略 (SCP) 来限制根用户的权限

    以下描述的方法适用于跨账户访问。

    根据文档,您可以按以下格式寻址 root 用户

    "Principal":{"AWS":"arn:aws:iam::AccountNumber-WithoutHyphens:root"}
    
    "Principal":{"AWS":["arn:aws:iam::AccountNumber1-WithoutHyphens:root","arn:aws:iam::AccountNumber2-WithoutHyphens:root"]}
    

    Grant permissions to an AWS Account

    例如

    {
      "Id": "Policy1616693279544",
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "Stmt161669321",
          "Action": [
            "s3:ListBucket"
          ],
          "Effect": "Deny",
          "Resource": "arn:aws:s3:::mybucketname",
          "Principal": {
            "AWS": [
              "arn:aws:iam::1234567890:root"
            ]
          }
        }
      ]
    }
    

    如果您不想强调正确的策略生成,您可以在此处使用此工具进行交叉验证

    AWS Policy Generator

    Your AWS account identifiers

    【讨论】:

    • 是的,我也在做同样的事情。但是对于账户号码,我使用的是规范用户 ID。
    • @learner CanonicalUser 用户 ID 在后台转换为 aws 帐号。 <When you use a canonical user ID in a policy, Amazon S3 might change the canonical ID to the corresponding AWS account ID. This does not impact the policy because both of these IDs identify the same account.>
    • 是的,你是对的。是的,它自动将规范 id 转换为我的 aws 帐号。所以你想使用帐号而不是规范 id ?
    • @learner 如果您想用于 root 用户,您可以按照上面Principal 部分中的说明进行操作
    • 我尝试在主体部分将规范更改为 root 用户,但我仍然收到响应。即使我从 s3 控制台取消选中所有 acls。但没有运气
    猜你喜欢
    • 2015-06-23
    • 2019-01-23
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2010-10-16
    • 1970-01-01
    相关资源
    最近更新 更多