Skip to content
IAM Policy Generator

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

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.

Open the workbench ยท All examples

{
  "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.

What it allows

  1. Allow 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.

    Action or patternActionsAccess levels
    kms:*58List 7, Read 7, Write 38, Permissions management 4, Tagging 2
  2. Allow 9 actions (kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey) on every resource for AWS arn:aws:iam::111122223333:role/app-role.

    Action or patternActionsAccess levels
    kms:Encrypt1Write 1
    kms:Decrypt1Write 1
    kms:ReEncrypt*2Write 2
    kms:GenerateDataKey*4Write 4
    kms:DescribeKey1Read 1

Checks

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

{
  "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.

What it allows

  1. Allow 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.

    Action or patternActionsAccess levels
    kms:*58List 7, Read 7, Write 38, Permissions management 4, Tagging 2
  2. Allow 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.

    Action or patternActionsAccess levels
    kms:Encrypt1Write 1
    kms:Decrypt1Write 1
    kms:ReEncrypt*2Write 2
    kms:GenerateDataKey*4Write 4
    kms:DescribeKey1Read 1

Checks

Sources

  1. AWS KMS Developer Guide: default key policy, read 16 Nov 2026
  2. AWS KMS Developer Guide: key policies, read 16 Nov 2026
  3. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.