Issue IAM user via OPENID authorization - amazon-web-services

I set up an ALB, that sit's in front of an ECS backend. I use a cognito user pool to authenticate the users via OAuth (with code grant). On my backend I receive all user claims and it just works nice.
However, I think the most secure and easiest way is, when i can associate an IAM user to the cognito user, which is passed with the user claims. Is there a way to do this in combination with ALB authentication?
My architecture:
Client --> ALB --> AWS Cognito --> ECS

Related

How can I add cognito username/password to authenticate ALB?

I deployed AWS application load balancer to route requests to my backend service. And I'd like to add authenticate on it via cognito basic username and password.
I have read this doc https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-authenticate-users.html and it only mentions about OIDC, SAML, LDAP etc. How can I use username/password to authenticate ALB?
The ALB itself provides direct integration with Cognito as an authenticator.
First, you need a Cognito User Pool. Within it, you need to create an App Client. This will then be used by the ALB when it uses OpenID Connect as a relying party in order to authenticate users against Cognito using the Authorization Code Flow.
So, for every route in your listener rules, you can add an "Authenticate using Cognito" step, where you then select your Cognito User Pool and the App Client Id.
After that, every request for this listener rule will first redirect the user to the Cognito login page.
Since Cognito itself can also federate authentication to other Identity Proviers, such as Facebook, Google, etc., this is also an option. But if you only want username/password authentication, then Cognito already gives this as an option for users in your user pool.
Basically, all the steps are explained in your mentioned AWS documentation page.

How to authenticate same user in two different AWS regions?

I have two services, sitting in two separate regions on their own, that have the same authentification solution, with AWS Cognito and each of those instances has federated in their user pool, the same identity provider.
In front of the application, there is an API Gateway, that should grant access to the desired service.
The user could have the following scenario: goes to authenticate in region1, gets his token, and then the API Gateway from region1 will permit his access based on it. Can this token be used to access a service in region2?
Assuming Cognito is configured in region1, if you set the Cognito pool from region1 as authorizer for the API Gateway in region2, that should allow this API Gateway to authenticate users in Cognito. It also works cross-account.
Hopefully the docs help: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html

Different access level for different authentication flows in AWS Cognito

I'm developing an app that users can access through both passwordless authentication and username/password authentication, but I want to limit the user access when they use passwordless sign in and give full access when they sign in using username/password.
A use case would be: A user signing in using passwordless auth flow would have limited access to resources. When user requests for specific resources, or want to modify resources, passwordless session shouldn't allow and the user should sign in with username and password.
Is there a way to do this on Cognito without implementing a whole protocol?
Some project information
Front-end: Angular + AWS Amplify
Back-end: API Gateway + Lambda
User authentication: AWS Cognito (+ passwordless CUSTOM_AUTH flow)

OAUTH2 server for getting AWS Cognito User Pool token?

I am attempting to allow a third party app (Google Home) to access information from a AWS Cognito User Pool.
The flow of the entire process is as follows (assuming I understand it correctly that is):
The user tries to link their devices (which are all managed inside various AWS services) to Google Home.
The user is then redirected to our oauth2 page where they log into their account in the cognito user pool
They succesfully log in and are provided with an oauth token
The Google Home app can then use that token to send requests to our back end, allowing them to control their devices, but not the devices belonging to other users.
I am not exactly sure how to setup the cognito user pool as an oauth2 provider. I can find lots of info going the other way (for instance using Google to sign into our AWS user pool using federated identities) but that doesn't solve our problem.
Any help or direction would be greatly appreciated.
Thanks in advance
Amazon Cognito now supports OAuth 2.0. Login to the Amazon Cognito Console and follow these steps for an existing user pool:
Create a domain in the "App Integration" section.
In the same navigation go to "App Client Settings" and enable the providers you want enabled on the client, in your case Cognito. Also add the allowed callback and logout URIs as well as the allowed OAuth flows and scopes.
Now your authorize endpoint is https://.auth..amazoncognito.com/authorize?client_id=&redirect_uri=&response_type= and same way you can find the token endpoint.
More details...

User authentication in microservice application hosted on Amazon WS

I am building web application based on microservice architecture. At this moment I am considering few ways of user authentication flow. I predict following, example user roles:
admin - is able to create content, upload files etc (admin account can be created only by another admin)
unauthorized user - can view content
authorized user - can comment content
Here is, how I was thinking about authentication flow so far:
authentication service - have access to DB with users credentials and permissions
api gateway - retrieve requests from user, check if user is logged in (ie verifies OAuth2 access token with auth service) and transfer flow to other services based on user request (attaching JWT token with some basic user info)
another service - accept only requests from api gateway, and trusts user data from JWT token (does not need to connect with auth service to get information about user).
After deploying some stuff on AWS infrastructure my way of thinking have changed a little bit. As far as I understand AWS products (Lambda - serverless applications and API gateway), I should implement authentication flow as follows:
authentication service - gets request from user, retrieve data from dynamoDB and provide user cookie with JWT signed by private key
any other service - retrieves request with JWT token, verifies signature using public key, and perform some action.
And now the question comes:
How deos AWS Cognito fits here? Is it something useful for me? As far as I understand, Cognito simplifies flow of authenticating users via 3rd parties (facebook, twitter etc. etc.). Does AWS Cognito serves login page, separated from my application, or it is only background/webservices impelementation?
So far I am thinking about Cognito as a replacement for my authentication service - any of my services, should impelemnt Cognito authentication flow provided by SDK from amazon, and my static website would implement JavaScript SDK for user login/register. Am I right?
First of all AWS Cognito consists of two services.
AWS Cognito UserPools (Which is the Identity Provider) - This is the service where you can create the users and manage their credentials with other policies. It can also provide the login screen where we can customize the logo and look and feel so that it can become a plug and play Login service. Then it is also possible to configure the authentication flow (For example to make the service as an OpenIDConnect authentication provider so that it will return a JWT token once user logs in). It is also possible to connect Social Identities (Facebook, Google & etc.) and SAML.
AWS Cognito Federated Identities (Identity Federation to grant users access AWS Services) - This service is capable of accepting AWS Cognito UserPool Token or direct access from other providers where we can federate the access to AWS resources. For example, AWS Cognito Federated Identities can grant temporal access to a User, Authenticated from another provider (e.g; AWS Cognito UserPools) to upload files to S3.
For more details refer the article The Difference Between AWS Cognito UserPools and Federated Identities?.
So coming back to your questions,
So far I am thinking about Cognito as a replacement for my
authentication service?
you can use AWS Cognito UserPools authentication service to issue JWT tokens and validate the token in AWS Lambda Custom Authorizer at your other service endpoints. This is also the place where you can do Authorization.
My static website would implement JavaScript SDK for user
login/register. Am I right?
Not necessarily. If you use AWS Cognito UserPools Hosted UI, you will get Login, Signup, Password Change, Confirmation pages, by default along with auto redirection for Federated Identities (Based on the configurations) such as Facebook, Google or Corporate Credentials like Office365. Although the customization is limited, you should be able to add your own logo and change the background color of these screens. If you plan to implement this by your self, then you can use AWS SDKs to implement these screens.
For more details on the serverless architecture refer Full Stack Serverless Web Apps with AWS.