Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amplify storage returns 403 #6777

Closed
ShehryarKh opened this issue Sep 11, 2020 · 10 comments
Closed

amplify storage returns 403 #6777

ShehryarKh opened this issue Sep 11, 2020 · 10 comments
Assignees
Labels
Storage Related to Storage components/category UI Related to UI Components

Comments

@ShehryarKh
Copy link

ShehryarKh commented Sep 11, 2020

Describe the bug
Retrieving images using amplify-s3-image returns 403 forbidden.

I have no issue adding to s3 bucket via amplify-s3-image-picker retrieving throws a 403. I've tried adding files to public folder directly and trying to retrieve, returns 403 .

To Reproduce
Steps to reproduce the behavior:

  1. setup auth amplify add auth
  2. setup api amplify add api
  3. setup storage amplify add storage
    -> auth users can create
    -> unauth/guest users can read.

Expected behavior
display the image on app

Code Snippet

                <div class="my-8">
                  <amplify-s3-image-picker
                    button-text="yes"
                    header-title="Campaign Photo"
                    track="true"
                    :path="imgpath"
                  ></amplify-s3-image-picker>
                </div>
                <div>
                  <amplify-s3-image level="public" track="true" img-key="ball.png" />  //image uploaded directly to /public
                </div>

What is Configured?
If applicable, please provide what is configured for Amplify CLI:

  • Which steps did you follow via Amplify CLI when configuring your resources.
  • Which resources do you have configured?
    • If applicable, please provide your aws-exports file:
    const awsmobile = {
        "aws_project_region": "us-east-1",
        "aws_cognito_identity_pool_id": "us-east-1:xxx-xxxx-xxxx-xxxx-xxxxxxxx",
        "aws_cognito_region": "us-east-1",
        "aws_user_pools_id": "us-east-1_xxx",
        "aws_user_pools_web_client_id": "xxxx",
        "oauth": {}
       "aws_appsync_graphqlEndpoint": "xx",
     "aws_appsync_region": "us-east-1",
     "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
     "aws_user_files_s3_bucket": "xx",
     "aws_user_files_s3_bucket_region": "us-east-1"
    };
    
@ShehryarKh ShehryarKh added the to-be-reproduced Used in order for Amplify to reproduce said issue label Sep 11, 2020
@harrysolovay
Copy link
Contributor

@ShehryarKh can you please provide the complete error message. Is there a user currently logged in?

Please try the following as well:

Retrieve the logged-in user's identityId:

// inside an async-friendly closure...
try {
  const { identityId } = await Auth.currentCredentials();
  // set the identityId in state
} catch(e) {}
// ... 

Then, in your component, specify the identity-id attributes:

<div class="my-8">
  <amplify-s3-image-picker
    button-text="yes"
    header-title="Campaign Photo"
    track="true"
    :path="imgpath"
+   identity-id={identityId}
  ></amplify-s3-image-picker>
</div>
<div>
- <amplify-s3-image level="public" track="true" img-key="ball.png" />
+ <amplify-s3-image
+   level="public"
+   track="true"
+   img-key="ball.png"
+   identity-id={identityId}
+ />
</div>

@ShehryarKh
Copy link
Author

ShehryarKh commented Sep 11, 2020

@harrysolovay I followed your advice and I am still getting 403.

Yes, there is an authenticated user logged in. Also, I will need the ability to show non authenticated users photos from storage.

Full error below:

Request URL: https://website184148-dev.s3.amazonaws.com/public/ball.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIASJJ4F3OVU3FDXJRU%2F20200911%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200911T181828Z&X-Amz-Expires=900&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEHMaCXVzLWVhc3QtMSJHMEUCIQCDzab53EfyrokH%2FVaX25i56H%2B6cWSHj%2FQM0O0fwV5WtAIgb6TjlX2%2BibWi%2F0%2BM2GsvwcoMeFqtL4I685RDDCgv%2Fo4qxAQIexABGgwxNTc0MjkzOTAyNTEiDMbP1J1v0R1Q9R4YLSqhBLghYOZ0o2XdYDA0C8LYrgzcyCQX0es90HuDbsN6NqEYK5qFq6kD9Dl%2FqR253OJIB%2BGeotoLK2vCzR6ySmh3IzhWcvBPGvBXKfPCC728h8cb2cMEz8EuC44tnqf8ikARKelRXJwRikBZ%2B41UTQzYZhzAgoXv60koJA0QRrOaV2EX4K7TVsDAeRhdaX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js-v3-%40aws-sdk%2Fclient-s3%2F1.0.0-gamma.4%20Mozilla%2F5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_15_4%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F84.0.4147.135%20Safari%2F537.36%20aws-amplify%2F3.5.0%20js&x-id=GetObject

