为什么 boto 使用正确的 IAM 密钥可能会被拒绝访问 S3?

问题描述 投票:0回答:3

我正在尝试使用 boto 访问 S3 上的存储桶。我已获得该存储桶的读取权限,并且当我在 S3 浏览器中浏览该存储桶时,我的密钥可以正常工作。以下代码返回 403 Forbidden Access Denied。

conn = S3Connection('Access_Key_ID', 'Secret_Access_Key')
conn.get_all_buckets()

通过 boto 配置文件使用访问密钥和秘密访问密钥时也会发生这种情况。因为密钥可能来自 IAM,我还需要做其他事情吗?这是否表明设置有错误?我对 IAM 不太了解,我只是得到了密钥。

amazon-s3 boto amazon-iam
3个回答
6
投票

一些需要检查的事情...

  • 如果您使用 boto,请确保使用 conn.get_bucket(bucket_name) 仅访问您有权访问的存储桶。

  • 在您的 IAM(用户)策略中,如果您限制对单个 存储桶,请确保该策略包含足够的权限 存储桶,并且 ARN 名称不包含尾部斜杠+星号(请参阅下面的示例)。

  • 请务必在 S3 中为该存储桶设置“已验证用户”的“上传/删除”权限。

权限示例:

enter image description here

IAM 政策示例:

注意:使用策略生成器时会自动生成SID

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:*"
      ],
      "Sid": "Stmt0000000000001",
      "Resource": [
        "arn:aws:s3:::myBucketName"
      ],
      "Effect": "Allow"
    }
  ]
}

4
投票

我的猜测是,这是因为您为您有权访问的单个存储桶调用

conn.get_all_buckets()
而不是
conn.get_bucket(bucket_name)


-2
投票

from boto.s3.connection import S3Connection
conn = S3Connection('access key', 'secret access key')
allBuckets = conn.get_all_buckets()
for bucket in allBuckets:
   print(str(bucket.name))

© www.soinside.com 2019 - 2024. All rights reserved.