cfn-nag 0.3.42 → 0.3.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cfn-nag/cfn_nag.rb +1 -1
  3. data/lib/cfn-nag/custom_rule_loader.rb +0 -2
  4. data/lib/cfn-nag/custom_rules/EbsVolumeHasSseRule.rb +1 -1
  5. data/lib/cfn-nag/custom_rules/IamManagedPolicyNotActionRule.rb +2 -2
  6. data/lib/cfn-nag/custom_rules/IamManagedPolicyNotResourceRule.rb +2 -2
  7. data/lib/cfn-nag/custom_rules/IamManagedPolicyWildcardActionRule.rb +2 -2
  8. data/lib/cfn-nag/custom_rules/IamManagedPolicyWildcardResourceRule.rb +2 -2
  9. data/lib/cfn-nag/custom_rules/IamPolicyNotActionRule.rb +2 -2
  10. data/lib/cfn-nag/custom_rules/IamPolicyNotResourceRule.rb +2 -2
  11. data/lib/cfn-nag/custom_rules/IamPolicyWildcardActionRule.rb +2 -2
  12. data/lib/cfn-nag/custom_rules/IamPolicyWildcardResourceRule.rb +2 -2
  13. data/lib/cfn-nag/custom_rules/IamRoleNotActionOnPermissionsPolicyRule.rb +4 -4
  14. data/lib/cfn-nag/custom_rules/IamRoleNotActionOnTrustPolicyRule.rb +2 -2
  15. data/lib/cfn-nag/custom_rules/IamRoleNotPrincipalOnTrustPolicyRule.rb +2 -2
  16. data/lib/cfn-nag/custom_rules/IamRoleNotResourceOnPermissionsPolicyRule.rb +4 -4
  17. data/lib/cfn-nag/custom_rules/IamRoleWildcardActionOnPermissionsPolicyRule.rb +4 -4
  18. data/lib/cfn-nag/custom_rules/IamRoleWildcardActionOnTrustPolicyRule.rb +2 -2
  19. data/lib/cfn-nag/custom_rules/IamRoleWildcardResourceOnPermissionsPolicyRule.rb +4 -4
  20. data/lib/cfn-nag/custom_rules/LambdaPermissionInvokeFunctionActionRule.rb +2 -2
  21. data/lib/cfn-nag/custom_rules/ManagedPolicyOnUserRule.rb +2 -2
  22. data/lib/cfn-nag/custom_rules/PolicyOnUserRule.rb +2 -2
  23. data/lib/cfn-nag/custom_rules/RDSInstanceMasterUserPasswordRule.rb +1 -5
  24. data/lib/cfn-nag/custom_rules/RDSInstancePubliclyAccessibleRule.rb +1 -1
  25. data/lib/cfn-nag/custom_rules/S3BucketPolicyNotActionRule.rb +2 -2
  26. data/lib/cfn-nag/custom_rules/S3BucketPolicyNotPrincipalRule.rb +2 -2
  27. data/lib/cfn-nag/custom_rules/S3BucketPolicyWildcardActionRule.rb +1 -1
  28. data/lib/cfn-nag/custom_rules/S3BucketPolicyWildcardPrincipalRule.rb +1 -1
  29. data/lib/cfn-nag/custom_rules/S3BucketPublicReadAclRule.rb +1 -3
  30. data/lib/cfn-nag/custom_rules/S3BucketPublicReadWriteAclRule.rb +1 -3
  31. data/lib/cfn-nag/custom_rules/SecurityGroupEgressOpenToWorldRule.rb +1 -3
  32. data/lib/cfn-nag/custom_rules/SecurityGroupEgressPortRangeRule.rb +5 -7
  33. data/lib/cfn-nag/custom_rules/SecurityGroupIngressCidrNon32Rule.rb +1 -3
  34. data/lib/cfn-nag/custom_rules/SecurityGroupIngressOpenToWorldRule.rb +1 -3
  35. data/lib/cfn-nag/custom_rules/SecurityGroupIngressPortRangeRule.rb +5 -7
  36. data/lib/cfn-nag/custom_rules/SecurityGroupMissingEgressRule.rb +1 -3
  37. data/lib/cfn-nag/custom_rules/SnsTopicPolicyNotActionRule.rb +2 -2
  38. data/lib/cfn-nag/custom_rules/SnsTopicPolicyNotPrincipalRule.rb +2 -2
  39. data/lib/cfn-nag/custom_rules/SnsTopicPolicyWildcardPrincipalRule.rb +1 -1
  40. data/lib/cfn-nag/custom_rules/SqsQueuePolicyNotActionRule.rb +2 -2
  41. data/lib/cfn-nag/custom_rules/SqsQueuePolicyNotPrincipalRule.rb +2 -2
  42. data/lib/cfn-nag/custom_rules/SqsQueuePolicyWildcardActionRule.rb +1 -1
  43. data/lib/cfn-nag/custom_rules/SqsQueuePolicyWildcardPrincipalRule.rb +1 -1
  44. data/lib/cfn-nag/custom_rules/UserHasInlinePolicyRule.rb +2 -2
  45. data/lib/cfn-nag/custom_rules/UserMissingGroupRule.rb +1 -3
  46. data/lib/cfn-nag/custom_rules/base.rb +1 -3
  47. data/lib/cfn-nag/ip_addr.rb +1 -3
  48. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e08294c96cc7f50e91056c95a4526f65f0411374c39cdaea005151d79edc827
