inspec 0.14.8 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -2
  3. data/bin/inspec +3 -4
  4. data/examples/inheritance/README.md +19 -0
  5. data/examples/inheritance/controls/example.rb +11 -0
  6. data/examples/inheritance/inspec.yml +10 -0
  7. data/lib/bundles/inspec-compliance/cli.rb +1 -4
  8. data/lib/bundles/inspec-supermarket/cli.rb +1 -4
  9. data/lib/inspec/dsl.rb +48 -55
  10. data/lib/inspec/profile.rb +6 -2
  11. data/lib/inspec/profile_context.rb +21 -8
  12. data/lib/inspec/runner.rb +17 -12
  13. data/lib/inspec/runner_rspec.rb +1 -0
  14. data/lib/inspec/version.rb +1 -1
  15. data/lib/resources/apache.rb +20 -18
  16. data/lib/resources/apache_conf.rb +92 -90
  17. data/lib/resources/apt.rb +92 -90
  18. data/lib/resources/audit_policy.rb +35 -33
  19. data/lib/resources/auditd_conf.rb +41 -39
  20. data/lib/resources/auditd_rules.rb +155 -153
  21. data/lib/resources/bond.rb +1 -1
  22. data/lib/resources/bridge.rb +97 -95
  23. data/lib/resources/command.rb +47 -45
  24. data/lib/resources/csv.rb +23 -21
  25. data/lib/resources/directory.rb +1 -1
  26. data/lib/resources/etc_group.rb +116 -114
  27. data/lib/resources/file.rb +1 -1
  28. data/lib/resources/gem.rb +39 -37
  29. data/lib/resources/group.rb +100 -98
  30. data/lib/resources/host.rb +103 -101
  31. data/lib/resources/inetd_conf.rb +42 -40
  32. data/lib/resources/ini.rb +15 -13
  33. data/lib/resources/interface.rb +106 -104
  34. data/lib/resources/iptables.rb +36 -34
  35. data/lib/resources/json.rb +64 -62
  36. data/lib/resources/kernel_module.rb +30 -28
  37. data/lib/resources/kernel_parameter.rb +44 -42
  38. data/lib/resources/limits_conf.rb +41 -39
  39. data/lib/resources/login_def.rb +38 -36
  40. data/lib/resources/mount.rb +43 -41
  41. data/lib/resources/mysql.rb +67 -65
  42. data/lib/resources/mysql_conf.rb +89 -87
  43. data/lib/resources/mysql_session.rb +46 -44
  44. data/lib/resources/npm.rb +35 -33
  45. data/lib/resources/ntp_conf.rb +44 -42
  46. data/lib/resources/oneget.rb +46 -44
  47. data/lib/resources/os.rb +22 -20
  48. data/lib/resources/os_env.rb +47 -45
  49. data/lib/resources/package.rb +213 -211
  50. data/lib/resources/parse_config.rb +59 -57
  51. data/lib/resources/passwd.rb +89 -87
  52. data/lib/resources/pip.rb +60 -58
  53. data/lib/resources/port.rb +352 -350
  54. data/lib/resources/postgres.rb +26 -24
  55. data/lib/resources/postgres_conf.rb +66 -64
  56. data/lib/resources/postgres_session.rb +47 -45
  57. data/lib/resources/processes.rb +56 -54
  58. data/lib/resources/registry_key.rb +150 -148
  59. data/lib/resources/script.rb +30 -28
  60. data/lib/resources/security_policy.rb +56 -54
  61. data/lib/resources/service.rb +638 -636
  62. data/lib/resources/shadow.rb +98 -96
  63. data/lib/resources/ssh_conf.rb +58 -56
  64. data/lib/resources/user.rb +363 -361
  65. data/lib/resources/windows_feature.rb +46 -44
  66. data/lib/resources/xinetd.rb +111 -109
  67. data/lib/resources/yaml.rb +16 -14
  68. data/lib/resources/yum.rb +107 -105
  69. data/lib/utils/base_cli.rb +18 -0
  70. data/test/helper.rb +2 -2
  71. data/test/unit/profile_context_test.rb +1 -1
  72. data/test/unit/resources/file_test.rb +1 -1
  73. data/test/unit/resources/mount_test.rb +1 -1
  74. metadata +5 -2
