> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.latch.bio/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup Forch Domain / BYOC (Beta)

> Latch allows you to run computation without data leaving your cloud

## Prerequisites

Before you start, ensure you have an IAM role in your AWS that permits you to [create CloudFormation Templates](https://aws.amazon.com/cloudformation/resources/templates/).

Latch utilizes CloudFormation Templates to establish an IAM role that provisions AWS Resources to create a forch domain

## Instructions

### Connecting an AWS Account

<Steps>
  <Step
    title={
    <div>
        Go to this{" "}
        <a
            href="https://console.aws.amazon.com/cloudformation/home?#/stacks/quickcreate?templateURL=https://forch-deployment.s3.us-west-2.amazonaws.com/forch_agent_template.json&stackName=forch"
            target="_blank"
            rel="noopener noreferrer"
        >
            link
        </a>
    </div>
}
  />

  <Step title="Log into the AWS account" />

  <Step title="You will be directed to an AWS CloudFormation 'Quick create stack' template.">
    When you open the CloudFormation template, you'll see an acknowledgment stating "The following resource(s) require capabilities: \[AWS::IAM::Role]. I acknowledge that AWS CloudFormation might create IAM resources with custom names." This pertains to you as the customer executing the CloudFormation stack.
    The stack creates a role that has permission to provision cloud resources, AWS ensures that you are aware of this action. The permissions of this role which can be verified by inspecting the cloudformation template in the AWS UI.

    Refer to \[Advanced Notes]\(#Advanced Notes) for an overview of the permission this IAM role.

    <img src="https://mintcdn.com/latchbio/UTu_UoopMmEaDrwq/images/pods/byoc-cloudformation.png?fit=max&auto=format&n=UTu_UoopMmEaDrwq&q=85&s=37550c13cb84f8d2f78b58e51a55cce9" className="h-56 border-slate-100 border rounded-md" width="2906" height="972" data-path="images/pods/byoc-cloudformation.png" />
  </Step>

  <Step title="Click on the checkbox to acknowledge that this stack will create an iam role." />

  <Step title="Click 'Create Stack' and wait for it to be created." />

  <Step title="Notify someone at Latch with the following details.">
    * AWS Account Id
    * Target AWS Region for this deployment (us-west-2, eu-central-1, etc)
  </Step>
</Steps>

## Architecture

Please refer to this blog [post](https://blog.latch.bio/p/forch-bring-your-own-compute-on-latch?open=false#%C2%A7node-mounts) for an overview of Forch's architecture

## IAM

Each forch domain requires a minimum of 4 IAM role to operate:

1. [forch-agent](#forch-agent) for provisioning cloud resources to setup the forch-domain
2. [forch-orchestrator](#forch-orchestrator) for scheduling and managing tasks in the forch-domain
3. [forch-node](#forch-node) for running the tasks in an compute instances the forch-domain
4. [forch-nat-\*](#forch-nat-*) for running NAT instance in the forch-domain (1 per vpc)

### `forch-agent`

`forch-agent` is created by the Cloudformation Stack from previous [section](#Instructions). This role is used when provisioning cloud resources to setup the forch domain. The list of cloud resources created are as follows:

1. Network resource including vpcs, subnets, internet gateways, security groups, network acls, route tables and elastic ip addresses
2. An S3 Bucket for storing logs
3. [forch-orchestrator](#forch-orchestrator), [forch-node](#forch-node) and [forch-nat-\*](#forch-nat-*) roles and their policies
4. A KMS key for encrypting and decrypting volumes created by forch
5. An ec2 instance running the NAT server on the vpc
6. Forch specific secrets

This role can be safely deleted once the setup of the forch-domain is complete.

<Tabs>
  <Tab title="Permisssions">
    | Rules                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Purpose                                                                                                                                                                                                                                                           |
    | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | [`s3:CreateBucket`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html), [`s3:ListBucket*`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html), [`s3:GetBucket*`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketVersioning.html), [`s3:GetAccelerateConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketAccelerateConfiguration.html), [`s3:GetLifecycleConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLifecycleConfiguration.html), [`s3:GetReplicationConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketReplication.html), [`s3:GetEncryptionConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketEncryption.html), [`s3:PutBucketCORS`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketCors.html), [`s3:PutBucketVersioning`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketVersioning.html), [`s3:PutEncryptionConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketEncryption.html), [`s3:PutBucketRequestPayment`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketRequestPayment.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Retrieve the bucket metadata and configuration, compare it against the desired state, and apply any necessary updates to the S3 bucket `arn:aws:s3:::forch-${AWS::AccountId}`                                                                                     |
    | [`iam:CreateRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html), [`iam:GetRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetRole.html), [`iam:DeleteRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteRole.html), [`iam:PutRolePolicy`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutRolePolicy.html), [`iam:AttachRolePolicy`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachRolePolicy.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Retrieve configurations, compare it against the desired state, and apply any necessary updates to the IAM roles: `arn:aws:iam::*:role/forch-orchestrator`, `arn:aws:iam::*:role/forch-node`, `arn:aws:iam::*:role/forch-nat-*`, `arn:aws:iam::*:role/forch-agent` |
    | [`iam:CreateServiceLinkedRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateServiceLinkedRole.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Create a service-linked role for the forch-agent linked service to AWS KMS                                                                                                                                                                                        |
    | [`iam:PassRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_PassRole.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Allows `forch-agent` to pass the forch-nat or forch-node role when launching NAT, SSH Forwarder and Pod Router instances                                                                                                                                          |
    | [`iam:CreatePolicy`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreatePolicy.html), [`iam:GetPolicy`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html), [`iam:DeletePolicy`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeletePolicy.html), [`iam:CreatePolicyVersion`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreatePolicyVersion.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Retrieve configuration, compare it against the desired state, and apply any necessary updates to the IAM roles: `arn:aws:iam::*:policy/forch-orchestrator-base`, `arn:aws:iam::*:policy/forch-node-base`, `arn:aws:iam::*:policy/forch-agent-delete-permissions`  |
    | [`iam:CreateInstanceProfile`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateInstanceProfile.html), [`iam:DeleteInstanceProfile`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteInstanceProfile.html), [`iam:AddRoleToInstanceProfile`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_AddRoleToInstanceProfile.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Create and manage instance profiles: `arn:aws:iam::*:instance-profile/forch-nat-*`, `arn:aws:iam::*:instance-profile/forch-node`                                                                                                                                  |
    | [`ec2:CreateTags`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Tag ec2 resources created by forch-agent                                                                                                                                                                                                                          |
    | [`ec2:CreateKeyPair`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateKeyPair.html), [`ec2:DeleteKeyPair`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DeleteKeyPair.html), [`ec2:ImportKeyPair`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ImportKeyPair.html), [`ec2:DescribeKeyPairs`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeKeyPairs.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Create, import and manage a specific SSH key pair for access to forch-created instances                                                                                                                                                                           |
    | [`ec2:CreateVpc`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVpc.html), [`ec2:DescribeVpcs`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html), [`ec2:DescribeVpcAttribute`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcAttribute.html), [`ec2:CreateInternetGateway`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateInternetGateway.html), [`ec2:AttachInternetGateway`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AttachInternetGateway.html), [`ec2:DescribeInternetGateways`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInternetGateways.html), [`ec2:CreateSecurityGroup`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateSecurityGroup.html), [`ec2:AuthorizeSecurityGroupIngress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AuthorizeSecurityGroupIngress.html)/[`Egress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AuthorizeSecurityGroupEgress.html), [`ec2:RevokeSecurityGroupIngress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RevokeSecurityGroupIngress.html)/[`Egress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RevokeSecurityGroupEgress.html), [`ec2:DescribeSecurityGroups`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html), [`ec2:DescribeSecurityGroupRules`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroupRules.html), [`ec2:CreateSubnet`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateSubnet.html), [`ec2:DescribeSubnets`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html), [`ec2:ModifySubnetAttribute`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifySubnetAttribute.html), [`ec2:CreateRouteTable`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateRouteTable.html), [`ec2:CreateRoute`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateRoute.html), [`ec2:DescribeRouteTables`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRouteTables.html), [`ec2:CreateNetworkAcl`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateNetworkAcl.html), [`ec2:DeleteNetworkAclEntry`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DeleteNetworkAclEntry.html), [`ec2:CreateNetworkAclEntry`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateNetworkAclEntry.html), [`ec2:ReplaceNetworkAclAssociation`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ReplaceNetworkAclAssociation.html) | Retrieve the configuration of the Forch VPC and its associated network resources, compare it to the desired state, and apply any necessary updates                                                                                                                |
    | [`ec2:AllocateAddress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AllocateAddress.html), [`ec2:AssociateAddress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateAddress.html), [`ec2:DescribeAddresses`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html), [`ec2:DescribeAddressesAttribute`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddressesAttribute.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Provision Elastic IP address for NAT instance, SSH Forwarder and Pod Router instance and associate them to the appropriate instances                                                                                                                              |
    | [`ec2:DescribeImages`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Retrieve information about Latch-owned Forch ami image                                                                                                                                                                                                            |
    | [`ec2:RunInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html), [`ec2:DescribeInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html), [`ec2:DescribeVolumes`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVolumes.html), [`ec2:DescribeAvailabilityZones`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Retrieve information about the NAT, SSH Forwarder and Pod Router instance and launch them if not present. Instance must be launched with the `forch-node` instance profile, use the Latch-owned forch ami image and launched only with forch created ebs volumes  |
    | [`ssm:GetParameters`](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetParameters.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Allows retrieving parameters (configuration data, environment variables, etc.) from AWS Systems Manager Parameter Store. **Note:** Required by AWS for `ec2:RunInstances`                                                                                         |
    | [`secretsmanager:CreateSecret`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_CreateSecret.html), [`secretsmanager:PutSecretValue`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_PutSecretValue.html), [`secretsmanager:DeleteSecret`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_DeleteSecret.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Create and manage the forch-nat JWT token, and ssh forwarder private keys                                                                                                                                                                                         |
    | [`kms:CreateKey`](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateKey.html), [`kms:PutKeyPolicy`](https://docs.aws.amazon.com/kms/latest/APIReference/API_PutKeyPolicy.html), [`kms:EnableKeyRotation`](https://docs.aws.amazon.com/kms/latest/APIReference/API_EnableKeyRotation.html), [`kms:CreateAlias`](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateAlias.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Create and manage the forch-volume key used to encrypt / decrypt forch created EBS volumes                                                                                                                                                                        |
    | [`kms:Encrypt`](https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html), [`kms:Decrypt`](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html), [`kms:GenerateDataKey*`](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html), [`kms:CreateGrant`](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Allows usage of KMS keys to decrypt EBS volumes and AMIs when launching instances                                                                                                                                                                                 |
  </Tab>

  <Tab title="Policy Document">
    ```json theme={null}
    {
        "Statement": [
            {
                "Action": [
                    "s3:CreateBucket",
                    "s3:GetBucket*",
                    "s3:ListBucket*",
                    "s3:PutBucketCORS",
                    "s3:GetAccelerateConfiguration",
                    "s3:PutBucketVersioning",
                    "s3:GetLifecycleConfiguration",
                    "s3:GetReplicationConfiguration",
                    "s3:GetEncryptionConfiguration",
                    "s3:PutEncryptionConfiguration",
                    "s3:PutBucketRequestPayment"
                ],
                "Effect": "Allow",
                "Resource": "arn:aws:s3:::forch-${aws_account_id}"
            },
            {
                "Action": [
                    "iam:CreateRole",
                    "iam:GetRole",
                    "iam:AttachRolePolicy",
                    "iam:DeleteRole",
                    "iam:ListRolePolicies",
                    "iam:PutRolePolicy",
                    "iam:ListInstanceProfilesForRole",
                    "iam:ListAttachedRolePolicies",
                    "iam:GetRolePolicy",
                    "iam:CreateServiceLinkedRole"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:iam::*:role/forch-orchestrator",
                    "arn:aws:iam::*:role/forch-node",
                    "arn:aws:iam::*:role/forch-nat-*",
                    "arn:aws:iam::*:role/forch-agent"
                ]
            },
            {
                "Action": ["iam:CreateServiceLinkedRole"],
                "Effect": "Allow",
                "Resource": ["arn:aws:iam::*:role/forch-agent"],
                "Condition": {
                    "StringEquals": {
                        "iam:AWSServiceName": "kms.amazonaws.com"
                    }
                }
            },
            {
                "Action": ["iam:PassRole"],
                "Effect": "Allow",
                "Resource": ["arn:aws:iam::*:role/forch-nat-*", "arn:aws:iam::*:role/forch-node"]
            },
            {
                "Action": [
                    "iam:CreatePolicy",
                    "iam:GetPolicy",
                    "iam:GetPolicyVersion",
                    "iam:CreatePolicyVersion",
                    "iam:DeletePolicy",
                    "iam:DeletePolicyVersion",
                    "iam:ListPolicyVersions"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:iam::*:policy/forch-orchestrator-base",
                    "arn:aws:iam::*:policy/forch-node-base",
                    "arn:aws:iam::*:policy/forch-agent-delete-permissions"
                ]
            },
            {
                "Action": [
                    "iam:CreateInstanceProfile",
                    "iam:GetInstanceProfile",
                    "iam:DeleteInstanceProfile",
                    "iam:AddRoleToInstanceProfile"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:iam::*:instance-profile/forch-nat-*",
                    "arn:aws:iam::*:instance-profile/forch-node"
                ]
            },
            {
                "Action": "ec2:CreateTags",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": ["ec2:CreateKeyPair", "ec2:DeleteKeyPair", "ec2:ImportKeyPair"],
                "Resource": "arn:aws:ec2:*:*:key-pair/forch/debug-root",
                "Effect": "Allow"
            },
            {
                "Action": "ec2:DescribeKeyPairs",
                "Resource": "*",
                "Effect": "Allow"
            },
            {
                "Action": ["ec2:CreateVpc", "ec2:DescribeVpcs", "ec2:DescribeVpcAttribute"],
                "Resource": "*",
                "Effect": "Allow"
            },
            {
                "Action": [
                    "ec2:CreateInternetGateway",
                    "ec2:AttachInternetGateway",
                    "ec2:DescribeInternetGateways"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:CreateSecurityGroup",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:security-group/*"
            },
            {
                "Action": "ec2:CreateSecurityGroup",
                "Effect":  "Allow",
                "Resource": "arn:aws:ec2:*:*:vpc/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/Created By": "Forch"
                    }
                }
            },
            {
                "Action": [
                    "ec2:RevokeSecurityGroupEgress",
                    "ec2:RevokeSecurityGroupIngress",
                    "ec2:AuthorizeSecurityGroupIngress",
                    "ec2:AuthorizeSecurityGroupEgress"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": ["ec2:DescribeSecurityGroups", "ec2:DescribeSecurityGroupRules"],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:CreateSubnet",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:subnet/*"
            },
            {
                "Action": "ec2:CreateSubnet",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:vpc/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/Created By": "Forch"
                    }
                }
            },
            {
                "Action": ["ec2:DescribeSubnets", "ec2:ModifySubnetAttribute"],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:CreateRouteTable",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:route-table/*"
            },
            {
                "Action": "ec2:CreateRouteTable",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:vpc/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/Created By": "Forch"
                    }
                }
            },
            {
                "Action": "ec2:CreateRoute",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:DescribeRouteTables",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:CreateNetworkAcl",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:network-acl/*"
            },
            {
                "Action": "ec2:CreateNetworkAcl",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:vpc/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/Created By": "Forch"
                    }
                }
            },
            {
                "Action": "ec2:DescribeNetworkAcls",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": [
                    "ec2:DeleteNetworkAclEntry",
                    "ec2:CreateNetworkAclEntry",
                    "ec2:ReplaceNetworkAclAssociation"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:AllocateAddress",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:AssociateAddress",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:elastic-ip/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/forch/allow": "true"
                    }
                }
            },
            {
                "Action": "ec2:AssociateAddress",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:instance/*"
            },
            {
                "Action": ["ec2:DescribeAddresses", "ec2:DescribeAddressesAttribute"],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:DescribeImages",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ec2:RunInstances",
                "Condition": {
                    "ArnLike": {
                        "ec2:InstanceProfile": [
                            "arn:aws:iam::*:instance-profile/forch-node",
                            "arn:aws:iam::*:instance-profile/forch-nat-*"
                        ]
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:instance/*"
            },
            {
                "Action": "ec2:RunInstances",
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:ec2:*:*:network-interface/*",
                    "arn:aws:ec2:*:*:security-group/*",
                    "arn:aws:ec2:*:*:subnet/*"
                ]
            },
            {
                "Action": "ec2:RunInstances",
                "Condition": {
                    "StringEquals": {
                        "ec2:Owner": "812206152185"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:image/*"
            },
            {
                "Action": "ec2:RunInstances",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:key-pair/forch/debug-root"
            },
            {
                "Action": "ec2:RunInstances",
                "Resource": "arn:aws:ec2:*:*:volume/*",
                "Effect": "Allow"
            },
            {
                "Action": [
                    "ec2:DescribeInstances",
                    "ec2:DescribeInstanceTypes",
                    "ec2:DescribeTags",
                    "ec2:DescribeInstanceAttribute"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": ["ec2:DescribeVolumes"],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": ["ec2:DescribeAvailabilityZones"],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": "ssm:GetParameters",
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": [
                    "secretsmanager:CreateSecret",
                    "secretsmanager:DescribeSecret",
                    "secretsmanager:PutSecretValue",
                    "secretsmanager:DeleteSecret",
                    "secretsmanager:GetSecretValue",
                    "secretsmanager:TagResource",
                    "secretsmanager:GetResourcePolicy"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:secretsmanager:*:*:secret:forch/nat-jwt*",
                    "arn:aws:secretsmanager:*:*:secret:forch/ssh-forwarder/ssh_host_ecdsa_key*",
                    "arn:aws:secretsmanager:*:*:secret:forch/ssh-forwarder/ssh_host_rsa_key*",
                    "arn:aws:secretsmanager:*:*:secret:forch/ssh-forwarder/ssh_host_ed25519_key*"
                ]
            },
            {
                "Action": [
                    "kms:CreateKey",
                    "kms:ReplicateKey",
                    "kms:DescribeKey",
                    "kms:TagResource",
                    "kms:GetKeyPolicy",
                    "kms:GetKeyRotationStatus",
                    "kms:ListResourceTags",
                    "kms:PutKeyPolicy",
                    "kms:EnableKeyRotation",
                    "kms:CreateAlias",
                    "kms:ListAliases"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "kms:Encrypt",
                    "kms:Decrypt",
                    "kms:ReEncrypt*",
                    "kms:GenerateDataKey*",
                    "kms:DescribeKey",
                    "kms:CreateGrant"
                ],
                "Resource": "*"
            }
        ],
        "Version": "2012-10-17"
    }
    ```
  </Tab>
</Tabs>

### `forch-orchestrator`

`forch-orchestrator` is assumed at runtime to schedule and manage tasks. It has permissions to:

1. Run and Terminate ec2 instances on forch created vpc
2. Assign Private IP Addresses to ec2 instances
3. Create, Modify, Detach, Attach and Delete volumes
4. Describe, Associate and Disassociate forch created elastic ip addresses
5. Use KMS Keys to decrypt volumes
6. Get and List objects in the S3 bucket storing logs

<Tabs>
  <Tab title="Permisssions">
    | Rules                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Purpose                                                                                                                                                                                                 |
    | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | [`ec2:RunInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Allows launching EC2 instances in the Forch VPC. Instance must be launched with the `forch-node` instance profile, use the Latch-owned forch ami image and launched only with forch created ebs volumes |
    | [`iam:PassRole`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_PassRole.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Allows the orchestrator to pass the forch-node IAM role to an EC2 instance upon creation, granting the instance its required permissions                                                                |
    | [`ssm:GetParameters`](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetParameters.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Allows retrieving parameters (configuration data, environment variables, etc.) from AWS Systems Manager Parameter Store. **Note:** Required by AWS for `ec2:RunInstances`                               |
    | [`ec2:TerminateInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_TerminateInstances.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Allows terminating EC2 instances that are tagged `Created By: Forch`                                                                                                                                    |
    | [`ec2:AssignPrivateIpAddresses`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssignPrivateIpAddresses.html), [`ec2:AssignIpv6Addresses`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssignIpv6Addresses.html)                                                                                                                                                                                                                                                                                                                                   | Assign private IPv4 and public IPv6 addresses to instances within the Forch VPC                                                                                                                         |
    | [`ec2:DescribeNetworkInterfaces`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeNetworkInterfaces.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Retrieve details of network interfaces attached to forch created instance to manage IP addresses                                                                                                        |
    | [`ec2:DescribeInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html), [`ec2:DescribeInstanceStatus`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceStatus.html)                                                                                                                                                                                                                                                                                                                                           | To retrieve details and poll status of instances                                                                                                                                                        |
    | [`ec2:ModifyVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyVolume.html), [`ec2:DetachVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DetachVolume.html), [`ec2:CreateVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVolume.html), [`ec2:DeleteVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DeleteVolume.html), [`ec2:AttachVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AttachVolume.html)                                                             | To manage EBS volumes created by forch orchestrator                                                                                                                                                     |
    | [`ec2:DetachVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DetachVolume.html), [`ec2:AttachVolume`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AttachVolume.html)                                                                                                                                                                                                                                                                                                                                                                         | Allows attaching/detaching volumes to/from instances using the forch-node Instance Profile AND is tagged `Created By: Forch`                                                                            |
    | [`ec2:DescribeVolumesModifications`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVolumesModifications.html), [`ec2:DescribeVolumes`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVolumes.html)                                                                                                                                                                                                                                                                                                                                   | Retrieve details of EBS volumes and storage device resize operations                                                                                                                                    |
    | [`ec2:DisassociateAddress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisassociateAddress.html), [`ec2:AssociateAddress`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateAddress.html)                                                                                                                                                                                                                                                                                                                                                   | Attach / Detach Elastic IPs to instances in the Forch VPC                                                                                                                                               |
    | [`ec2:DescribeAddresses`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Allows retrieving details of all Elastic IP addresses in the account                                                                                                                                    |
    | [`ec2:CreateTags`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Tag ec2 instances created by forch orchestrator                                                                                                                                                         |
    | [`s3:GetObject`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Retrieve logs from the log storage s3 bucket                                                                                                                                                            |
    | [`s3:ListBucket`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | List the contents of the log storage S3 bucket                                                                                                                                                          |
    | [`sts:AssumeRole`](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Allows the forch orchestrator to assume another IAM role in the AWS account                                                                                                                             |
    | [`secretsmanager:UpdateSecret`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_UpdateSecret.html), [`secretsmanager:CreateSecret`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_CreateSecret.html)                                                                                                                                                                                                                                                                                                                                   | Create and update secrets tagged with `forch/allow: true`                                                                                                                                               |
    | [`kms:ReEncrypt*`](https://docs.aws.amazon.com/kms/latest/APIReference/API_ReEncrypt.html), [`kms:GenerateDataKey*`](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html), [`kms:Encrypt`](https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html), [`kms:DescribeKey`](https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html), [`kms:Decrypt`](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html), [`kms:CreateGrant`](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html) | Allows usage of KMS keys to decrypt EBS volumes and AMIs when launching instances                                                                                                                       |
  </Tab>

  <Tab title="Policy Document">
    ```json theme={null}
    {
        "Statement": [
            {
                "Action": "ec2:RunInstances",
                "Condition": {
                    "StringEquals": {
                        "ec2:InstanceProfile": "arn:aws:iam::${aws_account_id}:instance-profile/forch-node"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:instance/*",
                "Sid": "ForchRunInstance"
            },
            {
                "Action": "ec2:RunInstances",
                "Condition": {
                    "StringEquals": {
                        "ec2:Vpc": "arn:aws:ec2:${aws_region}:${aws_account_id}:vpc/${vpc_id}""ec2:Vpc": "${vpc_arn}"
                    }
                },
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:ec2:*:*:subnet/*",
                    "arn:aws:ec2:*:*:security-group/*",
                    "arn:aws:ec2:*:*:network-interface/*"
                ],
                "Sid": "ForchRunInstanceVpcPolicy"
            },
            {
                "Action": "ec2:RunInstances",
                "Condition": {
                    "StringEquals": {
                        "ec2:Owner": "812206152185"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:image/*",
                "Sid": "ForchRunInstanceImages"
            },
            {
                "Action": "ec2:RunInstances",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:${aws_region}:${aws_account_id}:key-pair/forch/debug-root",
                "Sid": "ForchRunInstanceKeyPair"
            },
            {
                "Action": "ec2:RunInstances",
                "Effect": "Allow",
                "Resource": "arn:aws:ec2:*:*:volume/*",
                "Sid": "ForchRunInstanceVolumes"
            },
            {
                "Action": "iam:PassRole",
                "Effect": "Allow",
                "Resource": "arn:aws:iam::${aws_account_id}:role/forch-node",
                "Sid": "ForchNodePassRole"
            },
            {
                "Action": "ssm:GetParameters",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "SystemMangerParamters"
            },
            {
                "Action": "ec2:TerminateInstances",
                "Condition": {
                    "StringEquals": {
                        "ec2:ResourceTag/Created By": "Forch"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:instance/*",
                "Sid": "ForchTerminateNode"
            },
            {
                "Action": [
                    "ec2:AssignPrivateIpAddresses",
                    "ec2:AssignIpv6Addresses"
                ],
                "Condition": {
                    "StringEquals": {
                        "ec2:Vpc": "arn:aws:ec2:${aws_region}:${aws_account_id}:vpc/${vpc_id}"
                    }
                },
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "ForchNodeIps"
            },
            {
                "Action": [
                    "ec2:DescribeNetworkInterfaces",
                    "ec2:DescribeInstances",
                    "ec2:DescribeInstanceStatus"
                ],
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "ForchNodeDescribeInfo"
            },
            {
                "Action": [
                    "ec2:ModifyVolume",
                    "ec2:DetachVolume",
                    "ec2:CreateVolume",
                    "ec2:DeleteVolume",
                    "ec2:AttachVolume"
                ],
                "Condition": {
                    "StringEquals": {
                        "ec2:ResourceTag/CreatedBy": [
                            "nucleus/create_volume",
                            "nucleus/restore_snapshot",
                            "nucleus-workflows"
                        ]
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:volume/*",
                "Sid": "ForchNodeVolumes"
            },
            {
                "Action": [
                    "ec2:DetachVolume",
                    "ec2:AttachVolume"
                ],
                "Condition": {
                    "StringEquals": {
                        "ec2:InstanceProfile": "arn:aws:iam::${aws_account_id}:instance-profile/forch-node",
                        "ec2:ResourceTag/Created By": "Forch"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:instance/*",
                "Sid": "ForchNodeVolumesAllowedInstances"
            },
            {
                "Action": [
                    "ec2:DescribeVolumesModifications",
                    "ec2:DescribeVolumes"
                ],
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "ForchNodeDescribeVolumes"
            },
            {
                "Action": [
                    "ec2:DisassociateAddress",
                    "ec2:AssociateAddress"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:ec2:${aws_region}:${aws_account_id}:elastic-ip/${eipalloc_id}",
                    "arn:aws:ec2:${aws_region}:${aws_account_id}:elastic-ip/${eipalloc_id}"
                ],
                "Sid": "ForchElasticIp"
            },
            {
                "Action": [
                    "ec2:DisassociateAddress",
                    "ec2:AssociateAddress"
                ],
                "Condition": {
                    "StringEquals": {
                        "ec2:Vpc": "arn:aws:ec2:${aws_region}:${aws_account_id}:vpc/${vpc_id}"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:network-interface/*",
                "Sid": "ForchElasticIpNetworkInterface"
            },
            {
                "Action": [
                    "ec2:DisassociateAddress",
                    "ec2:AssociateAddress"
                ],
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:instance/*",
                "Sid": "ForchElasticIpInstances"
            },
            {
                "Action": "ec2:DescribeAddresses",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "ForchDescribeElasticIp"
            },
            {
                "Action": "ec2:CreateTags",
                "Condition": {
                    "StringEquals": {
                        "ec2:InstanceProfile": "arn:aws:iam::${aws_account_id}:instance-profile/forch-node"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:instance/*",
                "Sid": "ForchTagInstances"
            },
            {
                "Action": "ec2:CreateTags",
                "Condition": {
                    "StringEquals": {
                        "ec2:ResourceTag/Created By": "Forch"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:volume/*",
                "Sid": "ForchTagVolumes"
            },
            {
                "Action": "ec2:CreateTags",
                "Condition": {
                    "StringEquals": {
                        "ec2:Vpc": "arn:aws:ec2:${aws_region}:${aws_account_id}:vpc/${vpc_id}"
                    }
                },
                "Effect": "Allow",
                "Resource": "arn:*:ec2:*:*:network-interface/*",
                "Sid": "ForchNetworkInterfaces"
            },
            {
                "Action": "s3:GetObject",
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:s3:::forch-${aws_account_id}/logs/*",
                    "arn:aws:s3:::forch-${aws_account_id}/logs"
                ],
                "Sid": "ForchFluentdReadWrite"
            },
            {
                "Action": "s3:ListBucket",
                "Effect": "Allow",
                "Resource": "arn:aws:s3:::forch-${aws_account_id}",
                "Sid": "ForchFluentdList"
            },
            {
                "Action": "sts:AssumeRole",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "AllowAssumeRole"
            },
            {
                "Action": [
                    "secretsmanager:UpdateSecret",
                    "secretsmanager:CreateSecret"
                ],
                "Condition": {
                    "StringEquals": {
                        "secretsmanager:ResourceTag/forch/allow": "true"
                    }
                },
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Action": [
                    "kms:ReEncrypt*",
                    "kms:GenerateDataKey*",
                    "kms:Encrypt",
                    "kms:DescribeKey",
                    "kms:Decrypt",
                    "kms:CreateGrant"
                ],
                "Effect": "Allow",
                "Resource": "*"
            }
        ],
        "Version": "2012-10-17"
    }
    ```
  </Tab>
</Tabs>

### `forch-node`

`forch-node` role has permission to get the task secrets from secretsmanager, read and write logs to the s3 bucket and also assume the `forch-node-shared` role to get access to ecr images and secrets from Latch's aws account. This role's can only be assumed by roles within the forch domains' cloud account.

<Tabs>
  <Tab title="Permisssions">
    | Rules                                                                                                                                                                      | Purpose                                                                                                                                                 |
    | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | [`s3:PutObject`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html), [`s3:GetObject`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html) | Store log files to the S3 bucket. Retrieve files for log verification or log rotation                                                                   |
    | [`s3:ListBucket`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html)                                                                                  | List the bucket contents to check for the existence of the logs folder, manage file rotation, or check the state of previously uploaded batches of logs |
    | [`ec2:DescribeAddresses`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAddresses.html)                                                               | Retrieve information about EC2 Elastic IP addresses attached to the instance to configure networking                                                    |
    | [`sts:AssumeRole`](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html)                                                                                | Used to assume the IAM role `forch-node-shared` to get access to resources in Latch's AWS Account (ECR images, secrets)                                 |
    | [`secretsmanager:GetSecretValue`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html)                                                  | Retrieve secrets tagged with `forch/allow: true`                                                                                                        |
    | [`secretsmanager:BatchGetSecretValue`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_BatchGetSecretValue.html)                                        | Allows retrieving multiple secrets at once                                                                                                              |
  </Tab>

  <Tab title="Policy Document">
    ```json theme={null}
    {
        "Statement": [
            {
                "Action": [
                    "s3:PutObject",
                    "s3:GetObject"
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:s3:::forch-${aws_account_id}/logs/*",
                    "arn:aws:s3:::forch-${aws_account_id}/logs"
                ],
                "Sid": "ForchFluentdReadWrite"
            },
            {
                "Action": "s3:ListBucket",
                "Effect": "Allow",
                "Resource": "arn:aws:s3:::forch-${aws_account_id}",
                "Sid": "ForchFluentdList"
            },
            {
                "Action": "ec2:DescribeAddresses",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "ForchDescribeAddresses"
            },
            {
                "Action": "sts:AssumeRole",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "AllowAssumeRole"
            },
            {
                "Action": "secretsmanager:BatchGetSecretValue",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "BatchGetSecretValue"
            },
            {
                "Action": "secretsmanager:GetSecretValue",
                "Effect": "Allow",
                "Resource": "*",
                "Sid": "GetSecretValue",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/forch/account_id": "${aws:PrincipalAccount}",
                        "aws:ResourceTag/forch/allow": "true"
                    }
                }
            }
        ],
        "Version": "2012-10-17"
    }
    ```
  </Tab>
</Tabs>

### `forch-nat-*`

`forch-nat-*` role is a superset of forch-node. It has additional permissions to get the `nat-jwt-*` JWT token from secretsmanager to perform database authentication

<Tabs>
  <Tab title="Permisssions">
    | Rules                                                                                                                     | Purpose                                                  |
    | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
    | [`secretsmanager:GetSecretValue`](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html) | Retrieve JWT token to authenticate with Latch's database |
  </Tab>

  <Tab title="Policy Document">
    ```json theme={null}
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Action": "secretsmanager:GetSecretValue",
                "Effect": "Allow",
                "Resource": "arn:aws:secretsmanager:${aws_region}:${aws_account_id}:secret:forch/nat-jwt-*",
                "Sid": "JwtSecret"
            }
        ]
    }
    ```
  </Tab>
</Tabs>
