Microsoft ADFS With AWS Cognito - CloudFront¶
Secure a static AWS CloudFront page with AWS Cognito and Microsoft ADFS.
Resources¶
- cloudfront-authorization-at-edge git repo
- AWS Authorization@Edge Blog-post
- Cognito Signout flow
- AWS Serverless Application Repository
- AWS IdP response
- TechNet - ADFS Sign out
Deploy a demo page.¶
- Open the Auth@Edge demo from AWS Serverless Application Repository
- Add a valid e-mail address to the Cognito user pool. This user can be used to test the deployment.
- Check "I acknowledge that this app creates custom IAM roles and resource policies." and click deploy
Login to demo page.¶
- Check your e-mail for the temporary password. sender: no-reply@verificationemail.com
- Navigate to AWS -> CloudFormation -> serverlessrepo-cloudfront-auth-edge
- Navigate to Outputs-tab and scroll down to
WebsiteUrl
. This is the CloudFront URL that is protected with Cognito. - Login with your e-mail address and the password you got in the e-mail.
- You will be logged in to a page with a "Private" heading, some description of what's happening, and information about the page.
- Press the Sign-out button to get to the login screen again.
Configure Cognito for ADFS¶
- Navigate to AWS Cognito and click Manage User Pools
- Click the user pool previously deployed from the application repository. In my case 'serverlessrepo-cloudfront-auth-edge'.
- In the left menu. Click Identity providers located under Federation.
- Click SAML
- Add your ADFS Server metadata URL
https://sts.my-domain.com/FederationMetadata/2007-06/FederationMetadata.xml
- Check the 'Enable IdP sign out flow' to enable ADFS Sign out.
- Click Create Provider
- In the left menu. Click Attribute mapping located under Federation.
- Under SAML tab, select 'My-Domain-ADFS-Server' in the dropdown menu.
- Click Add SAML attribute
- Configure SAML Attribute
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
for User pool attribute Email. - Click Save Changes
- In the left menu. Click App Client Settings located under App integration.
- Deselect Cognito User Pool and select 'My-Domain-ADFS-Server'
- Click Save Changes
Get AWS attributes for ADFS configuration¶
- In the left menu. Click General settings.
- Note the Pool Id and add it after
urn:amazon:cognito:sp:
This will be the Relying Party Identifier in the ADFS server.urn:amazon:cognito:sp:us-east-1_G5zi7fNtT
- In the left menu. Click Domain name located under App integration.
- Note the Amazon Cognito domain. This will be used as Saml Assertion Consumer Endpoint in ADFS.
https://auth-0d591cb0-0fd4-11ec-9360-0eadc6b18409.auth.us-east-1.amazoncognito.com/saml2/idpresponse
The last part is documented here - Now change to CloudFront Service under services or the search bar.
- Copy the CloudFront Domain Name.
d1md7y7z21n5ag.cloudfront.net
or Alternative domain name if you have added one.
Configure Relying party trust in Microsoft ADFS for Cognito Part 1¶
- RDP to your ADFS Server.
- Open 'AD FS Management' Desktop App
- Click 'Add Relying Party Trust...' under Actions Menu
- Select Claims aware -> Start
- Select 'Enter data about the relying party manually' -> Next
- Display Name: AWS-Cognito -> Next
- Configure Certificate. Just press Next here
- Configure URL. Just press Next here
- Relying party trust identifier we got previously from cognito Pool ID + urn.
urn:amazon:cognito:sp:us-east-1_G5zi7fNtT
- Choose Access control policy - Select Permit everyone here or MFA if you have configured MFA.
- Press Next and Close to finish this configuration.
Configure Relying party trust in Microsoft ADFS for Cognito Part 2¶
- RDP to your ADFS Server.
- Open 'AD FS Management' Desktop App
- Navigate to AD FS -> Relying Party Trusts.
- Right-click AWS-Cognito -> Edit Claim Issuance Policy...
- Click Add Rule
- Claim rule template: Send LDAP Attribute as Claims
- Claim Rule name: Email-rule
- Attribute store: Active Directory
- Mapping of LDAP attribute 1: E-Mail-Addresses -> E-Mail Address
- Mapping of LDAP attribute 2: E-Mail-Addresses -> Name ID
- Finish
- Press OK to close this window.
- Right-click
AWS-Cognito
relying party and select properties. - Select Endpoints Tab.
- Click
Add SAML...
- Endpoint type: SAML Assertion Consumer
- Binding: POST
- Trusted URL:
https://auth-0d591cb0-0fd4-11ec-9360-0eadc6b18409.auth.us-east-1.amazoncognito.com/saml2/idpresponse
- Note: This is the Cognito Domain followed by saml2/idpresponse.
- Click
OK
- Click
Add SAML...
- Endpoint type: SAML Logout
- Binding: Redirect
- Trusted URL:
https://sts.my-domain.com/adfs/ls/?wa=wsignout1.0
TechNet - LINK - Response URL:
https://d1md7y7z21n5ag.cloudfront.net
This is the protected website url - Click
OK
Test configuration¶
- Open your AWS CloudFront URL in a browser.
https://d1md7y7z21n5ag.cloudfront.net
- Login will now work with ADFS.
- Logout will not work correctly. Following error message will be displayed
Error details: MSIS7054: The SAML logout did not complete properly.
Fix ADFS Sign Out¶
- To fix ADFS sign out. The Cognito SAML Certificate is required.
- Get the certificate with CLI
aws cognito-idp get-signing-certificate --user-pool us-east-1_G5zi7fNtT > cognito.crt
- Alternatively, the certificate is also visible in Cognito Dashboard. Go to Federation > Identity Providers > SAML > Active SAML Providers and click on show signing certificate. Copy / paste the contents into a file cognito.cer
- Copy the cognito.cer to the ADFS server.
- Open 'AD FS Management' Desktop App
- Right-click
AWS-Cognito
relying party and select properties. - Open the Signature tab.
- Click
Add..
- Select the cognito.cer file
- Click Open and OK.
- Sign in again on the cloud front page. Or sign out.