@@ -3,39 +3,41 @@
3
3
  # author: Dominik Richter
4
4
  # license: All rights reserved
5
5
 
6
- class KernelModule < Inspec.resource(1)
7
- name 'kernel_module'
8
- desc 'Use the kernel_module InSpec audit resource to test kernel modules on Linux platforms. These parameters are located under /lib/modules. Any submodule may be tested using this resource.'
9
- example "
10
- describe kernel_module('bridge') do
11
- it { should be_loaded }
12
- end
13
- "
6
+ module Inspec::Resources
7
+ class KernelModule < Inspec.resource(1)
8
+ name 'kernel_module'
9
+ desc 'Use the kernel_module InSpec audit resource to test kernel modules on Linux platforms. These parameters are located under /lib/modules. Any submodule may be tested using this resource.'
10
+ example "
11
+ describe kernel_module('bridge') do
12
+ it { should be_loaded }
13
+ end
14
+ "
14
15
 
15
- def initialize(modulename = nil)
16
- @module = modulename
16
+ def initialize(modulename = nil)
17
+ @module = modulename
17
18
 
18
- # this resource is only supported on Linux
19
- return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
20
- end
19
+ # this resource is only supported on Linux
20
+ return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
21
+ end
21
22
 
22
- def loaded?
23
- # default lsmod command
24
- lsmod_cmd = 'lsmod'
25
- # special care for CentOS 5 and sudo
26
- lsmod_cmd = '/sbin/lsmod' if inspec.os[:family] == 'centos' && inspec.os[:release].to_i == 5
23
+ def loaded?
24
+ # default lsmod command
25
+ lsmod_cmd = 'lsmod'
26
+ # special care for CentOS 5 and sudo
27
+ lsmod_cmd = '/sbin/lsmod' if inspec.os[:family] == 'centos' && inspec.os[:release].to_i == 5
27
28
 
28
- # get list of all modules
29
- cmd = inspec.command(lsmod_cmd)
30
- return false if cmd.exit_status != 0
29
+ # get list of all modules
30
+ cmd = inspec.command(lsmod_cmd)
31
+ return false if cmd.exit_status != 0
31
32
 
32
- # check if module is loaded
33
- re = Regexp.new('^'+Regexp.quote(@module)+'\s')
34
- found = cmd.stdout.match(re)
35
- !found.nil?
36
- end
33
+ # check if module is loaded
34
+ re = Regexp.new('^'+Regexp.quote(@module)+'\s')
35
+ found = cmd.stdout.match(re)
36
+ !found.nil?
37
+ end
37
38
 
38
- def to_s
39
- "Kernel Module #{@module}"
39
+ def to_s
40
+ "Kernel Module #{@module}"
41
+ end
40
42
  end
41
43
  end
@@ -2,56 +2,58 @@
2
2
  # author: Christoph Hartmann
3
3
  # license: All rights reserved
4
4
 
5
- class KernelParameter < Inspec.resource(1)
6
- name 'kernel_parameter'
7
- desc 'Use the kernel_parameter InSpec audit resource to test kernel parameters on Linux platforms.'
8
- example "
9
- describe kernel_parameter('net.ipv4.conf.all.forwarding') do
10
- its(:value) { should eq 0 }
5
+ module Inspec::Resources
6
+ class KernelParameter < Inspec.resource(1)
7
+ name 'kernel_parameter'
8
+ desc 'Use the kernel_parameter InSpec audit resource to test kernel parameters on Linux platforms.'
9
+ example "
10
+ describe kernel_parameter('net.ipv4.conf.all.forwarding') do
11
+ its(:value) { should eq 0 }
12
+ end
13
+ "
14
+
15
+ def initialize(parameter = nil)
16
+ @parameter = parameter
17
+
18
+ # this resource is only supported on Linux
19
+ return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
11
20
  end
12
- "
13
21
 
