I have an AWS account with read/write permissions as shown below:
I'd like to make it so that an IAM user can download files from an S3 bucket but I'm getting access denied when executing aws s3 sync s3://<bucket_name> .
I have tried various things, but not to avail. Some steps that I did:
aws configure
in my CLI and entered the generated access key id and secret access key for the above userMy bucket has a folder name AffectivaLogs in which files were being added anonymously by various users, and it seems like though the bucket is public, the folder inside it is not and I am not even able to make it public, and it leads to following error.
Following are the public access settings:
Update: I updated the bucket policy as follows, but it doesn't work.
答案 0 :(得分:0)
为了测试这种情况,我做了以下事情:
s3:*
对存储桶的内容的访问权限然后我跑aws s3 sync
并得到Access Denied
。
然后,我修改了策略以允许访问存储桶本身:
{
"Id": "Policy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "statement",
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::my-bucket/*",
"arn:aws:s3:::my-bucket"
],
"Principal": {
"AWS": [
"arn:aws:iam::123456789012:user/stack-user"
]
}
}
]
}
这行得通。
底线::除了存储桶的内容之外,还添加访问存储桶的权限。 (我怀疑这是因为aws s3 sync
除了访问对象本身之外,还需要列出存储桶内容。)
答案 1 :(得分:0)
您可以使用所需的 principal
配置 S3 策略{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListBucket",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::accountId:user/*
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::bucket"
},
{
"Sid": "GetObjects",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::accountId:user/*
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket/*"
}
]
}
或者您可以创建 IAM 策略并将其附加到角色
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::bucket"
},
{
"Sid": "GetObject",
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::bucket/*"
}
]
}
答案 2 :(得分:0)
如果您使用对存储桶启用的 KMS 加密,您还应该添加允许您使用 KMS 密钥解密数据的策略。