-
Notifications
You must be signed in to change notification settings - Fork 48
Eventbridge Cloudtrail Cloudformation Template #46
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
Open
klivan
wants to merge
11
commits into
master
Choose a base branch
from
ivan.klishch/eventbridge-cloudtrail-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f83f4ab
Eventbridge Cloudtrail Cloudformation Template
klivan 182362b
Rename resources
klivan 8f32fc5
Rename resources
klivan 33462f4
Some changes re: code review
klivan 8a99677
Removed unused conditions
klivan 46ab6d1
Rename dir
klivan 2ff5d38
Block public access on S3 backup bucket, and add kms encryption
klivan c6d810d
Remove unneeded permission
klivan 6d16079
Rename templates
klivan b1bd346
Update CF template to use StackSets with native regions
klivan 95336d8
Added NoEcho to the API Key
klivan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| AWSTemplateFormatVersion: 2010-09-09 | ||
| Description: Datadog AWS Cloudtrail Eventbridge Logs Integration | ||
| Parameters: | ||
| ApiKey: | ||
| Description: >- | ||
| Your Datadog API Key | ||
| Type: String | ||
| AllowedPattern: .+ | ||
| ConstraintDescription: ApiKey is required | ||
| NoEcho: true | ||
| DatadogSite: | ||
| Description: >- | ||
| Define your Datadog Site to send data to. | ||
| Type: String | ||
| Default: 'datadoghq.com' | ||
| ConstraintDescription: DatadogSite is required | ||
| AllowedValues: | ||
| - datadoghq.com | ||
| - datadoghq.eu | ||
| - us3.datadoghq.com | ||
| - us5.datadoghq.com | ||
| - ddog-gov.com | ||
| Resources: | ||
| DatadogCloudtrailLogs: | ||
| Type: AWS::Logs::LogGroup | ||
| Properties: | ||
| LogGroupName: "datadog-eventbridge-cloudtrail-stream" | ||
| RetentionInDays: 14 | ||
| HTTPLogStream: | ||
| Type: AWS::Logs::LogStream | ||
| Properties: | ||
| LogGroupName: !Ref DatadogCloudtrailLogs | ||
| LogStreamName: "http_endpoint_delivery" | ||
| S3Backup: | ||
| Type: AWS::Logs::LogStream | ||
| Properties: | ||
| LogGroupName: !Ref DatadogCloudtrailLogs | ||
| LogStreamName: "s3_backup" | ||
| DatadogCloudtrailBackupBucket: | ||
| Type: AWS::S3::Bucket | ||
| Properties: | ||
| BucketName: !Sub "datadog-aws-cloudtrail-backup-${AWS::AccountId}-${AWS::Region}" | ||
| BucketEncryption: | ||
| ServerSideEncryptionConfiguration: | ||
| - ServerSideEncryptionByDefault: | ||
| SSEAlgorithm: "aws:kms" | ||
| PublicAccessBlockConfiguration: | ||
| BlockPublicAcls: true | ||
| BlockPublicPolicy: true | ||
| IgnorePublicAcls: true | ||
| RestrictPublicBuckets: true | ||
| DatadogCloudtrailEventbridgeRole: | ||
| Type: AWS::IAM::Role | ||
| Properties: | ||
| RoleName: !Sub "DatadogCloudtrailEventbridgeRole-${AWS::Region}" | ||
| AssumeRolePolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Effect: Allow | ||
| Principal: | ||
| Service: | ||
| - events.amazonaws.com | ||
| Action: | ||
| - "sts:AssumeRole" | ||
| Path: / | ||
| Policies: | ||
| - PolicyName: "datadog_eventbridge_invoke_firehose_policy" | ||
| PolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Effect: Allow | ||
| Action: | ||
| - "firehose:PutRecord" | ||
| - "firehose:PutRecordBatch" | ||
| Resource: | ||
| - !Sub "arn:aws:firehose:${AWS::Region}:${AWS::AccountId}:deliverystream/datadog-eventbridge-cloudtrail-stream" | ||
| - PolicyName: "datadog_eventbridge_log_policy" | ||
| PolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Effect: Allow | ||
| Action: | ||
| - "logs:CreateLogGroup" | ||
| - "logs:CreateLogStream" | ||
| - "logs:PutLogEvents" | ||
| - "logs:DescribeLogStreams" | ||
| Resource: | ||
| - !Sub "arn:aws:firehose:${AWS::Region}:${AWS::AccountId}:deliverystream/datadog-eventbridge-cloudtrail-stream" | ||
| Description: A cloudtrail stream role | ||
| DatadogCloudtrailServiceRole: | ||
| Type: "AWS::IAM::Role" | ||
| Properties: | ||
| RoleName: !Sub "DatadogCloudtrailServiceRole-${AWS::Region}" | ||
| AssumeRolePolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Effect: "Allow" | ||
| Principal: | ||
| Service: | ||
| - "firehose.amazonaws.com" | ||
| Action: | ||
| - 'sts:AssumeRole' | ||
| Path: / | ||
| Policies: | ||
| - PolicyName: "datadog_cloudtrail_stream_s3_policy" | ||
| PolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Effect: "Allow" | ||
| Action: | ||
| - "s3:AbortMultipartUpload" | ||
| - "s3:GetBucketLocation" | ||
| - "s3:GetObject" | ||
| - "s3:ListBucket" | ||
| - "s3:ListBucketMultipartUploads" | ||
| - "s3:PutObject" | ||
| Resource: | ||
| - !Sub "arn:aws:s3:::datadog-aws-cloudtrail-backup-${AWS::AccountId}-${AWS::Region}" | ||
| - !Sub "arn:aws:s3:::datadog-aws-cloudtrail-backup-${AWS::AccountId}-${AWS::Region}/*" | ||
| DatadogCloudtrailKinesisFirehose: | ||
| Type: AWS::KinesisFirehose::DeliveryStream | ||
| Properties: | ||
| DeliveryStreamName: "datadog-eventbridge-cloudtrail-stream" | ||
| DeliveryStreamType: "DirectPut" | ||
| HttpEndpointDestinationConfiguration: | ||
| BufferingHints: | ||
| SizeInMBs: 4 | ||
| IntervalInSeconds: 60 | ||
| EndpointConfiguration: | ||
| Url: !Sub "https://aws-kinesis-http-intake.logs.${DatadogSite}/v1/input" | ||
| Name: "Kinesis intake" | ||
| AccessKey: !Ref ApiKey | ||
| CloudWatchLoggingOptions: | ||
| Enabled: True | ||
| LogGroupName: !Ref DatadogCloudtrailLogs | ||
| LogStreamName: "http_endpoint_delivery" | ||
| RoleARN: !GetAtt DatadogCloudtrailServiceRole.Arn | ||
| RetryOptions: | ||
| DurationInSeconds: 60 | ||
| S3BackupMode: "FailedDataOnly" | ||
| S3Configuration: | ||
| RoleARN: !GetAtt DatadogCloudtrailServiceRole.Arn | ||
| BucketARN: !GetAtt DatadogCloudtrailBackupBucket.Arn | ||
| ErrorOutputPrefix: "datadog_cloudtrail" | ||
| BufferingHints: | ||
| SizeInMBs: 4 | ||
| IntervalInSeconds: 60 | ||
| CompressionFormat: "GZIP" | ||
| CloudWatchLoggingOptions: | ||
| Enabled: True | ||
| LogGroupName: !Ref DatadogCloudtrailLogs | ||
| LogStreamName: "s3_backup" | ||
| Tags: | ||
| - Key: "Team" | ||
| Value: "aws-integration" | ||
| - Key: "StreamAccountID" | ||
| Value: !Ref "AWS::AccountId" | ||
| DatadogCloudtrailEventbridgeRule: | ||
| Type: AWS::Events::Rule | ||
| Properties: | ||
| Description: "Eventbridge Rule to Forward Cloudtrail Events to Datadog" | ||
| EventBusName: "default" | ||
| EventPattern: | ||
| detail-type: | ||
| - AWS API Call via CloudTrail | ||
| - AWS Insight via CloudTrail | ||
| - AWS Console Sign In via CloudTrail | ||
| - AWS Console Action via CloudTrail | ||
| - AWS Service Event via CloudTrail | ||
| Name: "datadog-eventbridge-cloudtrail" | ||
| RoleArn: !GetAtt DatadogCloudtrailEventbridgeRole.Arn | ||
| State: ENABLED | ||
| Targets: | ||
| - Arn: !GetAtt | ||
| - DatadogCloudtrailKinesisFirehose | ||
| - Arn | ||
| Id: Id123 | ||
| RoleArn: !GetAtt DatadogCloudtrailEventbridgeRole.Arn | ||
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,49 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Usage: ./release.sh <S3_Bucket> | ||
|
|
||
| set -e | ||
|
|
||
| # Read the S3 bucket | ||
| if [ -z "$1" ]; then | ||
| echo "Must specify a S3 bucket to publish the template" | ||
| exit 1 | ||
| else | ||
| BUCKET=$1 | ||
| fi | ||
|
|
||
| # Upload templates to a private bucket -- useful for testing | ||
| if [[ $# -eq 2 ]] && [[ $2 = "--private" ]]; then | ||
| PRIVATE_TEMPLATE=true | ||
| else | ||
| PRIVATE_TEMPLATE=false | ||
| fi | ||
|
|
||
| # Confirm to proceed | ||
| for i in *.yaml; do | ||
| [ -f "$i" ] || break | ||
| echo "About to upload $i to s3://${BUCKET}/aws/$i" | ||
| done | ||
| read -p "Continue (y/n)?" CONT | ||
| if [ "$CONT" != "y" ]; then | ||
| echo "Exiting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Update bucket placeholder | ||
| # Use datadog-cloudformation-template as the s3 template for production | ||
| cp cloudtrail-eventbridge.yaml cloudtrail-eventbridge.yaml.bak | ||
| perl -pi -e "s/<BUCKET_PLACEHOLDER>/${BUCKET}/g" cloudtrail-eventbridge.yaml | ||
| trap 'mv cloudtrail-eventbridge.yaml.bak cloudtrail-eventbridge.yaml' EXIT | ||
|
|
||
| # Upload | ||
| if [ "$PRIVATE_TEMPLATE" = true ] ; then | ||
| aws s3 cp . s3://${BUCKET}/aws --recursive --exclude "*" --include "*.yaml" | ||
| else | ||
| aws s3 cp . s3://${BUCKET}/aws --recursive --exclude "*" --include "*.yaml" \ | ||
| --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers | ||
| fi | ||
| echo "Done uploading the template, and here is the CloudFormation quick launch URL" | ||
| echo "https://console.aws.amazon.com/cloudformation/home#/stacks/create/review?stackName=datadog-aws-cloudtrail-eventbridge&templateURL=https://${BUCKET}.s3.amazonaws.com/aws/cloudtrail-eventbridge.yaml" | ||
|
|
||
| echo "Done!" |
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.
Uh oh!
There was an error while loading. Please reload this page.