inspec 2.1.84 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -8
  3. data/README.md +1 -0
  4. data/docs/dev/filtertable-internals.md +353 -0
  5. data/docs/dev/filtertable-usage.md +533 -0
  6. data/docs/matchers.md +36 -36
  7. data/docs/profiles.md +2 -2
  8. data/docs/resources/apache.md.erb +1 -1
  9. data/docs/resources/aws_elb.md.erb +144 -0
  10. data/docs/resources/aws_elbs.md.erb +242 -0
  11. data/docs/resources/aws_flow_log.md.erb +118 -0
  12. data/docs/resources/aws_iam_groups.md.erb +34 -1
  13. data/docs/resources/crontab.md.erb +10 -6
  14. data/docs/resources/dh_params.md.erb +71 -65
  15. data/docs/resources/docker_service.md.erb +1 -1
  16. data/docs/resources/etc_fstab.md.erb +1 -1
  17. data/docs/resources/firewalld.md.erb +1 -1
  18. data/docs/resources/http.md.erb +1 -1
  19. data/docs/resources/iis_app.md.erb +1 -1
  20. data/docs/resources/inetd_conf.md.erb +1 -1
  21. data/docs/resources/nginx.md.erb +1 -1
  22. data/docs/resources/npm.md.erb +9 -1
  23. data/docs/resources/os.md.erb +21 -19
  24. data/docs/resources/shadow.md.erb +37 -31
  25. data/docs/resources/x509_certificate.md.erb +2 -2
  26. data/examples/custom-resource/README.md +3 -0
  27. data/examples/custom-resource/controls/example.rb +7 -0
  28. data/examples/custom-resource/inspec.yml +8 -0
  29. data/examples/custom-resource/libraries/batsignal.rb +20 -0
  30. data/examples/custom-resource/libraries/gordon.rb +21 -0
  31. data/lib/inspec/reporters/junit.rb +1 -0
  32. data/lib/inspec/resource.rb +8 -0
  33. data/lib/inspec/version.rb +1 -1
  34. data/lib/resource_support/aws.rb +3 -0
  35. data/lib/resources/aws/aws_elb.rb +81 -0
  36. data/lib/resources/aws/aws_elbs.rb +78 -0
  37. data/lib/resources/aws/aws_flow_log.rb +102 -0
  38. data/lib/resources/aws/aws_iam_groups.rb +1 -2
  39. data/lib/resources/aws/aws_iam_users.rb +65 -47
  40. data/lib/resources/npm.rb +15 -2
  41. data/lib/resources/package.rb +1 -1
  42. data/lib/utils/filter.rb +243 -85
  43. metadata +15 -2
data/docs/matchers.md CHANGED
@@ -55,58 +55,58 @@ end
55
55
 
56
56
  * Compare strings to numbers
57
57
 
58
- ```ruby
59
- describe sshd_config do
60
- its('Protocol') { should eq '2' }
58
+ ```ruby
59
+ describe sshd_config do
60
+ its('Protocol') { should eq '2' }
61
61
 
62
- its('Protocol') { should cmp '2' }
63
- its('Protocol') { should cmp 2 }
64
- end
65
- ```
62
+ its('Protocol') { should cmp '2' }
63
+ its('Protocol') { should cmp 2 }
64
+ end
65
+ ```
66
66
 
67
67
  * String comparisons are not case-sensitive
68
68
 
69
- ```ruby
70
- describe auditd_conf do
71
- its('log_format') { should cmp 'raw' }
72
- its('log_format') { should cmp 'RAW' }
73
- end
74
- ```
69
+ ```ruby
70
+ describe auditd_conf do
71
+ its('log_format') { should cmp 'raw' }
72
+ its('log_format') { should cmp 'RAW' }
73
+ end
74
+ ```
75
75
  * Recognize versions embedded in strings
76
76
 
77
- ```ruby
78
- describe package(curl) do
79
- its('version') { should cmp > '7.35.0-1ubuntu2.10' }
80
- end
81
- ```
77
+ ```ruby
78
+ describe package(curl) do
79
+ its('version') { should cmp > '7.35.0-1ubuntu2.10' }
80
+ end
81
+ ```
82
82
 
83
83
  * Compare arrays with only one entry to a value
84
84
 
85
- ```ruby
86
- describe passwd.uids(0) do
87
- its('users') { should cmp 'root' }
88
- its('users') { should cmp ['root'] }
89
- end
90
- ```
85
+ ```ruby
86
+ describe passwd.uids(0) do
87
+ its('users') { should cmp 'root' }
88
+ its('users') { should cmp ['root'] }
89
+ end
90
+ ```
91
91
 
92
92
  * Single-value arrays of strings may also be compared to a regex
93
93
 
94
- ```ruby
95
- describe auditd_conf do
96
- its('log_format') { should cmp /raw/i }
97
- end
98
- ```
94
+ ```ruby
95
+ describe auditd_conf do
96
+ its('log_format') { should cmp /raw/i }
97
+ end
98
+ ```
99
99
 
100
100
  * Improved printing of octal comparisons
101
101
 
102
- ```ruby
103
- describe file('/proc/cpuinfo') do
104
- its('mode') { should cmp '0345' }
105
- end
102
+ ```ruby
103
+ describe file('/proc/cpuinfo') do
104
+ its('mode') { should cmp '0345' }
105
+ end
106
106
 
107
- expected: 0345
108
- got: 0444
109
- ```
107
+ expected: 0345
108
+ got: 0444
109
+ ```
110
110
  <br>
111
111
 
112
112
  ## eq
data/docs/profiles.md CHANGED
@@ -29,7 +29,7 @@ where:
29
29
  * `files` is the directory with additional files that a profile can access (optional)
30
30
  * `README.md` should be used to explain the profile, its scope, and usage
31
31
 
