> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/aws-iam-integration.md).

# Use IAM roles for authentication

There are three methods available for HCE to authenticate itself with AWS and obtain the necessary permissions that are specific to the targeted services:

* **IAM Roles for Service Accounts (IRSA) - OIDC method**

  IRSA leverages an OpenID Connect (OIDC) provider for authentication. This method is applicable when the execution plane is installed on an Amazon EKS cluster. It provides least-privilege access and credential isolation. This method requires setting up an OIDC provider in your EKS cluster and (for cross-account access) in each target account.
* **AWS Assume Role method**

  The Assume Role method uses [chained AssumeRole operations](https://docs.aws.amazon.com/eks/latest/userguide/cross-account-access.html) to enable cross-account access. It requires IRSA/OIDC only in the source account (where your EKS cluster is installed), and **does not require OIDC providers in any target account**, only standard IAM role trust relationships. This provides a simpler setup for cross-account chaos experiments.
* **Kubernetes Secret**

  This approach involves providing the necessary credentials through Kubernetes secrets. The advantage of this method is its compatibility with any cluster and platform. It is explained in the "notes" section of the experiment documentation.

Use the selector below to choose your preferred IAM role-based authentication method and follow the complete setup instructions.

{% @harness-package-selector/package-selector platforms="%5B%7B%22label%22%3A%22IRSA%20(OIDC%20Method)%22%2C%22slug%22%3A%22irsa-oidc-method%22%2C%22path%22%3A%22chaos-engineering%2Ffaults%2Fchaos-fault-categories%2Faws%2Fsecurity-configurations%2Faws-iam-integration%2Firsa-oidc-method-aws-iam-integration%22%7D%2C%7B%22label%22%3A%22AWS%20Assume%20Role%20Method%22%2C%22slug%22%3A%22aws-assume-role-method%22%2C%22path%22%3A%22chaos-engineering%2Ffaults%2Fchaos-fault-categories%2Faws%2Fsecurity-configurations%2Faws-iam-integration%2Faws-assume-role-method-aws-iam-integration%22%7D%5D" %}

{% tabs %}
{% tab title="AWS Assume Role Method" %}

The AWS Assume Role method provides a simplified approach for setting up cross-account access for chaos experiments. Unlike the OIDC method, the Assume Role method **does not require you to create OIDC providers in each target account**. Instead, it uses [chained AssumeRole operations](https://docs.aws.amazon.com/eks/latest/userguide/cross-account-access.html) — the source account's IAM role (which already has IRSA/OIDC credentials from the EKS cluster) assumes IAM roles in the target accounts using `sts:AssumeRole`.

This is especially useful when:

* You want to avoid the overhead of creating and managing OIDC identity providers in every target account.
* You need to target AWS resources across multiple accounts from a single chaos infrastructure.
* You prefer a simpler trust relationship setup using IAM role-to-role trust rather than OIDC federation in target accounts.

### Architecture <a href="#architecture" id="architecture"></a>

The following diagram illustrates how the Assume Role method works:

<img src="https://6a994c14e7528334531dbe29--harness-developer.netlify.app/assets/images/aws-assume-role-architecture-4f2ca5c45c875984b8cc45250e1b28d2.png" alt="AWS Assume Role Architecture" height="1878" width="2368">

**How it works:**

1. The **Harness K8s Delegate** in the AWS EKS cluster (source account) launches **Chaos Runners** to conduct chaos experiments against AWS resources (EC2, LB, ECS, Lambda) in the source account.
2. The **Service Account** in the EKS cluster is annotated with the **Chaos IAM Role** in the source account. The service account obtains credentials for this role via IRSA (OIDC federation with the EKS cluster).
3. To target resources in a different AWS account, the Chaos IAM Role in the source account **assumes** the Chaos IAM Role in the target account using `sts:AssumeRole`.
4. This is enabled by configuring a **trust relationship** in the target account's IAM role that allows the source account's IAM role to assume it.
5. You provide the **target account IAM role ARN** in the chaos experiment configuration for assume role to work.

### Account terminology <a href="#account-terminology" id="account-terminology"></a>

* **AWS source account:** The AWS account where your EKS cluster and chaos infrastructure are installed. This account hosts the Harness K8s Delegate that launches chaos runners. An OIDC provider is configured in this account for IRSA.
* **Target accounts:** AWS accounts where you'll run experiments against resources (EC2, LB, ECS, Lambda, etc.) to intentionally disrupt them. You can have many target accounts. **No OIDC provider is needed in target accounts**, only an IAM role trust relationship.
* **The experiment service account:** A Kubernetes service account (default: `litmus-admin`) in the EKS cluster that is annotated with the source account's Chaos IAM Role.

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Your execution plane must be installed on an Amazon EKS cluster.
* An [OIDC provider must be configured for your EKS cluster](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html) in the source account. This is a standard IRSA prerequisite. If you have already set up IRSA for your chaos infrastructure, this is already done.
* An IAM role in the source account (Chaos IAM Role) with the following trust policy that allows the EKS cluster's OIDC provider to issue credentials:

  ```
  {
      "Version": "2012-10-17",
      "Statement": [
          {
              "Effect": "Allow",
              "Principal": {
                  "Federated": "arn:aws:iam::<SOURCE_ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_PROVIDER_ID>"
              },
              "Action": "sts:AssumeRoleWithWebIdentity",
              "Condition": {
                  "StringEquals": {
                      "oidc.eks.<REGION>.amazonaws.com/id/<OIDC_PROVIDER_ID>:aud": "sts.amazonaws.com"
                  }
              }
          }
      ]
  }
  ```
* The experiment service account must be annotated with this IAM role:

  ```
  kubectl annotate serviceaccount -n <experiment_service_account_namespace> <experiment_service_account_name> \
  eks.amazonaws.com/role-arn=arn:aws:iam::<SOURCE_ACCOUNT_ID>:role/<SOURCE_CHAOS_IAM_ROLE>
  ```

{% hint style="info" %}

* The default name for the experiment service account is `litmus-admin` and the namespace for chaos infrastructure is `HCE`, however, you can use different names.
* If you have already completed the IRSA (OIDC method) setup for your source account, these prerequisites are already met. You only need to follow the steps below to configure cross-account access.
  {% endhint %}

### Step 1: Grant the source account role permission to assume target roles <a href="#step-1-grant-the-source-account-role-permission-to-assume-target-roles" id="step-1-grant-the-source-account-role-permission-to-assume-target-roles"></a>

Attach a permission policy to the source account's Chaos IAM Role that allows it to call `sts:AssumeRole` on the target account roles.

1. Navigate to the AWS IAM console in your **source account**.
2. Find the Chaos IAM Role that the experiment service account is annotated with.
3. Attach the following inline policy (or add to an existing policy) to allow assuming roles in target accounts:

   ```
   {
       "Version": "2012-10-17",
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "sts:AssumeRole",
               "Resource": [
                   "arn:aws:iam::<TARGET_ACCOUNT_ID_1>:role/<TARGET_ROLE_NAME_1>",
                   "arn:aws:iam::<TARGET_ACCOUNT_ID_2>:role/<TARGET_ROLE_NAME_2>"
               ]
           }
       ]
   }
   ```
4. Additionally, attach any policies needed for chaos experiments against resources in the source account itself. You can use the [AWS superset policy](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/policy-for-all-aws-faults.md) as a reference.

### Step 2: Create an IAM role and policy in each AWS target account <a href="#step-2-create-an-iam-role-and-policy-in-each-aws-target-account" id="step-2-create-an-iam-role-and-policy-in-each-aws-target-account"></a>

Create an IAM role in each target account that will be assumed by the source account's IAM role.

1. Navigate to the AWS IAM console in your **target account**.
2. Create a new IAM role with the following configuration:
   * **Trusted entity type**: Custom trust policy (configured in Step 3 below)
3. Create or attach a policy that grants the necessary permissions for chaos experiments on the target account's resources. You can use the [AWS superset policy](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/policy-for-all-aws-faults.md) as a reference for comprehensive permissions.
4. Note the ARN of the created role. You'll need this for the trust relationship configuration and experiment setup.

### Step 3: Configure the trust relationship in target accounts <a href="#step-3-configure-the-trust-relationship-in-target-accounts" id="step-3-configure-the-trust-relationship-in-target-accounts"></a>

Configure the trust relationship in the target account's IAM role to allow the source account's IAM role to assume it. This step **does not require an OIDC provider in the target account**. It uses a standard IAM role-to-role trust.

1. **In each target account**: Edit the trust relationship for the IAM role you created in Step 2.

   Navigate to **AWS IAM** > ***ROLE\_NAME*** > **Trust relationships** tab and update the trust policy:

   ```
   {
       "Version": "2012-10-17",
       "Statement": [
           {
               "Effect": "Allow",
               "Principal": {
                   "AWS": "arn:aws:iam::<SOURCE_ACCOUNT_ID>:role/<SOURCE_CHAOS_IAM_ROLE>"
               },
               "Action": "sts:AssumeRole"
           }
       ]
   }
   ```

   Where:

   * `<SOURCE_ACCOUNT_ID>`: The AWS account ID of your source account (where the EKS cluster and chaos infrastructure are installed).
   * `<SOURCE_CHAOS_IAM_ROLE>`: The name of the IAM role in the source account that the experiment service account is annotated with.

{% hint style="info" %}
For [least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege), always specify the exact role ARN in the `Principal` field (for example, `arn:aws:iam::111122223333:role/chaos-source-role`) rather than using the account root (`arn:aws:iam::111122223333:root`). Using the account root would allow **any** IAM principal in the source account to assume this role.
{% endhint %}

2. Repeat for each target account.

### Step 4: Configure experiments to use assume role <a href="#step-4-configure-experiments-to-use-assume-role" id="step-4-configure-experiments-to-use-assume-role"></a>

When creating chaos experiments that target resources in different accounts, specify the target account's role ARN directly in the chaos experiment configuration.

1. In the Harness Chaos Dashboard, navigate to your experiment configuration.
2. In the fault configuration panel, locate the **Assume Role ARN** field.
3. Enter the ARN of the target account role you created in Step 2:

   ```
   arn:aws:iam::<TARGET_ACCOUNT_ID>:role/<TARGET_ROLE_NAME>
   ```
4. The chaos infrastructure will automatically assume this role when executing the experiment against resources in the target account.

### Remove all secret references from experiment definitions <a href="#remove-all-secret-references-from-experiment-definitions" id="remove-all-secret-references-from-experiment-definitions"></a>

When you create a new AWS chaos experiment using the assume role method, you do not need to provide AWS access key secrets. The assume role functionality works seamlessly with the IAM role configuration.

<img src="https://6a994c14e7528334531dbe29--harness-developer.netlify.app/assets/images/use-secret-702798a81e58d32a2ac967055180035c.png" alt="Chaos experiment definition YAML" height="534" width="2566">
{% endtab %}

{% tab title="IRSA (OIDC Method)" %}
IRSA (IAM Roles for Service Accounts) leverages an OpenID Connect (OIDC) provider for authentication. This method is applicable when the execution plane is installed on an Amazon EKS cluster. With IRSA, you have these benefits:

* **Least privilege:** Using IRSA avoids extending permissions for the pods on the node, such as restricting the node IAM role for pods from making an AWS API call. You can scope IAM permissions to a service account, and this way, only pods that use that service account have access to those permissions.
* **Credential isolation:** An experiment can only retrieve credentials for the IAM role associated with a particular service account. This experiment does not have access to credentials for other experiments belonging to other pods.

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Your execution plane must be installed on an Amazon EKS cluster.
* You must have `eksctl` installed and configured.

### Account terminology <a href="#account-terminology" id="account-terminology"></a>

In this topic, Harness refers to three types of accounts:

* **The experiment service account:** A Kubernetes service account created when you install a chaos infrastructure on your EKS cluster. This is the account that executes and controls chaos experiments. Its default name is `litmus-admin`, however you can use a different name.
* **AWS source account:** This AWS account also resides where you install a chaos infrastructure, and serves as the host for the EKS cluster. This account enables Harness CE to access resources across multiple target accounts.
* **Target accounts:** These are AWS accounts where you'll run experiments against resources and services to intentionally disrupt them. You can have many target accounts.

### Enable the experiment service account to access AWS resources <a href="#enable-the-experiment-service-account-to-access-aws-resources" id="enable-the-experiment-service-account-to-access-aws-resources"></a>

Chaos experiments are initiated and controlled through this service account (usually named `litmus-admin`). You must enable this account to access AWS resources.

#### Step 1: Create an OIDC provider for your EKS cluster <a href="#step-1-create-an-oidc-provider-for-your-eks-cluster" id="step-1-create-an-oidc-provider-for-your-eks-cluster"></a>

You must create an IAM OpenID Connect (OIDC) identity provider for your cluster with `eksctl`. You only need to do this once for a cluster. For more information, go to [AWS documentation to set up an OIDC provider](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html).

To create an OIDC provider for your EKS cluster:

1. Run the following command to check if your cluster has an existing IAM OIDC provider.

```
aws eks describe-cluster --name <your-cluster-name> --query "cluster.identity.oidc.issuer" --output text
```

**Example output:**

```
https://oidc.eks.us-west-1.amazonaws.com/id/D054E55B6947B1A7B3F200297789662C
```

In the above example `us-west-1` is the region, and `D054E55B6947B1A7B3F200297789662C` is the OIDC provider ID.

1. Run the following command to list the IAM OIDC providers available to this account.

```
aws iam list-open-id-connect-providers | grep <Provider_ID>
```

Where: `Provider_ID` is the value returned from the output of the previous command. In our example, this value is `D054E55B6947B1A7B3F200297789662C`.

1. If no IAM OIDC identity provider is available for this account, create one for your cluster using the following command.

```
eksctl utils associate-iam-oidc-provider --cluster <your-cluster-name> --approve
```

**Example output:**

```
2021-09-07 14:54:01 [ℹ]  eksctl version 0.52.0
2021-09-07 14:54:01 [ℹ]  using region us-west-1
2021-09-07 14:54:04 [ℹ]  will create IAM Open ID Connect provider for cluster "udit-cluster-11" in "us-west-1"
2021-09-07 14:54:05 [✔]  created IAM Open ID Connect provider for cluster "litmus-demo" in "us-west-1"
```

tip

* By default, chaos infrastructure associated with your chaos experiment has `litmus-admin` as a chaos service account. Based on the chaos experiment you wish to execute, you can configure the policy and attach the policy to a role, and go to [step 2](#step-2-create-an-iam-role-and-policy-in-each-aws-target-account). Refer to [AWS superset policy](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/policy-for-all-aws-faults.md) to know more.
* If you wish to create a custom service account, you can create one and configure the policy and attach the policy with a role.
* For more information, go to [AWS IAM documentation](https://docs.aws.amazon.com/transfer/latest/userguide/requirements-roles.html).

#### Step 2: Configure the trust relationship of the IAM role in the source account <a href="#step-2-configure-the-trust-relationship-of-the-iam-role-in-the-source-account" id="step-2-configure-the-trust-relationship-of-the-iam-role-in-the-source-account"></a>

Configure the trust relationship in the IAM role associated with your experiment service account in the AWS source account. This step is required for both single-account and cross-account IRSA configurations.

Edit the trust relationship in the IAM role you created in Step 1.

You can find the JSON for the trust relationship in **AWS IAM >&#x20;*****ROLE\_NAME*****&#x20;> Trust relationship** tab.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::<SOURCE_ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_PROVIDER_ID>"
            },
            "Action": "sts:AssumeRoleWithWebIdentity"
        }
    ]
}
```

Where:

* `<SOURCE_ACCOUNT_ID>`: Your AWS source account ID
* `<REGION>`: The AWS region of your EKS cluster
* `<OIDC_PROVIDER_ID>`: The OIDC provider ID from your EKS cluster

#### Step 3: Associate the IAM role with the experiment service account <a href="#step-3-associate-the-iam-role-with-the-experiment-service-account" id="step-3-associate-the-iam-role-with-the-experiment-service-account"></a>

Associate the IAM role you created in Step 1 by annotating the experiment service account (usually `litmus-admin`). This will give it the required access to AWS resources.

To associate the IAM role to the experiment service account, run this command:

```
kubectl annotate serviceaccount -n <experiment_service_account_namespace> <experiment_service_account_name> \
eks.amazonaws.com/role-arn=arn:aws:iam::<account_ID>:role/<IAM_role_name>
```

{% hint style="info" %}

* The default name for the experiment service account is `litmus-admin` and the namespace for chaos infrastructure is `HCE`, however, you can use different names.
* For the cluster autoscaler experiment, annotate the experiment service account in the `kube-system` namespace.
  {% endhint %}

#### Step 4: Verify the association of the IAM role with the experiment service account <a href="#step-4-verify-the-association-of-the-iam-role-with-the-experiment-service-account" id="step-4-verify-the-association-of-the-iam-role-with-the-experiment-service-account"></a>

To verify the association between the experiment service account (`litmus-admin`) and the IAM role:

1. Run an experiment and describe one of the pods.
2. Verify whether the `AWS_WEB_IDENTITY_TOKEN_FILE` and `AWS_ROLE_ARN` environment variables exist. For example:

```
kubectl exec -n litmus <ec2-terminate-by-id-z4zdf> env | grep AWS
```

**Example output:**

```
AWS_VPC_K8S_CNI_LOGLEVEL=DEBUG
AWS_ROLE_ARN=arn:aws:iam::<ACCOUNT_ID>:role/<IAM_ROLE_NAME>
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
```

### Set up your target accounts for IRSA <a href="#set-up-your-target-accounts-for-irsa" id="set-up-your-target-accounts-for-irsa"></a>

Whereas chaos experiments are initiated and controlled through the experiment service account, **target accounts** are the accounts you'll subject to chaos experiments, so you can intentionally disrupt and manipulate their services.

In this section, you create an IAM role and set up an OIDC provider in each target account.

#### Step 1: Create an IAM role and policy in each AWS target account <a href="#step-1-create-an-iam-role-and-policy-in-each-aws-target-account" id="step-1-create-an-iam-role-and-policy-in-each-aws-target-account"></a>

This step lets you grant permissions for Harness CE to inject chaos targeting various AWS services in the target account.

Create an IAM role and policy in each target account to provide the required permissions to access the desired resources in that account. You have the flexibility to define the level of permissions you wish to assign to Harness CE. For instructions, go to [Create an IAM role and policy](https://docs.aws.amazon.com/transfer/latest/userguide/requirements-roles.html) in the AWS documentation.

#### Step 2: Add the OIDC provider in all target accounts <a href="#step-2-add-the-oidc-provider-in-all-target-accounts" id="step-2-add-the-oidc-provider-in-all-target-accounts"></a>

Follow this procedure for each one of your target accounts.

To add the OIDC provider to each target account:

1. Determine your OIDC URL.

   1. Open the AWS Management Console and navigate to the Amazon EKS service.
   2. Select the EKS cluster that corresponds to the OIDC provider.
   3. Select the **Configuration** tab.
   4. Under the **OpenID Connect (OIDC)** section, locate the **Issuer URL**.

   An example Issuer URL looks like this:

   ```
   https://oidc.eks.us-east-2.amazonaws.com/id/FOSBW293U0Q92423BR43290RU
   ```
2. Navigate to the target account.
3. In the IAM dashboard, select **Identity Providers**, and then select **Add Provider**.
4. In the **Add an Identity provider** screen, for **Provider type**, select **OpenID Connect**.
5. Provide these required details of the OIDC provider:
   * **Provider URL:** Use the URL you retrieved in Step 1.
   * **Audience:** Specify `sts.amazonaws.com`.
6. Select **Add provider**.
7. Repeat these steps for each target account.

### Establish trust between the AWS source account and target accounts <a href="#establish-trust-between-the-aws-source-account-and-target-accounts" id="establish-trust-between-the-aws-source-account-and-target-accounts"></a>

The AWS source account enables Harness CE to access resources across multiple target accounts.

#### Step 1: Configure trust relationship in target accounts <a href="#step-1-configure-trust-relationship-in-target-accounts" id="step-1-configure-trust-relationship-in-target-accounts"></a>

Configure the trust relationship for each IAM role you created in a target account to allow the AWS source account's OIDC provider to assume that role.

**In each target account:** Edit the trust relationship for the IAM role you [created on the target account](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/policy-for-all-aws-faults.md) as shown in the example below.

You can find the JSON for the trust relationship in **AWS IAM >&#x20;*****ROLE\_NAME*****&#x20;> Trust relationship** tab.

In this example `2222222222` is the target account ID.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::2222222222:oidc-provider/oidc.eks.us-east-2.amazonaws.com/id/AAAAA11111111C9909AEC6992AEFNWQO0"
            },
            "Action": "sts:AssumeRoleWithWebIdentity"
        }
    ]
}
```

