-
Notifications
You must be signed in to change notification settings - Fork 52
/
iam.sp
2293 lines (2137 loc) · 86.8 KB
/
iam.sp
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
locals {
conformance_pack_iam_common_tags = merge(local.aws_compliance_common_tags, {
service = "AWS/IAM"
})
}
control "iam_user_unused_credentials_45" {
title = "Ensure credentials unused for 45 days or greater are disabled"
description = "AWS IAM users can access AWS resources using different types of credentials, such as passwords or access keys. It is recommended that all credentials that have been unused in 45 or greater days be deactivated or removed."
query = query.iam_user_unused_credentials_45
tags = local.conformance_pack_iam_common_tags
}
control "iam_access_analyzer_enabled" {
title = "Ensure that IAM Access analyzer is enabled for all regions"
description = "This control checks whether IAM Access analyzer is enabled for all regions. The control fails if IAM Access analyzer is not enabled for all regions."
query = query.iam_access_analyzer_enabled
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_group_role_cloudshell_fullaccess_restricted" {
title = "Ensure access to AWSCloudShellFullAccess is restricted"
description = "This control checks whether the AWSCloudShellFullAccess policy is attached to any IAM user, group, or role. The control fails if the policy is attached to any IAM user, group, or role."
query = query.iam_user_group_role_cloudshell_fullaccess_restricted
tags = local.conformance_pack_iam_common_tags
}
control "iam_policy_all_attached_no_star_star" {
title = "Ensure IAM policies that allow full \"*:*\" administrative privileges are not attached"
description = "IAM policies are the means by which privileges are granted to users, groups, or roles. It is recommended and considered a standard security advice to grant least privilege -that is, granting only the permissions required to perform a task. Determine what users need to do and then craft policies for them that let the users perform only those tasks, instead of allowing full administrative privileges."
query = query.iam_policy_all_attached_no_star_star
tags = local.conformance_pack_iam_common_tags
}
control "iam_root_last_used" {
title = "Eliminate use of the 'root' user for administrative and daily tasks"
description = "This control checks whether the root user has been used in the last 90 days. The control fails if the root user has been used in the last 90 days."
query = query.iam_root_last_used
tags = local.conformance_pack_iam_common_tags
}
control "iam_server_certificate_not_expired" {
title = "Ensure that all the expired SSL/TLS certificates stored in AWS IAM are removed"
description = "To enable HTTPS connections to your website or application in AWS, you need an SSL/TLS server certificate. You can use ACM or IAM to store and deploy server certificates. Use IAM as a certificate manager only when you must support HTTPS connections in a region that is not supported by ACM. IAM securely encrypts your private keys and stores the encrypted version in IAM SSL certificate storage. IAM supports deploying server certificates in all regions, but you must obtain your certificate from an external provider for use with AWS. You cannot upload an ACM certificate to IAM. Additionally, you cannot manage your certificates from the IAM Console."
query = query.iam_server_certificate_not_expired
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_access_keys_and_password_at_setup" {
title = "Ensure IAM users are assigned access keys and passwords at setup"
description = "This control checks whether the IAM users have access keys and passwords at setup. The control fails if the IAM users do not have access keys and passwords at setup."
query = query.iam_user_access_keys_and_password_at_setup
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_no_policies" {
title = "Ensure IAM policies are attached only to groups or roles"
description = "By default, IAM users, groups, and roles have no access to AWS resources. IAM policies are the means by which privileges are granted to users, groups, or roles. It is recommended that IAM policies be applied directly to groups and roles but not users."
query = query.iam_user_no_policies
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_one_active_key" {
title = "Ensure there is only one active access key available for any single IAM user"
description = "Access keys are long-term credentials for an IAM user or the AWS account root user. You can use access keys to sign programmatic requests to the AWS CLI or AWS API (directly or using the AWS SDK)."
query = query.iam_user_one_active_key
tags = local.conformance_pack_iam_common_tags
}
control "iam_policy_custom_attached_no_star_star" {
title = "IAM policies should not allow full '*' administrative privileges"
description = "This control checks whether the default version of IAM policies (also known as customer managed policies) has administrator access that includes a statement with 'Effect': 'Allow' with 'Action': '*' over 'Resource': '*'. The control only checks the customer managed policies that you create. It does not check inline and AWS managed policies."
query = query.iam_policy_custom_attached_no_star_star
tags = local.conformance_pack_iam_common_tags
}
control "iam_account_password_policy_strong_min_length_8" {
title = "Password policies for IAM users should have strong configurations with minimum length of 8 or greater"
description = "This control checks whether the account password policy for IAM users uses the recommended configurations."
query = query.iam_account_password_policy_strong_min_length_8
tags = local.conformance_pack_iam_common_tags
}
control "iam_account_password_policy_strong_min_reuse_24" {
title = "IAM password policies for users should have strong configurations"
description = "The identities and the credentials are issued, managed, and verified based on an organizational IAM password policy."
query = query.iam_account_password_policy_strong_min_reuse_24
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "iam_group_not_empty" {
title = "IAM groups should have at least one user"
description = "AWS Identity and Access Management (IAM) can help you incorporate the principles of least privilege and separation of duties with access permissions and authorizations, by ensuring that IAM groups have at least one IAM user."
query = query.iam_group_not_empty
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_policy_no_star_star" {
title = "IAM policy should not have statements with admin access"
description = "AWS Identity and Access Management (IAM) can help you incorporate the principles of least privilege and separation of duties with access permissions and authorizations, restricting policies from containing 'Effect': 'Allow' with 'Action': '*' over 'Resource': '*'."
query = query.iam_policy_no_star_star
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "iam_root_user_no_access_keys" {
title = "IAM root user should not have access keys"
description = "Access to systems and assets can be controlled by checking that the root user does not have access keys attached to their AWS Identity and Access Management (IAM) role."
query = query.iam_root_user_no_access_keys
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "iam_root_user_hardware_mfa_enabled" {
title = "IAM root user hardware MFA should be enabled"
description = "Manage access to resources in the AWS Cloud by ensuring hardware MFA is enabled for the root user."
query = query.iam_root_user_hardware_mfa_enabled
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
soc_2 = "true"
})
}
control "iam_root_user_mfa_enabled" {
title = "IAM root user MFA should be enabled"
description = "Manage access to resources in the AWS Cloud by ensuring MFA is enabled for the root user."
query = query.iam_root_user_mfa_enabled
tags = merge(local.conformance_pack_iam_common_tags, {
audit_manager_control_tower = "true"
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_user_access_key_age_90" {
title = "IAM user access keys should be rotated at least every 90 days"
description = "The credentials are audited for authorized devices, users, and processes by ensuring IAM access keys are rotated as per organizational policy."
query = query.iam_user_access_key_age_90
tags = merge(local.conformance_pack_iam_common_tags, {
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_user_console_access_mfa_enabled" {
title = "IAM users with console access should have MFA enabled"
description = "Manage access to resources in the AWS Cloud by ensuring that MFA is enabled for all AWS Identity and Access Management (IAM) users that have a console password."
query = query.iam_user_console_access_mfa_enabled
tags = merge(local.conformance_pack_iam_common_tags, {
audit_manager_control_tower = "true"
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
soc_2 = "true"
})
}
control "iam_user_mfa_enabled" {
title = "IAM user MFA should be enabled"
description = "Enable this rule to restrict access to resources in the AWS Cloud."
query = query.iam_user_mfa_enabled
tags = merge(local.conformance_pack_iam_common_tags, {
audit_manager_control_tower = "true"
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
soc_2 = "true"
})
}
control "iam_user_no_inline_attached_policies" {
title = "IAM user should not have any inline or attached policies"
description = "This rule ensures AWS Identity and Access Management (IAM) policies are attached only to groups or roles to control access to systems and assets."
query = query.iam_user_no_inline_attached_policies
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "iam_user_unused_credentials_90" {
title = "IAM user credentials that have not been used in 90 days should be disabled"
description = "AWS Identity and Access Management (IAM) can help you with access permissions and authorizations by checking for IAM passwords and access keys that are not used for a specified time period."
query = query.iam_user_unused_credentials_90
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
soc_2 = "true"
})
}
control "iam_user_in_group" {
title = "IAM users should be in at least one group"
description = "AWS Identity and Access Management (IAM) can help you restrict access permissions and authorizations, by ensuring IAM users are members of at least one group."
query = query.iam_user_in_group
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_group_user_role_no_inline_policies" {
title = "IAM groups, users, and roles should not have any inline policies"
description = "Ensure an AWS Identity and Access Management (IAM) user, IAM role or IAM group does not have an inline policy to control access to systems and assets."
query = query.iam_group_user_role_no_inline_policies
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "iam_support_role" {
title = "Ensure a support role has been created to manage incidents with AWS Support"
description = "AWS provides a support center that can be used for incident notification and response, as well as technical support and customer services."
query = query.iam_support_role
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_account_password_policy_min_length_14" {
title = "Ensure IAM password policy requires a minimum length of 14 or greater"
description = "Password policies, in part, enforce password complexity requirements. Use IAM password policies to ensure that passwords are at least a given length. Security Hub recommends that the password policy require a minimum password length of 14 characters."
query = query.iam_account_password_policy_min_length_14
tags = merge(local.conformance_pack_iam_common_tags, {
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
gdpr = "true"
nist_800_53_rev_5 = "true"
})
}
control "iam_account_password_policy_reuse_24" {
title = "Ensure IAM password policy prevents password reuse"
description = "This control checks whether the number of passwords to remember is set to 24. The control fails if the value is not 24. IAM password policies can prevent the reuse of a given password by the same user."
query = query.iam_account_password_policy_reuse_24
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_account_password_policy_one_lowercase_letter" {
title = "Ensure IAM password policy requires at least one lowercase letter"
description = "Password policies, in part, enforce password complexity requirements. Use IAM password policies to ensure that passwords use different character sets. Security Hub recommends that the password policy require at least one lowercase letter. Setting a password complexity policy increases account resiliency against brute force login attempts."
query = query.iam_account_password_policy_one_lowercase_letter
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_account_password_policy_one_uppercase_letter" {
title = "Ensure IAM password policy requires at least one uppercase letter"
description = "Password policies, in part, enforce password complexity requirements. Use IAM password policies to ensure that passwords use different character sets."
query = query.iam_account_password_policy_one_uppercase_letter
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_account_password_policy_one_number" {
title = "Ensure IAM password policy requires at least one number"
description = "Password policies, in part, enforce password complexity requirements. Use IAM password policies to ensure that passwords use different character sets."
query = query.iam_account_password_policy_one_number
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_password_policy_expire_90" {
title = "Ensure IAM password policy expires passwords within 90 days or less"
description = "IAM password policies can require passwords to be rotated or expired after a given number of days. Security Hub recommends that the password policy expire passwords after 90 days or less. Reducing the password lifetime increases account resiliency against brute force login attempts."
query = query.iam_password_policy_expire_90
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_account_password_policy_one_symbol" {
title = "Ensure IAM password policy requires at least one symbol"
description = "Password policies, in part, enforce password complexity requirements. Use IAM password policies to ensure that passwords use different character sets. Security Hub recommends that the password policy require at least one symbol. Setting a password complexity policy increases account resiliency against brute force login attempts."
query = query.iam_account_password_policy_one_symbol
tags = merge(local.conformance_pack_iam_common_tags, {
gdpr = "true"
})
}
control "iam_all_policy_no_service_wild_card" {
title = "Ensure IAM policy should not grant full access to service"
description = "Checks if AWS Identity and Access Management (IAM) policies grant permissions to all actions on individual AWS resources. The rule is non-compliant if the managed IAM policy allows full access to at least 1 AWS service."
query = query.iam_all_policy_no_service_wild_card
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
})
}
control "iam_policy_custom_no_blocked_kms_actions" {
title = "Ensure managed IAM policies should not allow blocked actions on KMS keys"
description = "Checks if the managed AWS Identity and Access Management (IAM) policies that you create do not allow blocked actions on AWS KMS keys. The rule is non - compliant if any blocked action is allowed on AWS KMS keys by the managed IAM policy."
query = query.iam_policy_custom_no_blocked_kms_actions
tags = merge(local.conformance_pack_iam_common_tags, {
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
})
}
control "iam_policy_inline_no_blocked_kms_actions" {
title = "Ensure inline policies attached to IAM users, roles, and groups should not allow blocked actions on KMS keys"
description = "Checks if the inline policies attached to IAM users, roles, and groups do not allow blocked actions on all AWS Key Management Service (KMS) keys. The rule is non - compliant if any blocked action is allowed on all KMS keys in an inline policy."
query = query.iam_policy_inline_no_blocked_kms_actions
tags = merge(local.conformance_pack_iam_common_tags, {
cisa_cyber_essentials = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
})
}
control "iam_policy_custom_no_assume_role" {
title = "IAM roles should not have any assume role policies attached"
description = "Role assume policies can provide access to roles in external AWS accounts."
query = query.iam_policy_custom_no_assume_role
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_hardware_mfa_enabled" {
title = "IAM users should have hardware MFA enabled"
description = "Manage access to resources in the AWS Cloud by ensuring hardware MFA is enabled for the user."
query = query.iam_user_hardware_mfa_enabled
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_with_administrator_access_mfa_enabled" {
title = "IAM administrator users should have MFA enabled"
description = "Manage access to resources in the AWS Cloud by ensuring MFA is enabled for users with administrative privileges."
query = query.iam_user_with_administrator_access_mfa_enabled
tags = local.conformance_pack_iam_common_tags
}
control "iam_managed_policy_attached_to_role" {
title = "IAM AWS managed policies should be attached to IAM role"
description = "This control checks if all AWS managed policies specified in the list of managed policies are attached to the AWS Identity and Access Management (IAM) role. The rule is non-compliant if an AWS managed policy is not attached to the IAM role."
query = query.iam_managed_policy_attached_to_role
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
gxp_21_cfr_part_11 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_policy_unused" {
title = "IAM policy should be in use"
description = "This control checks whether the IAM policy ARN is attached to an IAM user, or a group with one or more IAM users, or an IAM role with one or more trusted entity."
query = query.iam_policy_unused
tags = merge(local.conformance_pack_iam_common_tags, {
cis_controls_v8_ig1 = "true"
nist_800_171_rev_2 = "true"
nist_csf = "true"
soc_2 = "true"
})
}
control "iam_access_analyzer_enabled_without_findings" {
title = "IAM Access analyzer should be enabled without findings"
description = "This control checks whether the IAM Access analyzer is enabled without findings. If you grant permissions to an S3 bucket in one of your organization member accounts to a principal in another organization member account, IAM Access Analyzer does not generate a finding. But if you grant permission to a principal in an account that is not a member of the organization, IAM Access Analyzer generates a finding."
query = query.iam_access_analyzer_enabled_without_findings
tags = local.conformance_pack_iam_common_tags
}
control "iam_role_unused_60" {
title = "IAM roles that have not been used in 60 days should be removed"
description = "This control checks whether the IAM role has been used in 60 days. Unused accounts and roles increase the attack surface area."
query = query.iam_role_unused_60
tags = local.conformance_pack_iam_common_tags
}
control "iam_custom_policy_unattached_no_star_star" {
title = "IAM unattached custom policy should not have statements with admin access"
description = "AWS Identity and Access Management (IAM) can help you incorporate the principles of least privilege and separation of duties with access permissions and authorizations, restricting policies from containing 'Effect': 'Allow' with 'Action': '*' over 'Resource': '*'."
query = query.iam_custom_policy_unattached_no_star_star
tags = local.conformance_pack_iam_common_tags
}
control "iam_policy_no_full_access_to_cloudtrail" {
title = "IAM policy should not grant full access to cloudtrail service"
description = "CloudTrail is a critical service and IAM policies should follow least privilege model for this service in particular. This control is non-compliant if the managed IAM policy allows full access to cloudtrail service."
query = query.iam_policy_no_full_access_to_cloudtrail
tags = local.conformance_pack_iam_common_tags
}
control "iam_policy_no_full_access_to_kms" {
title = "IAM policy should not grant full access to KMS service"
description = "KMS is a critical service and IAM policies should follow least privilege model for this service in particular. This control is non-compliant if the managed IAM policy allows full access to KMS service."
query = query.iam_policy_no_full_access_to_cloudtrail
tags = local.conformance_pack_iam_common_tags
}
control "iam_role_cross_account_read_only_access_policy" {
title = "IAM roles should not have read only access for external AWS accounts"
description = "Ensure IAM Roles do not have ReadOnlyAccess access for external AWS account. The AWS-managed ReadOnlyAccess policy carries a high risk of potential data leakage, posing a significant threat to customer security and privacy."
query = query.iam_role_cross_account_read_only_access_policy
tags = local.conformance_pack_iam_common_tags
}
control "iam_security_audit_role" {
title = "IAM Security Audit role should be created to conduct security audits"
description = "Ensure IAM Security Audit role is created. By creating an IAM role with a security audit policy, a distinct segregation of responsibilities is established between the security team and other teams within the organization."
query = query.iam_security_audit_role
tags = local.conformance_pack_iam_common_tags
}
control "iam_policy_custom_no_permissive_role_assumption" {
title = "IAM custom policy should not have overly permissive STS role assumption"
description = "Ensure that no custom IAM policies exist which allow permissive role assumption."
query = query.iam_policy_custom_no_permissive_role_assumption
tags = local.conformance_pack_iam_common_tags
}
control "iam_inline_policy_no_administrative_privileges" {
title = "IAM inline policy should not have administrative privileges"
description = "Ensure that no inline IAM policies exist that allow administrative privileges."
query = query.iam_inline_policy_no_administrative_privileges
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_console_access_unused_45" {
title = "Ensure IAM users with console access unused for 45 days or greater are disabled"
description = "AWS IAM users can access AWS resources using console access. It is recommended that console access that have been unused in 45 or greater days be deactivated or removed."
query = query.iam_user_console_access_unused_45
tags = local.conformance_pack_iam_common_tags
}
control "iam_user_access_key_unused_45" {
title = "Ensure IAM users with access keys unused for 45 days or greater are disabled"
description = "AWS IAM users can access AWS resources using access keys. It is recommended that access keys that have been unused in 45 or greater days be deactivated or removed."
query = query.iam_user_access_key_unused_45
tags = local.conformance_pack_iam_common_tags
}
control "iam_role_no_administrator_access_policy_attached" {
title = "Ensure IAM role not attached with Administratoraccess policy"
description = "AWS IAM role should not be attached Administratoraccess policy."
query = query.iam_role_no_administrator_access_policy_attached
tags = local.conformance_pack_iam_common_tags
}
query "iam_account_password_policy_strong_min_reuse_24" {
sql = <<-EOQ
select
'arn:' || a.partition || ':::' || a.account_id as resource,
case
when
minimum_password_length >= 14
and password_reuse_prevention >= 24
and require_lowercase_characters = 'true'
and require_uppercase_characters = 'true'
and require_numbers = 'true'
and require_symbols = 'true'
and max_password_age <= 90
then 'ok'
else 'alarm'
end as status,
case
when minimum_password_length is null then 'No password policy set.'
when
minimum_password_length >= 14
and password_reuse_prevention >= 24
and require_lowercase_characters = 'true'
and require_uppercase_characters = 'true'
and require_numbers = 'true'
and require_symbols = 'true'
and max_password_age <= 90
then 'Strong password policies configured.'
else 'Password policy ' ||
concat_ws(', ',
case when minimum_password_length < 14 then ('minimum password length set to ' || minimum_password_length) end,
case when password_reuse_prevention < 24 then ('password reuse prevention set to ' || password_reuse_prevention) end,
case when not (require_lowercase_characters = 'true') then 'lowercase characters not required' end,
case when not (require_uppercase_characters = 'true') then 'uppercase characters not required' end,
case when not (require_numbers) then 'numbers not required' end,
case when not (require_symbols) then 'symbols not required' end,
case when max_password_age > 90 then ('max password age set to ' || max_password_age) end
) || '.'
end as reason
${replace(local.common_dimensions_qualifier_global_sql, "__QUALIFIER__", "a.")}
from
aws_account as a
left join aws_iam_account_password_policy as pol on a.account_id = pol.account_id;
EOQ
}
query "iam_group_not_empty" {
sql = <<-EOQ
select
arn as resource,
case
when users is null then 'alarm'
else 'ok'
end as status,
case
when users is null then title || ' not associated with any IAM user.'
else title || ' associated with IAM user.'
end as reason
${local.common_dimensions_global_sql}
from
aws_iam_group;
EOQ
}
query "iam_policy_no_star_star" {
sql = <<-EOQ
with bad_policies as (
select
arn,
count(*) as num_bad_statements
from
aws_iam_policy,
jsonb_array_elements(policy_std -> 'Statement') as s,
jsonb_array_elements_text(s -> 'Resource') as resource,
jsonb_array_elements_text(s -> 'Action') as action
where
not is_aws_managed
and s ->> 'Effect' = 'Allow'
and resource = '*'
and (
(action = '*'
or action = '*:*'
)
)
group by
arn
)
select
p.arn as resource,
case
when bad.arn is null then 'ok'
else 'alarm'
end status,
p.name || ' contains ' || coalesce(bad.num_bad_statements,0) ||
' statements that allow action "*" on resource "*".' as reason
${replace(local.tag_dimensions_qualifier_sql, "__QUALIFIER__", "p.")}
${replace(local.common_dimensions_qualifier_global_sql, "__QUALIFIER__", "p.")}
from
aws_iam_policy as p
left join bad_policies as bad on p.arn = bad.arn
where
not p.is_aws_managed;
EOQ
}
query "iam_root_user_no_access_keys" {
sql = <<-EOQ
select
'arn:' || partition || ':::' || account_id as resource,
case
when account_access_keys_present > 0 then 'alarm'
else 'ok'
end status,
case
when account_access_keys_present > 0 then 'Root user access keys exist.'
else 'No root user access keys exist.'
end reason
${local.common_dimensions_global_sql}
from
aws_iam_account_summary;
EOQ
}
query "iam_root_user_hardware_mfa_enabled" {
sql = <<-EOQ
select
'arn:' || s.partition || ':::' || s.account_id as resource,
case
when account_mfa_enabled and serial_number is null then 'ok'
else 'alarm'
end status,
case
when account_mfa_enabled = false then 'MFA not enabled for root account.'
when serial_number is not null then 'MFA enabled for root account, but the MFA associated is a virtual device.'
else 'Hardware MFA device enabled for root account.'
end reason
${replace(local.common_dimensions_qualifier_global_sql, "__QUALIFIER__", "s.")}
from
aws_iam_account_summary as s
left join aws_iam_virtual_mfa_device on serial_number = 'arn:' || s.partition || ':iam::' || s.account_id || ':mfa/root-account-mfa-device';
EOQ
}
query "iam_root_user_mfa_enabled" {
sql = <<-EOQ
select
'arn:' || partition || ':::' || account_id as resource,
case
when account_mfa_enabled then 'ok'
else 'alarm'
end status,
case
when account_mfa_enabled then 'MFA enabled for root account.'
else 'MFA not enabled for root account.'
end reason
${local.common_dimensions_global_sql}
from
aws_iam_account_summary;
EOQ
}
query "iam_user_access_key_age_90" {
sql = <<-EOQ
select
'arn:' || partition || ':iam::' || account_id || ':user/' || user_name || '/accesskey/' || access_key_id as resource,
case
when create_date <= (current_date - interval '90' day) then 'alarm'
else 'ok'
end status,
user_name || ' ' || access_key_id || ' created ' || to_char(create_date , 'DD-Mon-YYYY') ||
' (' || extract(day from current_timestamp - create_date) || ' days).'
as reason
${local.common_dimensions_global_sql}
from
aws_iam_access_key;
EOQ
}
query "iam_user_console_access_mfa_enabled" {
sql = <<-EOQ
select
user_arn as resource,
case
when password_enabled and not mfa_active then 'alarm'
else 'ok'
end as status,
case
when not password_enabled then user_name || ' password login disabled.'
when password_enabled and not mfa_active then user_name || ' password login enabled but no MFA device configured.'
else user_name || ' password login enabled and MFA device configured.'
end as reason
${local.common_dimensions_global_sql}
from
aws_iam_credential_report;
EOQ
}
query "iam_user_mfa_enabled" {
sql = <<-EOQ
select
user_arn as resource,
case
when not mfa_active then 'alarm'
else 'ok'
end as status,
case
when not mfa_active then user_name || ' MFA device not configured.'
else user_name || ' MFA device configured.'
end as reason
${local.common_dimensions_global_sql}
from
aws_iam_credential_report;
EOQ
}
query "iam_user_no_inline_attached_policies" {
sql = <<-EOQ
select
arn as resource,
case
when inline_policies is null and attached_policy_arns is null then 'ok'
else 'alarm'
end status,
name || ' has ' || coalesce(jsonb_array_length(inline_policies),0) || ' inline and ' ||
coalesce(jsonb_array_length(attached_policy_arns),0) || ' directly attached policies.' as reason
${local.tag_dimensions_sql}
${local.common_dimensions_global_sql}
from
aws_iam_user;
EOQ
}
query "iam_user_unused_credentials_90" {
sql = <<-EOQ
select
user_arn as resource,
case
when user_name = '<root_account>'
then 'info'
when password_enabled and password_last_used is null and password_last_changed < (current_date - interval '90' day)
then 'alarm'
when password_enabled and password_last_used < (current_date - interval '90' day)
then 'alarm'
when access_key_1_active and access_key_1_last_used_date is null and access_key_1_last_rotated < (current_date - interval '90' day)
then 'alarm'
when access_key_1_active and access_key_1_last_used_date < (current_date - interval '90' day)
then 'alarm'
when access_key_2_active and access_key_2_last_used_date is null and access_key_2_last_rotated < (current_date - interval '90' day)
then 'alarm'
when access_key_2_active and access_key_2_last_used_date < (current_date - interval '90' day)
then 'alarm'
else 'ok'
end status,
user_name ||
case
when not password_enabled
then ' password not enabled,'
when password_enabled and password_last_used is null
then ' password created ' || to_char(password_last_changed, 'DD-Mon-YYYY') || ' never used,'
else
' password used ' || to_char(password_last_used, 'DD-Mon-YYYY') || ','
end ||
case
when not access_key_1_active
then ' key 1 not enabled,'
when access_key_1_active and access_key_1_last_used_date is null
then ' key 1 created ' || to_char(access_key_1_last_rotated, 'DD-Mon-YYYY') || ' never used,'
else
' key 1 used ' || to_char(access_key_1_last_used_date, 'DD-Mon-YYYY') || ','
end ||
case
when not access_key_2_active
then ' key 2 not enabled.'
when access_key_2_active and access_key_2_last_used_date is null
then ' key 2 created ' || to_char(access_key_2_last_rotated, 'DD-Mon-YYYY') || ' never used.'
else
' key 2 used ' || to_char(access_key_2_last_used_date, 'DD-Mon-YYYY') || '.'
end
as reason
${local.common_dimensions_global_sql}
from
aws_iam_credential_report;
EOQ
}
query "iam_user_in_group" {
sql = <<-EOQ
select
arn as resource,
case
when jsonb_array_length(groups) = 0 then 'alarm'
else 'ok'
end as status,
case
when jsonb_array_length(groups) = 0 then title || ' not associated with any IAM group.'
else title || ' associated with IAM group.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_global_sql}
from
aws_iam_user;
EOQ
}
query "iam_group_user_role_no_inline_policies" {
sql = <<-EOQ
select
arn as resource,
case
when inline_policies is null then 'ok'
else 'alarm'
end status,
'User ' || title || ' has ' || coalesce(jsonb_array_length(inline_policies), 0) || ' inline policies.' as reason
${local.common_dimensions_global_sql}
from
aws_iam_user
union
select
arn as resource,
case
when inline_policies is null then 'ok'
else 'alarm'