Skip to main content
CRITICALKMSSecurity

KMS Key Policy Allows Public Access

kms-key-rotation-disabled

What this rule checks

Detects KMS keys whose key policy grants access to a wildcard or public principal.

How to fix it

  1. 1Remove wildcard/public principals from the key policy
  2. 2Scope key access to specific IAM principals or accounts
FlaggedThe key policy grants an Allow to a wildcard principal (AnyPrincipal renders Principal.AWS = '*') with no scoping Condition, so any AWS account or anonymous caller can use the key. This is a critical exposure of key material.
import { Key } from 'aws-cdk-lib/aws-kms';
import { PolicyStatement, Effect, AnyPrincipal } from 'aws-cdk-lib/aws-iam';

const key = new Key(this, 'DataKey');
key.addToResourcePolicy(new PolicyStatement({
  effect: Effect.ALLOW,
  principals: [new AnyPrincipal()],
  actions: ['kms:Decrypt', 'kms:GenerateDataKey'],
  resources: ['*'],
}));
FixedAccess is granted to a specific IAM role rather than a wildcard principal, so the key policy has no public statement. (Key rotation is also enabled as a best practice.)
import { Key } from 'aws-cdk-lib/aws-kms';
import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';

const role = new Role(this, 'AppServiceRole', { assumedBy: new ServicePrincipal('lambda.amazonaws.com') });
const key = new Key(this, 'DataKey', { enableKeyRotation: true });
key.grantDecrypt(role);

CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.

Affected resource types

AWS::KMS::Key

Compliance frameworks

SOC2HIPAAPCI-DSSCISNIST

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate โ€” a genuinely public endpoint, say. You can dismiss kms-key-rotation-disabled and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "kms-key-rotation-disabled", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::kms-key-rotation-disabled',
  reason: 'Why this is intentional',
});

Use the rule ID kms-key-rotation-disabled shown above โ€” not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs โ†’

Catch this in your stack

$ npx cdk-insights scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More KMS rules