4
- data.tar.gz: d9131731e68fa304ac58ef12bb7c8503bc7286709095c47341ae67d65caf30de
3
+ metadata.gz: 431c10516146893563f42ae5a75a3fdb9019b03ae6feb03dcd16e5cb804a4b99
4
+ data.tar.gz: c0f24c8a080c368ea450344b3f981797d72b3c696ab8b1fd66c99060dfb822ef
5
5
  SHA512:
6
- metadata.gz: 30fe4795e72a5c982e0a9aebd6ff2277d1fe4614f9b31d62dfaa3ef20d241a72162162238582ef40cb72a6a9b69b69e589b437ee88ec940b51edbf4fc077760c
7
- data.tar.gz: 4d763411132face705b1a3a872319d56e671f5ca79a6661f4b86c5e0277bae656292c294ae3bf1a25afbf1670b7aa5e65183294628f020c0f97409581818b142
6
+ metadata.gz: 615aa2c6fae2c0b3b1b951812fb68953cf2c7700926314c5f8babc03286b0bf1d8b7e209cf925b481f475b19ba30f46a4ef2d4315762de7bab091f2fbf3d486f
7
+ data.tar.gz: 41002ed03b0a00deb1a1d40bceb8fa02ce5d25fd723d9c90c356a64060ccdb4a02583c74681afbe3c580363ca311b3de37d0b94c9f03cd11520cd4696c5011d7
@@ -114,7 +114,7 @@ class CfnNag
114
114
  end
115
115
 
116
116
  violations.reject do |violation|
117
- not profile.nil? and not profile.execute_rule?(violation.id)
117
+ !profile.nil? && !profile.execute_rule?(violation.id)
118
118
  end
119
119
  end
120
120
 
@@ -81,8 +81,6 @@ class CustomRuleLoader
81
81
  resource.metadata['cfn_nag']['rules_to_suppress']
82
82
 
83
83
  resource.metadata['cfn_nag']['rules_to_suppress']
84
- else
85
- nil
86
84
  end
87
85
  end
88
86
 
@@ -17,7 +17,7 @@ class EbsVolumeHasSseRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_volumes = \
19
19
  cfn_model.resources_by_type('AWS::EC2::Volume').select do |volume|
20
- volume.encrypted.nil? || volume.encrypted.to_s.downcase == 'false'
20
+ volume.encrypted.nil? || volume.encrypted.to_s.casecmp('false').zero?
21
21
  end
22
22
 
23
23
  violating_volumes.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamManagedPolicyNotActionRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::ManagedPolicy')
20
- .select do |policy|
21
- !policy.policy_document.allows_not_action.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.allows_not_action.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamManagedPolicyNotResourceRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::ManagedPolicy')
20
- .select do |policy|
21
- !policy.policy_document.allows_not_resource.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.allows_not_resource.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamManagedPolicyWildcardActionRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::ManagedPolicy')
20
- .select do |policy|
21
- !policy.policy_document.wildcard_allowed_actions.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.wildcard_allowed_actions.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamManagedPolicyWildcardResourceRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::ManagedPolicy')
20
- .select do |policy|
21
- !policy.policy_document.wildcard_allowed_resources.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.wildcard_allowed_resources.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamPolicyNotActionRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::Policy')
20
- .select do |policy|
21
- !policy.policy_document.allows_not_action.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.allows_not_action.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -17,8 +17,8 @@ class IamPolicyNotResourceRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  violating_policies = \
19
19
  cfn_model.resources_by_type('AWS::IAM::Policy')
