Amazon Managed Workflows for Apache Airflow (Amazon MWAA) provides a fully managed solution for orchestrating and automating complex workflows in the cloud. Amazon MWAA offers two network access modes for accessing the Apache Airflow web UI in your environments: public and private. Customers often deploy Amazon MWAA in private mode and want to use existing login authentication mechanisms and single sign-on (SSO) features to have seamless integration with the corporate Active Directory (AD). Also, the end-users don’t need to log in to the AWS Management Console to access the Airflow UI.
In this post, we illustrate how to configure an Amazon MWAA environment deployed in private network access mode with customer managed VPC endpoints and authenticate users using SAML federated identity using Microsoft Entra ID and Application Load Balancer (ALB). Users can seamlessly log in to the Airflow UI with their corporate credentials and access the DAGs. This solution can be modified for Amazon MWAA public network access mode as well.
Solution overview The architectural components involved in authenticating the Amazon MWAA environment using SAML SSO are depicted in the following diagram. The infrastructure components include two public subnets and three private subnets. The public subnets are required for the internet-facing ALB. Two private subnets are used to set up the Amazon MWAA environment, and the third private subnet is used to host the AWS Lambda authorizer function. This subnet will have a NAT gateway attached to it, because the function needs to verify the signer to confirm the JWT header has the expected LoadBalancer ARN.
The workflow consists of the following steps:
The following are the high-level steps to deploy the solution:
Prerequisites Before you get started, make sure you have the following prerequisites:
Create an S3 bucket In this step, we create an S3 bucket to store your Airflow DAGs, custom plugins in a plugins.zip file, and Python dependencies in a requirements.txt file. This bucket is used by the Amazon MWAA environment to fetch DAGs and dependency files.
Import certificates into ACM ACM is integrated with Elastic Load Balancing (ALB). In this step, you can request a public certificate using ACM or import a certificate into ACM. To import organization certificates linked to a custom DNS into ACM, you must provide the certificate and its private key. To import a certificate signed by a non-AWS Certificate Authority (CA), you must also include the private and public keys of the certificate.
After the import is successful, the status of the imported certificate will show as Issued.
Create the Azure AD service, users, groups, and enterprise application For the SSO integration with Azure, an enterprise application is required, which acts as the IdP for the SAML flow. We add relevant users and groups to the application and configure the SP (Amazon Cognito) details.
Airflow comes with five default roles: Public, Admin, Op, User, Viewer. In this post, we focus on three: Admin , User and Viewer. We create three roles and three corresponding users and assign memberships appropriately.
Next, you create users. 11. On the Overview page, on the Add menu, choose User and Create new user. 12. Enter a name for your user (for example, mwaa-user), display name, and password. 13. Choose Review + create. 14. Repeat these steps to create a user called mwaa-admin. 15. In your airflow-users group details page, choose Members in the navigation pane. 16. Choose Add members. 17. Search for and select the users you created and choose Select. 18. Repeat these steps to add the users to each group. 19. Navigate to your application and choose Assign users and groups. 20. Choose Add user/group. 21. Search for and select the groups you created, then choose Select.
Deploy the Amazon MWAA environment stack For this solution, we provide two CloudFormation templates that set up the services illustrated in the architecture. Deploying the CloudFormation stacks in your account incurs AWS usage charges.
The first CloudFormation stack creates the following resources: * A VPC with two public subnets and three private subnets and relevant route tables, NAT gateway, internet gateway, and security group * VPC endpoints required for the Amazon MWAA environment * An Amazon Cognito user pool and user pool domain * Application Load Balancer
Deploy the stack by completing the following steps: 1. Choose Launch Stack to launch the CloudFormation stack. 2. For Stack name, enter a name (for example, sso-blog-mwaa-infra-stack). 3. Enter the following parameters:
1. For **MWAAEnvironmentName**, enter the environment name.
2. For **MwaaS3Bucket**, enter the S3 artifacts bucket you created.
3. For **VpcCIDR**, enter the specify IP range (CIDR notation) for this VPC.
4. For **PrivateSubnet1CIDR**, enter the IP range (CIDR notation) for the private subnet in the first Availability Zone.
5. For **PrivateSubnet2CIDR**, enter the IP range (CIDR notation) for the private subnet in the second Availability Zone.
6. For **PrivateSubnet3CIDR**, enter the IP range (CIDR notation) for the private subnet in the third Availability Zone.
7. For **PublicSubnet1CIDR**, enter the IP range (CIDR notation) for the public subnet in the first Availability Zone.
8. For **PublicSubnet2CIDR**, enter the IP range (CIDR notation) for the public subnet in the second Availability Zone.
After the stack is deployed successfully, you can view the resources on the stack’s Outputs tab on the AWS CloudFormation console. Note the ALB URL, Amazon Cognito user pool ID, and domain.
Integrate the Amazon MWAA application with the Azure enterprise application Next, you configure the SAML configuration in the enterprise application by adding the SP details and redirect URLs (in this case, the Amazon Cognito details and ALB URL).
Deploy the ALB stack When the SAML configuration is complete on the Azure end, the IdP details have to be configured in Amazon Cognito. When users access the ALB URL, they will be authenticated against the corporate identity using SAML through Amazon Cognito. After they’re authenticated, they’re redirected to the Lambda function for authorization against the group they belong to. The user’s group is then validated against matching IAM role. If it’s valid, the Lambda function adds the web login token to the URL, and the user will gain access to the Amazon MWAA environment.
This CloudFormation stack creates the following resources:
Deploy the stack by completing the following steps:
Enter the following parameters:
Test the solution Now that the SAML configuration and relevant AWS services are created, it’s time to access the Amazon MWAA environment.
Clean up When you’re done experimenting with this solution, it’s essential to clean up your resources to avoid incurring AWS charges.
aws ssm delete-parameters --names "MyFirstParameter" "MySecondParameter"
aws ec2 delete-vpc-endpoints --vpc-endpoint-ids "Endpoint1" "Endpoint2"
3. Delete the users, groups, and enterprise application in the Azure environment.
Conclusion In this post, we demonstrated how to integrate Amazon MWAA with organization Azure AD services. We walked through the solution that solves this problem using infrastructure as code. This solution allows different end-user personas in your organization to access the Amazon MWAA Airflow UI using SAML SSO.
For additional details and code examples for Amazon MWAA, visit the Amazon MWAA User Guide and the Amazon MWAA examples GitHub repo.
About the Authors Satya Chikkala is a Solutions Architect at Amazon Web Services. Based in Melbourne, Australia, he works closely with enterprise customers to accelerate their cloud journey. Beyond work, he is very passionate about nature and photography.
Vijay Velpula is a Data Lake Architect with AWS Professional Services. He assists customers in building modern data platforms by implementing big data and analytics solutions. Outside of his professional responsibilities, Velpula enjoys spending quality time with his family, as well as indulging in travel, hiking, and biking activities.