-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from SumoLogic/sechub_timestamp_fix
Security Hub Timestamp fixed
- Loading branch information
Showing
13 changed files
with
294 additions
and
31 deletions.
There are no files selected for viewing
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,139 @@ | ||
{ | ||
|
||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Outputs": { | ||
"CloudWatchEventFunction": { | ||
"Description": "CloudWatchEvent Processor Function ARN", | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"CloudWatchEventFunction", | ||
"Arn" | ||
] | ||
}, | ||
"Export" : { | ||
"Name" : { "Fn::Join": [ "-", [ "CloudWatchEventFunctionArn", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] } | ||
} | ||
} | ||
}, | ||
"Mappings" : { | ||
"RegionMap" : { | ||
"us-east-1": {"bucketname": "appdevzipfiles-us-east-1"}, | ||
"us-east-2": {"bucketname": "appdevzipfiles-us-east-2"}, | ||
"us-west-1": {"bucketname": "appdevzipfiles-us-west-1"}, | ||
"us-west-2": {"bucketname": "appdevzipfiles-us-west-2"}, | ||
"ap-south-1": {"bucketname": "appdevzipfiles-ap-south-1"}, | ||
"ap-northeast-2": {"bucketname": "appdevzipfiles-ap-northeast-2"}, | ||
"ap-southeast-1": {"bucketname": "appdevzipfiles-ap-southeast-1"}, | ||
"ap-southeast-2": {"bucketname": "appdevzipfiles-ap-southeast-2"}, | ||
"ap-northeast-1": {"bucketname": "appdevzipfiles-ap-northeast-1"}, | ||
"ca-central-1": {"bucketname": "appdevzipfiles-ca-central-1"}, | ||
"eu-central-1": {"bucketname": "appdevzipfiles-eu-central-1"}, | ||
"eu-west-1": {"bucketname": "appdevzipfiles-eu-west-1"}, | ||
"eu-west-2": {"bucketname": "appdevzipfiles-eu-west-2"}, | ||
"eu-west-3": {"bucketname": "appdevzipfiles-eu-west-3"}, | ||
"eu-north-1": {"bucketname": "appdevzipfiles-eu-north-1s"}, | ||
"sa-east-1": {"bucketname": "appdevzipfiles-sa-east-1"} | ||
} | ||
}, | ||
"Resources": { | ||
"CloudWatchEventFunctionCloudWatchEventTrigger": { | ||
"Type": "AWS::Events::Rule", | ||
"Properties": { | ||
"EventPattern": { | ||
"source": [ | ||
"aws.guardduty" | ||
] | ||
}, | ||
"Targets": [ | ||
{ | ||
"Id": "CloudWatchEventFunctionCloudWatchEventTriggerLambdaTarget", | ||
"Arn": { | ||
"Fn::GetAtt": [ | ||
"CloudWatchEventFunction", | ||
"Arn" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"CloudWatchEventFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]}, | ||
"S3Key": "guardduty.zip" | ||
}, | ||
"Tags": [ | ||
{ | ||
"Value": "SAM", | ||
"Key": "lambda:createdBy" | ||
} | ||
], | ||
"Environment": { | ||
"Variables": { | ||
"SUMO_ENDPOINT": { | ||
"Ref": "SumoEndpointUrl" | ||
} | ||
} | ||
}, | ||
"Handler": "cloudwatchevents.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"CloudWatchEventFunctionRole", | ||
"Arn" | ||
] | ||
}, | ||
"Timeout": 300, | ||
"Runtime": "nodejs8.10" | ||
} | ||
}, | ||
"CloudWatchEventFunctionCloudWatchEventTriggerPermission": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:invokeFunction", | ||
"Principal": "events.amazonaws.com", | ||
"FunctionName": { | ||
"Ref": "CloudWatchEventFunction" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"CloudWatchEventFunctionCloudWatchEventTrigger", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"CloudWatchEventFunctionRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"ManagedPolicyArns": [ | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
], | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Description": "This function is invoked by AWS CloudWatch events in response to state change in your AWS resources which matches a event target definition. The event payload received is then forwarded to Sumo Logic HTTP source endpoint.\n", | ||
"Parameters": { | ||
"SumoEndpointUrl": { | ||
"Type": "String" | ||
} | ||
} | ||
|
||
} |
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
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,99 @@ | ||
import boto3 | ||
import os | ||
from argparse import ArgumentParser | ||
|
||
regions = [ | ||
"us-east-2", | ||
"us-east-1", | ||
"us-west-1", | ||
"us-west-2", | ||
"ap-south-1", | ||
"ap-northeast-2", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ap-northeast-1", | ||
"ca-central-1", | ||
# "cn-north-1", | ||
"eu-central-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"eu-west-3", | ||
"eu-north-1", | ||
"sa-east-1" | ||
] | ||
|
||
|
||
def get_bucket_name(bucket_prefix, region): | ||
if region == "eu-north-1": | ||
return '%s-%ss' % (bucket_prefix, region) | ||
return '%s-%s' % (bucket_prefix, region) | ||
|
||
|
||
def upload_code_in_multiple_regions(filepath, bucket_prefix): | ||
|
||
for region in regions: | ||
upload_code_in_S3(filepath, get_bucket_name(bucket_prefix, region), region) | ||
|
||
|
||
def create_buckets(bucket_prefix): | ||
for region in regions: | ||
s3 = boto3.client('s3', region) | ||
bucket_name = get_bucket_name(bucket_prefix, region) | ||
try: | ||
if region == "us-east-1": | ||
response = s3.create_bucket(Bucket=bucket_name) # the operation is idempotent | ||
else: | ||
response = s3.create_bucket(Bucket=bucket_name, | ||
CreateBucketConfiguration={ | ||
'LocationConstraint': region | ||
}) | ||
print("Creating bucket", region, response) | ||
except: | ||
pass | ||
|
||
|
||
def upload_code_in_S3(filepath, bucket_name, region): | ||
print("Uploading zip file in S3", region) | ||
s3 = boto3.client('s3', region) | ||
filename = os.path.basename(filepath) | ||
s3.upload_file(filepath, bucket_name, filename, | ||
ExtraArgs={'ACL': 'public-read'}) | ||
|
||
|
||
def upload_cftemplate(templatepath, bucket_name, region='us-east-1'): | ||
print("Uploading template file in S3") | ||
s3 = boto3.client('s3', region) | ||
filename = os.path.basename(templatepath) | ||
s3.upload_file(templatepath, bucket_name, filename, | ||
ExtraArgs={'ACL': 'public-read'}) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument("-t", "--templatefile", dest="templatefile", | ||
help="CF template") | ||
|
||
parser.add_argument("-z", "--zipfile", dest="zipfile", | ||
help="deployment package") | ||
|
||
parser.add_argument("-d", "--deployment", dest="deployment", default="dev", | ||
help="aws account type") | ||
|
||
args = parser.parse_args() | ||
if args.deployment == "prod": | ||
zip_bucket_prefix = "appdevzipfiles" | ||
template_bucket = "appdev-cloudformation-templates" | ||
else: | ||
zip_bucket_prefix = "appdevstore" | ||
template_bucket = "cf-templates-5d0x5unchag-us-east-1" | ||
|
||
if not os.path.isfile(args.templatefile): | ||
raise Exception("templatefile does not exists") | ||
if not os.path.isfile(args.zipfile): | ||
raise Exception("zipfile does not exists") | ||
|
||
create_buckets(zip_bucket_prefix) | ||
upload_code_in_multiple_regions(args.zipfile, zip_bucket_prefix) | ||
upload_cftemplate(args.templatefile, template_bucket) | ||
print("Deployment Successfull: ALL files copied to %s" % args.deployment) |
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
mkdir python | ||
cd python | ||
pip install -r ../requirements.txt -t ./ | ||
zip -r ../securityhub_deps.zip . | ||
cd .. | ||
aws s3 cp securityhub_deps.zip s3://appdevstore/ --region us-east-1 | ||
#!bash/bin | ||
|
||
aws lambda publish-layer-version --layer-name securityhub_deps --description "contains securityhub solution dependencies" --license-info "MIT" --content S3Bucket=appdevstore,S3Key=securityhub_deps.zip --compatible-runtimes python3.7 python3.6 --region us-east-1 | ||
if [ ! -f securityhub_deps.zip ]; then | ||
echo "creating zip file" | ||
mkdir python | ||
cd python | ||
pip install -r ../requirements.txt -t ./ | ||
zip -r ../securityhub_deps.zip . | ||
cd .. | ||
fi | ||
|
||
aws lambda add-layer-version-permission --layer-name securityhub_deps --statement-id securityhub-deps --version-number 3 --principal '*' --action lambda:GetLayerVersion --region us-east-1 | ||
declare -a regions=("us-east-2" "us-east-1" "us-west-1" "us-west-2" "ap-south-1" "ap-northeast-2" "ap-southeast-1" "ap-southeast-2" "ap-northeast-1" "ca-central-1" "eu-central-1" "eu-west-1" "eu-west-2" "eu-west-3" "sa-east-1") | ||
|
||
for i in "${regions[@]}" | ||
do | ||
echo "Deploying layer in $i" | ||
bucket_name="appdevzipfiles-$i" | ||
aws s3 cp securityhub_deps.zip s3://$bucket_name/ --region $i | ||
|
||
aws lambda publish-layer-version --layer-name securityhub_deps --description "contains securityhub solution dependencies" --license-info "MIT" --content S3Bucket=$bucket_name,S3Key=securityhub_deps.zip --compatible-runtimes python3.7 python3.6 --region $i | ||
|
||
aws lambda add-layer-version-permission --layer-name securityhub_deps --statement-id securityhub-deps --version-number 1 --principal '*' --action lambda:GetLayerVersion --region $i | ||
done | ||
|
||
# aws lambda remove-layer-version-permission --layer-name securityhub_deps --version-number 1 --statement-id securityhub-deps --region us-east-1 | ||
# aws lambda get-layer-version-policy --layer-name securityhub_deps --region us-east-1 |
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
Oops, something went wrong.