简体   繁体   English

为什么我无法使用具有管理员访问权限和正确策略集的 AWS Amplify storage.get 访问我的 s3 私有对象。 收到 403 错误

[英]Why can't I access my s3 private objects using AWS Amplify storage.get with Admin access and proper policy set. Getting 403 error

so the default "I looked all over...etc", but no luck.所以默认的“我看遍了……等等”,但没有运气。

My problem is I can't seem to download or access my s3 objects through my client.我的问题是我似乎无法通过我的客户端下载或访问我的 s3 对象。 I can't access it as the user who uploaded the object nor as a test user who has access to the group with a policy specifically set to access that bucket.我无法以上传 object 的用户身份访问它,也无法以有权访问具有专门设置为访问该存储桶的策略的组的测试用户身份访问它。 Uploading it is fine.上传就好了。

I tried downloading the file in the console and that works fine, but I get a 403 error when trying the url.我尝试在控制台中下载文件并且工作正常,但在尝试 url 时出现 403 错误。 I know they say that the URL request needs to be pre-signed but according to Amplify documentation, it should already be pre-signed.我知道他们说 URL 请求需要预先签名,但根据 Amplify 文档,它应该已经预先签名。 I don't know if it matters or not but I created the s3 bucket manually but grant access through the Amplify config.我不知道这是否重要,但我手动创建了 s3 存储桶,但通过 Amplify 配置授予访问权限。

My use case: I have a user authenticate with AWS Cognito, which allows them to upload a file to an s3 bucket.我的用例:我有一个用户使用 AWS Cognito 进行身份验证,这允许他们将文件上传到 s3 存储桶。 I then want to allow that user and users assigned to an AdminPortalUserAccess group to be able to access the objects.然后,我希望允许该用户和分配给 AdminPortalUserAccess 组的用户能够访问这些对象。 The goal is for our employees to review the files a user uploads and provide notes/feedback on the report back to the user through an interface.我们的目标是让我们的员工查看用户上传的文件,并通过界面向用户提供有关报告的注释/反馈。

Here is my set up and use:这是我的设置和使用:

Amplify Configuration:放大配置:

Amplify.configure({
  Auth: {
    identityPoolId: 'us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    region: 'us-east-2',
    userPoolId: 'us-east-2_xxxxxxxxx',
    userPoolWebClientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
  },
  Storage: {
    AWSS3: {
      bucket: 's3-credit-report-uploads-dev',
      region: 'us-east-2',
      identityPoolId: 'us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    }
  }
});

Here is my AdminPortalUserAccess group policy:这是我的 AdminPortalUserAccess 组策略:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::s3-credit-report-uploads-dev"
    },
    {
      "Sid": "VisualEditor1",
      "Effect": "Allow",
      "Action": "s3:ListAllMyBuckets",
      "Resource": "*"
    },
    {
      "Sid": "VisualEditor2",
      "Effect": "Allow",
      "Action": "s3:*Object",
      "Resource": "arn:aws:s3:::s3-credit-report-uploads-dev/*"
    }
  ]
}

Client side:客户端:

  async getSummaryPdf(report: any) {
    // const user = await Auth.currentCredentials(); // <-- just to confirm I am logged in
    // console.log('user: ', user); // <-- just to confirm I am logged in
    
    const data = await Storage.get(report.reportId, {
      level: 'private',
      identityId: report.reportUserId
    })
    console.log('data: ', data); // <-- never reaches here
    return data;
  }

If I change Storage.get to a then/catch, I can see what the pre-signed URL is and my public access key looks correct and is the one assigned to the identityId I use to put and get (attempt to) on the s3 bucket.如果我将 Storage.get 更改为 then/catch,我可以看到预签名的 URL 是什么,并且我的公共访问密钥看起来正确,并且是分配给我用来在 s3 上放置和获取(尝试)的 identityId 的那个桶。