20
- .select do |policy|
21
- !policy.policy_document.allows_not_resource.empty?
20
+ .reject do |policy|
21
+ policy.policy_document.allows_not_resource.empty?
22
22
  end
23
23
 
24
24
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class IamPolicyWildcardActionRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').select do |policy|
19
- !policy.policy_document.wildcard_allowed_actions.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').reject do |policy|
19
+ policy.policy_document.wildcard_allowed_actions.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class IamPolicyWildcardResourceRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').select do |policy|
19
- !policy.policy_document.wildcard_allowed_resources.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').reject do |policy|
19
+ policy.policy_document.wildcard_allowed_resources.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,11 +15,11 @@ class IamRoleNotActionOnPermissionsPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- violating_policies = role.policy_objects.select do |policy|
20
- !policy.policy_document.allows_not_action.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ violating_policies = role.policy_objects.reject do |policy|
20
+ policy.policy_document.allows_not_action.empty?
21
21
  end
22
- !violating_policies.empty?
22
+ violating_policies.empty?
23
23
  end
24
24
 
25
25
  violating_roles.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class IamRoleNotActionOnTrustPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- !role.assume_role_policy_document.allows_not_action.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ role.assume_role_policy_document.allows_not_action.empty?
20
20
  end
21
21
 
22
22
  violating_roles.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class IamRoleNotPrincipalOnTrustPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- !role.assume_role_policy_document.allows_not_principal.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ role.assume_role_policy_document.allows_not_principal.empty?
20
20
  end
21
21
 
22
22
  violating_roles.map(&:logical_resource_id)
@@ -15,11 +15,11 @@ class IamRoleNotResourceOnPermissionsPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- violating_policies = role.policy_objects.select do |policy|
20
- !policy.policy_document.allows_not_resource.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ violating_policies = role.policy_objects.reject do |policy|
20
+ policy.policy_document.allows_not_resource.empty?
21
21
  end
22
- !violating_policies.empty?
22
+ violating_policies.empty?
23
23
  end
24
24
 
25
25
  violating_roles.map(&:logical_resource_id)
@@ -15,11 +15,11 @@ class IamRoleWildcardActionOnPermissionsPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- violating_policies = role.policy_objects.select do |policy|
20
- !policy.policy_document.wildcard_allowed_actions.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ violating_policies = role.policy_objects.reject do |policy|
20
+ policy.policy_document.wildcard_allowed_actions.empty?
21
21
  end
22
- !violating_policies.empty?
22
+ violating_policies.empty?
23
23
  end
24
24
 
25
25
  violating_roles.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class IamRoleWildcardActionOnTrustPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- !role.assume_role_policy_document.wildcard_allowed_actions.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ role.assume_role_policy_document.wildcard_allowed_actions.empty?
20
20
  end
21
21
 
22
22
  violating_roles.map(&:logical_resource_id)
@@ -15,11 +15,11 @@ class IamRoleWildcardResourceOnPermissionsPolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').select do |role|
19
- violating_policies = role.policy_objects.select do |policy|
20
- !policy.policy_document.wildcard_allowed_resources.empty?
18
+ violating_roles = cfn_model.resources_by_type('AWS::IAM::Role').reject do |role|
19
+ violating_policies = role.policy_objects.reject do |policy|
20
+ policy.policy_document.wildcard_allowed_resources.empty?
21
21
  end
22
- !violating_policies.empty?
22
+ violating_policies.empty?
23
23
  end
24
24
 
25
25
  violating_roles.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class LambdaPermissionInvokeFunctionActionRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_lambdas = cfn_model.resources_by_type('AWS::Lambda::Permission').select do |lambda_permission|
19
- lambda_permission.action != 'lambda:InvokeFunction'
18
+ violating_lambdas = cfn_model.resources_by_type('AWS::Lambda::Permission').reject do |lambda_permission|
19
+ lambda_permission.action == 'lambda:InvokeFunction'
20
20
  end
21
21
 
