

# Permissions for penetration testing

**Note**  
This guide covers Continuum for penetration testing, which you use in the AWS Continuum console. If you run penetration tests in the AWS Security Agent console or web application, see the [AWS Security Agent User Guide](https://docs.aws.amazon.com/securityagent/latest/userguide/what-is.html) instead. For the differences, see [Comparing Continuum for penetration testing and AWS Security Agent](pt-security-agent-comparison.md).  
Penetration testing policies in this guide use the `continuum:` action prefix and the `pentesting.continuum.amazonaws.com` service principal. AWS Security Agent policies use the `securityagent:` prefix and the `securityagent.amazonaws.com` service principal. A policy written for one service doesn't work for the other.

Continuum for penetration testing uses two kinds of permissions. Your users need permissions to call the penetration testing actions. AWS Continuum needs a service role in each environment so that it can access your AWS resources while it tests your application.

For policies that you can attach to your users and roles, see [Identity-based policy examples for penetration testing](pt-security-iam-policy-examples.md).

**Topics**
+ [Actions for penetration testing](#pt-security-iam-actions)
+ [Service role for penetration testing](#pt-security-iam-service-role)
+ [Identity-based policy examples for penetration testing](pt-security-iam-policy-examples.md)

## Actions for penetration testing
<a name="pt-security-iam-actions"></a>

Penetration testing actions use the `continuum` service prefix, the same as other AWS Continuum actions. The following table lists the main actions.


**Main penetration testing actions**  

| Task | Actions | 
| --- | --- | 
| Manage penetration tests | continuum:CreatePentest, continuum:UpdatePentest, continuum:BatchDeletePentests, continuum:BatchGetPentests, continuum:ListPentests | 
| Start and stop runs | continuum:StartPentestJob, continuum:StopPentestJob, continuum:BatchGetPentestJobs, continuum:ListPentestJobsForPentest | 
| Run threat models and review threats | continuum:StartPentestThreatModelRun, continuum:StopPentestThreatModelRun, continuum:ListPentestThreatModelRunsForPentest, continuum:BatchGetPentestThreatModelRuns, continuum:ListPentestThreats, continuum:BatchGetPentestThreats | 
| Review and update findings | continuum:ListPentestFindings, continuum:BatchGetPentestFindings, continuum:UpdatePentestFinding, continuum:StartPentestCodeRemediation | 
| Manage target domains | continuum:CreateTargetDomain, continuum:UpdateTargetDomain, continuum:DeleteTargetDomain, continuum:VerifyTargetDomain, continuum:BatchGetTargetDomains, continuum:ListTargetDomains | 

When you create or update a resource that uses an IAM role, such as the environment's service role, you also need permission to pass that role. Grant `iam:PassRole` on the role, and use the `iam:PassedToService` condition key with the value `pentesting.continuum.amazonaws.com`.

For an example policy, see [Example: Pass the service role to AWS Continuum](pt-security-iam-policy-examples.md#pt-security-iam-policy-examples-passrole).

## Service role for penetration testing
<a name="pt-security-iam-service-role"></a>

AWS Continuum assumes a service role in your account to reach the AWS resources that you choose for an environment, such as log groups, secrets, Lambda functions, and VPC resources. Each environment has one service role. When you create an environment in the console, AWS Continuum creates the role for you in the `/service-role/` path, and generates its permissions from the resources that you select. You don't need to write these policies by hand. This topic describes what the console creates, so that you can review and audit it.

You can also use your own role. The console accepts a role from any IAM path. A role that you choose must already have the trust policy and the base policy in this topic. When you choose resource types for the environment, the console adds or updates the per-resource policies on the role. For more information about choosing a role when you create an environment, see [Creating an environment](pt-getting-started.md#pt-getting-started-environment).

In the policies that follow, replace `{{111122223333}}` with your account ID, `{{us-east-1}}` with your Region, `{{environment-id}}` with the ID of the environment, `{{role-path}}` with the IAM path of the role, and `{{role-name}}` with the name of the role. For a role in the root path, omit the path and its slash. Replace the other placeholder values with the names or IDs of your own resources.

### Trust policy
<a name="pt-security-iam-service-role-trust"></a>

With the trust policy, the `pentesting.continuum.amazonaws.com` service principal can assume the role.

The `aws:SourceAccount` and `aws:SourceArn` conditions limit the role to calls that AWS Continuum makes for your account and for your environments. For more information about the confused deputy problem, see [The confused deputy problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html) in the *IAM User Guide*.

The value of `aws:SourceArn` depends on how you get the role.

For a role that the console creates, AWS Continuum creates the environment first, so the trust policy names the exact environment ARN:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowContinuumPentestEnvironmentAssumeRole",
      "Effect": "Allow",
      "Principal": {
        "Service": "pentesting.continuum.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "{{111122223333}}"
        },
        "ArnLike": {
          "aws:SourceArn": "arn:aws:continuum:{{us-east-1}}:{{111122223333}}:environments/{{environment-id}}"
        }
      }
    }
  ]
}
```

For an existing role that you choose when you create an environment, the environment doesn't exist yet, so its ID isn't known. Use `environments/*` in the ARN:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowContinuumPentestEnvironmentAssumeRole",
      "Effect": "Allow",
      "Principal": {
        "Service": "pentesting.continuum.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "{{111122223333}}"
        },
        "ArnLike": {
          "aws:SourceArn": "arn:aws:continuum:{{us-east-1}}:{{111122223333}}:environments/*"
        }
      }
    }
  ]
}
```

After you create the environment, we recommend that you narrow the role to that environment for least privilege. The console doesn't do this for you.

**To narrow a role that you created before the environment**

1. Copy the environment ID from the environment page in the AWS Continuum console.

1. In the trust policy, change `aws:SourceArn` from `environments/*` to `environments/{{environment-id}}`.

1. In the base policy, change the AWS Secrets Manager resource ARN and the Amazon CloudWatch Logs resource ARNs from `aws-continuum/pentest/*` to `aws-continuum/pentest/{{environment-id}}/*`.

### Permissions policies
<a name="pt-security-iam-service-role-permissions"></a>

The console attaches a base policy to the role, plus one more policy for each type of resource that you choose for the environment. If you don't choose a resource type, the role gets no permissions for it. The following table lists the policies and when each one is created.

If you use an existing role that you create before the environment, the environment ID doesn't exist yet. In the base policy, replace `aws-continuum/pentest/{{environment-id}}/*` with `aws-continuum/pentest/*`.


| Policy | Created when | Grants | 
| --- | --- | --- | 
| Base policy | Always | Read the role itself, read the secrets that AWS Continuum creates for the environment, and write test logs for the environment | 
| VPC policy | You choose a VPC, subnets, and security groups | Create and manage network interfaces, and describe VPC settings | 
| Amazon CloudWatch Logs policy | You choose Amazon CloudWatch Logs log groups | Write to the log groups that you choose | 
| AWS Secrets Manager policy | You choose AWS Secrets Manager secrets | Read the secrets that you choose | 
| Lambda policy | You choose Lambda functions | Invoke the functions that you choose | 
| Amazon S3 policy | You choose Amazon S3 buckets | Read the buckets that you choose | 

The base policy, which the console always creates:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "InspectPentestRole",
      "Effect": "Allow",
      "Action": [
        "iam:GetRole",
        "iam:SimulatePrincipalPolicy"
      ],
      "Resource": "arn:aws:iam::{{111122223333}}:role/{{role-path}}/{{role-name}}"
    },
    {
      "Sid": "ReadEnvironmentManagedSecrets",
      "Effect": "Allow",
      "Action": "secretsmanager:GetSecretValue",
      "Resource": [
        "arn:aws:secretsmanager:{{us-east-1}}:{{111122223333}}:secret:aws-continuum/pentest/{{environment-id}}/*"
      ]
    },
    {
      "Sid": "CreateEnvironmentLogGroups",
      "Effect": "Allow",
      "Action": "logs:CreateLogGroup",
      "Resource": "arn:aws:logs:{{us-east-1}}:{{111122223333}}:log-group:aws-continuum/pentest/{{environment-id}}/*",
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "{{111122223333}}"
        }
      }
    },
    {
      "Sid": "WriteEnvironmentLogs",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": [
        "arn:aws:logs:{{us-east-1}}:{{111122223333}}:log-group:aws-continuum/pentest/{{environment-id}}/*:log-stream:*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "{{111122223333}}"
        }
      }
    }
  ]
}
```

The VPC policy, which lets AWS Continuum attach a network interface to your VPC so that it can reach targets inside it:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DescribeVpcResources",
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeDhcpOptions",
        "ec2:DescribeNetworkInterfaces",
        "ec2:DescribeNetworkInterfaceAttribute",
        "ec2:DescribeSubnets",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeVpcs"
      ],
      "Resource": "*"
    },
    {
      "Sid": "CreateEnvironmentNetworkInterfaces",
      "Effect": "Allow",
      "Action": "ec2:CreateNetworkInterface",
      "Resource": [
        "arn:aws:ec2:{{us-east-1}}:{{111122223333}}:network-interface/*",
        "arn:aws:ec2:{{us-east-1}}:*:security-group/{{sg-021345abcdef6789}}",
        "arn:aws:ec2:{{us-east-1}}:*:subnet/{{subnet-0bb1c79de3EXAMPLE}}"
      ]
    },
    {
      "Sid": "ManageEnvironmentNetworkInterfaces",
      "Effect": "Allow",
      "Action": [
        "ec2:ModifyNetworkInterfaceAttribute",
        "ec2:DeleteNetworkInterface"
      ],
      "Resource": "arn:aws:ec2:{{us-east-1}}:{{111122223333}}:network-interface/*",
      "Condition": {
        "ArnEquals": {
          "ec2:Subnet": [
            "arn:aws:ec2:{{us-east-1}}:*:subnet/{{subnet-0bb1c79de3EXAMPLE}}"
          ]
        }
      }
    },
    {
      "Sid": "ModifyEnvironmentNetworkInterfaceAttachments",
      "Effect": "Allow",
      "Action": "ec2:ModifyNetworkInterfaceAttribute",
      "Resource": "arn:aws:ec2:{{us-east-1}}:{{111122223333}}:instance/*"
    },
    {
      "Sid": "CreateSelectedSubnetPermissions",
      "Effect": "Allow",
      "Action": "ec2:CreateNetworkInterfacePermission",
      "Resource": "arn:aws:ec2:{{us-east-1}}:{{111122223333}}:network-interface/*",
      "Condition": {
        "ArnEquals": {
          "ec2:Subnet": [
            "arn:aws:ec2:{{us-east-1}}:*:subnet/{{subnet-0bb1c79de3EXAMPLE}}"
          ]
        },
        "StringEquals": {
          "ec2:Permission": "INSTANCE-ATTACH"
        }
      }
    }
  ]
}
```

The Amazon CloudWatch Logs policy, scoped to the log groups that you choose. AWS Continuum uses the environment ID as the log stream prefix:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CreateSelectedLogGroups",
      "Effect": "Allow",
      "Action": "logs:CreateLogGroup",
      "Resource": [
        "arn:aws:logs:{{us-east-1}}:{{111122223333}}:log-group:{{my-log-group}}:*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "{{111122223333}}"
        }
      }
    },
    {
      "Sid": "WriteSelectedLogGroups",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": [
        "arn:aws:logs:{{us-east-1}}:{{111122223333}}:log-group:{{my-log-group}}:log-stream:{{environment-id}}/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "{{111122223333}}"
        }
      }
    }
  ]
}
```

The AWS Secrets Manager policy, scoped to the secrets that you choose, such as secrets that hold sign-in credentials for a test:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadSelectedSecrets",
      "Effect": "Allow",
      "Action": "secretsmanager:GetSecretValue",
      "Resource": [
        "arn:aws:secretsmanager:{{us-east-1}}:{{111122223333}}:secret:{{my-secret-AbCdEf}}"
      ]
    }
  ]
}
```

The Lambda policy, scoped to the functions that you choose, such as a function that returns sign-in credentials:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "InvokeSelectedFunctions",
      "Effect": "Allow",
      "Action": "lambda:InvokeFunction",
      "Resource": [
        "arn:aws:lambda:{{us-east-1}}:{{111122223333}}:function:{{my-function}}"
      ]
    }
  ]
}
```

The Amazon S3 policy, scoped to the buckets that you choose, such as a bucket that holds context for the agent:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadSelectedBuckets",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::{{amzn-s3-demo-bucket}}",
        "arn:aws:s3:::{{amzn-s3-demo-bucket}}/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:ResourceAccount": "{{111122223333}}"
        }
      }
    }
  ]
}
```

**Warning**  
Changing the permissions for the service role might stop penetration tests from reaching your resources. Edit the role only when AWS Continuum provides guidance to do so.