Skip to content

Commit f2d5276

Browse files
author
Joshua Leaverton
committed
Updated to v1.1.0
1 parent 6a3bd42 commit f2d5276

36 files changed

+1770
-1106
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.0] - 2020-11-15
8+
### Changed
9+
- Added support for AWS partitions other than 'aws' (aws-us-gov, aws-cn)
10+
- Updated CDK support to 1.68.0
11+
712
## [1.0.1] - 2020-09-18
813
### Changed
914
- Added info-level messages indicating action (CREATE/UPDATE) from the CreateCustomAction lambda

deployment/build-s3-dist.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# - version-code: version of the package
1818

1919
# Important: CDK global version number
20-
required_cdk_version=1.60.0
20+
required_cdk_version=1.68.0
2121

2222
# Functions to reduce repetitive code
2323
# do_cmd will exit if the command has a non-zero return code.
@@ -204,10 +204,8 @@ do_cmd npm install -s
204204
do_cmd npm run build
205205

206206
# Create the template for the compliance pack
207-
cdk synth CisStack -c solutionId=$SOLUTION_ID > $template_dist_dir/playbooks/CIS.template
208-
echo -e "AWSTemplateFormatVersion: \"2010-09-09\"\n$(cat ${template_dist_dir}/playbooks/CIS.template)" > $template_dist_dir/playbooks/CIS.template
209-
cdk synth CisPermissionsStack -c solutionId=$SOLUTION_ID > $template_dist_dir/playbooks/CISPermissions.template
210-
echo -e "AWSTemplateFormatVersion: \"2010-09-09\"\n$(cat ${template_dist_dir}/playbooks/CISPermissions.template)" > $template_dist_dir/playbooks/CISPermissions.template
207+
cdk --no-version-reporting synth CisStack > $template_dist_dir/playbooks/CIS.template
208+
cdk --no-version-reporting synth CisPermissionsStack > $template_dist_dir/playbooks/CISPermissions.template
211209

212210
if [[ -d ./lambda ]]; then
213211
do_cmd mkdir -p ${build_dir}/playbooks/CIS/tests # output directory
@@ -243,18 +241,14 @@ cd $temp_work_dir/source/solution_deploy
243241
for template in `cdk ls`; do
244242
echo Create template $template
245243
# do_cmd npm run build
246-
cdk synth $template -c solutionId=$SOLUTION_ID > ${template_dist_dir}/${template}.template
244+
cdk --no-version-reporting synth $template -c solutionId=$SOLUTION_ID > ${template_dist_dir}/${template}.template
247245
done
248246
cd ${template_dir}
249247