22
22
  violating_lambdas.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class ManagedPolicyOnUserRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::IAM::ManagedPolicy').select do |policy|
19
- policy.users.size > 0
18
+ violating_policies = cfn_model.resources_by_type('AWS::IAM::ManagedPolicy').reject do |policy|
19
+ policy.users.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class PolicyOnUserRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').select do |policy|
19
- policy.users.size > 0
18
+ violating_policies = cfn_model.resources_by_type('AWS::IAM::Policy').reject do |policy|
19
+ policy.users.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -32,11 +32,7 @@ class RDSInstanceMasterUserPasswordRule < BaseRule
32
32
  private
33
33
 
34
34
  def to_boolean(string)
35
- if string.to_s.downcase == 'true'
36
- true
37
- else
38
- false
39
- end
35
+ string.to_s.casecmp('true').zero?
40
36
  end
41
37
 
42
38
  def references_no_echo_parameter_without_default?(cfn_model, master_user_password)
@@ -16,7 +16,7 @@ class RDSInstancePubliclyAccessibleRule < BaseRule
16
16
 
17
17
  def audit_impl(cfn_model)
18
18
  violating_rdsinstances = cfn_model.resources_by_type('AWS::RDS::DBInstance').select do |instance|
19
- instance.publiclyAccessible.nil? || instance.publiclyAccessible.to_s.downcase == 'true'
19
+ instance.publiclyAccessible.nil? || instance.publiclyAccessible.to_s.casecmp('true').zero?
20
20
  end
21
21
 
22
22
  violating_rdsinstances.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class S3BucketPolicyNotActionRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::S3::BucketPolicy').select do |policy|
19
- !policy.policy_document.allows_not_action.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::S3::BucketPolicy').reject do |policy|
19
+ policy.policy_document.allows_not_action.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class S3BucketPolicyNotPrincipalRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::S3::BucketPolicy').select do |policy|
19
- !policy.policy_document.allows_not_principal.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::S3::BucketPolicy').reject do |policy|
19
+ policy.policy_document.allows_not_principal.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -18,7 +18,7 @@ class S3BucketPolicyWildcardActionRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::S3::BucketPolicy').each do |bucket_policy|
21
- if !bucket_policy.policy_document.wildcard_allowed_actions.empty?
21
+ unless bucket_policy.policy_document.wildcard_allowed_actions.empty?
22
22
  logical_resource_ids << bucket_policy.logical_resource_id
23
23
  end
24
24
  end
@@ -18,7 +18,7 @@ class S3BucketPolicyWildcardPrincipalRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::S3::BucketPolicy').each do |topic_policy|
21
- if !topic_policy.policy_document.wildcard_allowed_principals.empty?
21
+ unless topic_policy.policy_document.wildcard_allowed_principals.empty?
22
22
  logical_resource_ids << topic_policy.logical_resource_id
23
23
  end
24
24
  end
@@ -18,9 +18,7 @@ class S3BucketPublicReadAclRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::S3::Bucket').each do |bucket|
21
- if bucket.accessControl == 'PublicRead'
22
- logical_resource_ids << bucket.logical_resource_id
23
- end
21
+ logical_resource_ids << bucket.logical_resource_id if bucket.accessControl == 'PublicRead'
24
22
  end
25
23
 
26
24
  logical_resource_ids
@@ -18,9 +18,7 @@ class S3BucketPublicReadWriteAclRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::S3::Bucket').each do |bucket|
21
- if bucket.accessControl == 'PublicReadWrite'
22
- logical_resource_ids << bucket.logical_resource_id
23
- end
21
+ logical_resource_ids << bucket.logical_resource_id if bucket.accessControl == 'PublicReadWrite'
24
22
  end
25
23
 
26
24
  logical_resource_ids
@@ -26,9 +26,7 @@ class SecurityGroupEgressOpenToWorldRule < BaseRule
26
26
  ip4_open?(egress) || ip6_open?(egress)
27
27
  end
28
28
 
29
- unless violating_egresses.empty?
30
- logical_resource_ids << security_group.logical_resource_id
31
- end
29
+ logical_resource_ids << security_group.logical_resource_id unless violating_egresses.empty?
32
30
  end
33
31
 
34
32
  violating_egresses = cfn_model.standalone_egress.select do |standalone_egress|
