

# AWS Assurance identity-based policy examples

By default, users and roles can’t use AWS Assurance. To let them, an IAM administrator creates policies and adds them to roles. Users then assume the roles.

To learn how to create an IAM identity-based policy using these example JSON policy documents, see [Creating policies on the JSON tab](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-json-editor) in the *IAM User Guide*.

## Policy best practices
<a name="security-iam-service-with-iam-policy-best-practices"></a>

Identity-based policies control who can create, view, and delete AWS Assurance resources in your account. When you write these policies, follow these guidelines:
+  **Apply least-privilege permissions** – Grant only the permissions that a task needs. For more information about using IAM to apply permissions, see [Policies and permissions in IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) in the *IAM User Guide*.
+  **Scope permissions to specific environments** – Use environment ARNs or tag conditions instead of `"*"` wherever an action supports them.
+  **Use conditions to further restrict access** – Add conditions to limit when a statement applies. For example, you can require that all requests use SSL. For more information, see [IAM JSON policy elements: condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html) in the *IAM User Guide*.
+  **Validate your policies with IAM Access Analyzer ** – IAM Access Analyzer checks that your policies use valid syntax and follow best practices. For more information, see [IAM Access Analyzer policy validation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-policy-validation.html) in the *IAM User Guide*.
+  **Require multi-factor authentication (MFA)** – If you use IAM users or the root user, turn on MFA. To require MFA for API calls, add MFA conditions to your policies. For more information, see [Configuring MFA-protected API access](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_configure-api-require.html) in the *IAM User Guide*.

## Using the AWS Assurance console
<a name="security-iam-id-based-policy-examples-console"></a>

To use the AWS Assurance AWS Management Console, a principal must be able to list and view environments. The following policy grants read-only access to one environment. It also allows listing environments and environment connections, which don’t support a resource type and so use `"*"`. Attach it to users who need to view, but not change, an environment in the AWS Management Console.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ListAccountLevelItems",
            "Effect": "Allow",
            "Action": [
                "assurance:ListEnvironmentConnections",
                "assurance:ListEnvironments"
            ],
            "Resource": "*"
        },
        {
            "Sid": "ReadOneEnvironment",
            "Effect": "Allow",
            "Action": [
                "assurance:BatchGet*",
                "assurance:Get*",
                "assurance:List*"
            ],
            "Resource": "arn:aws:assurance:us-east-1:111122223333:environment/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
        }
    ]
}
```

Replace {{us-east-1}}, {{111122223333}}, and {{a1b2c3d4-5678-90ab-cdef-EXAMPLE11111}} with the Region, account ID, and environment ID of your environment.

Some AWS Management Console pages also call other services. For example, the **Identity Center access** section of the environment page reads users and groups from IAM Identity Center. To use those pages, a principal also needs the corresponding permissions for those services.

You don’t need to allow AWS Management Console permissions for users who call only the AWS CLI or the AWS Assurance API. Instead, allow access to only the actions that match the API operations that they call.

## Creating and managing environments
<a name="security-iam-id-based-policy-examples-admin"></a>

The following policy lets a principal create, view, update, tag, untag, and delete environments in one AWS account and AWS Region. It also lets the principal pass the environment’s roles to AWS Assurance and create the service-linked role. It also allows the organization reads that `CreateEnvironment` and `UpdateEnvironment` need.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CreateAndListEnvironments",
            "Effect": "Allow",
            "Action": [
                "assurance:CreateEnvironment",
                "assurance:ListEnvironments"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:RequestedRegion": "us-east-1"
                }
            }
        },
        {
            "Sid": "ManageEnvironments",
            "Effect": "Allow",
            "Action": [
                "assurance:DeleteEnvironment",
                "assurance:GetEnvironment",
                "assurance:TagResource",
                "assurance:UntagResource",
                "assurance:UpdateEnvironment"
            ],
            "Resource": "arn:aws:assurance:us-east-1:111122223333:environment/*"
        },
        {
            "Sid": "PassEnvironmentRoles",
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::111122223333:role/AssuranceOperatorRole",
                "arn:aws:iam::111122223333:role/AssuranceIdentityCenterRole"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "assurance.amazonaws.com"
                }
            }
        },
        {
            "Sid": "CreateServiceLinkedRole",
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "arn:aws:iam::111122223333:role/aws-service-role/assurance.amazonaws.com/AWSServiceRoleForAssurance",
            "Condition": {
                "StringEquals": {
                    "iam:AWSServiceName": "assurance.amazonaws.com"
                }
            }
        },
        {
            "Sid": "ReadOrganization",
            "Effect": "Allow",
            "Action": [
                "organizations:DescribeOrganization",
                "organizations:ListAWSServiceAccessForOrganization"
            ],
            "Resource": "*"
        }
    ]
}
```

Replace {{us-east-1}} and {{111122223333}} with your Region and account ID. Replace {{AssuranceOperatorRole}} and {{AssuranceIdentityCenterRole}} with the names of the roles that you specify for your environments. Remove any role that you don’t use. Keep the `CreateServiceLinkedRole` statement. AWS Assurance creates the service-linked role when you create an environment or accept an invitation.

If the environment uses a customer managed key, the principal also needs permissions on that key. For more information, see [Encryption at rest for AWS Assurance](encryption-rest.md).

## Accessing environments based on tags
<a name="security-iam-id-based-policy-examples-abac"></a>

The following policy grants read access to environments whose `team` tag matches the caller’s `team` tag. For example, a principal tagged `team=payments` can read environments tagged `team=payments`, but not environments tagged `team=identity`. `ListEnvironments` doesn’t support tag conditions, so the principal can still see every environment’s name.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ListEnvironments",
            "Effect": "Allow",
            "Action": "assurance:ListEnvironments",
            "Resource": "*"
        },
        {
            "Sid": "ReadEnvironmentsForTeam",
            "Effect": "Allow",
            "Action": [
                "assurance:BatchGet*",
                "assurance:Get*",
                "assurance:List*"
            ],
            "Resource": "arn:aws:assurance:*:111122223333:environment/*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/team": "${aws:PrincipalTag/team}"
                }
            }
        }
    ]
}
```

Replace {{111122223333}} with your account ID, and {{team}} with the tag key that you use. Condition key names aren’t case sensitive, so the `team` condition matches both `team` and `Team` tag keys. For more information, see [IAM JSON policy elements: condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html) in the *IAM User Guide*.