

# Prerequisites and required IAM permissions for the Secrets Manager extension in AWS Systems Manager Cloud Extensions

Review the IAM permissions and resources that you need before you use the Secrets Manager extension.

**Topics**
+ [Prerequisites](#cloud-extensions-ext-secrets-manager-prerequisites-prerequisites)
+ [Required IAM permissions](#cloud-extensions-ext-secrets-manager-prerequisites-required-iam-permissions)

## Prerequisites
<a name="cloud-extensions-ext-secrets-manager-prerequisites-prerequisites"></a>

Before you use the Secrets Manager extension:

1. Create secrets in Secrets Manager.

1. Install the Cloud Extensions runtime in your Lambda function or container.

1. Create an IAM execution role that has permissions to read the secrets. For the permissions, see [Required IAM permissions](#cloud-extensions-ext-secrets-manager-prerequisites-required-iam-permissions).

1. For secrets that a customer managed AWS Key Management Service (AWS KMS) key encrypts, make sure that the role can use the key.

1. Approve the capabilities of the extension on the profile entry. For the steps, see step 4 of [Adding the extension with the AWS CLI](cloud-extensions-ext-secrets-manager-add-to-profile.md#cloud-extensions-ext-secrets-manager-add-to-profile-adding-the-extension-with-the-aws-cli).

## Required IAM permissions
<a name="cloud-extensions-ext-secrets-manager-prerequisites-required-iam-permissions"></a>

The execution role of the extension needs the following permissions. If neither the profile entry nor the profile sets an execution role, the credentials of the runtime need the permissions.
+ `secretsmanager:GetSecretValue`
+ `secretsmanager:DescribeSecret`
+ `secretsmanager:BatchGetSecretValue` on `*`, for prefetch
+ `secretsmanager:ListSecrets`, for prefetch by tag
+ `kms:Decrypt`, for secrets that a customer managed KMS key encrypts
+ `sts:AssumeRole` on each role that you pass as `roleArn`

The following example policy allows the extension to read the secrets that start with `myapp/`:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "secretsmanager:GetSecretValue",
        "secretsmanager:DescribeSecret"
      ],
      "Resource": "arn:aws:secretsmanager:region:account-id:secret:myapp/*"
    },
    {
      "Effect": "Allow",
      "Action": "kms:Decrypt",
      "Resource": "arn:aws:kms:region:account-id:key/key-id"
    }
  ]
}
```

You need the KMS permission only if a customer managed KMS key encrypts your secrets. Add the other permissions in the preceding list for the features that you use.

The trust policy of the role must allow the role that the runtime runs as to assume the role. The name of the role can contain only letters, numbers, `/`, `_`, and `-`. To set an execution role, you need `iam:PassRole` with `iam:PassedToService` set to `cloudextensions.amazonaws.com`. The runtime retrieves the profile with the credentials that it uses for AWS calls. In Lambda, those credentials belong to the function role. In a container, the credentials depend on how you run the container. Grant the credentials that the runtime uses `cloudextensions:SyncState` on all resources. For more information, see [IAM permissions for the Cloud Extensions API](cloud-extensions-security.md#cloud-extensions-security-iam-permissions-for-the-cloud-extensions-api).

After a secret is in the cache, any caller that can reach the extension and pass its caller authentication can read the secret. For more information, see [Security considerations for the Secrets Manager extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-secrets-manager-security.md).