@@ -19,17 +19,15 @@ class SecurityGroupEgressPortRangeRule < BaseRule
19
19
  def audit_impl(cfn_model)
20
20
  logical_resource_ids = []
21
21
  cfn_model.security_groups.each do |security_group|
22
- violating_egresses = security_group.egresses.select do |egress|
23
- egress.fromPort != egress.toPort
22
+ violating_egresses = security_group.egresses.reject do |egress|
23
+ egress.fromPort == egress.toPort
24
24
  end
25
25
 
26
- unless violating_egresses.empty?
27
- logical_resource_ids << security_group.logical_resource_id
28
- end
26
+ logical_resource_ids << security_group.logical_resource_id unless violating_egresses.empty?
29
27
  end
30
28
 
31
- violating_egresses = cfn_model.standalone_egress.select do |standalone_egress|
32
- standalone_egress.fromPort != standalone_egress.toPort
29
+ violating_egresses = cfn_model.standalone_egress.reject do |standalone_egress|
30
+ standalone_egress.fromPort == standalone_egress.toPort
33
31
  end
34
32
 
35
33
  logical_resource_ids + violating_egresses.map(&:logical_resource_id)
@@ -26,9 +26,7 @@ class SecurityGroupIngressCidrNon32Rule < BaseRule
26
26
  ip4_cidr_range?(ingress) || ip6_cidr_range?(ingress)
27
27
  end
28
28
 
29
- unless violating_ingresses.empty?
30
- logical_resource_ids << security_group.logical_resource_id
31
- end
29
+ logical_resource_ids << security_group.logical_resource_id unless violating_ingresses.empty?
32
30
  end
33
31
 
34
32
  violating_ingresses = cfn_model.standalone_ingress.select do |standalone_ingress|
@@ -28,9 +28,7 @@ class SecurityGroupIngressOpenToWorldRule < BaseRule
28
28
  ip4_open?(ingress) || ip6_open?(ingress)
29
29
  end
30
30
 
31
- unless violating_ingresses.empty?
32
- logical_resource_ids << security_group.logical_resource_id
33
- end
31
+ logical_resource_ids << security_group.logical_resource_id unless violating_ingresses.empty?
34
32
  end
35
33
 
36
34
  violating_ingresses = cfn_model.standalone_ingress.select do |standalone_ingress|
@@ -19,17 +19,15 @@ class SecurityGroupIngressPortRangeRule < BaseRule
19
19
  def audit_impl(cfn_model)
20
20
  logical_resource_ids = []
21
21
  cfn_model.security_groups.each do |security_group|
22
- violating_ingresses = security_group.ingresses.select do |ingress|
23
- ingress.fromPort != ingress.toPort
22
+ violating_ingresses = security_group.ingresses.reject do |ingress|
23
+ ingress.fromPort == ingress.toPort
24
24
  end
25
25
 
26
- unless violating_ingresses.empty?
27
- logical_resource_ids << security_group.logical_resource_id
28
- end
26
+ logical_resource_ids << security_group.logical_resource_id unless violating_ingresses.empty?
29
27
  end
30
28
 
31
- violating_ingresses = cfn_model.standalone_ingress.select do |standalone_ingress|
32
- standalone_ingress.fromPort != standalone_ingress.toPort
29
+ violating_ingresses = cfn_model.standalone_ingress.reject do |standalone_ingress|
30
+ standalone_ingress.fromPort == standalone_ingress.toPort
33
31
  end
34
32
 
35
33
  logical_resource_ids + violating_ingresses.map(&:logical_resource_id)
@@ -17,9 +17,7 @@ class SecurityGroupMissingEgressRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  logical_resource_ids = []
19
19
  cfn_model.security_groups.each do |security_group|
20
- if security_group.egresses.empty?
21
- logical_resource_ids << security_group.logical_resource_id
22
- end
20
+ logical_resource_ids << security_group.logical_resource_id if security_group.egresses.empty?
23
21
  end
24
22
 
25
23
  logical_resource_ids
