

# Trusted identity propagation with Amazon MWAA Serverless

Trusted identity propagation is an Amazon MWAA Serverless security capability. With it, you can run workflows with the identity of a workforce user from AWS IAM Identity Center or IAM federation. Amazon MWAA Serverless passes your identity to the AWS services that your workflow tasks call.

Some services authorize access based on user identity, such as AWS Lake Formation, Amazon S3 Access Grants, and Amazon Redshift. These services can then grant or deny data access for you, not only for the workflow execution role. AWS CloudTrail (CloudTrail) also records who you are.

You can use trusted identity propagation in two ways:
+ **On-demand runs** – When you start a workflow run with `StartWorkflowRun`, the run carries your identity. You don't need to change the workflow.
+ **Scheduled runs on your behalf** – When you create or update a scheduled workflow, set the `OnBehalfOf` parameter to `ORIGIN_IDENTITY`. Each scheduled run then carries the identity of the user who created or last updated the workflow.

For more information about the capability, see [Simplified experience for trusted identity propagation](https://docs.aws.amazon.com/singlesignon/latest/userguide/simplified-tip-overview.html) in the *IAM Identity Center User Guide*.

**Topics**
+ [Understanding how trusted identity propagation works in Amazon MWAA Serverless](#security-iam-tip-how-it-works)
+ [Reviewing supported sign-in paths](#security-iam-tip-sign-in-paths)
+ [Completing the prerequisites](#security-iam-tip-prerequisites)
+ [Running workflows on demand with your identity](#security-iam-tip-on-demand)
+ [Running scheduled workflows on your behalf](#security-iam-tip-scheduled)
+ [Auditing propagated identities with CloudTrail](#security-iam-tip-auditing)
+ [Data protection](#security-iam-tip-data-protection)
+ [Security best practices](#security-iam-tip-best-practices)
+ [Resolving trusted identity propagation errors](#security-iam-tip-errors)
+ [Considerations and limitations for trusted identity propagation](#security-iam-tip-considerations)
+ [Example – Restrict Amazon S3 writes to a user's scheduled workflow](security-iam-tip-example.md)

## Understanding how trusted identity propagation works in Amazon MWAA Serverless
<a name="security-iam-tip-how-it-works"></a>

When you call `StartWorkflowRun`, `CreateWorkflow`, or `UpdateWorkflow`, Amazon MWAA Serverless captures your identity from the credentials that you sign the request with. When a task in the run needs credentials, Amazon MWAA Serverless assumes the workflow execution role and adds your identity to the role session. The task's credentials then carry your identity.

Access depends on both the execution role and your identity:
+ The execution role's permissions policies control which AWS API actions your tasks can call.
+ Services that authorize access based on user identity, such as AWS Lake Formation and Amazon S3 Access Grants, use your identity to decide which data you can access. Your policies can also check the identity with condition keys such as `aws:OriginIdentity/Subject`.

The identity applies to the whole workflow run. Every task in a run uses the same identity. You can't set a different identity for individual tasks.

Some credentials don't carry an identity, such as credentials for an IAM user. If you start a run with those credentials, the run uses only the execution role. The run works the same as a workflow run without trusted identity propagation.

## Reviewing supported sign-in paths
<a name="security-iam-tip-sign-in-paths"></a>

The way that you sign in to AWS determines whether Amazon MWAA Serverless can propagate your identity. The following table shows the run types that each sign-in path supports.


| Sign-in path | On-demand runs | Scheduled runs on your behalf | 
| --- | --- | --- | 
| IAM Identity Center, with the simplified experience for trusted identity propagation turned on | Yes | Yes | 
| IAM federation with Security Assertion Markup Language (SAML) 2.0 or OpenID Connect (OIDC), with an IAM Identity Center instance attached to the IAM identity provider | Yes | Yes | 
| IAM federation with SAML 2.0 or OIDC, without IAM Identity Center | Yes | No | 
| IAM users and roles that are assumed without an identity | No. Runs use the execution role | No | 

## Completing the prerequisites
<a name="security-iam-tip-prerequisites"></a>

Before you use trusted identity propagation with Amazon MWAA Serverless, complete the following setup:
+ **Set up IAM Identity Center** – If you sign in with IAM Identity Center, turn on the simplified experience for trusted identity propagation for your instance. For more information, see [Enable the simplified experience](https://docs.aws.amazon.com/singlesignon/latest/userguide/simplified-tip-enabling.html) in the *IAM Identity Center User Guide*.
+ **Set up IAM federation** – If you sign in with IAM federation, configure your IAM SAML or OIDC identity provider for trusted identity propagation. To run scheduled workflows on your behalf, also attach an IAM Identity Center instance to the identity provider. For more information, see [Trusted identity propagation with an IAM identity provider](https://docs.aws.amazon.com/singlesignon/latest/userguide/simplified-tip-enabling.html#tip-iam-federation) in the *IAM Identity Center User Guide*.
+ **Turn on user background sessions** – Scheduled runs on your behalf use an IAM Identity Center user background session. The background session keeps your identity available after you sign out. Make sure that user background sessions are turned on for your IAM Identity Center instance. The background session duration that you configure limits how long scheduled runs can use your identity. For more information, see [User background sessions](https://docs.aws.amazon.com/singlesignon/latest/userguide/user-background-sessions.html) in the *IAM Identity Center User Guide*.
+ **Grant data access to users** – In the downstream service, grant users or groups access to the data. For example, use AWS Lake Formation permissions, Amazon S3 Access Grants, or policies that use the `aws:OriginIdentity/Subject` condition key.

You don't need to change the workflow execution role. The execution role's trust policy continues to allow `sts:AssumeRole` for the Amazon MWAA Serverless service principal and doesn't need the `sts:SetContext` permission. For information about the execution role, see [Execution roles](get-started-execution-role.md).

## Running workflows on demand with your identity
<a name="security-iam-tip-on-demand"></a>

When you call `StartWorkflowRun` with credentials that carry an identity, the run carries your identity. You don't set a parameter, and the workflow's `OnBehalfOf` setting doesn't affect on-demand runs.

To find the identity that a run used, call `GetWorkflowRun`. The `OnBehalfOf.Subject` field in the response shows the user's subject. Runs that used only the execution role don't include this field.

Amazon MWAA Serverless keeps the identity of an on-demand run active while tasks in the run are running. Your run fails in the following cases:
+ The first task of the run doesn't start within about 1 hour after you call `StartWorkflowRun`.
+ More than about 2 hours pass with no task in the run running. The next task that starts fails. For example, this can happen when a task waits for a long retry delay. It can also happen when an Apache Airflow sensor waits a long time between checks.

A single task that runs for a long time isn't affected. For runs with long pauses between tasks, use scheduled runs on your behalf instead. Amazon MWAA Serverless renews the identity for scheduled runs in the background, so these limits don't apply.

## Running scheduled workflows on your behalf
<a name="security-iam-tip-scheduled"></a>

To run a scheduled workflow with your identity, create or update the workflow with the `OnBehalfOf` parameter set to `ORIGIN_IDENTITY`. Amazon MWAA Serverless captures your identity from the request. Each scheduled run then carries your identity, even when you aren't signed in.

The `OnBehalfOf` parameter accepts the following values:

`EXECUTION_ROLE`  
Scheduled runs use only the execution role. This is the default value.

`ORIGIN_IDENTITY`  
Scheduled runs carry the identity of the user who created or last updated the workflow.

To use `ORIGIN_IDENTITY`, make sure that the following are true. Otherwise, the request fails with a `ValidationException`.
+ Your workflow definition includes a schedule.
+ You sign the request with credentials that carry an identity from a supported sign-in path. For the supported sign-in paths, see [Reviewing supported sign-in paths](#security-iam-tip-sign-in-paths).

`ORIGIN_IDENTITY` doesn't affect on-demand runs of the workflow. When you call `StartWorkflowRun`, the run carries your identity, not the stored identity.

### Updating the workflow
<a name="security-iam-tip-scheduled-update"></a>

Each call to `UpdateWorkflow` creates a new workflow version and sets its identity again:
+ If you set `OnBehalfOf` to `ORIGIN_IDENTITY`, Amazon MWAA Serverless captures your identity. Scheduled runs then use your identity, with a new expiration time.
+ If you omit `OnBehalfOf` or set it to `EXECUTION_ROLE`, Amazon MWAA Serverless removes the stored identity. Scheduled runs then use only the execution role.

**Important**  
To keep running scheduled runs on a user's behalf, include `OnBehalfOf` set to `ORIGIN_IDENTITY` in every `UpdateWorkflow` request. Sign each update request as the user whose identity the runs carry.

### Checking the identity status
<a name="security-iam-tip-scheduled-status"></a>

To check the identity that scheduled runs use, call `GetWorkflow`. For workflows that use `ORIGIN_IDENTITY`, the response includes the following fields:

`OnBehalfOf.Subject`  
Identifies the user whose identity scheduled runs carry, such as by user name or email address. The value depends on how the user signs in.

`IdentityContextStatus.Status`  
`ACTIVE` if scheduled runs can use the identity, or `EXPIRED` if they can't.

`IdentityContextStatus.Reason`  
The reason that the identity expired.

`IdentityContextStatus.ExpiresAt`  
The latest time that scheduled runs can use the identity.

For a scheduled run, `GetWorkflowRun` also returns `OnBehalfOf.Subject`.

### Understanding identity lifetime and expiration
<a name="security-iam-tip-scheduled-lifetime"></a>

As long as the identity is active, Amazon MWAA Serverless renews it in the background about once an hour. Amazon MWAA Serverless can't renew the identity past the time in `ExpiresAt`. For IAM Identity Center users, the user background session duration that you configure sets this limit. To extend the expiration time, update the workflow as the user.

The identity expires in the following cases:
+ The time in `ExpiresAt` passes.
+ You end the user's session, or disable or delete the user in IAM Identity Center. Amazon MWAA Serverless detects the change at the next renewal.
+ Amazon MWAA Serverless can't renew the identity. For example, AWS denies access when Amazon MWAA Serverless tries to renew it.

When the identity expires, `IdentityContextStatus.Status` changes to `EXPIRED`, and the following happens:
+ The schedule keeps running. Each scheduled run starts and fails with the message `Identity context for scheduled runs is unavailable. Update the workflow to re-establish it.`
+ Scheduled runs don't fall back to the execution role.
+ Amazon MWAA Serverless doesn't restore the identity automatically, even if you restore the user's access.

To resume scheduled runs, sign in as the user and call `UpdateWorkflow` with `OnBehalfOf` set to `ORIGIN_IDENTITY`. To run the workflow with only the execution role instead, call `UpdateWorkflow` with `OnBehalfOf` set to `EXECUTION_ROLE`.

## Auditing propagated identities with CloudTrail
<a name="security-iam-tip-auditing"></a>

When Amazon MWAA Serverless assumes the execution role for a run that carries a user's identity, CloudTrail records an `AssumeRole` event. The event includes an `onBehalfOf` section that identifies the user. The event also shows that the Amazon MWAA Serverless service principal, `airflow-serverless.amazonaws.com`, made the request.

For information about identity fields in CloudTrail events, see [Identity fields for the simplified experience](https://docs.aws.amazon.com/singlesignon/latest/userguide/sso-info-in-cloudtrail.html#sso-cloudtrail-simplified-tip-fields) in the *IAM Identity Center User Guide*.

For information about Amazon MWAA Serverless events, see [Logging Amazon MWAA Serverless APIs with CloudTrail](log-apis-with-cloudtrail.md).

## Data protection
<a name="security-iam-tip-data-protection"></a>

Amazon MWAA Serverless stores the subject of the user whose identity a workflow or run carries. The following sections describe how Amazon MWAA Serverless protects this data. For general information about data protection, see [Data protection in Amazon MWAA Serverless](data-protection.md).

### Encryption at rest
<a name="security-iam-tip-data-protection-at-rest"></a>

Amazon MWAA Serverless encrypts the stored subject at rest, for both scheduled workflows and on-demand runs. If you specify a customer managed AWS KMS key (KMS key) for the workflow, Amazon MWAA Serverless uses that key. Otherwise, Amazon MWAA Serverless uses an AWS owned key.

### Encryption in transit
<a name="security-iam-tip-data-protection-in-transit"></a>

Requests to the Amazon MWAA Serverless API use Transport Layer Security (TLS). The subject in API responses is encrypted in transit.

### Key management
<a name="security-iam-tip-data-protection-keys"></a>

You manage the KMS key that you specify for a workflow.

The Amazon MWAA Serverless API marks the `Subject` field as sensitive, so AWS SDKs that support sensitive fields redact it from their logs. Amazon MWAA Serverless doesn't write the subject to service logs.

## Security best practices
<a name="security-iam-tip-best-practices"></a>

Use the following practices to help secure workflows that run with a user's identity.

### Preventative
<a name="security-iam-tip-best-practices-preventative"></a>
+ Limit who can call `UpdateWorkflow` on workflows that use `ORIGIN_IDENTITY`. The user who makes the last update determines the identity of scheduled runs.
+ Check the identity provider in your policies with condition keys such as `aws:OriginIdentity/Issuer`, because the subject isn't guaranteed to be unique across identity providers.
+ Set the user background session duration in IAM Identity Center to the shortest period that meets your scheduling needs.

### Detective
<a name="security-iam-tip-best-practices-detective"></a>
+ Review the `onBehalfOf` section of CloudTrail events to confirm which user's identity your workflows use.
+ Check `IdentityContextStatus` in the `GetWorkflow` response regularly, so that you update a workflow before its identity expires.

## Resolving trusted identity propagation errors
<a name="security-iam-tip-errors"></a>

This section helps you resolve errors that you might get when you use trusted identity propagation. Most errors happen because your credentials don't carry an identity, your session ended, or your identity expired.

The following table lists the trusted identity propagation error messages, their causes, and how to resolve them.


| Error message | Cause and resolution | 
| --- | --- | 
| `onBehalfOf ORIGIN_IDENTITY requires the caller to have identity context.` | Your request credentials don't carry an identity. Sign in through a supported sign-in path and try again. | 
| `onBehalfOf ORIGIN_IDENTITY requires a schedule in the workflow definition.` | Add a schedule to your workflow definition, or set `OnBehalfOf` to `EXECUTION_ROLE`. | 
| `The identity context is no longer active` | Your session ended, or an administrator revoked it. Sign in again and retry the request. | 
| `The identity context could not be established for background use` | Amazon MWAA Serverless couldn't get a user background session. Turn on user background sessions for your IAM Identity Center instance. | 
| `The identity context could not be obtained because access was denied. Contact your administrator.` | AWS denied the request for your identity. Check your trusted identity propagation configuration, or contact your administrator. | 
| `Identity context for scheduled runs is unavailable. Update the workflow to re-establish it.` | The identity for scheduled runs expired. To find the cause, check `IdentityContextStatus.Reason` in the `GetWorkflow` response. Then update the workflow as the user to set the identity again. For more information, see [Understanding identity lifetime and expiration](#security-iam-tip-scheduled-lifetime). | 

If Amazon MWAA Serverless can't capture your identity, it doesn't create the workflow version or the run. You can retry the request with the same client token (`ClientToken`).

To prevent these errors, check `IdentityContextStatus` before the identity expires, and keep user background sessions turned on. For more information about setup, see [Completing the prerequisites](#security-iam-tip-prerequisites) and [User background sessions](https://docs.aws.amazon.com/singlesignon/latest/userguide/user-background-sessions.html) in the *IAM Identity Center User Guide*.

## Considerations and limitations for trusted identity propagation
<a name="security-iam-tip-considerations"></a>

Consider the following when you use trusted identity propagation with Amazon MWAA Serverless:
+ A workflow stores one identity for scheduled runs, from the user who created or last updated it.
+ With CloudFormation, you can't set the `OnBehalfOf` parameter. Use the Amazon MWAA Serverless API, the AWS CLI, or an AWS SDK instead.
+ Scheduled runs on your behalf require IAM Identity Center, either as your sign-in path or attached to your IAM identity provider.
+ The identity applies to an entire workflow run. All tasks in a run use the same identity.