-
Notifications
You must be signed in to change notification settings - Fork 137
Security Hub Timestamp fixed #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21de229
create layer script/template changes
himanshu219 3b51b01
adding deploy function/adding stockholm region
himanshu219 0bdf888
Merge branch 'hpal_newregion_fixes' into sechub_timestamp_fix
himanshu219 d450731
function modified to accept string
himanshu219 a72056e
package.yaml updated with new version
himanshu219 7c6f28f
file path change
himanshu219 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change regions to an explicit map in case someone already claimed a bucket with the same format for a new region.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to find a better way for escaping strings in associated arrays in bash script.