我们希望在S3上存储一些数据,并且仅允许EC2实例或具有特定IAM角色的特定用户访问它们。不幸的是,我们在执行此操作时遇到了一些麻烦。
我们像这样在水桶上设定政策
{
"Version": "2012-10-17",
"Id": "SamplePolicy",
"Statement": [
{
"Sid": "Stmt1331136294179",
"Effect": "Deny",
"NotPrincipal": {
"AWS": [
"arn:aws:iam::our-account-number:user/the-user",
"arn:aws:iam::our-account-number:role/the-role"
]
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::the-bucket/*"
},
{
"Sid": "Stmt1331136364169",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::our-account-number:user/the-user",
"arn:aws:iam::our-account-number:role/the-role"
]
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::the-bucket/*"
}
]}
当我们使用用户 key 访问存储桶(使用boto)时,它可以从本地计算机或任何EC2实例正常运行。
但是,当我们从Boto访问存储桶时,会得到
ClientError: An error occurred (AccessDenied) when calling the GetObject operation: Access Denied
我已确认实例具有正确的IAM角色
curl http://169.254.169.254/latest/meta-data/iam/info/
{
"Code" : "Success",
"LastUpdated" : "2015-10-22T09:09:31Z",
"InstanceProfileArn" : "our-account-number:instance-profile/the-role",
"InstanceProfileId" : "instance-rpofile-id"
}
我还尝试过从存储桶中删除该策略,的确使它可以再次访问。
有什么想法如何处理吗?
我在此处共享的示例是我一直在进行调试的简化版本。在生产中,我们希望强制使用KMS对对象进行加密,并且还对 key 具有访问策略。我们非常喜欢该解决方案,并且如果可以的话,宁愿保留它。
谢谢
最佳答案
我已经犯过很多次这样的错误,涉及到您的ARN
对于某些权限,您需要在存储桶本身上使用它(否/*)...,而在您的内容上则需要一些权限。
我会尝试使用您目前拥有的东西,只包括两者,所以类似...
"Resource": ["arn:aws:s3:::the-bucket/*", "arn:aws:s3:::the-bucket"]
关于amazon-web-services - 如何限制特定IAM角色对S3存储桶的访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33278314/