#### Step 2: Enable the experiment service account to switch between target accounts <a href="#step-2-enable-the-experiment-service-account-to-switch-between-target-accounts" id="step-2-enable-the-experiment-service-account-to-switch-between-target-accounts"></a>

This procedure enables the experiment service account (`litmus-admin`) to seamlessly switch between target accounts when running experiments. To do this, you must annotate the experiment service account with the corresponding chaos role in each target account.

For example, if the target account has a role named `chaos-role`, you must annotate the litmus-admin service account with the unique ARN of that role. This enables seamless switching between target accounts for running experiments.

**To annotate the experiment service account with the role ARN:**

1. Run the following command:

`kubectl annotate serviceaccount -n <chaos-namespace> <experiment-service-account-name> eks.amazonaws.com/role-arn=<role-arn>`

Where:

* `<chaos-namespace>` is the namespace where the chaos infrastructure is installed (usually `HCE`).
* `<experiment-service-account-name>` is the name of your experiment service account (usually `litmus`).
* `<role-arn>` is the ARN of the role in the target account.

2. Repeat the above step for the chaos role in each target account.

### Remove all secret references from experiment definitions <a href="#remove-all-secret-references-from-experiment-definitions" id="remove-all-secret-references-from-experiment-definitions"></a>

When you create a new AWS chaos experiment, you can choose to enable or disable AWS access. You can select or deselect the button depending on your use of the secret references.

<img src="https://6a994c14e7528334531dbe29--harness-developer.netlify.app/assets/images/use-secret-702798a81e58d32a2ac967055180035c.png" alt="Chaos experiment definition YAML" height="534" width="2566">

<br>
{% endtab %}
{% endtabs %}

{% @harness-feedback/feedback %}
