On Astronomer, IAM roles can be appended to the webserver, scheduler and worker pods within any individual Airflow Deployment on the platform.
IAM roles on AWS and other platforms are often used to manage the level of access a specific user (or object, or group of users) has to some resource (or set of resources). The resource in question could be an S3 bucket or Secret Backend, both of which are commonly used in tandem with Airflow and Astronomer and can now be configured to be accessible only to a subset of Kubernetes pods within your wider Astronomer cluster.
Consider the following when you integrate IAM roles:
$ kubectl describe po)Before you can integrate IAM with an Airflow Deployment on Astronomer, you’ll need to do the following within AWS:
Retrieve your EKS cluster with the following AWS CLI command:
The output of this command should look something like this:
Retrieve and make note of your cluster’s OIDC issuer URL with the following AWS CLI command:
The output of this command should be a URL with the format https://oidc.eks.[region].amazonaws.com/id/[id].
Open the IAM console.
In the navigation pane, click Identity Providers > Create Provider.
For Provider Type, click Choose a provider type > OpenID Connect.
For Provider URL, use the OIDC issuer URL for your cluster.
For Audience, use sts.amazonaws.com.
Verify that the provider information is correct, and then click Add provider to create your identity provider.
For additional information, refer to Enable IAM roles for service accounts.
Open the IAM console at https://console.aws.amazon.com/iam/.
In the navigation panel, click Policies > Create Policy.
Open the JSON tab.
In the Policy Document field, specify the permissions you’d like to apply (or restrict) to the resource in question (e.g. read / write access to an AWS S3 bucket). You can also use the visual editor to construct your own policy.
The following example will grant your IAM role read/write permissions to an S3 bucket named astronomer-bucket:
Review and create your policy.
For additional information, refer to Create service account IAM Policy and Role.
To create a trust relationship between your IAM role and OIDC identity provider:
Open the IAM console at https://console.aws.amazon.com/iam/.
In the navigation panel, choose Roles and open your role created in the previous section.
Select the Trust relationships tab and choose Edit trust policy.
Create a trust relationship between your IAM role and OIDC identity provider with the following format:
Example:
For additional information, refer to IAM role Configuration.
In order to apply your IAM role to any Airflow Deployment on Astronomer, you’ll need to explicitly pass an annotation key to the platform. To do so:
Set the following in your values.yaml file under astronomer.houston.config.deployments:
Example:
Push the configuration change to your platform as described in Apply a config change.
To create a new Airflow Deployment with your IAM role attached, run the following Astro CLI command:
Alternatively, to update an existing Airflow Deployment with your IAM role attached, run the following:
Confirm the role was passed successfully to all webserver, scheduler and worker pods within your Airflow Deployment by running the following command:
You should see the following in your output:
1.10.5, you’ll need to add boto3 >=1.9 and botocore >= 1.12 to your requirements.txt file.Workload Identity is a secure and manageable way to access Google Cloud services from applications running on GKE. This guide walks through the necessary steps for integrating IAM roles with Airflow Deployments running on GKE using Workload Identity.
Create a new cluster with Workload Identity enabled by running the following command:
Alternatively, run the following to enable Workload Identity on an existing cluster:
Configure your node pool to use Workload Identity by running the following command:
To create a GCP service account, run the following command:
Add the following to your values.yaml file and push it to your platform as described in Apply a config change:
Create an Airflow Deployment with your GCP service account attached by running the following command:
Note the name of the worker, triggerer, scheduler, webserver, cleanup, and migrate-database-job service accounts that appear when you run the following command:
Create an IAM policy binding your Google and GKE service accounts by running the following command for both the worker and scheduler GKE service accounts you noted:
Create an interactive session by running the following command:
In the interactive session, confirm you’re able to authenticate successfully via Workload Identity by running the following command:
If Workload Identity is working, you should see a list of credentialed accounts related to your GCP service account.
Astronomer Software creates a set of service accounts for each Airflow instance it manages. The following roles can require access to Airflow Xcom backends or secrets backends to function: