-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AwsSolutions): new ECS, EKS, EMR, Glue, MediaStore, RDS, SNS, an…
…d SQS rules (#621) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
34 changed files
with
2,079 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { parse } from 'path'; | ||
import { CfnResource, Stack } from 'aws-cdk-lib'; | ||
import { CfnCluster } from 'aws-cdk-lib/aws-eks'; | ||
import { NagRuleCompliance, NagRules } from '../../nag-rules'; | ||
|
||
/** | ||
* EKS Clusters publish 'api', 'audit', 'authenticator, 'controllerManager', and 'scheduler' control plane logs | ||
* @param node the CfnResource to check | ||
*/ | ||
export default Object.defineProperty( | ||
(node: CfnResource): NagRuleCompliance => { | ||
if (node instanceof CfnCluster) { | ||
const logging = Stack.of(node).resolve(node.logging); | ||
if (logging === undefined) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
const clusterLogging = Stack.of(node).resolve(logging.clusterLogging); | ||
if (clusterLogging === undefined) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
const enabledTypes = Stack.of(node).resolve(clusterLogging.enabledTypes); | ||
if (!Array.isArray(enabledTypes)) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
const requiredTypes = new Set([ | ||
'api', | ||
'audit', | ||
'authenticator', | ||
'controllerManager', | ||
'scheduler', | ||
]); | ||
for (const enabled of enabledTypes) { | ||
requiredTypes.delete(NagRules.resolveIfPrimitive(node, enabled.type)); | ||
if (requiredTypes.size === 0) { | ||
break; | ||
} | ||
} | ||
if (requiredTypes.size !== 0) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
return NagRuleCompliance.COMPLIANT; | ||
} else if (node.cfnResourceType === 'Custom::AWSCDK-EKS-Cluster') { | ||
// The CDK uses a Custom Resource with AWS SDK calls to create EKS Clusters | ||
const props = Stack.of(node).resolve((<any>node)._cfnProperties); | ||
const clusterLogging = Stack.of(node).resolve( | ||
props?.Config?.logging?.clusterLogging | ||
); | ||
if (!Array.isArray(clusterLogging)) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
const requiredTypes = new Set([ | ||
'api', | ||
'audit', | ||
'authenticator', | ||
'controllerManager', | ||
'scheduler', | ||
]); | ||
for (const config of clusterLogging) { | ||
if (config?.enabled === true) { | ||
for (const type of config?.types) { | ||
requiredTypes.delete(type); | ||
if (requiredTypes.size === 0) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if (requiredTypes.size !== 0) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
return NagRuleCompliance.COMPLIANT; | ||
} else { | ||
return NagRuleCompliance.NOT_APPLICABLE; | ||
} | ||
}, | ||
'name', | ||
{ value: parse(__filename).name } | ||
); |
Oops, something went wrong.