250248
[ -e ${template_dir}/*.template ] && do_cmd cp $template_dir/*.template $template_dist_dir/
251249

252-
for f in ${template_dist_dir}/*.template; do
253-
echo Prepending AWSTemplateFormatVersion
254-
echo -e "AWSTemplateFormatVersion: \"2010-09-09\"\n$(cat $f)" > $f
255-
done
256-
257250
# Rename SolutionDeployStack.template
258251
mv ${template_dist_dir}/SolutionDeployStack.template ${template_dist_dir}/aws-sharr-deploy.template
252+
mv ${template_dist_dir}/ServiceCatalogStack.template ${template_dist_dir}/aws-sharr-portolio-deploy.template
259253

260254
echo Build Complete

deployment/run-unit-tests.sh

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ maxrc=0
1010
rc=0
1111
export overrideWarningsEnabled=false
1212

13+
[[ $1 == 'update' ]] && {
14+
update="true"
15+
echo "UPDATE MODE: CDK Snapshots will be updated. CDK UNIT TESTS WILL BE SKIPPED"
16+
} || update="false"
17+
1318
#!/bin/bash
1419
echo 'Installing required Python testing modules'
1520
pip install -r ./testing_requirements.txt
1621

1722
# Get reference for all important folders
1823
template_dir="$PWD"
19-
source_dir="$template_dir/temp/source"
24+
source_dir="$template_dir/../source"
25+
temp_source_dir="$template_dir/temp/source"
26+
2027
if [[ -e './solution_env.sh' ]]; then
2128
chmod +x ./solution_env.sh
2229
source ./solution_env.sh
@@ -50,18 +57,23 @@ fi
5057
echo "------------------------------------------------------------------------------"
5158
echo "[Test] CDK Unit Tests - playbook CIS"
5259
echo "------------------------------------------------------------------------------"
53-
cd $source_dir/playbooks/CIS
54-
npm run test
55-
rc=$?
56-
echo CDK Unit Tests RC=$rc
57-
if [ "$rc" -gt "$maxrc" ]; then
58-
maxrc=$rc
59-
fi
60+
cd $temp_source_dir/playbooks/CIS
61+
[[ $update == "true" ]] && {
62+
npm run test -- -u
63+
cp -f test/__snapshots__/* $source_dir/playbooks/CIS/test/__snapshots__/
64+
} || {
65+
npm run test
66+
rc=$?
67+
echo CDK Unit Tests RC=$rc
68+
if [ "$rc" -gt "$maxrc" ]; then
69+
maxrc=$rc
70+
fi
71+
}
6072

6173
echo "------------------------------------------------------------------------------"
6274
echo "[Test] CDK Unit Tests - core"
6375
echo "------------------------------------------------------------------------------"
64-
cd $source_dir/playbooks/core
76+
cd $temp_source_dir/playbooks/core
6577
npm run test
6678
rc=$?
6779
echo CDK Unit Tests RC=$rc
@@ -73,13 +85,18 @@ fi
7385
echo "------------------------------------------------------------------------------"
7486
echo "[Test] CDK Unit Tests - solution_deploy"
7587
echo "------------------------------------------------------------------------------"
76-
cd $source_dir/solution_deploy
77-
npm run test
78-
rc=$?
79-
echo CDK Unit Tests RC=$rc
80-
if [ "$rc" -gt "$maxrc" ]; then
81-
maxrc=$rc
82-
fi
88+
cd $temp_source_dir/solution_deploy
89+
[[ $update == "true" ]] && {
90+
npm run test -- -u
91+
cp -f test/__snapshots__/* $source_dir/solution_deploy/test/__snapshots__/
92+
} || {
93+
npm run test
94+
rc=$?
95+
echo CDK Unit Tests RC=$rc
96+
if [ "$rc" -gt "$maxrc" ]; then
97+
maxrc=$rc
98+
fi
99+
}
83100

84101
echo "------------------------------------------------------------------------------"
85102
echo "[Test] Python Unit Tests"

source/playbooks/CIS/lambda/cis1314.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# Get AWS region from Lambda environment. If not present then we're not
4141
# running under lambda, so defaulting to us-east-1
4242
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
43+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
44+
4345
# Append region name to LAMBDA_ROLE
4446
LAMBDA_ROLE += '_' + AWS_REGION
4547
BOTO_CONFIG = Config(
@@ -48,7 +50,7 @@
4850
},
4951
region_name=AWS_REGION
5052
)
51-
AWS = AWSClient()
53+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5254

5355
#------------------------------------------------------------------------------
5456
# HANDLER

source/playbooks/CIS/lambda/cis15111.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# Get AWS region from Lambda environment. If not present then we're not
4141
# running under lambda, so defaulting to us-east-1
4242
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
43+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
44+
4345
# Append region name to LAMBDA_ROLE
4446
LAMBDA_ROLE += '_' + AWS_REGION
4547
BOTO_CONFIG = Config(
@@ -48,7 +50,7 @@
4850
},
4951
region_name=AWS_REGION
5052
)
51-
AWS = AWSClient()
53+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5254

5355
#------------------------------------------------------------------------------
5456
# HANDLER

source/playbooks/CIS/lambda/cis22.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
# Get AWS region from Lambda environment. If not present then we're not
4040
# running under lambda, so defaulting to us-east-1
4141
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
42+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
43+
4244
# Append region name to LAMBDA_ROLE
4345
LAMBDA_ROLE += '_' + AWS_REGION
4446
BOTO_CONFIG = Config(
@@ -47,7 +49,7 @@
4749
},
4850
region_name=AWS_REGION
4951
)
50-
AWS = AWSClient()
52+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5153

5254
#------------------------------------------------------------------------------
5355
# HANDLER

source/playbooks/CIS/lambda/cis23.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.awsapi_helpers import AWSClient, BotoSession
2424
from lib.applogger import LogHandler
2525
from lib.metrics import Metrics
26+
from lib.aws_utils import remove_arn_prefix
2627

2728
#------------------------------
2829
# Remediation-Specific
@@ -40,6 +41,8 @@
4041
# Get AWS region from Lambda environment. If not present then we're not
4142
# running under lambda, so defaulting to us-east-1
4243
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
44+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
45+
4346
# Append region name to LAMBDA_ROLE
4447
LAMBDA_ROLE += '_' + AWS_REGION
4548
BOTO_CONFIG = Config(
@@ -48,7 +51,7 @@
4851
},
4952
region_name=AWS_REGION
5053
)
51-
AWS = AWSClient()
54+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5255

5356
#------------------------------------------------------------------------------
5457
# HANDLER
@@ -126,7 +129,7 @@ def failed():
126129
raw_bucket_info = str(finding.details['Resources'][0]['Id'])
127130

128131
# Remove ARN string, create new variable
129-
noncompliant_bucket = raw_bucket_info.replace("arn:aws:s3:::", "")
132+
noncompliant_bucket = remove_arn_prefix(raw_bucket_info)
130133

131134
except Exception as e:
132135
message['Note'] = str(e) + ' - Finding format is not as expected.'
@@ -153,11 +156,11 @@ def failed():
153156
remove_public = s3.put_public_access_block(
154157
Bucket=noncompliant_bucket,
155158
PublicAccessBlockConfiguration={
156-
'BlockPublicAcls': True,
157-
'IgnorePublicAcls': True,
158-
'BlockPublicPolicy': True,
159-
'RestrictPublicBuckets': True
160-
}
159+
'BlockPublicAcls': True,
160+
'IgnorePublicAcls': True,
161+
'BlockPublicPolicy': True,
162+
'RestrictPublicBuckets': True
163+
}
161164
)
162165

163166
LOGGER.debug(remove_public)

source/playbooks/CIS/lambda/cis24.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
# Get AWS region from Lambda environment. If not present then we're not
4444
# running under lambda, so defaulting to us-east-1
4545
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
46+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
47+
4648
# Append region name to LAMBDA_ROLE
4749
LAMBDA_ROLE += '_' + AWS_REGION
4850
BOTO_CONFIG = Config(
@@ -51,7 +53,7 @@
5153
},
5254
region_name=AWS_REGION
5355
)
54-
AWS = AWSClient()
56+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5557

5658
#------------------------------------------------------------------------------
5759
# HANDLER
@@ -140,7 +142,8 @@ def failed():
140142
# Set name for Cloudwatch logs group
141143
cloudwatchLogGroup = 'CloudTrail/CIS2-4-' + non_compliant_trail
142144
# CloudTrail to CloudWatch logging IAM Role on for each account
143-
cloudtrailLoggingArn = 'arn:aws:iam::' + finding.account_id + ':role/SO0111_CIS24_remediationRole_' + AWS_REGION
145+
cloudtrailLoggingArn = 'arn:' + AWS_PARTITION + ':iam::' + \
146+
finding.account_id + ':role/SO0111_CIS24_remediationRole_' + AWS_REGION
144147

145148
# Connect to APIs
146149
try:

source/playbooks/CIS/lambda/cis26.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.awsapi_helpers import AWSClient, BotoSession
2424
from lib.applogger import LogHandler
2525
from lib.metrics import Metrics
26+
from lib.aws_utils import remove_arn_prefix
2627

2728
#------------------------------
2829
# Remediation-Specific
@@ -43,6 +44,8 @@
4344
# Get AWS region from Lambda environment. If not present then we're not
4445
# running under lambda, so defaulting to us-east-1
4546
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
47+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
48+
4649
# Append region name to LAMBDA_ROLE
4750
LAMBDA_ROLE += '_' + AWS_REGION
4851
BOTO_CONFIG = Config(
@@ -51,7 +54,7 @@
5154
},
5255
region_name=AWS_REGION
5356
)
54-
AWS = AWSClient()
57+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5558

5659
#------------------------------------------------------------------------------
5760
# HANDLER
@@ -127,7 +130,7 @@ def failed():
127130
try:
128131
ctBucket = str(finding.details['Resources'][0]['Id'])
129132
# Remove ARN string, create new variable
130-
formattedCTBucket = ctBucket.replace("arn:aws:s3:::", "")
133+
formattedCTBucket = remove_arn_prefix(ctBucket)
131134
except Exception as e:
132135
message['Note'] = str(e) + ' - Finding format is not as expected.'
133136
message['State'] = 'FAILED'
@@ -205,7 +208,8 @@ def failed():
205208
'GranteeUri': ['http://acs.amazonaws.com/groups/s3/LogDelivery'], ## Must Use URI, fails with Canonical Group Id
206209
'TargetPrefix' : [formattedCTBucket + '/'],
207210
'TargetBucket': [accessLoggingBucket],
208-
'AutomationAssumeRole': ['arn:aws:iam::' + finding.account_id + ':role/' + LAMBDA_ROLE]
211+
'AutomationAssumeRole': ['arn:' + AWS_PARTITION + ':iam::' + \
212+
finding.account_id + ':role/' + LAMBDA_ROLE]
209213
}
210214
)
211215
LOGGER.debug(response)

source/playbooks/CIS/lambda/cis28.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
LOGGER = Logger(loglevel=LOG_LEVEL)
3939
APPLOGGER = LogHandler(PLAYBOOK) # application LOGGER for CW Logs
4040

41-
4241
# Get AWS region from Lambda environment. If not present then we're not
4342
# running under lambda, so defaulting to us-east-1
4443
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'us-east-1')
44+
AWS_PARTITION = os.getenv('AWS_PARTITION', 'aws')
45+
4546
# Append region name to LAMBDA_ROLE
4647
LAMBDA_ROLE += '_' + AWS_REGION
4748
BOTO_CONFIG = Config(
@@ -50,7 +51,7 @@
5051
},
5152
region_name=AWS_REGION
5253
)
53-
AWS = AWSClient()
54+
AWS = AWSClient(AWS_PARTITION, AWS_REGION)
5455

5556
#------------------------------------------------------------------------------
5657
# HANDLER

0 commit comments

Comments
 (0)