14
- def initialize(parameter = nil)
15
- @parameter = parameter
16
-
17
- # this resource is only supported on Linux
18
- return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
19
- end
20
-
21
- def value
22
- cmd = inspec.command("/sbin/sysctl -q -n #{@parameter}")
23
- return nil if cmd.exit_status != 0
24
- # remove whitespace
25
- cmd = cmd.stdout.chomp.strip
26
- # convert to number if possible
27
- cmd = cmd.to_i if cmd =~ /^\d+$/
28
- cmd
29
- end
22
+ def value
23
+ cmd = inspec.command("/sbin/sysctl -q -n #{@parameter}")
24
+ return nil if cmd.exit_status != 0
25
+ # remove whitespace
26
+ cmd = cmd.stdout.chomp.strip
27
+ # convert to number if possible
28
+ cmd = cmd.to_i if cmd =~ /^\d+$/
29
+ cmd
30
+ end
30
31
 
31
- def to_s
32
- "Kernel Parameter #{@parameter}"
32
+ def to_s
33
+ "Kernel Parameter #{@parameter}"
34
+ end
33
35
  end
34
- end
35
36
 
36
- # for compatability with serverspec
37
- # this is deprecated syntax and will be removed in future versions
38
- class LinuxKernelParameter < KernelParameter
39
- name 'linux_kernel_parameter'
37
+ # for compatability with serverspec
38
+ # this is deprecated syntax and will be removed in future versions
39
+ class LinuxKernelParameter < KernelParameter
40
+ name 'linux_kernel_parameter'
40
41
 
41
- def initialize(parameter)
42
- super(parameter)
43
- end
42
+ def initialize(parameter)
43
+ super(parameter)
44
+ end
44
45
 
45
- def value
46
- deprecated
47
- super()
48
- end
46
+ def value
47
+ deprecated
48
+ super()
49
+ end
49
50
 
50
- def deprecated
51
- warn '[DEPRECATION] `linux_kernel_parameter(parameter)` is deprecated. Please use `kernel_parameter(parameter)` instead.'
52
- end
51
+ def deprecated
52
+ warn '[DEPRECATION] `linux_kernel_parameter(parameter)` is deprecated. Please use `kernel_parameter(parameter)` instead.'
53
+ end
53
54
 
54
- def to_s
55
- "Kernel Parameter #{@parameter}"
55
+ def to_s
56
+ "Kernel Parameter #{@parameter}"
57
+ end
56
58
  end
57
59
  end
@@ -6,50 +6,52 @@
6
6
 
7
7
  require 'utils/simpleconfig'
8
8
 
9
- class LimitsConf < Inspec.resource(1)
10
- name 'limits_conf'
11
- desc 'Use the limits_conf InSpec audit resource to test configuration settings in the /etc/security/limits.conf file. The limits.conf defines limits for processes (by user and/or group names) and helps ensure that the system on which those processes are running remains stable. Each process may be assigned a hard or soft limit.'
12
- example "
13
- describe limits_conf do
14
- its('*') { should include ['hard','core','0'] }
9
+ module Inspec::Resources
10
+ class LimitsConf < Inspec.resource(1)
11
+ name 'limits_conf'
12
+ desc 'Use the limits_conf InSpec audit resource to test configuration settings in the /etc/security/limits.conf file. The limits.conf defines limits for processes (by user and/or group names) and helps ensure that the system on which those processes are running remains stable. Each process may be assigned a hard or soft limit.'
13
+ example "
14
+ describe limits_conf do
15
+ its('*') { should include ['hard','core','0'] }
16
+ end
17
+ "
18
+
19
+ def initialize(path = nil)
20
+ @conf_path = path || '/etc/security/limits.conf'
15
21
  end
16
- "
17
22
 
18
- def initialize(path = nil)
19
- @conf_path = path || '/etc/security/limits.conf'
20
- end
21
-
22
- def method_missing(name)
23
- read_params[name.to_s]
24
- end
25
-
26
- def read_params
27
- return @params if defined?(@params)
28
-
29
- # read the file
30
- file = inspec.file(@conf_path)
31
- if !file.file?
32
- skip_resource "Can't find file \"#{@conf_path}\""
33
- return @params = {}
23
+ def method_missing(name)
24
+ read_params[name.to_s]
34
25
  end
