1- # Trust Scope Security Rules
2- # This rule file checks for overly broad trust scopes in IAM resources
1+ #
2+ #####################################
3+ ## AWS CDK ##
4+ #####################################
5+ # Rule Identifier:
6+ # IAM_ROLE_NO_BROAD_PRINCIPALS
7+ #
8+ # Description:
9+ # Checks if IAM roles have overly permissive assume role policies by identifying:
10+ # 1. Use of account root in AWS principals
11+ # 2. Use of wildcards in AWS principals
12+ # 3. Use of wildcards as entire principal
13+ # 4. Allows specific role ARNs that are not root
14+ # 5. Catches use of !Join function to construct root ARNs
15+ #
16+ # Reports on:
17+ # AWS::IAM::Role
18+ #
19+ # Evaluates:
20+ # AWS CloudFormation
21+ #
22+ # Rule Parameters:
23+ # None
24+ #
25+ # Scenarios:
26+ # a) SKIP: when there are no IAM Role resources
27+ # b) SKIP: when IAM Role resources only have service principals
28+ # c) PASS: when IAM Role resources with AWS principals use specific ARNs (not root or wildcards)
29+ # d) PASS: when IAM Role resources with AWS principals use specific role ARNs
30+ # e) FAIL: when any IAM Role resource uses account root in AWS principal
31+ # f) FAIL: when any IAM Role resource uses wildcard in AWS principal
32+ # g) FAIL: when any IAM Role resource uses wildcard as entire principal
333
4- # Rule to check for overly permissive IAM role trust policies
5- rule iam_role_trust_policy_not_overly_permissive {
6- when AWS::IAM::Role exists {
7- Properties exists
8- Properties is_struct
9-
10- Properties.AssumeRolePolicyDocument exists
11- Properties.AssumeRolePolicyDocument is_struct
12-
13- Properties.AssumeRolePolicyDocument {
14- Statement exists
15- Statement is_list
16-
17- # For each statement in the policy
18- Statement[*] {
19- # Check if Principal is overly permissive
34+ #
35+ # Select all IAM Role resources from incoming template
36+ #
37+ let iam_roles_no_broad_principals = Resources.*[ Type == 'AWS::IAM::Role'
38+ Metadata.guard.SuppressedRules not exists or
39+ Metadata.guard.SuppressedRules.* != "IAM_ROLE_NO_BROAD_PRINCIPALS"
40+ ]
41+
42+ rule IAM_ROLE_NO_BROAD_PRINCIPALS when %iam_roles_no_broad_principals !empty {
43+ %iam_roles_no_broad_principals.Properties.AssumeRolePolicyDocument.Statement[*] {
2044 when Principal exists {
21- # Check if Principal is a string (direct "*" case)
22- when Principal is_string {
23- Principal != "*"
24- }
25-
45+ # Check for wildcard as entire principal
46+ when Principal is_string {
47+ Principal != "*"
48+ }
2649 # Check if AWS principal exists
2750 when Principal.AWS exists {
2851 # Check if AWS is a string
@@ -31,9 +54,6 @@ rule iam_role_trust_policy_not_overly_permissive {
3154 Principal.AWS != /(?i):root/
3255 }
3356 }
34- }
35- }
3657 }
3758 }
38- }
39-
59+ }
0 commit comments