-
Notifications
You must be signed in to change notification settings - Fork 0
/
wazuh_template.yml
581 lines (562 loc) · 15.8 KB
/
wazuh_template.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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
AWSTemplateFormatVersion: 2010-09-09
Mappings:
RegionMap:
us-east-1:
HVM64: ami-0ff8a91507f77f867
us-east-2:
HVM64: ami-0b59bfac6be064b78
us-west-1:
HVM64: ami-0019ef04ac50be30f
us-west-2:
HVM64: ami-a0cfeed8
ca-central-1:
HVM64: ami-0b18956f
eu-central-1:
HVM64: ami-0233214e13e500f77
eu-west-1:
HVM64: ami-047bb4163c506cd98
eu-west-2:
HVM64: ami-f976839e
eu-west-3:
HVM64: ami-0ebc281c20e89ba4b
ap-northeast-1:
HVM64: ami-06cd52961ce9f0d85
ap-northeast-2:
HVM64: ami-0a10b2721688ce9d2
ap-southeast-1:
HVM64: ami-08569b978cc4dfa10
ap-southeast-2:
HVM64: ami-09b42976632b27e9b
ap-south-1:
HVM64: ami-0912f71e06545ad88
sa-east-1:
HVM64: ami-07b14488da8ea02a0
SubnetConfig:
WazuhVpc:
CIDR: 10.0.0.0/16
SubnetWazuh:
CIDR: 10.0.2.0/24
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: "Environment type"
Parameters:
- EnvironmentType
-
Label:
default: "AWS environment"
Parameters:
- WazuhVpc
- AvailabilityZone
- KeyPairName
- pSubnetWazuh
-
Label:
default: "Version and instance types"
Parameters:
- ElasticWazuhVersion
- WazuhInstanceType
- ElasticInstanceType
- KibanaInstanceType
- SshUsername
- SshPassword
-
Label:
default: "Wazuh configuration"
Parameters:
- WazuhServerPort
- WazuhRegistrationPort
- WazuhApiPort
- WazuhApiAdminUsername
- WazuhApiAdminPassword
- WazuhClusterKey
-
Label:
default: "Kibana configuration"
Parameters:
- KibanaPort
- KibanaUsername
- KibanaPassword
-
Label:
default: "Integration keys"
Parameters:
- AwsSecretKey
- AwsAccessKey
-
Label:
default: "SSL Certificate"
Parameters:
- SSLCertificateARN
Parameters:
WazuhVpc:
Description: The VPC where the infrastructure will be isolated.
Type: AWS::EC2::VPC::Id
pSubnetWazuh:
Description: The Subnet where resources will be located
Type: AWS::EC2::Subnet::Id
# AWS environment
AvailabilityZone:
Description: Select an availability zone for the VPC
Type: 'List<AWS::EC2::AvailabilityZone::Name>'
KeyPairName:
Description: Existing EC2 key pair for SSH access
Type: 'AWS::EC2::KeyPair::KeyName'
SshUsername:
Default: wazuh
Description: SSH username
Type: String
MinLength: '5'
MaxLength: '32'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters. Minimum length 5. Maximum length 32.
SshPassword:
Description: SSH Password
NoEcho: 'True'
Type: String
MinLength: '8'
MaxLength: '64'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters. Minimum length 8. Maximum length 64.
# Version and instance types
ElasticWazuhVersion:
AllowedValues:
- 6.5.0_3.7.0
- 6.5.1_3.7.1
- 6.5.2_3.7.1
- 6.5.3_3.7.2
- 6.5.4_3.7.2
- 6.6.2_3.9.0
- 6.7.0_3.9.0
- 6.7.1_3.9.0
- 6.8.0_3.9.2
ConstraintDescription: Format is ElasticVersion_WazuhVersion
Default: 6.8.0_3.9.2
Description: Elastic and Wazuh versions to be installed
Type: String
WazuhInstanceType:
AllowedValues:
- t2.micro
- t2.medium
- t2.large
- m5.large
- m5.xlarge
- m5.2xlarge
ConstraintDescription: Must contain valid instance type
Default: t2.medium
Description: Type of EC2 instance for Wazuh instance
Type: String
EnvironmentType:
AllowedValues:
- production
- staging
- devel
ConstraintDescription: Must contain valid instance type
Default: production
Description: Select a stage
Type: String
ElasticInstanceType:
AllowedValues:
- t2.medium
- t2.large
- i3.large
- i3.xlarge
- i3.2xlarge
ConstraintDescription: Must contain valid instance type
Default: t2.medium
Description: Type of EC2 instance for Elastic instance
Type: String
KibanaInstanceType:
AllowedValues:
- t2.medium
- t2.large
- m5.large
- m5.xlarge
- m5.2xlarge
- r5.large
ConstraintDescription: Must contain valid instance type
Default: t2.medium
Description: Type of EC2 instance for Kibana instance
Type: String
# Wazuh configuration
WazuhServerPort:
Default: '1514'
Description: Port for agents connection with Wazuh server
Type: String
WazuhRegistrationPort:
Default: '1515'
Description: Port for agents registration with Wazuh server
Type: String
WazuhApiPort:
Default: '55000'
Description: Port for Wazuh server API
Type: String
WazuhApiAdminUsername:
Default: admin
Description: Admin username for Wazuh API
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters
WazuhApiAdminPassword:
Description: Admin password for Wazuh API
NoEcho: 'True'
Type: String
MinLength: '1'
MaxLength: '48'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters
WazuhClusterKey:
Description: Key used for Wazuh servers cluster
Default: 'abcdefghijklmnopqrstuvwxyz012345'
Type: String
MinLength: '32'
MaxLength: '32'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Any alphanumeric string of 32 characters
# Kibana configuration
KibanaPort:
Default: '443'
Description: Port for Kibana WUI
Type: String
KibanaUsername:
Default: wazuh
Description: Username for Kibana access
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters
KibanaPassword:
Description: Password for Kibana access
NoEcho: 'True'
Type: String
MinLength: '1'
MaxLength: '48'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: Only alphanumeric characters
AwsSecretKey:
Description: (Optional) Secret key for AWS integration
Type: String
AwsAccessKey:
Description: (Optional) Access key for AWS integration
Type: String
SSLCertificateARN:
Description: 'Used for HTTPS access to WUI. Existent certificate, identified by its Amazon Resource Name (ARN).'
Type: String
Resources:
# Instance security groups
ElasticSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Elasticsearch security group
VpcId: !Ref WazuhVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 5000
ToPort: 5000
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
- IpProtocol: tcp
FromPort: 9200
ToPort: 9400
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ElasticSecurityGroup'
KibanaSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Kibana security group
VpcId: !Ref WazuhVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: !Ref KibanaPort
ToPort: !Ref KibanaPort
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 9200
ToPort: 9400
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-KibanaSecurityGroup'
WazuhSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Wazuh security group
VpcId: !Ref WazuhVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 3389
ToPort: 3389
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: icmp
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: !Ref WazuhServerPort
ToPort: !Ref WazuhServerPort
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: !Ref WazuhRegistrationPort
ToPort: !Ref WazuhRegistrationPort
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 1516
ToPort: 1516
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
- IpProtocol: tcp
FromPort: !Ref WazuhApiPort
ToPort: !Ref WazuhApiPort
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-WazuhSecurityGroup'
# Elasticsearch load balancer
ElbElasticSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: ELB Elasticsearch security group
VpcId: !Ref WazuhVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 9200
ToPort: 9200
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ElbElasticSecurityGroup'
# Logstash load balancer
ElbLogstashSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: ELB Logstash security group
VpcId: !Ref WazuhVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 5000
ToPort: 5000
CidrIp: !FindInMap
- SubnetConfig
- WazuhVpc
- CIDR
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ElbLogstashSecurityGroup'
# IAM role and profile
InstanceRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
- cloudformation.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: !Sub '${AWS::StackName}-GetCloudformation'
PolicyDocument:
Statement:
- Action:
- 'cloudformation:DescribeStack*'
- 'cloudformation:DescribeStackResource*'
- 'cloudformation:List*'
Resource: '*'
Effect: Allow
- PolicyName: !Sub '${AWS::StackName}-DescribeInstances'
PolicyDocument:
Statement:
- Action:
- 'ec2:DescribeInstances'
Resource: '*'
Effect: Allow
InstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
Roles:
- !Ref InstanceRole
# Wazuh master instance
WazuhMasterInstance:
Type: AWS::EC2::Instance
Metadata:
'AWS::CloudFormation::Init':
configSets:
WazuhInstallationSet:
- WazuhFiles
- WazuhInstall
WazuhFiles:
files:
/tmp/wazuh_cf_settings:
content: !Sub |
SshUsername: ${SshUsername}
SshPassword: ${SshPassword}
mode: '000600'
owner: root
group: root
/tmp/wazuh_cf_master.sh:
source: !Sub >-
https://raw.githubusercontent.com/wazuh/wazuh-cloudformation/aws-nist/wazuh/cluster/wazuh_cf_master.sh
mode: '000700'
owner: root
group: root
WazuhInstall:
commands:
01_RunInstallationScript:
command: /tmp/wazuh_cf_master.sh
Properties:
ImageId: !FindInMap
- "RegionMap"
- Ref: "AWS::Region"
- HVM64
InstanceType: !Ref WazuhInstanceType
IamInstanceProfile: !Ref InstanceProfile
KeyName: !Ref KeyPairName
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 200
VolumeType: gp2
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "WazuhSecurityGroup"
SubnetId:
Ref: "pSubnetWazuh"
Tags:
- Key: Name
Value: WazuhMaster
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
/opt/aws/bin/cfn-init --stack ${AWS::StackName} --resource WazuhMasterInstance --configsets WazuhInstallationSet --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WazuhMasterInstance --region ${AWS::Region}
WazuhMasterEth0:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref pSubnetWazuh
GroupSet: [!Ref 'WazuhSecurityGroup']
WazuhMasterEIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
WazuhMasterEIPAssociation:
Type: 'AWS::EC2::EIPAssociation'
Properties:
NetworkInterfaceId: !Ref WazuhMasterEth0
AllocationId: !GetAtt
- WazuhMasterEIP
- AllocationId
# Wazuh worker instance
WazuhWorkerInstance:
Type: AWS::EC2::Instance
Metadata:
'AWS::CloudFormation::Init':
configSets:
WazuhInstallationSet:
- WazuhFiles
- WazuhInstall
WazuhFiles:
files:
/tmp/wazuh_cf_settings:
content: !Sub |
SshUsername: ${SshUsername}
SshPassword: ${SshPassword}
mode: '000600'
owner: root
group: root
/tmp/wazuh_cf_worker.sh:
source: !Sub >-
https://raw.githubusercontent.com/wazuh/wazuh-cloudformation/aws-nist/wazuh/cluster/wazuh_cf_worker.sh
mode: '000700'
owner: root
group: root
WazuhInstall:
commands:
01_RunInstallationScript:
command: /tmp/wazuh_cf_worker.sh
Properties:
ImageId: !FindInMap
- "RegionMap"
- Ref: "AWS::Region"
- HVM64
InstanceType: !Ref WazuhInstanceType
IamInstanceProfile: !Ref InstanceProfile
KeyName: !Ref KeyPairName
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 200
VolumeType: gp2
NetworkInterfaces:
- NetworkInterfaceId: !Ref WazuhWorkerEth0
DeviceIndex: 0
Tags:
- Key: Name
Value: WazuhWorker
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
/opt/aws/bin/cfn-init --stack ${AWS::StackName} --resource WazuhWorkerInstance --configsets WazuhInstallationSet --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WazuhWorkerInstance --region ${AWS::Region}
WazuhWorkerEth0:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref pSubnetWazuh
GroupSet: [!Ref 'WazuhSecurityGroup']
WazuhWorkerEIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
WazuhWorkerEIPAssociation:
Type: 'AWS::EC2::EIPAssociation'
Properties:
NetworkInterfaceId: !Ref WazuhWorkerEth0
AllocationId: !GetAtt
- WazuhWorkerEIP
- AllocationId
Outputs:
WazuhMasterIp:
Description: Wazuh Master instance IP
Value: ${WazuhMasterInstance.PrivateIp}