我将以下策略附加到 IAM 用户:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutAnalyticsConfiguration",
"s3:GetObjectVersionTagging",
"s3:CreateBucket",
"s3:ReplicateObject",
"s3:GetObjectAcl",
"s3:DeleteBucketWebsite",
"s3:PutLifecycleConfiguration",
"s3:GetObjectVersionAcl",
"s3:PutBucketAcl",
"s3:PutObjectTagging",
"s3:DeleteObject",
"s3:DeleteObjectTagging",
"s3:GetBucketWebsite",
"s3:PutReplicationConfiguration",
"s3:DeleteObjectVersionTagging",
"s3:GetBucketNotification",
"s3:PutBucketCORS",
"s3:DeleteBucketPolicy",
"s3:GetReplicationConfiguration",
"s3:ListMultipartUploadParts",
"s3:PutObject",
"s3:GetObject",
"s3:PutBucketNotification",
"s3:PutBucketLogging",
"s3:PutObjectVersionAcl",
"s3:GetAnalyticsConfiguration",
"s3:GetObjectVersionForReplication",
"s3:GetLifecycleConfiguration",
"s3:GetInventoryConfiguration",
"s3:GetBucketTagging",
"s3:PutAccelerateConfiguration",
"s3:DeleteObjectVersion",
"s3:GetBucketLogging",
"s3:ListBucketVersions",
"s3:ReplicateTags",
"s3:RestoreObject",
"s3:ListBucket",
"s3:GetAccelerateConfiguration",
"s3:GetBucketPolicy",
"s3:PutEncryptionConfiguration",
"s3:GetEncryptionConfiguration",
"s3:GetObjectVersionTorrent",
"s3:AbortMultipartUpload",
"s3:PutBucketTagging",
"s3:GetBucketRequestPayment",
"s3:GetObjectTagging",
"s3:GetMetricsConfiguration",
"s3:DeleteBucket",
"s3:PutBucketVersioning",
"s3:PutObjectAcl",
"s3:ListBucketMultipartUploads",
"s3:PutMetricsConfiguration",
"s3:PutObjectVersionTagging",
"s3:GetBucketVersioning",
"s3:GetBucketAcl",
"s3:PutInventoryConfiguration",
"s3:GetObjectTorrent",
"s3:ObjectOwnerOverrideToBucketOwner",
"s3:PutBucketWebsite",
"s3:PutBucketRequestPayment",
"s3:GetBucketCORS",
"s3:PutBucketPolicy",
"s3:GetBucketLocation",
"s3:ReplicateDelete",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::xyz123-mycloud-dump",
"arn:aws:s3:::xyz123-mycloud-dump/SAMPLE/*"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:HeadBucket"
],
"Resource": "*"
}
]
}
现在有了 IAM 用户的访问凭证,附加了上述策略,我正在尝试运行以下命令:
s3api put-bucket-policy --bucket xyz123-mycloud-dump --policy file://policy.json
文件 policy.json 的内容在哪里:
{
"Statement": [
{
"Effect": "Allow",
"Principal": "arn:aws:iam::<the_account_number_to_which_the_user_belongs>:user/<the_IAM_user_name>",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::xyz123-mycloud-dump/SAMPLE/*", "arn:aws:s3:::xyz123-mycloud-dump"]
}
]
}
然后我得到一个
<块引用>调用 PutBucketPolicy 操作时发生错误 (AccessDenied):拒绝访问
现在我想知道为什么?
用户的政策声明允许对资源进行 PutBucketPolicy
:
xyz123-mycloud-dump,
xyz123-mycloud-dump/SAMPLE/
这就是我试图对上述政策做的事情。那为什么访问被拒绝了?
答案 0 :(得分:0)
如果您在发布时使用了政策policy.json
我试过它给了我错误:
{
"Version":"2012-10-17",
"Id": "randome",
"Statement":[
{
"Effect":"Allow",
"Principal": "arn:aws:iam::1234567890:user/username",
"Action": "s3:*",
"Resource":[
"arn:aws:s3:::mybucket",
"arn:aws:s3:::mybucket/random/*"
]
}
]
}
$aws s3api put-bucket-policy --bucket mybucket --policy file://x.json
An error occurred (MalformedPolicy) when calling the PutBucketPolicy operation: Invalid policy syntax.
当我按照文档建议使用正确的策略时;
{
"Version":"2012-10-17",
"Id": "randome",
"Statement":[
{
"Effect":"Allow",
"Principal": {
"AWS": "arn:aws:iam::1234567890:user/username"
},
"Action": "s3:*",
"Resource":[
"arn:aws:s3:::mybucket",
"arn:aws:s3:::mybucket/random/*"
]
}
]
}
有效
$ aws s3api put-bucket-policy --bucket mybucket --policy file://x.json
$ echo $?
0
答案 1 :(得分:0)
来自here:
<块引用>要解决拒绝访问错误,请检查以下内容:
检查您是否有您不知道的活动组织级别的 SCP,或者是否启用了阻止公共访问。