However, as noted in the above documentation, the rule is still included in the NIST 800-53 Rev.5 standard.
Therefore, the rule should be added back to cdk-nag for the NIST 800-53 rev 5 pack, although it can still be excluded for the AwsSolutions pack.
This also breaks custom nag packs that were importing the premade rule for use, even though the change was introduced in a minor version upgrade.
Reproduction Steps
Sample 1: Using NIST 800-53 rev. 5 rule pack
import { App, Aspects, Stack } from "aws-cdk-lib";
import { Topic } from "aws-cdk-lib/aws-sns";
import { Construct } from "constructs";
import { NIST80053R5Checks } from "cdk-nag";
const app = new App();
Aspects.of(app).add(new NIST80053R5Checks({ verbose: true }));
class InfrastructureStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
// Unencrypted SNS topic
new Topic(this, "SNSTopic");
}
}
new InfrastructureStack(app, "CDKNagTest");
Sample 2: Import SNSEncryptedKMS rule into custom nag packs
import { App, Aspects, CfnResource, Stack } from 'aws-cdk-lib';
import { Construct, IConstruct } from 'constructs';
import {
NagMessageLevel,
NagPack,
NagPackProps,
rules,
} from 'cdk-nag';
import { Topic } from 'aws-cdk-lib/aws-sns';
import { Key } from 'aws-cdk-lib/aws-kms';
export class ExampleChecks extends NagPack {
constructor (props?: NagPackProps) {
super(props);
this.packName = 'Example';
}
public visit (node: IConstruct) {
if (node instanceof CfnResource) {
this.applyRule({
info: 'SNS KMS required.',
explanation: 'Please enabled SNS KMS.',
level: NagMessageLevel.ERROR,
rule: rules.sns.SNSEncryptedKMS,
node: node,
});
}
}
}
const app = new App();
Aspects.of(app).add(new ExampleChecks({ verbose: true }));
class InfrastructureStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const key = new Key(this, "Key", { enableKeyRotation: true });
new Topic(this, "SNSTopic", { masterKey: key });
}
}
new InfrastructureStack(app, "CDKNagTest");
What did you expect to happen?
Sample 1
This code is supposed to trigger an Error finding due to the SNS topic not using KMS encryption.
> tsc && cdk synth
[Error at /CDKNagTest/SNSTopic/Resource] NIST.800.53.R5-SNSEncryptedKMS: The SNS topic does not have KMS encryption enabled - (Control IDs: AU-9(3), CP-9d, SC-8(3), SC-8(4), SC-13a, SC-28(1)). To help protect data at rest, ensure that your Amazon Simple Notification Service (Amazon SNS) topics require encryption using AWS Key Management Service (AWS KMS) Because sensitive data can exist at rest in published messages, enable encryption at rest to help protect that data.
Sample 2
This code is supposed to synthesize properly into CloudFormation without a runtime error.
What actually happened?
Sample 1
cdk synth succeeds instead of raising the Error finding.
Typescript compilation fails since the rule has been deleted
> tsc && cdk synth
lib/test.ts:23:25 - error TS2339: Property 'SNSEncryptedKMS' does not exist on type 'typeof import("/Users/username/CDKTest/node_modules/cdk-nag/lib/rules/sns/index")'.
23 rule: rules.sns.SNSEncryptedKMS,
~~~~~~~~~~~~~~~
Found 1 error in lib/test.ts:23
What is the problem?
In a prior change #1821 , the SNSEncryptedKMS rule was removed from cdk-nag entirely due to updated AWS guidance that retired this control for AWS Foundational Security Best Practices: https://docs.aws.amazon.com/securityhub/latest/userguide/sns-controls.html#sns-1
However, as noted in the above documentation, the rule is still included in the NIST 800-53 Rev.5 standard.
Therefore, the rule should be added back to cdk-nag for the NIST 800-53 rev 5 pack, although it can still be excluded for the AwsSolutions pack.
This also breaks custom nag packs that were importing the premade rule for use, even though the change was introduced in a minor version upgrade.
Reproduction Steps
Sample 1: Using NIST 800-53 rev. 5 rule pack
Sample 2: Import SNSEncryptedKMS rule into custom nag packs
What did you expect to happen?
Sample 1
This code is supposed to trigger an Error finding due to the SNS topic not using KMS encryption.
Sample 2
This code is supposed to synthesize properly into CloudFormation without a runtime error.
What actually happened?
Sample 1
cdk synth succeeds instead of raising the Error finding.
Sample 2
Typescript compilation fails since the rule has been deleted
cdk-nag version
2.34.3
Language
Typescript
Other information
No response