@@ -15,8 +15,8 @@ class SnsTopicPolicyNotActionRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::SNS::TopicPolicy').select do |policy|
19
- !policy.policy_document.allows_not_action.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::SNS::TopicPolicy').reject do |policy|
19
+ policy.policy_document.allows_not_action.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class SnsTopicPolicyNotPrincipalRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::SNS::TopicPolicy').select do |policy|
19
- !policy.policy_document.allows_not_principal.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::SNS::TopicPolicy').reject do |policy|
19
+ policy.policy_document.allows_not_principal.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -18,7 +18,7 @@ class SnsTopicPolicyWildcardPrincipalRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::SNS::TopicPolicy').each do |topic_policy|
21
- if !topic_policy.policy_document.wildcard_allowed_principals.empty?
21
+ unless topic_policy.policy_document.wildcard_allowed_principals.empty?
22
22
  logical_resource_ids << topic_policy.logical_resource_id
23
23
  end
24
24
  end
@@ -15,8 +15,8 @@ class SqsQueuePolicyNotActionRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::SQS::QueuePolicy').select do |policy|
19
- !policy.policy_document.allows_not_action.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::SQS::QueuePolicy').reject do |policy|
19
+ policy.policy_document.allows_not_action.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -15,8 +15,8 @@ class SqsQueuePolicyNotPrincipalRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_policies = cfn_model.resources_by_type('AWS::SQS::QueuePolicy').select do |policy|
19
- !policy.policy_document.allows_not_principal.empty?
18
+ violating_policies = cfn_model.resources_by_type('AWS::SQS::QueuePolicy').reject do |policy|
19
+ policy.policy_document.allows_not_principal.empty?
20
20
  end
21
21
 
22
22
  violating_policies.map(&:logical_resource_id)
@@ -18,7 +18,7 @@ class SqsQueuePolicyWildcardActionRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::SQS::QueuePolicy').each do |queue_policy|
21
- if !queue_policy.policy_document.wildcard_allowed_actions.empty?
21
+ unless queue_policy.policy_document.wildcard_allowed_actions.empty?
22
22
  logical_resource_ids << queue_policy.logical_resource_id
23
23
  end
24
24
  end
@@ -18,7 +18,7 @@ class SqsQueuePolicyWildcardPrincipalRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::SQS::QueuePolicy').each do |topic_policy|
21
- if !topic_policy.policy_document.wildcard_allowed_principals.empty?
21
+ unless topic_policy.policy_document.wildcard_allowed_principals.empty?
22
22
  logical_resource_ids << topic_policy.logical_resource_id
23
23
  end
24
24
  end
@@ -15,8 +15,8 @@ class UserHasInlinePolicyRule < BaseRule
15
15
  end
16
16
 
17
17
  def audit_impl(cfn_model)
18
- violating_users = cfn_model.iam_users.select do |iam_user|
19
- iam_user.policy_objects.size > 0
18
+ violating_users = cfn_model.iam_users.reject do |iam_user|
19
+ iam_user.policy_objects.empty?
20
20
  end
21
21
 
22
22
  violating_users.map(&:logical_resource_id)
@@ -17,9 +17,7 @@ class UserMissingGroupRule < BaseRule
17
17
  def audit_impl(cfn_model)
18
18
  logical_resource_ids = []
19
19
  cfn_model.iam_users.each do |iam_user|
20
- if iam_user.group_names.empty?
21
- logical_resource_ids << iam_user.logical_resource_id
22
- end
20
+ logical_resource_ids << iam_user.logical_resource_id if iam_user.group_names.empty?
23
21
  end
24
22
 
25
23
  logical_resource_ids
@@ -15,13 +15,11 @@ class BaseRule
15
15
  def audit(cfn_model)
16
16
  logical_resource_ids = audit_impl(cfn_model)
17
17
 
18
- if !logical_resource_ids.empty?
18
+ unless logical_resource_ids.empty?
19
19
  Violation.new(id: rule_id,
20
20
  type: rule_type,
21
21
  message: rule_text,
22
22
  logical_resource_ids: logical_resource_ids)
23
- else
24
- nil
25
23
  end
26
24
  end
27
25
  end
@@ -39,11 +39,9 @@ module IpAddr
39
39
  #
40
40
  def normalize_cidr_ip6(ingress)
41
41
  if ingress.cidrIpv6.is_a?(Symbol)
42
- ":#{ingress.cidrIpv6.to_s}"
42
+ ":#{ingress.cidrIpv6}"
43
43
  elsif ingress.cidrIpv6.is_a?(String)
44
44
  ingress.cidrIpv6
45
- else
46
- nil
47
45
  end
48
46
  end
49
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-nag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.42
4
+ version: 0.3.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec