How to Integrate AWS Cognito with OpenShift 4
Philippe Bürgisser
Posted on March 26, 2021
In this post, we are going to integrate the Cognito authentication service from AWS with Red Hat OpenShift 4.
OpenShift 4 comes with a wide range of authentication providers to authenticate users, they can be very basic (HTPasswd), traditional (LDAP), integrated (GitHub) or based on OpenID Connect. We're going to focus on the OpenID Connect identity provider.
Configure AWS Cognito
Creating of the service
- Open your AWS Console and go to the Cognito service
- Create a user pool and choose the Step trough settings option
- In the Attributes section, ensure you configure the following:
- How do you want your end users to sign in? Username (you can also allow users to use their e-mail address)
- Which standard attributes do you want to require?: email, profile, preferred username
- In the App client section, click on Add an app client, enter an app name (e.g.: OCP) and ensure you select Enable username password based authentication (
ALLOW_USER_PASSWORD_AUTH
), keep the rest as it is and click on Create app client - Once the pool is created, go to App integration > App client settings and configure the following:
- Enabled Identity Providers: Select all
- Cognito User Pool: Checked
- Callback URL(s):
https://oauth-openshift.apps.demo.example.com/oauth2callback/Cognito
(Match to your domain) - Allowed OAuth Flows: Authorization code grant
- Allowed OAuth Scopes: email,openid,aws.cognito.signin.user.admin,profile
- Confirm configuration by clicking on Create pool in the Review section
Configuration of the service
Now that the user pool has been created and configured to accept authentication requests from OpenShift, we'll have to gather some information:
- Go to freshly created pool and go to the General settings section and copy the value from Pool Id
- On the App clients section, you should find the the app client created previously, click on Show Details to expend and gather the App client id and the App client secret
- Create some users in your pool
Configure OpenShift 4
Now that Cognito is ready, let's configure OpenShift to use the values gathered previously.
- Go to Administration > Cluster Settings
- Go to Global Configuration and search for OAuth
- In the dropdown located in the Identity providers part at the bottom, choose OpenID Connect and enter the following information
- Name: Cognito
- Client ID: {Gathered client ID from previous step}
- Client Secret: {Gathered client secret}
- Issuer URL:
https://cognito-idp.{aws_region}.amazonaws.com/{ pool ID eg: eu-west-1_sLzMKS}
- Leave the other parameters and click Add
-
Leave a few minutes to the Authentication Operator to reload and try to logout
oc get clusteroperator authentication
Once the authentication operator has restarted, logout from OpenShift. On the login page, you should now see a button named Cognito.
When clicking on the Cognito button, you'll be redirected to the Cognito login page.
Use the account you previously created in Cognito and voilà!
Conclusion
This gives you an overview on how to get Cognito working with your OpenShift. It still requires to manage the RBAC and the groups for the users so they have correct permissions on the cluster. Also note that all theses steps can be automated.
Posted on March 26, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.