-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkloadsecurity-events-aws-sns-cloudwatchlogs-cloudformation.json
More file actions
445 lines (445 loc) · 21.1 KB
/
workloadsecurity-events-aws-sns-cloudwatchlogs-cloudformation.json
File metadata and controls
445 lines (445 loc) · 21.1 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "CloudFormation template for Trend Micro Cloud One Workload Security Events - Amazon SNS Integration with Amazon CloudWatch Logs. For cost and billing purposes, all resources are tagged with Project=TrendMicro tags. Use AWS Resource Groups' tag filter to identify created resources.",
"Metadata": {
"AWS::CloudFormation::Interface": {
"ParameterGroups": [
{
"Label": {
"default": "[ Required section ]"
},
"Parameters": [
"C1WSApiSecretKey",
"C1WSCloudWatchLogRetentionPeriod"
]
},
{
"Label": {
"default": "[ Optional: resource prefixes ] Warning: These fields need to be filled only when previous deployment of the following resources exist."
},
"Parameters": [
"C1WSSnsTopicArn",
"C1WSAPIUsername"
]
}
],
"ParameterLabels": {
"C1WSApiSecretKey": {
"default": "C1WSApiSecretKey"
},
"C1WSSnsTopicArn": {
"default": "C1WSSnsTopicArn"
},
"C1WSCloudWatchLogRetentionPeriod": {
"default": "C1WSCloudWatchLogRetentionPeriod"
},
"C1WSAPIUsername": {
"default": "C1WSAPIUsername"
}
}
}
},
"Parameters": {
"C1WSApiSecretKey": {
"Type": "String",
"Description": "Cloud One Workload Security API Secret Key. To create an API key, refer https://cloudone.trendmicro.com/docs/workload-security/api-send-request/#create-an-api-key",
"ConstraintDescription": "must be a valid Cloud One Workload Security API Secret."
},
"C1WSAPIUsername": {
"Type": "String",
"Description": "Cloud One Workload Security API Username. Enter the username of the IAM User created for Workload Security. Default: CloudOneWorkloadSecurityAPIUser",
"ConstraintDescription": "must be a valid IAM User."
},
"C1WSCloudWatchLogRetentionPeriod":{
"Type": "Number",
"Description": "Choose a number of days to retain Workload Security Events in CloudWatch Logs. Choose 9999 to Never Expire",
"AllowedValues": [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, 9999]
},
"C1WSSnsTopicArn": {
"Type": "String",
"Description": "OPTIONAL. Cloud One Workload Security SNS Topic ARN. Must be a valid SNS Topic ARN configured with Cloud One Workload Security - SNS integration prior to running this template.",
"ConstraintDescription": "must be a valid SNS Topic ARN configured with Cloud One Workload Security - SNS integration prior to running this template."
}
},
"Conditions": {
"CreateC1WSSnsTopicArn": {
"Fn::Equals" : [
{
"Ref" : "C1WSSnsTopicArn"
},
""
]
},
"ProvidedC1WSSnsTopicArn": {
"Fn::Not" : [
{
"Fn::Equals" : [
{
"Ref" : "C1WSSnsTopicArn"
},
""
]
}
]
},
"IsC1WSApiSecretPresent": {
"Fn::Equals" : [
{
"Ref" : "C1WSApiSecretKey"
},
""
]
},
"IsCWLogsRetentionSetToNeverExpire": {
"Fn::Equals" : [
{
"Ref" : "C1WSCloudWatchLogRetentionPeriod"
},
9999
]
}
},
"Resources": {
"C1WSSnsTopic": {
"Type": "AWS::SNS::Topic",
"Condition": "CreateC1WSSnsTopicArn",
"Properties": {
"DisplayName": "CloudOneWorkloadSecuritySnsCWLogsTopic",
"TopicName": "CloudOneWorkloadSecuritySnsCWLogsTopic",
"KmsMasterKeyId": {
"Fn::Join" : [
"", [
"arn:aws:kms:",
{ "Ref" : "AWS::Region" },
":",
{ "Ref" : "AWS::AccountId" },
":alias/aws/sns"
]
]
},
"Tags": [
{
"Key": "Owner",
"Value": "TrendMicro"
},
{
"Key": "Product",
"Value": "CloudOneWorkloadSecurity"
},
{
"Key": "Name",
"Value": "CloudOneWorkloadSecuritySnsCWLogsTopic"
}
]
}
},
"C1WSAPIUserSnsPolicy": {
"Type": "AWS::IAM::Policy",
"Condition": "CreateC1WSSnsTopicArn",
"Properties": {
"PolicyName": "CloudOneWorkloadSecurityEvent-Sns-Policy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sns:Publish"
],
"Effect": "Allow",
"Resource": {
"Ref": "C1WSSnsTopic"
}
},
{
"Action": [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*"
],
"Effect": "Allow",
"Resource": {
"Fn::Join" : [
"", [
"arn:aws:kms:",
{ "Ref" : "AWS::Region" },
":",
{ "Ref" : "AWS::AccountId" },
":alias/aws/sns"
]
]
}
}
]
},
"Users": [
{
"Ref": "C1WSAPIUser"
}
]
}
},
"C1WSEventsCWLogsGroup": {
"Type" : "AWS::Logs::LogGroup",
"Properties" : {
"LogGroupName" : "CloudOneWorkloadSecurityEventsLogGroup",
"RetentionInDays" : { "Fn::If": [ "IsCWLogsRetentionSetToNeverExpire", { "Ref": "AWS::NoValue" }, { "Ref": "C1WSCloudWatchLogRetentionPeriod" }]}
}
},
"C1WSLambdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Description": "Workload Security Lambda IAM Role",
"Path": "/",
"RoleName": "CloudOneWorkloadSecurityLambdaRole",
"Tags": [
{
"Key": "Owner",
"Value": "TrendMicro"
},
{
"Key": "Product",
"Value": "CloudOneWorkloadSecurity"
},
{
"Key": "Name",
"Value": "CloudOneWorkloadSecurityLambdaRole"
}
]
}
},
"C1WSCWLogsLambdaPolicy": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "CloudOneWorkloadSecurityEvent-CWLogs-Policy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
{
"Fn::GetAtt": [
"C1WSEventsCWLogsGroup",
"Arn"
]
}
]
}
]
},
"Roles": [
{
"Ref": "C1WSLambdaRole"
}
]
}
},
"C1WSAPIUser": {
"Type": "AWS::IAM::User",
"Condition": "IsC1WSApiSecretPresent",
"Properties": {
"Path": "/",
"Tags": [
{
"Key": "Owner",
"Value": "TrendMicro"
},
{
"Key": "Product",
"Value": "CloudOneWorkloadSecurity"
},
{
"Key": "Name",
"Value": "CloudOneWorkloadSecurityAPIUser"
}
],
"UserName": "CloudOneWorkloadSecurityAPIUser"
}
},
"C1WSAPIUserIAMAccessKey": {
"Type": "AWS::IAM::AccessKey",
"Condition": "IsC1WSApiSecretPresent",
"Properties": {
"Status": "Active",
"UserName": {
"Ref": "C1WSAPIUser"
}
}
},
"C1WSLambdaSnsCWLogsWriter": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Description": "Trend Micro Cloud One Workload Security lambda function to read Workload Security SIEM Events from the designated SNS topic and write to the designated CloudWatch Logs Group. Refer tags for the SNS Topic and CloudWatch Logs Group information.",
"FunctionName": "CloudOneWorkloadSecurityLambdaSnsCWLogsWriter",
"Handler": "index.lambda_handler",
"Timeout": 15,
"Role": {
"Fn::GetAtt": [
"C1WSLambdaRole",
"Arn"
]
},
"Runtime": "python3.8",
"InlineCode": "import os\nimport boto3\nimport string\nimport random\nimport time\n\ncwlogs = boto3.client('logs')\ndef createLogGroup(logGroupName):\n\tcreateLogGroupResponse = cwlogs.create_log_group(\n\t\tlogGroupName=logGroupName,\n\t\ttags={\n\t\t\t\"Owner\": \"TrendMicro\",\n\t\t\t\"Product\": \"CloudOneWorkloadSecurity\",\n\t\t\t\"Name\": logGroupName\n\t\t}\n\t)\n\ndef ifLogGroupExists(logGroupName):\n\tlistLogGroupsResponse = cwlogs.describe_log_groups()\n\tfor logGroup in listLogGroupsResponse[\"logGroups\"]:\n\t\tif logGroupName in logGroup[\"logGroupName\"]:\n\t\t\treturn True\n\treturn False\n\ndef createLogStream(logGroupName, logStreamName):\n\tcreateLogStreamResponse = cwlogs.create_log_stream(\n\t\tlogGroupName=logGroupName,\n\t\tlogStreamName=logStreamName\n\t)\n\tif createLogStreamResponse[\"ResponseMetadata\"][\"HTTPStatusCode\"] == 200:\n\t\treturn logStreamName\n\treturn \"\"\n\ndef putLogEvents(logGroupName, logStreamName, logEvents):\n\n\tputLogEventsResponse = cwlogs.put_log_events(\n\t\tlogGroupName=logGroupName,\n\t\tlogStreamName=logStreamName,\n\t\tlogEvents=logEvents\n\t)\n\tif \"rejectedLogEventsInfo\" not in putLogEventsResponse:\n\t\treturn True\n\treturn False\n\ndef lambda_handler(event, context):\n\n\tlogGroupName = str(os.environ.get(\"CloudWatchLogGroupName\"))\n\tlogStreamNamePrefix = str(os.environ.get(\"CloudWatchLogStreamNamePrefix\"))\n\n\tnonce = ''.join(random.choices(string.ascii_letters + string.digits, k=8)).upper()\n\n\tlogEvents = []\n\n\tepoch_time = int(round(time.time() * 1000))\n\n\ttempDict = {}\n\ttempDict.update({\"timestamp\": epoch_time, \"message\": event[\"Records\"][0][\"Sns\"][\"Message\"]})\n\n\tlogEvents.append(tempDict)\n\n\tif len(logEvents) > 0:\n\t\tif ifLogGroupExists(logGroupName):\n\t\t\tlogStreamName = createLogStream(logGroupName, logStreamNamePrefix + \"-\" + nonce)\n\t\t\tresult = putLogEvents(logGroupName, logStreamName, logEvents)\n\t\telse:\n\t\t\tcreateLogGroup(logGroupName)\n\t\t\tlogStreamName = createLogStream(logGroupName, logStreamNamePrefix + \"-\" + nonce)\n\t\t\tresult = putLogEvents(logGroupName, logStreamName, logEvents)\n",
"Environment": {
"Variables": {
"CloudWatchLogGroupName": "CloudOneWorkloadSecurityEventsLogGroup",
"CloudWatchLogStreamNamePrefix": "CloudOneWorkloadSecurityEventsLogStream"
}
},
"Events": {
"SnsTriggerEvent": {
"Type": "SNS",
"Properties": {
"Topic": {
"Ref": "C1WSSnsTopic"
}
}
}
},
"Tags": {
"Owner": "TrendMicro",
"Product": "CloudOneWorkloadSecurity",
"Name": "CloudOneWorkloadSecurityLambdaSnsCWLogsWriter",
"SnsTopicArn": {
"Ref": "C1WSSnsTopic"
},
"CloudWatchLogGroup": {
"Fn::GetAtt": [
"C1WSEventsCWLogsGroup",
"Arn"
]
}
}
}
},
"C1WSConfigureSIEMLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Description": "Trend Micro Cloud One Workload Security lambda function to configure Workload Security SNS Event Forwarding using REST APIs",
"Handler": "index.lambda_handler",
"Timeout": 15,
"Role": {
"Fn::GetAtt": [
"C1WSLambdaRole",
"Arn"
]
},
"Runtime": "python3.8",
"Code": {
"ZipFile": "import cfnresponse\nimport urllib3\nimport json\n\ndef callCloudOneWorkloadSecurityApi(c1wsSecret, configKey, configValue):\n\tbaseUrl = 'https:\/\/app.deepsecurity.trendmicro.com\/api\/systemsettings\/'\n\turl = baseUrl + configKey\n\thttpBody = json.dumps({ \"value\": configValue })\n\thttp = urllib3.PoolManager()\n\theader = { 'Content-Type': 'application/json', 'Content-Length': str(len(httpBody)), 'Host': 'app.deepsecurity.trendmicro.com', 'api-version': 'v1', 'api-secret-key': c1wsSecret }\n\tx = http.request('POST', url, headers=header, body=httpBody)\n\treturn str(x.data)\n\ndef lambda_handler(event, context):\n\tprint(f\"Data in event: {event}\")\n\tresponse_data = \"\"\n\tresponseObj = {}\n\tif event[\"RequestType\"] == \"Create\" or event[\"RequestType\"] == \"Update\":\n\t\taws_sns_topic = str(event[\"ResourceProperties\"][\"C1WSSnsTopicArn\"])\n\t\tc1wsAwsIamUserAccesskey = str(event[\"ResourceProperties\"][\"C1WSAPIUserAccessKey\"])\n\t\tc1wsAwsIamUserSecretkey = str(event[\"ResourceProperties\"][\"C1WSAPIUserAccessSecret\"])\n\t\tc1wsApiSecretKey = str(event[\"ResourceProperties\"][\"C1WSApiSecretKey\"])\n\t\tc1wsSnsEventForwardingConfigJson = '{ \"platformSettingEventForwardingSnsAdvancedConfigEnabled\": \"false\", \"platformSettingEventForwardingSnsEnabled\": \"true\", \"platformSettingEventForwardingSnsConfigJson\": { \"Version\": \"2014-09-24\", \"Statement\": [ { \"Topic\": \"\", \"Condition\": { \"StringEquals\": { \"EventType\": [ \"SystemEvent\", \"AntiMalwareEvent\", \"WebReputationEvent\", \"AppControlEvent\", \"IntegrityEvent\", \"LogInspectionEvent\", \"PacketLog\", \"PayloadLog\" ] } } } ] }, \"platformSettingEventForwardingSnsSecretKey\": \"\", \"platformSettingEventForwardingSnsAccessKey\": \"\" }'\n\t\tc1wsSnsEventForwardingConfigDict = json.loads(c1wsSnsEventForwardingConfigJson)\n\t\tc1wsSnsEventForwardingConfigDict[\"platformSettingEventForwardingSnsConfigJson\"][\"Statement\"][0][\"Topic\"] = aws_sns_topic\n\t\tc1wsSnsEventForwardingConfigDict[\"platformSettingEventForwardingSnsSecretKey\"] = c1wsAwsIamUserSecretkey\n\t\tc1wsSnsEventForwardingConfigDict[\"platformSettingEventForwardingSnsAccessKey\"] = c1wsAwsIamUserAccesskey\n\n\t\tfor item in c1wsSnsEventForwardingConfigDict:\n\t\t\tresponse = \"\"\n\t\t\tresponse = callCloudOneWorkloadSecurityApi(c1wsApiSecretKey, str(item), str(c1wsSnsEventForwardingConfigDict[item]))\n\t\t\tresponse_data += response\n\t\t\tresponseObj = { \"Output\": response_data }\n\n\tcfnresponse.send(event, context, cfnresponse.SUCCESS, responseObj)"
},
"Tags": [
{
"Key": "Owner",
"Value": "TrendMicro"
},
{
"Key": "Product",
"Value": "CloudOneWorkloadSecurity"
},
{
"Key": "Name",
"Value": "CloudOneWorkloadSecurityLambdaConfigureSnsEventForwarding"
}
]
}
},
"CloudOneWorkloadSecurityConfigResource": {
"Type": "Custom::CloudOneWorkloadSecurityConfigResource",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"C1WSConfigureSIEMLambdaFunction",
"Arn"
]
},
"C1WSSnsTopicArn": {
"Ref": "C1WSSnsTopic"
},
"C1WSAPIUserAccessSecret": {
"Fn::GetAtt": [
"C1WSAPIUserIAMAccessKey",
"SecretAccessKey"
]
},
"C1WSAPIUserAccessKey": {
"Ref": "C1WSAPIUserIAMAccessKey"
},
"C1WSApiSecretKey": {
"Ref": "C1WSApiSecretKey"
}
}
}
},
"Outputs": {
"ProvidedC1WSSnsTopicArn": {
"Description": "Provided SNS Topic ARN for Trend Micro Cloud One Workload Security",
"Condition": "ProvidedC1WSSnsTopicArn",
"Value": {
"Ref": "C1WSSnsTopicArn"
}
},
"C1WSSnsTopicArn": {
"Description": "SNS Topic ARN for Trend Micro Cloud One Workload Security",
"Condition": "CreateC1WSSnsTopicArn",
"Value": {
"Ref": "C1WSSnsTopic"
}
},
"C1WSEventsCWLogsGroupArn": {
"Value": {
"Fn::GetAtt": [
"C1WSEventsCWLogsGroup",
"Arn"
]
},
"Description": "Bucket Name of the newly created S3 Bucket for Trend Micro Cloud One Workload Security"
},
"C1WSLambdaSnsCWLogsWriter": {
"Description": "Lambda Function ARN for Trend Micro Cloud One Workload Security",
"Value": {
"Fn::GetAtt": [
"C1WSLambdaSnsCWLogsWriter",
"Arn"
]
}
},
"C1WSConfigureSIEMLambdaFunction": {
"Description": "One-time configuration Lambda Function ARN for Trend Micro Cloud One Workload Security",
"Value": {
"Fn::GetAtt": [
"C1WSConfigureSIEMLambdaFunction",
"Arn"
]
}
}
}
}