Skip to content

Commit 287a742

Browse files
committed
05142022 - Add cfn_nag
1 parent 96bd011 commit 287a742

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

application/application_stack.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
aws_glue_alpha as glue,
77
aws_iam as iam,
88
aws_s3 as s3,
9+
aws_logs as logs,
910
aws_s3_deployment as s3_deployment,
10-
Stack,RemovalPolicy,Aws,Duration,CfnOutput
11+
Aspects,Stack,RemovalPolicy,Aws,Duration,CfnOutput
1112

1213
)
1314
from constructs import Construct
1415

1516
import json,os
1617

18+
from cdk_nag import ( AwsSolutionsChecks, NagSuppressions )
19+
1720
class ApplicationStack(Stack):
1821

1922
def create_pypi_repo(self):
@@ -39,6 +42,29 @@ def create_code_repo(self):
3942
def __init__(self, scope: Construct, construct_id: str, cidr_block: str,**kwargs) -> None:
4043
super().__init__(scope, construct_id, **kwargs)
4144

45+
############################################
46+
##
47+
## CDK Nag - https://pypi.org/project/cdk-nag/
48+
## https://github.com/cdklabs/cdk-nag
49+
##
50+
## CDK Nag Checks for AWS Engagement Solutions Secuirty Rules:
51+
## https://github.com/cdklabs/cdk-nag/blob/main/RULES.md#awssolutions
52+
## Also checks for:
53+
## HIPAA Security
54+
## NIST 800-53 rev 4
55+
## NIST 800-53 rev 5
56+
##
57+
############################################
58+
Aspects.of(self).add(AwsSolutionsChecks())
59+
##
60+
## Supressed Errors
61+
##
62+
NagSuppressions.add_stack_suppressions(self, [{"id":"AwsSolutions-S1", "reason":"TODO: Set *server_access_logs_bucket* and *server_access_logs_prefix* to enable server access logging."}])
63+
NagSuppressions.add_stack_suppressions(self, [{"id":"AwsSolutions-IAM4", "reason":"TODO: Stop using AWS managed policies."}])
64+
NagSuppressions.add_stack_suppressions(self, [{"id":"AwsSolutions-IAM5", "reason":"TODO: Remove Wildcards in IAM roles."}])
65+
NagSuppressions.add_stack_suppressions(self, [{"id":"AwsSolutions-SF2", "reason":"TODO: Set the X-Ray Tracing on the Step Function."}])
66+
NagSuppressions.add_stack_suppressions(self, [{"id":"AwsSolutions-SF1", "reason":"TODO: Set the Step Function CloudWatch Logs log events to 'ALL' "}])
67+
4268
## Variable Initialization
4369
cdk_account_id:str = os.environ["CDK_DEFAULT_ACCOUNT"]
4470

@@ -79,6 +105,17 @@ def __init__(self, scope: Construct, construct_id: str, cidr_block: str,**kwargs
79105
)
80106
count += 1
81107

108+
log_group = logs.LogGroup(self, "enterprise-repo-log-group")
109+
110+
role = iam.Role(self, "enterprise-repo-vpc-flow-log-role",
111+
assumed_by=iam.ServicePrincipal("vpc-flow-logs.amazonaws.com")
112+
)
113+
114+
ec2.FlowLog(self, "enterprise-repo-vpc-flow-log",
115+
resource_type=ec2.FlowLogResourceType.from_vpc(self.vpc),
116+
destination=ec2.FlowLogDestination.to_cloud_watch_logs(log_group, role)
117+
)
118+
82119
########################################
83120
##
84121
## S3 Bucket

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
aws-cdk-lib==2.7.0
22
constructs>=10.0.0
33
#boto3==1.21.16
4-
aws_cdk.aws_glue_alpha
4+
aws_cdk.aws_glue_alpha
5+
cdk-nag>=1.0.0,<=2.0.0

0 commit comments

Comments
 (0)