35
26
 
36
- content = file.content
37
- if content.empty? && file.size > 0
38
- skip_resource "Can't read file \"#{@conf_path}\""
39
- return @params = {}
27
+ def read_params
28
+ return @params if defined?(@params)
29
+
30
+ # read the file
31
+ file = inspec.file(@conf_path)
32
+ if !file.file?
33
+ skip_resource "Can't find file \"#{@conf_path}\""
34
+ return @params = {}
35
+ end
36
+
37
+ content = file.content
38
+ if content.empty? && file.size > 0
39
+ skip_resource "Can't read file \"#{@conf_path}\""
40
+ return @params = {}
41
+ end
42
+
43
+ # parse the file
44
+ conf = SimpleConfig.new(
45
+ content,
46
+ assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
47
+ key_vals: 3,
48
+ multiple_values: true,
49
+ )
50
+ @params = conf.params
40
51
  end
41
52
 
42
- # parse the file
43
- conf = SimpleConfig.new(
44
- content,
45
- assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
46
- key_vals: 3,
47
- multiple_values: true,
48
- )
49
- @params = conf.params
50
- end
51
-
52
- def to_s
53
- 'limits.conf'
53
+ def to_s
54
+ 'limits.conf'
55
+ end
54
56
  end
55
57
  end
@@ -18,49 +18,51 @@ require 'utils/simpleconfig'
18
18
  # }
19
19
  # end
20
20
 
21
- class LoginDef < Inspec.resource(1)
22
- name 'login_defs'
23
- desc 'Use the login_defs InSpec audit resource to test configuration settings in the /etc/login.defs file. The logins.defs file defines site-specific configuration for the shadow password suite on Linux and UNIX platforms, such as password expiration ranges, minimum/maximum values for automatic selection of user and group identifiers, or the method with which passwords are encrypted.'
24
- example "
25
- describe login_defs do
26
- its('ENCRYPT_METHOD') { should eq 'SHA512' }
21
+ module Inspec::Resources
22
+ class LoginDef < Inspec.resource(1)
23
+ name 'login_defs'
24
+ desc 'Use the login_defs InSpec audit resource to test configuration settings in the /etc/login.defs file. The logins.defs file defines site-specific configuration for the shadow password suite on Linux and UNIX platforms, such as password expiration ranges, minimum/maximum values for automatic selection of user and group identifiers, or the method with which passwords are encrypted.'
25
+ example "
26
+ describe login_defs do
27
+ its('ENCRYPT_METHOD') { should eq 'SHA512' }
28
+ end
29
+ "
30
+
31
+ def initialize(path = nil)
32
+ @conf_path = path || '/etc/login.defs'
27
33
  end
28
- "
29
34
 
30
- def initialize(path = nil)
31
- @conf_path = path || '/etc/login.defs'
32
- end
35
+ def method_missing(name)
36
+ read_params[name.to_s]
37
+ end
33
38
 
34
- def method_missing(name)
35
- read_params[name.to_s]
36
- end
39
+ def read_params
40
+ return @params if defined?(@params)
37
41
 
38
- def read_params
39
- return @params if defined?(@params)
42
+ # read the file
43
+ file = inspec.file(@conf_path)
44
+ if !file.file?
45
+ skip_resource "Can't find file \"#{@conf_path}\""
46
+ return @params = {}
47
+ end
40
48
 
41
- # read the file
42
- file = inspec.file(@conf_path)
43
- if !file.file?
44
- skip_resource "Can't find file \"#{@conf_path}\""
45
- return @params = {}
46
- end
49
+ content = file.content
50
+ if content.empty? && file.size > 0
51
+ skip_resource "Can't read file \"#{@conf_path}\""
52
+ return @params = {}
53
+ end
47
54
 
48
- content = file.content
49
- if content.empty? && file.size > 0
50
- skip_resource "Can't read file \"#{@conf_path}\""
51
- return @params = {}
55
+ # parse the file
56
+ conf = SimpleConfig.new(
57
+ content,
58
+ assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
59
+ multiple_values: false,
60
+ )
61
+ @params = conf.params
52
62
  end
53
63
 
54
- # parse the file
55
- conf = SimpleConfig.new(
56
- content,
57
- assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
58
- multiple_values: false,
59
- )
60
- @params = conf.params
61
- end
62
-
63
- def to_s
64
- 'login.defs'
64
+ def to_s
65
+ 'login.defs'
66
+ end
65
67
  end
66
68
  end
@@ -4,54 +4,56 @@
4
4
 
5
5
  require 'utils/simpleconfig'
6
6
 
7
- class Mount < Inspec.resource(1)
8
- name 'mount'
9
- desc 'Use the mount InSpec audit resource to test if mount points.'
10
- example "
11
- describe mount('/') do
12
- it { should be_mounted }
13
- its(:count) { should eq 1 }
14
- its('device') { should eq '/dev/mapper/VolGroup-lv_root' }
15
- its('type') { should eq 'ext4' }
16
- its('options') { should eq ['rw', 'mode=620'] }
7
+ module Inspec::Resources
8
+ class Mount < Inspec.resource(1)
9
+ name 'mount'
10
+ desc 'Use the mount InSpec audit resource to test if mount points.'
11
+ example "
12
+ describe mount('/') do
13
+ it { should be_mounted }
14
+ its(:count) { should eq 1 }
15
+ its('device') { should eq '/dev/mapper/VolGroup-lv_root' }
16
+ its('type') { should eq 'ext4' }
17
+ its('options') { should eq ['rw', 'mode=620'] }
18
+ end
19
+ "
20
+ include MountParser
21
+
22
+ attr_reader :file
23
+
24
+ def initialize(path)
25
+ @path = path
26
+ return skip_resource 'The `mount` resource is not supported on your OS yet.' if !inspec.os.linux?
27
+ @file = inspec.backend.file(@path)
17
28
  end
18
- "
19
- include MountParser
20
29
 
21
- attr_reader :file
22
-
23
- def initialize(path)
24
- @path = path
25
- return skip_resource 'The `mount` resource is not supported on your OS yet.' if !inspec.os.linux?
26
- @file = inspec.backend.file(@path)
27
- end
28
-
29
- def mounted?
30
- file.mounted?
31
- end
30
+ def mounted?
31
+ file.mounted?
32
+ end
32
33
 
33
- def count
34
- mounted = file.mounted
35
- return nil if mounted.nil? || mounted.stdout.nil?
36
- mounted.stdout.lines.count
37
- end
34
+ def count
35
+ mounted = file.mounted
36
+ return nil if mounted.nil? || mounted.stdout.nil?
37
+ mounted.stdout.lines.count
38
+ end
38
39
 
39
- def method_missing(name)
40
- return nil if !file.mounted?
40
+ def method_missing(name)
41
+ return nil if !file.mounted?
41
42
 
42
- mounted = file.mounted
43
- return nil if mounted.nil? || mounted.stdout.nil?
43
+ mounted = file.mounted
44
+ return nil if mounted.nil? || mounted.stdout.nil?
44
45
 
45
- line = mounted.stdout
46
- # if we got multiple lines, only use the last entry
47
- line = mounted.stdout.lines.to_a.last if mounted.stdout.lines.count > 1
46
+ line = mounted.stdout
47
+ # if we got multiple lines, only use the last entry
48
+ line = mounted.stdout.lines.to_a.last if mounted.stdout.lines.count > 1
48
49
 
49
- # parse content if we are on linux
50
- @mount_options ||= parse_mount_options(line)
51
- @mount_options[name]
52
- end
50
+ # parse content if we are on linux
51
+ @mount_options ||= parse_mount_options(line)
52
+ @mount_options[name]
53
+ end
53
54
 
54
- def to_s
55
- "Mount #{@path}"
55
+ def to_s
56
+ "Mount #{@path}"
57
+ end
56
58
  end
57
59
  end