sst.dev icon indicating copy to clipboard operation
sst.dev copied to clipboard

Serverless Stack Update to IAM

Open jayair opened this issue 9 years ago • 30 comments

Update July 19

The guide and the sample projects have been updated. A few links for reference:


What is going on

We are updating the Serverless backend API to use IAM as an authorizer and React.js app to make signed API requests.

What is going to happen

Over the next few days we'll post the chageset for the proposed update to give people a chance to review it. And then we'll update Serverless-Stack.com and all the code for the demo project. We'll still leave the changeset up and tag the repo in case people still want to look at the older version of the tutorial.

What should I do

If you are currently working through the tutorial there will be a changeset to refer to. And use this comment thread for help if you have any questions.

Why the change

The current version of the tutorial uses the User Pool directly as an authorizer for the backend. While this works, the recommended way to do authorization in AWS is by using the IAM. All AWS API requests must be securely signed with Signature Version 4 using IAM credentials. Serverless Framework added support for IAM as an authorizer relatively recently. To use IAM as an authorizer we need to use our Cognito Identity Pool to grant our users temporary IAM credentials. This setup is also necessary in the case where you would like to add Google or Facebook as a way to authenticate your users.

Is this a big change

It is not a very big change to the code base of our demo project. But the flow is a little different and the two setups (the current one and the IAM one) cannot work together at the same time. Also, IAM as an authorizer is more secure but it can be a lot more confusing to set up and difficult to work through.


As always feel free to contact us via Twitter (@fanjiewang or @jayair) or email if you have any questions.

jayair avatar Jul 12 '17 23:07 jayair

That's great! Will you also include an example with a Social Identity Provider (Google, Facebook,...)?

dbeja avatar Jul 13 '17 17:07 dbeja

@dbeja It's not in this update but we will work on that after we roll this out. We haven't been able to write about the social logins pretty much because we needed to do make this update first.

jayair avatar Jul 13 '17 17:07 jayair

Thanks! This is great.

reverend333 avatar Jul 13 '17 18:07 reverend333

Proposed Chageset (WIP)

https://github.com/AnomalyInnovations/serverless-stack-com/compare/dev

The new changes are being worked on in the above brach. Feel free to take an early peek.

jayair avatar Jul 13 '17 19:07 jayair

Waiting for your update !!! You're doing great work.

larrybek avatar Jul 14 '17 14:07 larrybek

Love this tutorial. Any idea of a specific time frame we can expect these changes to get published?

bharloe avatar Jul 14 '17 18:07 bharloe

@bharloe Yeah they are just about ready to be published. We just wanted to make sure we give folks who are going through the tutorial currently a bit of a heads up.

Ideally, it should be up early next week.

jayair avatar Jul 14 '17 19:07 jayair

Thanks, looking forward to it!

bharloe avatar Jul 14 '17 19:07 bharloe

Thanks for the heads up! For those who have already worked through most of the tutorial and made some customizations for their own specific needs, do these changes imply starting from scratch on the API side of things or is it something that can be migrated to with relative ease?

zamirkhan avatar Jul 14 '17 20:07 zamirkhan

@zamirkhan Yeah you should be able to migrate. It's just a few changes to different parts of the setup.

jayair avatar Jul 14 '17 20:07 jayair

i would like to start the tutorial - if it is ready to publish, why not publish it now and make the old tutorial available via subfolder / subdomain...

muescha avatar Jul 16 '17 18:07 muescha

@muescha It's almost ready. Just need to wrap up the code samples for all the chapters. I'm aiming for Wednesday.

jayair avatar Jul 16 '17 18:07 jayair

This is great. I have struggling through the net to find proper way to integrate with apigClient sdk to my react app. Hopefully you will be able to release this soon. Thank you for the great work :)

CharithW avatar Jul 18 '17 06:07 CharithW

Serverless Stack has been updated to use IAM as an authorizer. A few links for reference:

jayair avatar Jul 19 '17 20:07 jayair

Will this guide include how to write tests for the system in the future? (e.g. with mocha or jasmine)

huatzhi avatar Jul 26 '17 07:07 huatzhi

@jayair wanted to ask you if you could help me with an issue I tried to upload S3 bucket nested folder with IAM example that you have provided but Im getting Network Forbidden. Do you have some ideas why it can be. I tried without nesting folder its working properly.

larrybek avatar Jul 26 '17 07:07 larrybek

@larrybek The ARN we are using for S3 arn:aws:s3:::YOUR_S3_UPLOADS_BUCKET_NAME/${cognito-identity.amazonaws.com:sub}* is looking for files inside a given bucket pre-fixed the identity user sub (or user id for our case).

What does the path of your S3 bucket (with the nested folders) look like?

jayair avatar Jul 26 '17 17:07 jayair

@huatzhi Yeah we are planning to. We do have a repo that we are using with tests running using Jest. If folks are interested then we can share that.

jayair avatar Jul 26 '17 17:07 jayair

@jayair I changed the identity pool policy to access nested folders and it worked. Thanks.

larrybek avatar Jul 26 '17 17:07 larrybek

@jayair the cognito is using customized authentication ? Also are you using Secure Remote Password (SRP) protocol. or planning to ? Thanks for doing this 👍

rajeget avatar Jul 28 '17 20:07 rajeget