Thanks for the continuous help.

@ashika01
Copy link
Contributor

@ShehryarKh So when you try to retrieve image as both auth and unauth user you get 403?

@ShehryarKh
Copy link
Author

@ashika01 Yes. I am not sure why. I can put to the s3 bucket fine.

<amplify-s3-image-picker
                    button-text="yes"
                    header-title="Campaign Photo"
                    track="true"
                    :path="imgpath"
                    :identity-id="identityId"
                  ></amplify-s3-image-picker>

but 403 on

<amplify-s3-image
                    level="public"
                    track="true"
                    img-key="ball.png"
                    :identity-id="identityId"
                  />

@ashika01
Copy link
Contributor

Couple of thing:

  1. I see you set your permission create only for auth and read only for un-auth. Can you confirm if thats the case?
  2. s3-image-picker actually takes does both put and get. So can you check if that works without any error remove any s3-image code to test this?
  3. Do you actually see the file in the s3 bucket? Looking at your code, s3-image should automatically put the code in public folder, is that happening.

Sorry for the prior comment about identityId you shouldn't need that if you are using just public.

@ashika01
Copy link
Contributor

Also, I notice you save in path imgpath but when you trying to retrieve you are not using it. So you need to call with something like this,

<amplify-s3-image
                    level="public"
                    track="true"
                    img-key="imgpath/ball.png"
                  />

@ashika01 ashika01 added Storage Related to Storage components/category and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Sep 11, 2020
@ShehryarKh
Copy link
Author

ShehryarKh commented Sep 11, 2020

@ashika01 I am not sure what you mean by s3-image-picker take both get and put How and what does the code look like? I'm sorry for the confusion there, but I added a ball.png manually into the public folder in s3 and tried to retrieve it via
amplify-s3-image
Yes I have seen photos being added to s3 from the <amplify-s3-image-picker> and that works perfectly.

How can I confirm permission for auth on the s3 bucket? if there a command? Or somewhere where amplify stores that?

{
    "bucketName": "x",
    "authPolicyName": "xx",
    "unauthPolicyName": "xx",
    "authRoleName": {
        "Ref": "AuthRoleName"
    },
    "unauthRoleName": {
        "Ref": "UnauthRoleName"
    },
    "selectedGuestPermissions": [
        "s3:GetObject",
        "s3:ListBucket"
    ],
    "selectedAuthenticatedPermissions": [
        "s3:PutObject"
    ],
    "s3PermissionsAuthenticatedPublic": "s3:PutObject",
    "s3PublicPolicy": "xx",
    "s3PermissionsAuthenticatedUploads": "s3:PutObject",
    "s3UploadsPolicy": "Uploads_policy_x",
    "s3PermissionsAuthenticatedProtected": "s3:PutObject",
    "s3ProtectedPolicy": "Protected_policy_x",
    "s3PermissionsAuthenticatedPrivate": "s3:PutObject",
    "s3PrivatePolicy": "Private_policy_x",
    "AuthenticatedAllowList": "DISALLOW",
    "s3ReadPolicy": "read_policy_x",
    "s3PermissionsGuestPublic": "s3:GetObject",
    "s3PermissionsGuestUploads": "DISALLOW",
    "GuestAllowList": "ALLOW",
    "triggerFunction": "NONE"
}

@ashika01
Copy link
Contributor

Right here,

   "selectedGuestPermissions": [
        "s3:GetObject",
        "s3:ListBucket"
    ],
    "selectedAuthenticatedPermissions": [
        "s3:PutObject"
    ],

So in theselectedAuthenticatedPermissions, it says you have only given put permission. Can you try updating the storage to give get permissions there,

try amplify update storage and make sure to select both get and put for auth users. And lets see if that does the job.

@ashika01 ashika01 self-assigned this Sep 11, 2020
@ShehryarKh
Copy link
Author

@ashika01 Thank you. That was the issue. I'm not sure why it got set up that way. I got it to work by upgrading the storage to those permissions.
Closing Issue.

@ErikCH ErikCH added UI Related to UI Components and removed Amplify UI Components labels May 19, 2021
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Storage Related to Storage components/category UI Related to UI Components
Projects
None yet
Development

No branches or pull requests

5 participants