-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserverless.yml
More file actions
220 lines (216 loc) · 7.35 KB
/
serverless.yml
File metadata and controls
220 lines (216 loc) · 7.35 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
service: sls-aws-ct-processing
frameworkVersion: ">=1.5.0 < 2.0.0"
provider:
name: aws
runtime: python2.7
stage: ${opt:stage, self:custom.defaultStage}
profile: ${self:custom.profile}
region: ${opt:region, self:custom.defaultRegion}
cfLogs: true
stackTags:
DEPLOYMENT_TOOL: sls
OWNER: ${self:custom.owner}
DESCRIPTION: ${self:custom.description}
custom:
owner: ${self:custom.environment.owner}
description: ${self:custom.environment.description}
defaultStage: dev
defaultRegion: us-east-1
environment: ${file(environment/${opt:stage}.yml)}
profile: ${self:custom.environment.profile}
functions:
cloudtrail-process:
handler: cloudtrail.process
name: ${self:service}-${self:provider.stage}
description: This function parses through all CloudTrail logs as they are put into the primary S3 bucket, adds additional metadata, and pushes them into AWS Elasticsearch
memorySize: 512
timeout: 300
role: CloudTrailProcessRole
environment:
ES_DOMAIN_NAME: "${self:service}-${self:provider.stage}"
events:
- sns:
arn:
Fn::Join:
- ":"
- - "arn:aws:sns"
- Ref: "AWS::Region"
- Ref: "AWS::AccountId"
- "${self:service}-${self:provider.stage}-topic"
topicName: ${self:service}-${self:provider.stage}-topic
resources:
Resources:
CloudTrailProcessRole:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: ${self:service}-${self:provider.stage}
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: CloudTrailProcessPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- Fn::Join:
- ":"
-
- "arn:aws:logs"
- Ref: "AWS::Region"
- Ref: "AWS::AccountId"
- "log-group:/aws/lambda/*:*:*"
- Effect: Allow
Action:
- ec2:CreateNetworkInterface
- ec2:DescribeNetworkInterfaces
- ec2:DetachNetworkInterface
- ec2:DeleteNetworkInterface
Resource: "*"
- Effect: "Allow"
Action:
- "es:ESHttpPost"
- "es:ESHttpGet"
- "es:ESHttpPut"
- "es:DescribeElasticsearchDomain"
Resource:
- Fn::Join:
- ":"
- - "arn:aws:es"
- Ref: "AWS::Region"
- Ref: "AWS::AccountId"
- "domain/${self:service}-${self:provider.stage}"
- Fn::Join:
- ":"
- - "arn:aws:es"
- Ref: "AWS::Region"
- Ref: "AWS::AccountId"
- "domain/${self:service}-${self:provider.stage}/*"
- Effect: "Allow"
Action:
- "s3:GetObject"
Resource:
- "arn:aws:s3:::${self:custom.environment.newctbucket}/*"
ElasticsearchDomain:
DependsOn:
- CloudTrailTopic
Type: "AWS::Elasticsearch::Domain"
Properties:
DomainName: ${self:service}-${self:provider.stage}
ElasticsearchClusterConfig:
DedicatedMasterEnabled: "true"
InstanceCount: "2"
ZoneAwarenessEnabled: "true"
InstanceType: "m4.large.elasticsearch"
DedicatedMasterType: "m4.large.elasticsearch"
DedicatedMasterCount: "3"
ElasticsearchVersion: "6.2"
EncryptionAtRestOptions:
Enabled: true
EBSOptions:
EBSEnabled: true
Iops: 0
VolumeSize: 20
VolumeType: "gp2"
SnapshotOptions:
AutomatedSnapshotStartHour: "0"
AccessPolicies:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
AWS: "*"
Action: "es:*"
Resource:
- Fn::Join:
- ":"
- - "arn:aws:es"
- Ref: "AWS::Region"
- Ref: "AWS::AccountId"
- "domain/${self:service}-${self:provider.stage}/*"
Condition:
IpAddress:
aws:SourceIp: ${self:custom.environment.esipaddress}
AdvancedOptions:
rest.action.multi.allow_explicit_index: "true"
CloudTrailS3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
BucketName: ${self:custom.environment.newctbucket}
CloudTrailBucketPolicy:
DependsOn:
- CloudTrailS3Bucket
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: ${self:custom.environment.newctbucket}
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AWSCloudTrailAclCheck"
Effect: "Allow"
Principal:
Service: "cloudtrail.amazonaws.com"
Action: "s3:GetBucketAcl"
Resource: "arn:aws:s3:::${self:custom.environment.newctbucket}"
-
Sid: "AWSCloudTrailWrite"
Effect: "Allow"
Principal:
Service: "cloudtrail.amazonaws.com"
Action: "s3:PutObject"
Resource: "arn:aws:s3:::${self:custom.environment.newctbucket}/AWSLogs/*"
Condition:
StringEquals:
s3:x-amz-acl: "bucket-owner-full-control"
CloudTrailTopic:
DependsOn:
- CloudTrailProcessRole
Type: "AWS::SNS::Topic"
Properties:
DisplayName: ${self:service}-${self:provider.stage}-topic
TopicName: ${self:service}-${self:provider.stage}-topic
CloudTrailTopicPolicy:
Type: "AWS::SNS::TopicPolicy"
Properties:
Topics:
- Ref: "CloudTrailTopic"
PolicyDocument:
Version: "2008-10-17"
Statement:
-
Sid: "AWSCloudTrailSNSPolicy"
Effect: "Allow"
Principal:
Service: "cloudtrail.amazonaws.com"
Resource: "*"
Action: "SNS:Publish"
CloudTrail:
DependsOn:
- CloudTrailS3Bucket
- CloudTrailBucketPolicy
- CloudTrailTopic
- CloudTrailTopicPolicy
Type: "AWS::CloudTrail::Trail"
Properties:
S3BucketName: ${self:custom.environment.newctbucket}
IsLogging: true
SnsTopicName: ${self:service}-${self:provider.stage}-topic
EnableLogFileValidation: true
IsMultiRegionTrail: true
IncludeGlobalServiceEvents: true
TrailName: ${self:service}-${self:provider.stage}
Outputs: