-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaf_kinesis_log.yml
111 lines (105 loc) · 3.83 KB
/
waf_kinesis_log.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
AWSTemplateFormatVersion: '2010-09-09'
Description: Kinesis Firehose for WAF logs
Parameters:
AppEnvironment:
Description: Type of app environment.
Type: String
Default: staging
AllowedValues:
- staging
- production
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${AppEnvironment}-cfj-decidim-waf-log
AccessControl: LogDeliveryWrite
LifecycleConfiguration:
Rules:
- Id: !Sub ${AppEnvironment}-cfj-decidim-waf-log-life-cycle
Status: Enabled
Transitions:
- StorageClass: STANDARD_IA
TransitionInDays: 30
WAFLogDeliveryStream:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamName: !Sub "aws-waf-logs-${AppEnvironment}-cfj-decidim"
DeliveryStreamType: DirectPut
S3DestinationConfiguration:
BucketARN: !Sub "${S3Bucket.Arn}"
BufferingHints:
SizeInMBs: 5
IntervalInSeconds: 300
CloudWatchLoggingOptions:
Enabled: true
LogGroupName: !Sub "/aws/kinesisfirehose/aws-waf-logs-${AppEnvironment}-cfj-decidim"
LogStreamName: S3Delivery
CompressionFormat: GZIP
EncryptionConfiguration:
NoEncryptionConfig: NoEncryption
ErrorOutputPrefix: ""
Prefix: ""
RoleARN: !Sub "${FirehoseRole.Arn}"
WAFLogDeliveryStreamLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/kinesisfirehose/aws-waf-logs-${AppEnvironment}-cfj-decidim"
WAFLogDeliveryStreamLogStream:
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref WAFLogDeliveryStreamLogGroup
LogStreamName: S3Delivery
FirehoseRole:
Type: AWS::IAM::Role
DeletionPolicy: Retain
Properties:
RoleName: !Sub "${AppEnvironment}-cfj-decidim-FirehoseRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: firehose.amazonaws.com
Policies:
- PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- glue:GetTable
- glue:GetTableVersion
- glue:GetTableVersions
Effect: Allow
Resource: "*"
- Action:
- s3:AbortMultipartUpload
- s3:GetBucketLocation
- s3:GetObject
- s3:ListBucket
- s3:ListBucketMultipartUploads
- s3:PutObject
Effect: Allow
Resource:
- !Sub "${S3Bucket.Arn}"
- !Sub "${S3Bucket.Arn}/*"
- arn:aws:s3:::%FIREHOSE_BUCKET_NAME%
- arn:aws:s3:::%FIREHOSE_BUCKET_NAME%/*
- Action: kms:Decrypt
Effect: Allow
Resource: !Sub "arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/%SSE_KEY_ID%"
- Action:
- lambda:InvokeFunction
- lambda:GetFunctionConfiguration
Effect: Allow
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:%FIREHOSE_DEFAULT_FUNCTION%:%FIREHOSE_DEFAULT_VERSION%"
- Action: logs:PutLogEvents
Effect: Allow
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/kinesisfirehose/${S3Bucket}:log-stream:*"
- Action:
- kinesis:DescribeStream
- kinesis:GetShardIterator
- kinesis:GetRecords
Effect: Allow
Resource: !Sub "arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/%FIREHOSE_STREAM_NAME%"
PolicyName: firehose_delivery_role_policy