AWS S3 ACL 策略条件
AWS S3 ACL Policy Condition
我正在尝试为 S3 设置我的角色策略。我想做的是允许用户取出他们名字中包含 "public" 的任何图像。问题是我似乎已经获得了正确的策略(它在策略模拟器中成功)但是当我在我的应用程序中 运行 它似乎无法正常工作。
这是我的政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::*"
],
"Condition": {
"StringLike": {
"s3:prefix": "*public*"
}
}
}
]
}
我将 s3:prefix
设置为 user1/image1-public
。正如我之前提到的,在策略模拟器上,它允许所有 "Get" 和 "List" 命令(就像它应该的那样)。
问题是当我使用 iOS 应用程序中的传输管理器从数据库下载示例图像时,出现以下错误:
2015-10-07 14:22:01.716 SimpleAuth[71584:8584520] Error: Error Domain=com.amazonaws.AWSS3ErrorDomain Code=1 "The operation couldn’t be completed. (com.amazonaws.AWSS3ErrorDomain error 1.)" UserInfo=0x7fcbf2d8c560 {HostId=ke/f5x+DKCnjuzlbH5XBWCQfawbkUIRWWhPcY9LdqjPqP5kUyq0rzIjkqeL+8Bm/fvr/l24Wm94=, Message=Access Denied, Code=AccessDenied, RequestId=180803E4DDD0BB73}
我在 Xcode 项目中的代码是
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];
downloadRequest.bucket = @"test";
downloadRequest.key = @"user1/image1-public";
downloadRequest.downloadingFileURL = downloadingFileURL;
// Download the file.
[[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
withBlock:^id(AWSTask *task)
{
if (task.error){
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;
default:
NSLog(@"Error: %@", task.error);
break;
}
} else {
// Unknown error.
NSLog(@"Error: %@", task.error);
}
}
if (task.result)
{
AWSS3TransferManagerDownloadOutput *downloadOutput = task.result;
//File downloaded successfully.
NSLog(@"Now go to the next screen");
[self performSegueWithIdentifier:@"LoginSuccessSegue" sender:self];
}
return nil;
}];
如有任何帮助,我们将不胜感激。我从来没有得到 "Condition" 来处理 ACL。
"s3:prefix": "*public*"
基本上永远不会匹配任何有意义的东西。
它指定了一个前缀 -- 不是通配符匹配。
要匹配位于 /user-1/image/public/kitten.jpg
的图像对象和同一结构级别的所有其他内容,策略条件需要为 "s3:prefix": "user-1/image/public/"
要使这样的策略起作用,"public" 需要位于路径的最左侧 -- 前缀。
文档不清楚,但可能您可以在资源中使用通配符而不是条件。它简单地说,"You can use wild card."。如果为真,那么可能是这样的:
"Resource": [
"arn:aws:s3:::example-bucket/*/public/*"
],
如果不是,您将再次受限于前缀,我怀疑可能是这种情况。
不过,我本以为政策模拟器会发出类似这样的警告,让您知道对于某些服务,政策模拟器并未全面评估政策的所有方面:
“This action belongs to a service that supports access control mechanisms attached to resources. The simulator does not model these mechanisms, so results may differ in your production environment.”
http://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html
我正在尝试为 S3 设置我的角色策略。我想做的是允许用户取出他们名字中包含 "public" 的任何图像。问题是我似乎已经获得了正确的策略(它在策略模拟器中成功)但是当我在我的应用程序中 运行 它似乎无法正常工作。
这是我的政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::*"
],
"Condition": {
"StringLike": {
"s3:prefix": "*public*"
}
}
}
]
}
我将 s3:prefix
设置为 user1/image1-public
。正如我之前提到的,在策略模拟器上,它允许所有 "Get" 和 "List" 命令(就像它应该的那样)。
问题是当我使用 iOS 应用程序中的传输管理器从数据库下载示例图像时,出现以下错误:
2015-10-07 14:22:01.716 SimpleAuth[71584:8584520] Error: Error Domain=com.amazonaws.AWSS3ErrorDomain Code=1 "The operation couldn’t be completed. (com.amazonaws.AWSS3ErrorDomain error 1.)" UserInfo=0x7fcbf2d8c560 {HostId=ke/f5x+DKCnjuzlbH5XBWCQfawbkUIRWWhPcY9LdqjPqP5kUyq0rzIjkqeL+8Bm/fvr/l24Wm94=, Message=Access Denied, Code=AccessDenied, RequestId=180803E4DDD0BB73}
我在 Xcode 项目中的代码是
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];
downloadRequest.bucket = @"test";
downloadRequest.key = @"user1/image1-public";
downloadRequest.downloadingFileURL = downloadingFileURL;
// Download the file.
[[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
withBlock:^id(AWSTask *task)
{
if (task.error){
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;
default:
NSLog(@"Error: %@", task.error);
break;
}
} else {
// Unknown error.
NSLog(@"Error: %@", task.error);
}
}
if (task.result)
{
AWSS3TransferManagerDownloadOutput *downloadOutput = task.result;
//File downloaded successfully.
NSLog(@"Now go to the next screen");
[self performSegueWithIdentifier:@"LoginSuccessSegue" sender:self];
}
return nil;
}];
如有任何帮助,我们将不胜感激。我从来没有得到 "Condition" 来处理 ACL。
"s3:prefix": "*public*"
基本上永远不会匹配任何有意义的东西。
它指定了一个前缀 -- 不是通配符匹配。
要匹配位于 /user-1/image/public/kitten.jpg
的图像对象和同一结构级别的所有其他内容,策略条件需要为 "s3:prefix": "user-1/image/public/"
要使这样的策略起作用,"public" 需要位于路径的最左侧 -- 前缀。
文档不清楚,但可能您可以在资源中使用通配符而不是条件。它简单地说,"You can use wild card."。如果为真,那么可能是这样的:
"Resource": [
"arn:aws:s3:::example-bucket/*/public/*"
],
如果不是,您将再次受限于前缀,我怀疑可能是这种情况。
不过,我本以为政策模拟器会发出类似这样的警告,让您知道对于某些服务,政策模拟器并未全面评估政策的所有方面:
“This action belongs to a service that supports access control mechanisms attached to resources. The simulator does not model these mechanisms, so results may differ in your production environment.”
http://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html