简体   繁体   English

如何将Cognito用户池用户减少到S3存储桶中自己的文件夹?

[英]How to reduce a cognito userpool user to their own folder in S3 bucket?

I am writing a basic react native app where users will be able to register themselves to an AWS cognito userpool and log in with that identity to store/retrieve their data from S3. 我正在编写一个基本的react native应用程序,用户可以在其中注册自己到AWS Cognito用户池并使用该身份登录以从S3存储/检索其数据。 I only have one bucket and every user will have their own folder in that bucket. 我只有一个存储桶,每个用户在该存储桶中都有自己的文件夹。 How can I restrict each user to their own folder in that case. 在这种情况下,如何限制每个用户使用自己的文件夹。 Here is the scenario. 这是场景。

I created two users in the user pool. 我在用户池中创建了两个用户。

在此处输入图片说明

I then created a federated identity for my userpool. 然后,我为用户池创建了一个联合身份。 This federated identity has two IAM roles, authorized and unauthorized. 该联合身份具有两个IAM角色:授权和未授权。

在此处输入图片说明

I then added a policy to the auth role of federated identity. 然后,我向联合身份验证的auth角色添加了一个策略。

在此处输入图片说明

Here is my policy: 这是我的政策:

 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "*", "Resource": "arn:aws:s3:::mybucket/${cognito-identity.amazonaws.com:sub}/*" } ] } 

I then tried to retrieve data from S3 using Javascript SDK and I could ListObjects from "album-b207a8df-58e8-49cf-ba1b-0b48b7252291" where "b207a8df-58e8-49cf-ba1b-0b48b7252291" is the sub of "madi" user. 然后,我尝试使用Javascript SDK从S3检索数据,并且可以从“ album-b207a8df-58e8-49cf-ba1b-0b48b7252291”中列出对象,其中“ b207a8df-58e8-49cf-ba1b-0b48b7252291”是“ madi”用户的子对象。 Why was "test2" able to list that object? 为什么“ test2”能够列出该对象?

Can you provide a snippet of the onClick_Cognito_receiptsdumpAuth_Role.*** ?? 您能否提供onClick_Cognito_receiptsdumpAuth_Role的代码段。


My guess (without your logs) 我的猜测(没有您的日志)

  1. is that your policy is probably good, but you might have a policy that grants list access to too much. 是因为您的策略可能不错,但是您可能有一项策略授予列表访问权限过多。

  2. Your AWS class is being inited with your developer credentials (which might have full Admin) 正在使用开发人员凭证(可能具有完整的管理员)来初始化AWS类

  3. Cognito might have an issue and its worth logging a support ticket. Cognito可能有问题,值得记录支持记录。

Next steps I would try is 我要尝试的下一步是

You might have a action:List* or equivalent 您可能有一个action:List*或同等功能

Also best hidden secret (it's not really a secret) is the policy simulator . 策略模拟器也是最好的隐藏秘密(这不是真正的秘密)。 Test your policy against that and it will tell you if at least the policy is good and don't forget that iam policies are concatenated. 针对此测试您的策略,它将告诉您至少该策略是否正确,并且不要忘记iam策略已串联。

Lastly, if you can't figure out how the access is provided to the List Operation, you can enable CloudTrail to dump API logs to S3 and verify that the listobjects is being run by the cognito user you are expecting. 最后,如果您不知道如何提供对列表操作的访问权限,则可以使CloudTrail将API日志转储到S3并验证列表对象是否正在由您期望的认知用户运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为用户池添加对 s3 存储桶的访问权限 - How to add access to s3 bucket for userpool AWS API网关-如何进行S3 Cognito用户池限制的文件夹访问? - AWS API gateway - how to do S3 Cognito userpool-restricted folder access? 如何只允许经过身份验证的用户(使用Cognito)访问他们自己的S3存储桶/密钥? - How do I only allow authenticated user (using cognito) access to their own S3 bucket/key specifically? Cognito用户如何在S3上操作特定文件夹 - How does cognito user operate specific folder on S3 AWS iOS Cognito-如何在Userpool中检查用户? - AWS iOS Cognito - How To Check For a User in a Userpool? 如何将用户添加到AWS Cognito用户池组中? - How to add a user into a AWS Cognito userpool group? 用户通过cognito身份验证后,如何通过用户凭据访问s3存储桶? - How do i pass the user credential to access s3 bucket once user is authenticated by cognito? 无法授予 Cognito 用户对特定 S3 存储桶的访问权限 - Not able to give a Cognito User access on a certain S3 bucket AWS S3允许Cognito用户访问存储桶前缀 - aws s3 allow access to bucket prefix for cognito user 允许外部用户(通过 Cognito)访问 S3 存储桶和控制台 - Allow an external user (through Cognito) to access a S3 bucket and console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM