forked from bridgecrewio/cfngoat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfngoat.yaml
1327 lines (1293 loc) · 42.8 KB
/
cfngoat.yaml
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template to deploy insecure infrastructure
Parameters:
CompanyName:
Description: Company Name
Type: String
Default: acme
Environment:
Description: Environment
Type: String
Default: dev
DBName:
Description: Name of the Database
Type: String
Default: db1
Password:
Description: Database Password
Type: String
NoEcho: True
MinLength: 1
MaxLength: 41
AllowedPattern: ^[a-zA-Z0-9]*$
LatestAmiId:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
Resources:
####################
### EC2 in VPC ###
####################
EC2Instance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
Fn::Select:
- "0"
- Fn::GetAZs: ""
InstanceType: t2.nano
SecurityGroupIds:
- !Ref WebNodeSG
ImageId: !Ref LatestAmiId
SubnetId: !Ref WebSubnet
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ec2"
- Key: yor_trace
Value: 595b9b79-bd1e-45fd-a297-d521ebdf15e7
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
UserData:
Fn::Base64: |
#!/bin/bash
sudo yum -y update
sudo yum -y install httpd php php-mysqlnd
sudo systemctl enable httpd
sudo systemctl start httpd
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMAAA
export AWS_SECRET_ACCESS_KEY=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
export AWS_DEFAULT_REGION=us-west-2
echo "<h1>Deployed via CloudFormation</h1>" | sudo tee /var/www/html/index.html
WebHostStorage:
# Unencrypted Volume
Type: AWS::EC2::Volume
Properties:
AvailabilityZone:
Fn::Select:
- "0"
- Fn::GetAZs: ""
#Encrypted: False
Size: 1
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ebs"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 838685b6-8fac-42eb-9cf4-008dd36216a1
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
### CFN Does not Support Volume Snapshot
EBSAttachment:
Type: AWS::EC2::VolumeAttachment
Properties:
InstanceId: !Ref EC2Instance
VolumeId: !Ref WebHostStorage
Device: /dev/sdh
# Security Group SSH port open to the world
WebNodeSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-sg"
GroupDescription: !Sub "${AWS::AccountId}-${CompanyName}-${Environment} Security Group"
VpcId: !Ref WebVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: "-1"
FromPort: 0
ToPort: 0
CidrIp: 0.0.0.0/0
Tags:
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: d4d72008-2b73-4635-9df6-8035c8850d66
- Key: git_org
Value: bridgecrewio
WebVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 172.16.0.0/16
EnableDnsSupport: True
EnableDnsHostnames: True
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-vpc"
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: eeb90d09-d35e-440f-ac67-2f96e472b2e0
WebSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref WebVPC
CidrBlock: 172.16.10.0/24
AvailabilityZone:
Fn::Select:
- "0"
- Fn::GetAZs: ""
MapPublicIpOnLaunch: True
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-subnet"
- Key: yor_trace
Value: 4f6434ca-b2c2-4fe3-88fc-9ad969965958
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
WebSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref WebVPC
CidrBlock: 172.16.11.0/24
AvailabilityZone:
Fn::Select:
- "1"
- Fn::GetAZs: ""
MapPublicIpOnLaunch: True
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-subnet2"
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 68c27f34-7110-458d-98b3-b9a7307638dc
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
WebIGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-igw"
- Key: yor_trace
Value: 39d8202d-7126-40dd-afa0-4554eeadada4
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref WebIGW
VpcId: !Ref WebVPC
WebRTB:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref WebVPC
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-rtb"
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 0613f2a9-ccbb-4e77-839b-bc0a7681bd9c
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
WebDefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn:
- InternetGatewayAttachment
Properties:
RouteTableId: !Ref WebRTB
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref WebIGW
RTBAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref WebSubnet
RouteTableId: !Ref WebRTB
RTBAssoc2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref WebSubnet2
RouteTableId: !Ref WebRTB
WebENI:
Type: AWS::EC2::NetworkInterface
Properties:
Description: A nice description.
SubnetId: !Ref WebSubnet
PrivateIpAddress: 172.16.10.100
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-primary_network_interface"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: ebfdc86d-55a5-4df1-88fd-2f3bc869549c
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
VpcFlowLogs:
Type: AWS::EC2::FlowLog
Properties:
ResourceId: !Ref WebVPC
ResourceType: VPC
LogDestination: !GetAtt FlowBucket.Arn
LogDestinationType: s3
TrafficType: ALL
Tags:
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 077d3a3d-66bc-4fe9-8839-b59a40785234
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
FlowBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-flowlogs"
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-flowlogs"
- Key: yor_trace
Value: a148a687-a031-4491-8fc9-6bb78fef0572
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
#############
### IAM ###
#############
User:
Type: AWS::IAM::User
Properties:
UserName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-user"
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-user"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 346804e2-5a21-4f1b-a8bf-f3c3fc9c7d15
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
AccessKey:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref User
UserPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: excess_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- "ec2:*"
- "s3:*"
- "lambda:*"
- "cloudwatch:*"
Resource: "*"
Users:
- !Ref User
#############
### KMS ###
#############
LogsKey:
# Key does not have rotation enabled
Type: AWS::KMS::Key
Properties:
Description: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-logs bucket key"
PendingWindowInDays: 7
KeyPolicy:
Version: '2012-10-17'
Id: key-default-1
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource: '*'
Tags:
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: bd68272a-4d3b-44e6-a2f0-ad783935c332
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
LogsKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub "alias/${AWS::AccountId}-${CompanyName}-${Environment}-logs-bucket-key"
TargetKeyId: !Ref LogsKey
################
### DB App ###
################
DefaultDB:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
Properties:
DBName: !Ref DBName
Engine: MySQL
OptionGroupName: !Ref DefaultDBOptionGroup
DBParameterGroupName: !Ref DefaultDBParameterGroup
DBSubnetGroupName: !Ref DefaultSubnetGroup
VPCSecurityGroups:
- !Ref DefaultSG
DBInstanceIdentifier: !Sub "rds-${AWS::AccountId}-${CompanyName}-${Environment}"
EngineVersion: "8.0"
DBInstanceClass: db.t3.micro
AllocatedStorage: "20"
MasterUsername: admin
MasterUserPassword: !Ref Password
MultiAZ: False
BackupRetentionPeriod: 0
StorageEncrypted: False
MonitoringInterval: 0
PubliclyAccessible: True
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-rds"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: ca176a04-46cc-411d-a062-222ae03835a8
DefaultDBOptionGroup:
Type: AWS::RDS::OptionGroup
Properties:
EngineName: mysql
MajorEngineVersion: "8.0"
OptionGroupDescription: CloudFormation OG
OptionConfigurations: []
Tags:
- Key: Name
Value: !Sub "og-${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 6d7cc8b8-ee12-4ad2-940c-324b6eeca646
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
DefaultDBParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Terraform PG
Family: mysql8.0
Parameters:
character_set_client: utf8
character_set_server: utf8
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-pg"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 88c3fff0-8627-4e00-8e10-086c1651370a
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
DefaultSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupName: !Sub "sg-${AWS::AccountId}-${CompanyName}-${Environment}"
DBSubnetGroupDescription: CloudFormation DB Subnet Group
SubnetIds:
- !Ref WebSubnet
- !Ref WebSubnet2
Tags:
- Key: Name
Value: !Sub "sg-${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 3c0704d6-7b98-472d-a6b2-c3085cb87024
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
DefaultSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-rds-sg"
GroupDescription: !Sub "${AWS::AccountId}-${CompanyName}-${Environment} RDS Security Group"
VpcId: !Ref WebVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: !GetAtt WebVPC.CidrBlock
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-rds-sg"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 3d3b2421-0886-4ab8-88ec-e4bef646fdf6
EC2Profile:
Type: AWS::IAM::InstanceProfile
Properties:
InstanceProfileName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-profile"
Path: "/"
Roles:
- !Ref EC2Role
EC2Role:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "ec2.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-role"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 47d128cd-8fec-4d80-a768-e5e4c133b61a
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
EC2Policy:
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:*"
- "ec2:*"
- "rds:*"
Resource: "*"
Roles:
- !Ref EC2Role
DBAppInstance:
# EC2 have plain text secrets in user data
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
Fn::Select:
- "0"
- Fn::GetAZs: ""
ImageId: !Ref LatestAmiId
InstanceType: t2.nano
IamInstanceProfile: !Ref EC2Profile
SecurityGroupIds:
- !Ref WebNodeSG
SubnetId: !Ref WebSubnet
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-dbapp"
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 35854694-8244-4717-8f50-146fbec15c61
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
UserData:
Fn::Base64: !Sub |
#!/bin/bash
### Config from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateWebServer.html
sudo yum -y update
sudo yum -y install httpd php php-mysqlnd
sudo systemctl enable httpd
sudo systemctl start httpd
sudo mkdir /var/www/inc
cat << EnD > /tmp/dbinfo.inc
<?php
define('DB_SERVER', '${DefaultDB.Endpoint.Address}:${DefaultDB.Endpoint.Port}');
define('DB_USERNAME', 'admin');
define('DB_PASSWORD', '${Password}');
define('DB_DATABASE', '${DefaultDB}');
?>
EnD
sudo mv /tmp/dbinfo.inc /var/www/inc
sudo chown root:root /var/www/inc/dbinfo.inc
cat << EnD > /tmp/index.php
<?php include "../inc/dbinfo.inc"; ?>
<html>
<body>
<h1>Sample page</h1>
<?php
/* Connect to MySQL and select the database. */
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
$database = mysqli_select_db($connection, DB_DATABASE);
/* Ensure that the EMPLOYEES table exists. */
VerifyEmployeesTable($connection, DB_DATABASE);
/* If input fields are populated, add a row to the EMPLOYEES table. */
$employee_name = htmlentities($_POST['NAME']);
$employee_address = htmlentities($_POST['ADDRESS']);
if (strlen($employee_name) || strlen($employee_address)) {
AddEmployee($connection, $employee_name, $employee_address);
}
?>
<!-- Input form -->
<form action="<?PHP echo $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<table border="0">
<tr>
<td>NAME</td>
<td>ADDRESS</td>
</tr>
<tr>
<td>
<input type="text" name="NAME" maxlength="45" size="30" />
</td>
<td>
<input type="text" name="ADDRESS" maxlength="90" size="60" />
</td>
<td>
<input type="submit" value="Add Data" />
</td>
</tr>
</table>
</form>
<!-- Display table data. -->
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>ID</td>
<td>NAME</td>
<td>ADDRESS</td>
</tr>
<?php
$result = mysqli_query($connection, "SELECT * FROM EMPLOYEES");
while($query_data = mysqli_fetch_row($result)) {
echo "<tr>";
echo "<td>",$query_data[0], "</td>",
"<td>",$query_data[1], "</td>",
"<td>",$query_data[2], "</td>";
echo "</tr>";
}
?>
</table>
<!-- Clean up. -->
<?php
mysqli_free_result($result);
mysqli_close($connection);
?>
</body>
</html>
<?php
/* Add an employee to the table. */
function AddEmployee($connection, $name, $address) {
$n = mysqli_real_escape_string($connection, $name);
$a = mysqli_real_escape_string($connection, $address);
$query = "INSERT INTO EMPLOYEES (NAME, ADDRESS) VALUES ('$n', '$a');";
if(!mysqli_query($connection, $query)) echo("<p>Error adding employee data.</p>");
}
/* Check whether the table exists and, if not, create it. */
function VerifyEmployeesTable($connection, $dbName) {
if(!TableExists("EMPLOYEES", $connection, $dbName))
{
$query = "CREATE TABLE EMPLOYEES (
ID int(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
NAME VARCHAR(45),
ADDRESS VARCHAR(90)
)";
if(!mysqli_query($connection, $query)) echo("<p>Error creating table.</p>");
}
}
/* Check for the existence of a table. */
function TableExists($tableName, $connection, $dbName) {
$t = mysqli_real_escape_string($connection, $tableName);
$d = mysqli_real_escape_string($connection, $dbName);
$checktable = mysqli_query($connection,
"SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME = '$t' AND TABLE_SCHEMA = '$d'");
if(mysqli_num_rows($checktable) > 0) return true;
return false;
}
?>
EnD
sudo mv /tmp/index.php /var/www/html
sudo chown root:root /var/www/html/index.php
################
### Lambda ###
################
IAM4Lambda:
Type: "AWS::IAM::Role"
Properties:
RoleName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-analysis-lambda"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-analysis-lambda"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 2c07712d-22f5-42be-946e-1c2e71d2e275
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
AnalysisLambda:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-analysis"
Runtime: nodejs12.x
Role: !GetAtt IAM4Lambda.Arn
Handler: exports.test
Code:
ZipFile: |
console.log("Hello World");
Environment:
Variables:
access_key: "AKIAIOSFODNN7EXAMPLE"
secret_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-analysis"
- Key: Environment
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 5939cdf9-4e86-4208-80d1-095c367c2c13
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: 42153ba22c28f5c0bff388b24a6344137a5dfe26
- Key: git_modifiers
Value: jonathan.jozwiak/nimrodkor
- Key: git_last_modified_at
Value: "2021-08-23 13:51:41"
############
### S3 ###
############
DataBucket:
# Public, not encrypted, no access logs, no versioning
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-data"
AccessControl: PublicRead
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-data"
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 509b197d-4f87-4ae1-aa43-8cca13c9e92e
- Key: git_org
Value: bridgecrewio
### TODO - Custom Upload of insecure document
FinancialsBucket:
# not encrypted, no access logs, no versioning
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-financials"
AccessControl: Private
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-financials"
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 7d0b70d4-58fb-4d2d-b966-177d349932da
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
OperationsBucket:
# not encrypted, no access logs
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-operations"
AccessControl: Private
VersioningConfiguration:
Status: Enabled
Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-operations"
- Key: git_org
Value: bridgecrewio
- Key: git_repo
Value: cfngoat
- Key: git_file
Value: cfngoat.yaml
- Key: git_commit
Value: b1681f3806db6656faf4107ceceb77e9364e59b7
- Key: git_modifiers
Value: jonathan.jozwiak
- Key: git_last_modified_at
Value: "2020-04-25 01:13:26"
- Key: git_last_modified_by
Value: [email protected]
- Key: yor_trace
Value: 9e00e7c2-b27c-4141-af5a-2d90c9632a23
DataScienceBucket:
# not encrypted