32
- See a complete example profile in the InSpec open source repository: [https://github.com/chef/inspec/tree/master/examples/profile](https://github.com/chef/inspec/tree/master/examples/profile)
32
+ See a complete example profile in the InSpec open source repository: [Example InSpec Profile](https://github.com/chef/inspec/tree/master/examples/profile)
33
33
 
34
34
  Also check out [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about how profiles are structured with hands-on examples.
35
35
 
@@ -300,7 +300,7 @@ The following command runs the tests and applies the secrets specified in `profi
300
300
 
301
301
  $ inspec exec examples/profile-attribute --attrs examples/profile-attribute.yml
302
302
 
303
- See the full example in the InSpec open source repository: https://github.com/chef/inspec/tree/master/examples/profile-attribute
303
+ See the full example in the InSpec open source repository: [Example InSpec Profile with Attributes](https://github.com/chef/inspec/tree/master/examples/profile-attribute)
304
304
 
305
305
  # Profile files
306
306
 
@@ -28,7 +28,7 @@ where
28
28
 
29
29
  ## Properties
30
30
 
31
- * 'service', 'conf_dir', 'conf_path', 'user'
31
+ * `service`, `conf_dir`, `conf_path`, `user`
32
32
 
33
33
  <br>
34
34
 
@@ -0,0 +1,144 @@
1
+ ---
2
+ title: About the aws_elb Resource
3
+ platform: aws
4
+ ---
5
+
6
+ # aws\_elb
7
+
8
+ Use the `aws_elb` InSpec audit resource to test properties of a single AWS Elastic Load Balancer (ELB, also known as a Classic Load Balancer).
9
+
10
+ To audit ELBs in bulk or to search, use `aws_elbs` (plural).
11
+
12
+ <br>
13
+
14
+ ## Resource Parameters
15
+
16
+ An `aws_elb` resource block declares the tests for a single AWS ELB by ELB name.
17
+
18
+ describe aws_elb('my-elb') do
19
+ it { should exist }
20
+ end
21
+
22
+ describe aws_elb(elb_name: 'my-elb') do
23
+ its('instance_ids.count') { should cmp 2 }
24
+ end
25
+
26
+ <br>
27
+
28
+ ## Examples
29
+
30
+ The following examples show how to use this InSpec audit resource.
31
+
32
+ ### Test that an ELB does not exist
33
+
34
+ describe aws_elb('bad-elb') do
35
+ it { should_not exist }
36
+ end
37
+
38
+ ### Test that an ELB has a presence in at least two availability zones
39
+
40
+ describe aws_elb('web') do
41
+ its('availability_zones.count') { should be > 1 }
42
+ end
43
+
44
+ <br>
45
+
46
+ ## Properties
47
+
48
+ ### availability\_zones
49
+
50
+ Returns an array of strings identifying which availability zones in which the load balancer is located.
51
+
52
+ # Verify we are in both us-east-2a and us-east-2b
53
+ describe aws_elb('web-elb') do
54
+ its('availability_zones') { should include 'us-east-2a' }
55
+ its('availability_zones') { should include 'us-east-2b' }
56
+ end
57
+
58
+ ### dns\_name
59
+
60
+ Returns the FQDN of the load balancer. This is the hostname which is exposed to the world.
61
+
62
+ # Ensure that the ELB has a DNS name
63
+ describe aws_elb('web-elb') do
64
+ its('dns_name') { should match /\.com/ }
65
+ end
66
+
67
+ ### elb\_name
68
+
69
+ The name of the ELB within AWS. The ELB name is unique within the region.
70
+
71
+ # Ensure that the ELB's name is what we said it was
72
+ describe aws_elb('web-elb') do
73
+ its('elb_name') { should match /web-elb/ }
74
+ end
75
+
76
+ ### external\_ports
77
+
78
+ Returns an array of integers reflecting the public-facing ports on which the load balancer will be listening for traffic.
79
+
80
+ # Ensure that we are listening on port 80 and nothing else
81
+ describe aws_elb('web-elb') do
82
+ its('external_ports') { should include 80 }
83
+ its('external_ports.count') { should cmp 1 }
84
+ end
85
+
86
+ ### instance\_ids
87
+
88
+ Returns an array of strings reflecting the instance IDs of the EC2 instances attached to the ELB.
89
+
90
+ # Ensure that a specific instance is attached
91
+ describe aws_elb('web-elb') do
92
+ its('instance_ids') { should include 'i-12345678' }
93
+ end
94
+
95
+
96
+ ### internal\_ports
97
+
98
+ Returns an array of integers reflecting the EC2-facing ports on which the load balancer will be sending traffic to.
99
+
100
+ # Ensure that we are sending traffic to port 80 on the instances and nothing else
101
+ describe aws_elb('web-elb') do
102
+ its('internal_ports') { should include 80 }
103
+ its('internal_ports.count') { should cmp 1 }
104
+ end
105
+
106
+ ### security\_group\_ids
107
+
108
+ Returns an array of strings reflecting the security group IDs (firewall rule sets) assigned to the ELB.
109
+
110
+ # Ensure that a specific SG ID is assigned
111
+ describe aws_elb('web-elb') do
112
+ its('security_group_ids') { should include 'sg-12345678' }
113
+ end
114
+
115
+ ### subnet\_ids
116
+
117
+ Returns an array of strings reflecting the subnet IDs on which the ELB is located.
118
+
119
+ # Ensure that the ELB is on a specific subnet
120
+ describe aws_elb('web-elb') do
121
+ its('subnet_ids') { should include 'subnet-12345678' }
122
+ end
123
+
124
+ ### vpc\_id
125
+
126
+ Returns a String reflecting the ID of the VPC in which the ELB is located.
127
+
128
+ # Ensure that the ELB is on a specific VPC
129
+ describe aws_elb('web-elb') do
130
+ its('vpc_id') { should cmp 'vpc-12345678' }
131
+ end
132
+
133
+ <br>
134
+
135
+ ## Matchers
136
+
137
+ This InSpec audit resource has no special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).
138
+
139
+
140
+ ## AWS Permissions
141
+
142
+ Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `elasticloadbalancing:DescribeLoadBalancers` action set to Allow.
143
+
144
+ You can find detailed documentation at [Authentication and Access Control for Your Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/load-balancer-authentication-access-control.html)
@@ -0,0 +1,242 @@
1
+ ---
2
+ title: About the aws_elbs Resource
3
+ platform: aws
4
+ ---
5
+
6
+ # aws\_elbs
7
+
8
+ Use the `aws_elbs` InSpec audit resource to test properties of AWS Elastic Load Balancers (ELBs, also known as a Classic Load Balancers) in bulk, or to search for a group of them based on their properties.
9
+
10
+ To audit a specific ELB in detail when its name is known, use `aws_elb` (singular).
11
+
12
+ <br>
13
+
14
+ ## Syntax
15
+
16
+ An `aws_elb` resource block uses an optional filter to select a group of ELBs and then tests that group.
17
+
18
+ # Check that you have at aleast one ELB
19
+ describe aws_elbs do
20
+ it { should exist }
21
+ end
22
+
23
+ # Ensure that you have at least one ELB in a specific VPC
24
+ describe aws_elb.where(vpc_id: 'vpc-12345678') do
25
+ it { should exist }
26
+ end
27
+
28
+ <br>
29
+
30
+ ## Filter Criteria
31
+
32
+ Use filter criteria with `where` to search for ELBs by their properties. `where` may be used in method mode (as in `aws_elbs.where(criterion: value)`) or in block mode (as in `aws_elbs.where { any code here }`). Several criteria on this resource may only be used with block-mode, because they are list-based.
33
+
34
+ ### availability\_zones
35
+
36
+ An array of strings identifying which availability zones in which the load balancer is located. This criterion must be used with block-mode `where`.
37
+
38
+ # Find ELBs with a footprint in us-east-2a
39
+ describe aws_elbs.where { availability_zones.include? 'us-east-2a' } do
40
+ it { should exist }
41
+ end
42
+
43
+ ### dns\_name
44
+
45
+ Returns the FQDN of the load balancer. This is the hostname which is exposed to the world.
46
+
47
+ # Find ELBs that have the letter z in their DNS name
48
+ describe aws_elbs.where(dns_name: /z/) do
49
+ it { should exist }
50
+ end
51
+
52
+ ### elb\_name
53
+
54
+ The name of the ELB within AWS. The ELB name is unique within the region. If you know the full ELB name, you should use the `aws_elb` resource instead, as it is much more efficient for testing a specific ELB.
55
+
56
+ # Find ELBs whose name ends in `prod`
57
+ describe aws_elbs.where(elb_name: /prod$/) do
58
+ it { should exist }
59
+ end
60
+
61
+ ### external\_ports
62
+
63
+ An array of integers reflecting the public-facing ports on which the load balancer will be listening for traffic. This criterion must be used with block-mode `where`.
64
+
65
+ # Find ELBs listening on port 80
66
+ describe aws_elbs.where { external_ports.include? 80 } do
67
+ it { should exist }
68
+ end
69
+
70
+ ### instance\_ids
71
+
72
+ An array of strings reflecting the instance IDs of the EC2 instances attached to the ELB. This criterion must be used with block-mode `where`.
73
+
74
+ # Find ELBs with at least 3 instances
75
+ describe aws_elbs.where { instance_ids.count > 2 } do
76
+ it { should exist }
77
+ end
78
+
79
+
80
+ ### internal\_ports
81
+
82
+ An array of integers reflecting the EC2-facing ports on which the load balancer will be sending traffic to. This criterion must be used with block-mode `where`.
83
+
84
+ # Find ELBs sending traffic to port 80
85
+ describe aws_elbs.where { internal_ports.include? 80 } do
86
+ it { should exist }
87
+ end
88
+
89
+ ### security\_group\_ids
90
+
91
+ An array of strings reflecting the security group IDs (firewall rule sets) assigned to the ELB. This criterion must be used with block-mode `where`.
92
+
93
+ # Find ELBs using a particular security group
94
+ describe aws_elbs.where { security_group_ids.include? 'sg-12345678' } do
95
+ it { should exist }
96
+ end
97
+
98
+ ### subnet\_ids
99
+
100
+ An array of strings reflecting the subnet IDs on which the ELB is located. This criterion must be used with block-mode `where`.
101
+
102
+ # Find ELBs located on a particular subnet
103
+ describe aws_elbs.where { subnet_ids.include? 'subnet-12345678' } do
104
+ it { should exist }
105
+ end
106
+
107
+ ### vpc\_id
108
+
109
+ A String reflecting the ID of the VPC in which the ELB is located.
110
+
111
+ # Find all ELBs in a specific VPC.
112
+ describe aws_elbs.where(vpc_id: 'vpc-12345678') do
113
+ it { should exist }
114
+ end
115
+
116
+ <br>
117
+
118
+ ## Properties
119
+
120
+ ### availability\_zones
121
+
122
+ An array of strings identifying which availability zones in which the selected load balancers are located. The array is de-duplicated.
123
+
124
+ # Ensure none of our ELBs are in us-east-1c
125
+ describe aws_elbs do
126
+ its('availability_zones') { should_not include 'us-east-1c' }
127
+ end
128
+
129
+ ### count
130
+
131
+ Returns an integer reflecting the number of matched ELBs.
132
+
133
+ # Ensure we have 4 ELBs total.
134
+ describe aws_elbs do
135
+ its('count') { should cmp 4 }
136
+ end
137
+
138
+ ### dns\_names
139
+
140
+ An array of FQDNs of the selected load balancers. These are the hostnames which are exposed to the world.
141
+
142
+ # Ensure none of the DNS names are an old name
143
+ describe aws_elbs do
144
+ its('dns_names') { should_not include 'some.horrid.name' }
145
+ end
146
+
147
+ ### elb\_names
148
+
149
+ The names of the selected ELBs within AWS. The ELB name is unique within the region.
150
+
151
+ # You can use this to enumerate the ELBs for detailed tests
152
+ # Search using the plural, analyze using the singular.
153
+ aws_elbs.where { instance_ports.include? 80 }.elb_names.each do |elb_name|
154
+ describe aws_elb(elb_name) do
155
+ its('security_group_ids') { should include 'sg-12345678' }
156
+ end
157
+ end
158
+
159
+ ### external\_ports
160
+
161
+ An array of integers reflecting the public-facing ports on which the selected load balancers will be listening for traffic. The array is de-duplicated.
162
+
163
+ # Ensure that the only ports we are listening on are 80 and 443
164
+ describe aws_elbs do
165
+ its('external_ports') { should include 80 }
166
+ its('external_ports') { should include 443 }
167
+ its('external_ports.count') { should cmp 2 }
168
+ end
169
+
170
+
171
+ ### instance\_ids
172
+
173
+ An array of strings reflecting the instance IDs of the EC2 instances attached to the selected ELBs.
174
+
175
+ # Ensure there are 10-20 instances total attached to all ELBs
176
+ describe aws_elbs do
177
+ its('instance_ids.count') { should be >= 10 }
178
+ its('instance_ids.count') { should be <= 20 }
179
+ end
180
+
181
+ ### internal\_ports
182
+
183
+ An array of integers reflecting the EC2-facing ports on which the selected load balancers will be sending traffic to. The array is de-duplicated.
184
+
185
+ # Ensure all ELBs only talk to port 80
186
+ describe aws_elbs do
187
+ its('internal_ports') { should contain 80 }
188
+ its('internal_ports.count') { should cmp 1 }
189
+ end
190
+
191
+ ### security\_group\_ids
192
+
193
+ An array of strings reflecting the security group IDs (firewall rule sets) assigned to the selected ELBs. The array is de-duplicated.
194
+
195
+ # Ensure all ELBs are using one specific security group
196
+ describe aws_elbs do
197
+ its('security_group_ids') { should include 'sg-12345678' }
198
+ its('security_group_ids.count') { should cmp 1 }
199
+ end
200
+
201
+ ### subnet\_ids
202
+
203
+ An array of strings reflecting the subnet IDs on which the selected ELBs are located. The array is de-duplicated.
204
+
205
+ # Ensure all ELBs are on a particular subnet
206
+ describe aws_elbs do
207
+ its('subnet_ids') { should include 'subnet-12345678' }
208
+ its('subnet_ids.count') { should cmp 1 }
209
+ end
210
+
211
+ ### vpc\_ids
212
+
213
+ An array of strings reflecting the ID of the VPCs in which the selected ELBs are located. The array is de-duplicated.
214
+
215
+ # Ensure all ELBs are in one VPC
216
+ describe aws_elbs do
217
+ its('vpc_ids.count') { should cmp 1 }
218
+ end
219
+
220
+ ## Matchers
221
+
222
+ This InSpec audit resource has the following resource-specific matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).
223
+
224
+ ### exists
225
+
226
+ The audit test will pass if at least one ELB was matched by the filter. Use with `should_not` to test for absence.
227
+
228
+ # We like z's in our DNS names
229
+ describe aws_elbs.where(dns_name: /z/) do
230
+ it { should exist }
231
+ end
232
+
233
+ # But k's are just awful
234
+ describe aws_elbs.where(dns_name: /k/) do
235
+ it { should_not exist }
236
+ end
237
+
238
+ ## AWS Permissions
239
+
240
+ Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `elasticloadbalancing:DescribeLoadBalancers` action set to Allow.
241
+
242
+ You can find detailed documentation at [Authentication and Access Control for Your Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/load-balancer-authentication-access-control.html)