# IAM policy example: write a KMS key policy, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

A key policy with the two statements the AWS documentation describes: one gives the account root access so IAM policies can grant key use, and one lets a named role use the key for cryptographic actions. The rewrite narrows the key user to calls made through S3.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "EnableIamPolicies",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "kms:*",
      "Resource": "*"
    },
    {
      "Sid": "KeyUsers",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:role/app-role"
      },
      "Action": [
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:ReEncrypt*",
        "kms:GenerateDataKey*",
        "kms:DescribeKey"
      ],
      "Resource": "*"
    }
  ]
}
```

## What it allows

- The first statement lets the account's IAM policies grant any KMS action on this key.
- The second statement lets the role app-role encrypt, decrypt, re-encrypt, generate data keys and describe the key.

- Allows 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.
- Allows 9 actions (kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey) on every resource for AWS arn:aws:iam::111122223333:role/app-role.

Checks:
- high: Allows 42 write or permissions-management actions (4 permissions management) on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
- medium: Allows 8 write or permissions-management actions on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

The root statement uses kms:*, which delegates 58 actions to IAM, and the user statement has no condition on the calling service.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "EnableIamPolicies",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "kms:*",
      "Resource": "*"
    },
    {
      "Sid": "KeyUsers",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:role/app-role"
      },
      "Action": [
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:ReEncrypt*",
        "kms:GenerateDataKey*",
        "kms:DescribeKey"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "kms:ViaService": "s3.us-east-1.amazonaws.com",
          "kms:CallerAccount": "111122223333"
        }
      }
    }
  ]
}
```

The rewrite keeps the root statement, which prevents lockout, and limits the key user to calls through S3 from account 111122223333.

- Allows 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.
- Allows 9 actions (kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey) on every resource for AWS arn:aws:iam::111122223333:role/app-role when kms:ViaService StringEquals s3.us-east-1.amazonaws.com and kms:CallerAccount StringEquals 111122223333.

Checks:
- high: Allows 42 write or permissions-management actions (4 permissions management) on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
- medium: Allows 8 write or permissions-management actions on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

- [Paste it into the workbench](/)
- [Every KMS action and its access level](/actions/kms/)

## Related pages

- [IAM policy example: let an SNS topic send to an SQS queue](/examples/sqs-queue-policy-allow-sns-topic/)
- [IAM policy example: let S3 invoke a Lambda function](/examples/lambda-resource-policy-allow-s3-invoke/)
- [IAM policy example: SNS topic policy for alarms](/examples/sns-topic-policy-allow-cloudwatch-alarms/)
- [All of them](/examples/)

## Sources

- AWS KMS Developer Guide: default key policy: https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html (read 16 Nov 2026)
- AWS KMS Developer Guide: key policies: https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-overview.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/kms-key-policy-account-admin-and-key-user/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
