inspec 0.14.8 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -2
- data/bin/inspec +3 -4
- data/examples/inheritance/README.md +19 -0
- data/examples/inheritance/controls/example.rb +11 -0
- data/examples/inheritance/inspec.yml +10 -0
- data/lib/bundles/inspec-compliance/cli.rb +1 -4
- data/lib/bundles/inspec-supermarket/cli.rb +1 -4
- data/lib/inspec/dsl.rb +48 -55
- data/lib/inspec/profile.rb +6 -2
- data/lib/inspec/profile_context.rb +21 -8
- data/lib/inspec/runner.rb +17 -12
- data/lib/inspec/runner_rspec.rb +1 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/apache.rb +20 -18
- data/lib/resources/apache_conf.rb +92 -90
- data/lib/resources/apt.rb +92 -90
- data/lib/resources/audit_policy.rb +35 -33
- data/lib/resources/auditd_conf.rb +41 -39
- data/lib/resources/auditd_rules.rb +155 -153
- data/lib/resources/bond.rb +1 -1
- data/lib/resources/bridge.rb +97 -95
- data/lib/resources/command.rb +47 -45
- data/lib/resources/csv.rb +23 -21
- data/lib/resources/directory.rb +1 -1
- data/lib/resources/etc_group.rb +116 -114
- data/lib/resources/file.rb +1 -1
- data/lib/resources/gem.rb +39 -37
- data/lib/resources/group.rb +100 -98
- data/lib/resources/host.rb +103 -101
- data/lib/resources/inetd_conf.rb +42 -40
- data/lib/resources/ini.rb +15 -13
- data/lib/resources/interface.rb +106 -104
- data/lib/resources/iptables.rb +36 -34
- data/lib/resources/json.rb +64 -62
- data/lib/resources/kernel_module.rb +30 -28
- data/lib/resources/kernel_parameter.rb +44 -42
- data/lib/resources/limits_conf.rb +41 -39
- data/lib/resources/login_def.rb +38 -36
- data/lib/resources/mount.rb +43 -41
- data/lib/resources/mysql.rb +67 -65
- data/lib/resources/mysql_conf.rb +89 -87
- data/lib/resources/mysql_session.rb +46 -44
- data/lib/resources/npm.rb +35 -33
- data/lib/resources/ntp_conf.rb +44 -42
- data/lib/resources/oneget.rb +46 -44
- data/lib/resources/os.rb +22 -20
- data/lib/resources/os_env.rb +47 -45
- data/lib/resources/package.rb +213 -211
- data/lib/resources/parse_config.rb +59 -57
- data/lib/resources/passwd.rb +89 -87
- data/lib/resources/pip.rb +60 -58
- data/lib/resources/port.rb +352 -350
- data/lib/resources/postgres.rb +26 -24
- data/lib/resources/postgres_conf.rb +66 -64
- data/lib/resources/postgres_session.rb +47 -45
- data/lib/resources/processes.rb +56 -54
- data/lib/resources/registry_key.rb +150 -148
- data/lib/resources/script.rb +30 -28
- data/lib/resources/security_policy.rb +56 -54
- data/lib/resources/service.rb +638 -636
- data/lib/resources/shadow.rb +98 -96
- data/lib/resources/ssh_conf.rb +58 -56
- data/lib/resources/user.rb +363 -361
- data/lib/resources/windows_feature.rb +46 -44
- data/lib/resources/xinetd.rb +111 -109
- data/lib/resources/yaml.rb +16 -14
- data/lib/resources/yum.rb +107 -105
- data/lib/utils/base_cli.rb +18 -0
- data/test/helper.rb +2 -2
- data/test/unit/profile_context_test.rb +1 -1
- data/test/unit/resources/file_test.rb +1 -1
- data/test/unit/resources/mount_test.rb +1 -1
- metadata +5 -2
@@ -3,39 +3,41 @@
|
|
3
3
|
# author: Dominik Richter
|
4
4
|
# license: All rights reserved
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
16
|
+
def initialize(modulename = nil)
|
17
|
+
@module = modulename
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# get list of all modules
|
30
|
+
cmd = inspec.command(lsmod_cmd)
|
31
|
+
return false if cmd.exit_status != 0
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def initialize(parameter)
|
43
|
+
super(parameter)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def value
|
47
|
+
deprecated
|
48
|
+
super()
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def deprecated
|
52
|
+
warn '[DEPRECATION] `linux_kernel_parameter(parameter)` is deprecated. Please use `kernel_parameter(parameter)` instead.'
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
data/lib/resources/login_def.rb
CHANGED
@@ -18,49 +18,51 @@ require 'utils/simpleconfig'
|
|
18
18
|
# }
|
19
19
|
# end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
35
|
+
def method_missing(name)
|
36
|
+
read_params[name.to_s]
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
39
|
+
def read_params
|
40
|
+
return @params if defined?(@params)
|
37
41
|
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
data/lib/resources/mount.rb
CHANGED
@@ -4,54 +4,56 @@
|
|
4
4
|
|
5
5
|
require 'utils/simpleconfig'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
40
|
+
def method_missing(name)
|
41
|
+
return nil if !file.mounted?
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
mounted = file.mounted
|
44
|
+
return nil if mounted.nil? || mounted.stdout.nil?
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# parse content if we are on linux
|
51
|
+
@mount_options ||= parse_mount_options(line)
|
52
|
+
@mount_options[name]
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
def to_s
|
56
|
+
"Mount #{@path}"
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|