Enforce AWS CDK security and compliance controls with cdk-nag. Use when adding rule packs, triaging findings, writing justified suppressions, integrating checks in CI/CD, or preventing insecure infrastructure patterns in CDK stacks.
Overall
score
100%
Does it follow best practices?
Validation for skill structure
CDK Nag rules evolve over time based on changes in AWS security best practices, compliance requirements, and user feedback. Understanding rule evolution helps maintain accurate suppressions and stay current with security recommendations.
Timeline:
Background: AWS Security Hub retired the SNS.1 control on April 10, 2024, changing the official guidance on SNS encryption requirements.
AWS's Updated Position:
"By default, SNS encrypts topics at rest with disk encryption. Using AWS KMS to encrypt topics is no longer recommended as a security best practice."
Current Status:
Impact on Code:
// Before October 2024 - this suppression was needed
NagSuppressions.addResourceSuppressions(topic, [
{ id: 'AwsSolutions-SNS2', reason: 'KMS encryption configured' }, // No longer needed
{ id: 'AwsSolutions-SNS3', reason: 'SSL auto-enforced with KMS' }, // Still needed
]);
// After October 2024 - SNS2 suppression can be removed for AwsSolutions pack
NagSuppressions.addResourceSuppressions(topic, [
{ id: 'AwsSolutions-SNS3', reason: 'SSL auto-enforced with KMS' },
]);
// For compliance packs - SNS2 rule is still active
if (usingHIPAA || usingNIST || usingPCI) {
NagSuppressions.addResourceSuppressions(topic, [
{
id: 'HIPAA.Security-SNSEncryptedKMS',
reason: 'KMS encryption required for HIPAA',
},
]);
}Key Insights:
Ongoing Changes:
AwsSolutions-L1: Continuously updated as AWS deprecates older Lambda runtimesPattern:
// Rule behavior changes as runtimes are deprecated
const lambda = new Function(this, 'Function', {
runtime: Runtime.PYTHON_3_8, // May trigger AwsSolutions-L1 if deprecated
});
// Suppressions need review when runtimes change
NagSuppressions.addResourceSuppressions(lambda, [
{
id: 'AwsSolutions-L1',
reason:
'Python 3.8 required for legacy dependency compatibility. Migration planned for Q2 2024.',
},
]);Evolution Pattern: Container security rules have become more granular over time
Example:
// Newer rules are more specific about container configurations
NagSuppressions.addResourceSuppressions(taskDefinition, [
{
id: 'AwsSolutions-ECS2',
reason: 'Environment variables contain non-sensitive configuration only',
appliesTo: ['ContainerDefinition::AppContainer::Environment::NODE_ENV'],
},
]);Regular Audit Process:
// 1. Review suppressions for non-existent rules
NagSuppressions.addResourceSuppressions(topic, [
// This rule no longer exists in AwsSolutions pack
{ id: 'AwsSolutions-SNS2', reason: 'Can be removed' }, // Remove this
{ id: 'AwsSolutions-SNS3', reason: 'Still needed' }, // Keep this
]);
// 2. Check if suppressions are still needed
const bucket = new Bucket(this, 'Bucket', {
accessLogsBucket: logsBucket, // Now configured
});
// This suppression may no longer be needed:
// { id: 'AwsSolutions-S1', reason: 'Access logging configured' }// Consider documenting version context in suppressions
NagSuppressions.addResourceSuppressions(resource, [
{
id: 'AwsSolutions-L1',
reason:
'Python 3.9 required for compatibility. CDK Nag v2.28 considers this deprecated. Review after CDK Nag v3.0.',
},
]);# Test CDK Nag updates in non-production first
npm install cdk-nag@latest --save-dev
npm run cdk -- synth
# Review any new violations or removed rules
# Update suppressions as needed// Include review metadata in suppressions
NagSuppressions.addResourceSuppressions(resource, [
{
id: 'AwsSolutions-IAM5',
reason:
'CloudWatch Logs wildcard pattern required. Last reviewed: 2024-01-15 with CDK Nag v2.28',
},
]);// Script to identify potentially obsolete suppressions
const suppressionAudit = {
checkObsoleteRules: (stackSuppressions: any[]) => {
const obsoleteRules = ['AwsSolutions-SNS2']; // Known removed rules
return stackSuppressions.filter((s) => obsoleteRules.includes(s.id));
},
checkRulePackMismatch: (ruleId: string, activePacks: string[]) => {
// Logic to check if rule exists in active rule packs
},
};// Migrating from deprecated to new rule pack
// OLD:
// Aspects.of(app).add(new DeprecatedChecks());
// NEW:
Aspects.of(app).add(new UpdatedSecurityChecks());
// Update related suppressions to use new rule IDs
NagSuppressions.addResourceSuppressions(resource, [
// { id: 'Deprecated-Rule1', reason: 'Old rule' }, // Remove
{ id: 'Updated-Rule1', reason: 'Same logic, new rule ID' }, // Add
]);Rule evolution reflects the dynamic nature of cloud security. Regular review and updates ensure continued compliance with current best practices.
Install with Tessl CLI
npx tessl i pantheon-ai/cdk-nag@0.1.1