Amazon web services 对于通过Cognito认证的用户,Amazon S3特定文件夹,对于listObjects返回403
我正在尝试在Amazon web services 对于通过Cognito认证的用户,Amazon S3特定文件夹,对于listObjects返回403,amazon-web-services,amazon-s3,amazon-cognito,Amazon Web Services,Amazon S3,Amazon Cognito,我正在尝试在s3中创建一个特定的用户文件夹。所有用户都通过Cognito(谷歌提供商)进行身份验证。 我对Cognito角色有这样的政策 { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "cognito-ident
s3
中创建一个特定的用户文件夹。所有用户都通过Cognito
(谷歌提供商)进行身份验证。
我对Cognito角色有这样的政策
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"cognito-identity:*",
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Resource": "*"
},
{
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::fake-youtube-videos"
],
"Condition": {
"StringLike": {
"s3:prefix": [
"${accounts.google.com:sub}/*"
]
}
}
},
{
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::fake-youtube-videos/${accounts.google.com:sub}/*"
]
}
]
}
还有一桶政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::fake-youtube-videos",
"Condition": {
"StringLike": {
"s3:prefix": "${accounts.google.com:sub}/*"
}
}
},
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::fake-youtube-videos/${accounts.google.com:sub}/*"
}
]
}
当我从前端获得授权时
var id\u token=googleUser.getAuthResponse().id\u token;
var profile=googleUser.getBasicProfile();
AWS.config.apiVersions='2012-10-17'
AWS.config.region='us-east-1';//区域
AWS.config.credentials=新的AWS.CognitoIdentityCredentials({
IdentityPoolId:'us-east-1:c1f4182d-4598-4c83-80ff-896B6FF632F',
登录:{
'accounts.google.com':id\u令牌
}
});
var identityId=AWS.config.credentials.identityId;
var s3=新的AWS.s3();
s3.listObjects({Bucket:'fake youtube videos'},函数(err,url){
log('URL是',URL);
log(“错误”,err);
})
而且每件事都是无效的
我得到了403个对象列表
拒绝访问
。我卡住了。我做错了什么 对于那些遇到同样问题的人:
var identityId=AWS.config.credentials.identityId
与accounts.google.com:sub不同
Assub
是唯一的用户id
你应该使用
var sub=profile.getId()//可以从google
s3.listObjects({Bucket:'fake youtube videos',前缀:sub},函数(err,url){
log('URL是',URL);
log(“错误”,err);
})
在一个问题中,我犯了一个错误,我试图获取bucket根上的对象列表,但当您尝试使用特定前缀进行生成时,您将获得一个列表。
@约翰罗滕斯坦感谢你指出我的问题可能是${accounts.google.com:sub}
的价值造成了问题。如果您通过删除条件和路径临时修改bucket策略,它是否有效?@JohnRotenstein-yeap,它有效。我从所有策略中删除了${accounts.google.com:sub}
。但是,现在,用户开始获取所有对象的列表,这些对象位于伪造的youtube视频存储桶中。但我的目标是仅显示特定文件夹下的对象列表,在本例中,基于GoogleID。太棒了!所以现在我们知道问题在于这个特殊的价值。如果将它们放回原处,请尝试找出它的值,然后确保API调用使用这些值。例如,在列出bucket时,请确保前缀设置正确。@JohnRotenstein我试图添加到bucket策略json”条件:{“StringLike”:{“s3:Prefix”:[“${accounts.google.com:sub}/*”]}
并从javascript调用javascript s3.listObjects({Bucket:'fake youtube videos',前缀:AWS.config.credentials.identityId},函数(err,url){console.log('url为',url);console.log('The error',err);})
也可以调用``s3.listObjects({Bucket:'fake youtube shootsta videos',前缀:'${ProfileId}',函数(err,url){console.log('url是',url);console.log('The error',err);})“``whereProfileId
我从谷歌上取的,这是一个相等的子项。你确定它是Key
?它可能应该是前缀
。