https://s3-credit-report-uploads-dev.s3.us-east-2.amazonaws.com/private/8ef10ec4-efd2-47c3-bed9-f6c878c8ce29/910c335a-46a6-42d1-b4f3-67507cd11322?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAUEICY4AUUI3VO4FS%2F20200620%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20200620T204746Z&X-Amz-Expires=900&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEK3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMiJG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xAI%2BGnWOy4ifjMePcF38OMJ7HwM5N9Y7UcjBM96DKGJ24EGHdfD50c9DI66X6LLuV%2FhmEA93cjrmDWfA8fT%2BKS4JAqANpnyL%2FWmYucwBjpseUS0Nnd4fYD4G5Pu3Z5mBW3Zh7ySdZvhTEnOIpw0kzgC%2BR%2FJE2urE5%2FjDAw7sUyXKsW0IiIHwmelMnN6DXnDapGPow2z5wERahFVnJqRjpzr%2BYfJgx3%2F4LwT05cCUff&X-Amz-Signature=84b15e834dd93f9dc1f7995097a18c9ad6c58235674e4b0fd48dd42767315cf7&X-Amz-SignedHeaders=host&x-amz-user-agent=aws-sdk-js-v3-%40aws-sdk%2Fclient-s3%2F1.0.0-gamma.2%20Mozilla%2F5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_13_6%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F83.0.4103.61%20Safari%2F537.36%20aws-amplify%2F3.2.8%20js&x-id=GetObject

What am I missing?我错过了什么?

EDIT So I was able to figure out the root cause although I don't think this will solve the problem.编辑所以我能够找出根本原因,尽管我认为这不能解决问题。 When I call Storage.put it is creating a new identity in my federated identity pool and using these as credentials.当我调用 Storage.put 时,它会在我的联合身份池中创建一个新身份并将其用作凭据。 One that is unauthenticated and does not have the proper role assigned to access the bucket.未经身份验证且未分配适当角色来访问存储桶的一种。 I found this by calling currentUserCredentials(), which returned a completely different identity ID.我通过调用 currentUserCredentials() 发现了这一点,它返回了一个完全不同的身份 ID。 Now the question is, why is Amplify not using the identity ID associated with my login which links the user pool to the identity ID????现在的问题是,为什么 Amplify 不使用与我的登录关联的身份 ID,它将用户池链接到身份 ID?????

So after looking at the docs and several github bug reports, I determined that the config was incorrect in my.amplify folder.因此,在查看文档和几个 github 错误报告后,我确定 my.amplify 文件夹中的配置不正确。 I recreated the storage through the amplify cli and deployed the resource and it worked.我通过放大 cli 重新创建了存储并部署了资源并且它工作。 So nothing appears wrong with my approach above other than my.amplify files must have been altered when we migrated the repo earlier this week.因此,我的上述方法似乎没有任何问题,除了 my.amplify 文件必须在我们本周早些时候迁移 repo 时被更改。

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

相关问题 aws-amplify S3 存储上传文件,但尽管有明确的公共访问配置,但仍将它们设为“私有” - aws-amplify S3 Storage uploads files but put them as "private" despite of explicit public access configuration 使用放大角度访问任意S3对象 - Access arbitrary S3 object using amplify-angular 为什么我的函数没有返回正确的JSON数据,如何访问它? - Why isn't my function returning the proper JSON data and how can I access it? S3静态网站在使用网址时给出403禁止访问被拒绝错误 - S3 Static website give 403 forbidden access denied error when using urls 将Angular Project部署到S3时为什么会遇到403和502错误? - Why am I encountering a 403 and a 502 error when deploying my Angular Project to S3? 使用AWS Amplify将文件上传到S3时获取上传进度的状态 - Get status of upload progress while uploading files to S3 using AWS Amplify S3访问专用存储桶文件 - S3 access private bucket files 使用promise在storage.get后发送http请求 - Using promise to send http request after storage.get 为什么我不能访问我的angular2类属性 - Why can't I access my angular2 class property 为什么我不能使用 AuthGuard 的异步来获得存储的价值? - Why can't I get the value of storage using async for AuthGuard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM