inspec 1.0.0 → 1.35.1
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 +933 -101
- data/Gemfile +8 -17
- data/MAINTAINERS.md +2 -1
- data/MAINTAINERS.toml +9 -4
- data/README.md +49 -28
- data/Rakefile +54 -39
- data/bin/inspec +1 -1
- data/docs/dsl_inspec.md +17 -4
- data/docs/dsl_resource.md +1 -1
- data/docs/habitat.md +192 -0
- data/docs/inspec_and_friends.md +4 -2
- data/docs/matchers.md +11 -0
- data/docs/migration.md +293 -0
- data/docs/profiles.md +124 -76
- data/docs/resources/aide_conf.md.erb +81 -0
- data/docs/resources/apache_conf.md.erb +10 -10
- data/docs/resources/apt.md.erb +13 -13
- data/docs/resources/audit_policy.md.erb +10 -10
- data/docs/resources/auditd_conf.md.erb +10 -10
- data/docs/resources/auditd_rules.md.erb +11 -11
- data/docs/resources/bash.md.erb +12 -12
- data/docs/resources/bond.md.erb +15 -15
- data/docs/resources/bridge.md.erb +11 -11
- data/docs/resources/bsd_service.md.erb +11 -11
- data/docs/resources/command.md.erb +23 -23
- data/docs/resources/crontab.md.erb +84 -0
- data/docs/resources/csv.md.erb +10 -10
- data/docs/resources/dh_params.md +191 -0
- data/docs/resources/directory.md.erb +8 -8
- data/docs/resources/docker.md.erb +160 -0
- data/docs/resources/docker_container.md.erb +89 -0
- data/docs/resources/docker_image.md.erb +86 -0
- data/docs/resources/etc_group.md.erb +16 -16
- data/docs/resources/etc_hosts.md.erb +62 -0
- data/docs/resources/file.md.erb +80 -58
- data/docs/resources/gem.md.erb +32 -13
- data/docs/resources/group.md.erb +12 -12
- data/docs/resources/grub_conf.md.erb +11 -11
- data/docs/resources/host.md.erb +27 -18
- data/docs/resources/http.md.erb +104 -0
- data/docs/resources/iis_app.md.erb +126 -0
- data/docs/resources/iis_site.md.erb +17 -17
- data/docs/resources/inetd_conf.md.erb +10 -10
- data/docs/resources/ini.md.erb +9 -9
- data/docs/resources/interface.md.erb +13 -13
- data/docs/resources/iptables.md.erb +21 -14
- data/docs/resources/json.md.erb +11 -11
- data/docs/resources/kernel_module.md.erb +73 -12
- data/docs/resources/kernel_parameter.md.erb +12 -12
- data/docs/resources/key_rsa.md.erb +70 -0
- data/docs/resources/launchd_service.md.erb +11 -11
- data/docs/resources/limits_conf.md.erb +10 -10
- data/docs/resources/login_def.md.erb +12 -12
- data/docs/resources/mount.md.erb +14 -14
- data/docs/resources/mssql_session.md.erb +62 -0
- data/docs/resources/mysql_conf.md.erb +14 -14
- data/docs/resources/mysql_session.md.erb +22 -10
- data/docs/resources/npm.md.erb +13 -13
- data/docs/resources/ntp_conf.md.erb +9 -9
- data/docs/resources/oneget.md.erb +11 -11
- data/docs/resources/oracledb_session.md.erb +53 -0
- data/docs/resources/os.md.erb +17 -17
- data/docs/resources/os_env.md.erb +12 -12
- data/docs/resources/package.md.erb +29 -16
- data/docs/resources/parse_config.md.erb +18 -18
- data/docs/resources/parse_config_file.md.erb +29 -23
- data/docs/resources/{etc_passwd.md.erb → passwd.md.erb} +17 -17
- data/docs/resources/pip.md.erb +15 -15
- data/docs/resources/port.md.erb +23 -23
- data/docs/resources/postgres_conf.md.erb +15 -13
- data/docs/resources/postgres_hba_conf.md.erb +104 -0
- data/docs/resources/postgres_ident_conf.md.erb +87 -0
- data/docs/resources/postgres_session.md.erb +28 -21
- data/docs/resources/powershell.md.erb +14 -14
- data/docs/resources/processes.md.erb +123 -0
- data/docs/resources/rabbitmq_config.md.erb +55 -0
- data/docs/resources/registry_key.md.erb +44 -21
- data/docs/resources/runit_service.md.erb +11 -11
- data/docs/resources/security_policy.md.erb +10 -10
- data/docs/resources/service.md.erb +18 -18
- data/docs/resources/{etc_shadow.md.erb → shadow.md.erb} +19 -19
- data/docs/resources/ssh_config.md.erb +13 -13
- data/docs/resources/sshd_config.md.erb +15 -15
- data/docs/resources/ssl.md.erb +13 -13
- data/docs/resources/sys_info.md.erb +10 -10
- data/docs/resources/systemd_service.md.erb +11 -11
- data/docs/resources/sysv_service.md.erb +11 -11
- data/docs/resources/upstart_service.md.erb +11 -11
- data/docs/resources/user.md.erb +20 -20
- data/docs/resources/users.md.erb +19 -19
- data/docs/resources/vbscript.md.erb +13 -13
- data/docs/resources/virtualization.md.erb +71 -0
- data/docs/resources/windows_feature.md.erb +10 -10
- data/docs/resources/windows_task.md.erb +103 -0
- data/docs/resources/wmi.md.erb +10 -10
- data/docs/resources/x509_certificate.md.erb +146 -0
- data/docs/resources/xinetd_conf.md.erb +17 -17
- data/docs/resources/xml.md.erb +75 -0
- data/docs/resources/yaml.md.erb +25 -11
- data/docs/resources/yum.md.erb +24 -16
- data/docs/resources/zfs_dataset.md.erb +63 -0
- data/docs/resources/zfs_pool.md.erb +57 -0
- data/docs/ruby_usage.md +50 -0
- data/docs/shared/matcher_cmp.md.erb +4 -6
- data/examples/inheritance/README.md +49 -3
- data/examples/inheritance/controls/example.rb +4 -1
- data/examples/inheritance/inspec.yml +3 -1
- data/examples/meta-profile/README.md +29 -3
- data/examples/meta-profile/controls/example.rb +10 -5
- data/examples/meta-profile/inspec.yml +4 -8
- data/examples/profile/README.md +1 -1
- data/examples/profile/controls/example.rb +0 -1
- data/examples/profile/controls/gordon.rb +0 -1
- data/examples/profile/inspec.yml +1 -1
- data/examples/profile-attribute/inspec.yml +1 -1
- data/examples/profile-sensitive/README.md +29 -0
- data/examples/profile-sensitive/controls/sensitive-failures.rb +9 -0
- data/examples/profile-sensitive/controls/sensitive.rb +9 -0
- data/examples/profile-sensitive/inspec.yml +8 -0
- data/inspec.gemspec +10 -2
- data/lib/bundles/inspec-artifact/README.md +1 -0
- data/lib/bundles/inspec-artifact/cli.rb +284 -0
- data/lib/bundles/inspec-artifact.rb +7 -0
- data/lib/bundles/inspec-compliance/README.md +44 -15
- data/lib/bundles/inspec-compliance/api.rb +135 -29
- data/lib/bundles/inspec-compliance/cli.rb +128 -21
- data/lib/bundles/inspec-compliance/configuration.rb +8 -0
- data/lib/bundles/inspec-compliance/http.rb +26 -19
- data/lib/bundles/inspec-compliance/target.rb +50 -25
- data/lib/bundles/inspec-habitat/cli.rb +31 -0
- data/lib/bundles/inspec-habitat/log.rb +10 -0
- data/lib/bundles/inspec-habitat/profile.rb +372 -0
- data/lib/bundles/inspec-habitat.rb +12 -0
- data/lib/bundles/inspec-init/templates/profile/controls/example.rb +0 -1
- data/lib/bundles/inspec-init/templates/profile/inspec.yml +1 -1
- data/lib/bundles/inspec-supermarket/api.rb +7 -5
- data/lib/bundles/inspec-supermarket/cli.rb +2 -2
- data/lib/fetchers/git.rb +4 -2
- data/lib/fetchers/local.rb +4 -1
- data/lib/fetchers/url.rb +64 -10
- data/lib/inspec/archive/tar.rb +1 -1
- data/lib/inspec/backend.rb +26 -3
- data/lib/inspec/base_cli.rb +44 -7
- data/lib/inspec/cached_fetcher.rb +2 -2
- data/lib/inspec/cli.rb +34 -12
- data/lib/inspec/completions/fish.sh.erb +34 -0
- data/lib/inspec/control_eval_context.rb +0 -2
- data/lib/inspec/dependencies/cache.rb +0 -1
- data/lib/inspec/dependencies/dependency_set.rb +2 -2
- data/lib/inspec/dependencies/lockfile.rb +13 -6
- data/lib/inspec/dependencies/requirement.rb +6 -6
- data/lib/inspec/dependencies/resolver.rb +4 -4
- data/lib/inspec/dsl.rb +3 -5
- data/lib/inspec/env_printer.rb +9 -1
- data/lib/inspec/exceptions.rb +8 -0
- data/lib/inspec/fetcher.rb +1 -1
- data/lib/inspec/file_provider.rb +47 -11
- data/lib/inspec/library_eval_context.rb +1 -1
- data/lib/inspec/metadata.rb +62 -18
- data/lib/inspec/method_source.rb +24 -0
- data/lib/inspec/objects/attribute.rb +21 -0
- data/lib/inspec/objects/control.rb +21 -3
- data/lib/inspec/objects/each_loop.rb +2 -1
- data/lib/inspec/objects/list.rb +1 -1
- data/lib/inspec/objects/or_test.rb +17 -2
- data/lib/inspec/objects/tag.rb +27 -0
- data/lib/inspec/objects/test.rb +9 -8
- data/lib/inspec/objects.rb +1 -0
- data/lib/inspec/plugins/fetcher.rb +4 -5
- data/lib/inspec/plugins/resource.rb +1 -2
- data/lib/inspec/plugins/source_reader.rb +3 -3
- data/lib/inspec/plugins.rb +1 -1
- data/lib/inspec/polyfill.rb +0 -1
- data/lib/inspec/profile.rb +92 -23
- data/lib/inspec/profile_context.rb +1 -1
- data/lib/inspec/profile_vendor.rb +66 -0
- data/lib/inspec/resource.rb +29 -3
- data/lib/inspec/rspec_json_formatter.rb +672 -285
- data/lib/inspec/rule.rb +12 -16
- data/lib/inspec/runner.rb +26 -15
- data/lib/inspec/runner_rspec.rb +1 -0
- data/lib/inspec/runtime_profile.rb +26 -0
- data/lib/inspec/schema.rb +185 -0
- data/lib/inspec/secrets/yaml.rb +8 -1
- data/lib/inspec/secrets.rb +1 -1
- data/lib/inspec/shell.rb +92 -22
- data/lib/inspec/source_reader.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/inspec.rb +1 -1
- data/lib/matchers/matchers.rb +67 -17
- data/lib/resources/aide_conf.rb +162 -0
- data/lib/resources/apache.rb +0 -1
- data/lib/resources/apache_conf.rb +3 -3
- data/lib/resources/apt.rb +2 -1
- data/lib/resources/audit_policy.rb +0 -1
- data/lib/resources/auditd_conf.rb +1 -2
- data/lib/resources/auditd_rules.rb +5 -5
- data/lib/resources/bond.rb +1 -1
- data/lib/resources/bridge.rb +1 -1
- data/lib/resources/command.rb +5 -3
- data/lib/resources/crontab.rb +102 -0
- data/lib/resources/csv.rb +18 -1
- data/lib/resources/dh_params.rb +84 -0
- data/lib/resources/directory.rb +7 -3
- data/lib/resources/docker.rb +198 -0
- data/lib/resources/docker_container.rb +114 -0
- data/lib/resources/docker_image.rb +96 -0
- data/lib/resources/etc_group.rb +2 -3
- data/lib/resources/etc_hosts.rb +81 -0
- data/lib/resources/file.rb +88 -30
- data/lib/resources/gem.rb +26 -6
- data/lib/resources/groups.rb +4 -5
- data/lib/resources/grub_conf.rb +3 -4
- data/lib/resources/host.rb +175 -35
- data/lib/resources/http.rb +73 -0
- data/lib/resources/iis_app.rb +103 -0
- data/lib/resources/iis_site.rb +23 -0
- data/lib/resources/inetd_conf.rb +9 -4
- data/lib/resources/interface.rb +4 -3
- data/lib/resources/json.rb +37 -14
- data/lib/resources/kernel_module.rb +77 -10
- data/lib/resources/kernel_parameter.rb +0 -1
- data/lib/resources/key_rsa.rb +67 -0
- data/lib/resources/limits_conf.rb +3 -4
- data/lib/resources/login_def.rb +2 -3
- data/lib/resources/mount.rb +34 -4
- data/lib/resources/mssql_session.rb +81 -12
- data/lib/resources/mysql.rb +0 -1
- data/lib/resources/mysql_conf.rb +1 -2
- data/lib/resources/mysql_session.rb +18 -7
- data/lib/resources/nginx_conf.rb +95 -0
- data/lib/resources/ntp_conf.rb +2 -3
- data/lib/resources/oracledb_session.rb +138 -0
- data/lib/resources/os_env.rb +7 -5
- data/lib/resources/package.rb +70 -13
- data/lib/resources/packages.rb +111 -0
- data/lib/resources/parse_config.rb +3 -4
- data/lib/resources/passwd.rb +4 -5
- data/lib/resources/pip.rb +29 -21
- data/lib/resources/port.rb +133 -14
- data/lib/resources/postgres.rb +53 -43
- data/lib/resources/postgres_conf.rb +40 -13
- data/lib/resources/postgres_hba_conf.rb +101 -0
- data/lib/resources/postgres_ident_conf.rb +79 -0
- data/lib/resources/postgres_session.rb +28 -20
- data/lib/resources/powershell.rb +2 -2
- data/lib/resources/processes.rb +61 -26
- data/lib/resources/rabbitmq_conf.rb +53 -0
- data/lib/resources/registry_key.rb +34 -11
- data/lib/resources/security_policy.rb +2 -2
- data/lib/resources/service.rb +17 -7
- data/lib/resources/ssh_conf.rb +17 -6
- data/lib/resources/ssl.rb +3 -4
- data/lib/resources/sys_info.rb +1 -1
- data/lib/resources/toml.rb +26 -0
- data/lib/resources/users.rb +41 -41
- data/lib/resources/virtualization.rb +252 -0
- data/lib/resources/windows_task.rb +106 -0
- data/lib/resources/x509_certificate.rb +143 -0
- data/lib/resources/xinetd.rb +18 -2
- data/lib/resources/xml.rb +27 -0
- data/lib/resources/yaml.rb +10 -2
- data/lib/resources/yum.rb +25 -7
- data/lib/resources/zfs_dataset.rb +60 -0
- data/lib/resources/zfs_pool.rb +49 -0
- data/lib/source_readers/flat.rb +2 -1
- data/lib/source_readers/inspec.rb +30 -11
- data/lib/utils/command_wrapper.rb +3 -3
- data/lib/utils/database_helpers.rb +77 -0
- data/lib/utils/erlang_parser.rb +192 -0
- data/lib/utils/filter.rb +2 -1
- data/lib/utils/filter_array.rb +0 -1
- data/lib/utils/find_files.rb +1 -2
- data/lib/utils/latest_version.rb +21 -0
- data/lib/utils/nginx_parser.rb +76 -0
- data/lib/utils/object_traversal.rb +5 -4
- data/lib/utils/parser.rb +23 -4
- data/lib/utils/plugin_registry.rb +3 -3
- data/lib/utils/simpleconfig.rb +25 -8
- data/lib/utils/spdx.rb +13 -0
- data/lib/utils/spdx.txt +344 -0
- metadata +168 -22
- data/docs/cli.md +0 -342
- data/docs/resources/process.md.erb +0 -73
- /data/docs/{plugin_kitchen_inspec.html.md → plugin_kitchen_inspec.md} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# copyright: 2017, Criteo
|
|
3
|
+
# copyright: 2017, Chef Software Inc
|
|
4
|
+
# author: Guilhem Lettron, Christoph Hartmann
|
|
5
|
+
# license: Apache v2
|
|
6
|
+
|
|
7
|
+
require 'faraday'
|
|
8
|
+
require 'hashie'
|
|
9
|
+
|
|
10
|
+
module Inspec::Resources
|
|
11
|
+
class Http < Inspec.resource(1)
|
|
12
|
+
name 'http'
|
|
13
|
+
desc 'Use the http InSpec audit resource to test http call.'
|
|
14
|
+
example "
|
|
15
|
+
describe http('http://localhost:8080/ping', auth: {user: 'user', pass: 'test'}, params: {format: 'html'}) do
|
|
16
|
+
its('status') { should cmp 200 }
|
|
17
|
+
its('body') { should cmp 'pong' }
|
|
18
|
+
its('headers.Content-Type') { should cmp 'text/html' }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe http('http://example.com/ping').headers do
|
|
22
|
+
its('Content-Length') { should cmp 258 }
|
|
23
|
+
its('Content-Type') { should cmp 'text/html; charset=UTF-8' }
|
|
24
|
+
end
|
|
25
|
+
"
|
|
26
|
+
|
|
27
|
+
def initialize(url, opts = {})
|
|
28
|
+
@url = url
|
|
29
|
+
@method = opts.fetch(:method, 'GET')
|
|
30
|
+
@params = opts.fetch(:params, nil)
|
|
31
|
+
@auth = opts.fetch(:auth, {})
|
|
32
|
+
@headers = opts.fetch(:headers, {})
|
|
33
|
+
@data = opts.fetch(:data, nil)
|
|
34
|
+
@open_timeout = opts.fetch(:open_timeout, 60)
|
|
35
|
+
@read_timeout = opts.fetch(:read_timeout, 60)
|
|
36
|
+
@ssl_verify = opts.fetch(:ssl_verify, true)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def status
|
|
40
|
+
response.status
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def body
|
|
44
|
+
response.body
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def headers
|
|
48
|
+
Hashie::Mash.new(response.headers.to_h)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def to_s
|
|
52
|
+
"http #{@method} on #{@url}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def response
|
|
58
|
+
return @response if @response
|
|
59
|
+
conn = Faraday.new url: @url, headers: @headers, params: @params, ssl: { verify: @ssl_verify }
|
|
60
|
+
|
|
61
|
+
# set basic authentication
|
|
62
|
+
conn.basic_auth @auth[:user], @auth[:pass] unless @auth.empty?
|
|
63
|
+
|
|
64
|
+
# set default timeout
|
|
65
|
+
conn.options.timeout = @read_timeout # open/read timeout in seconds
|
|
66
|
+
conn.options.open_timeout = @open_timeout # connection open timeout in seconds
|
|
67
|
+
|
|
68
|
+
@response = conn.send(@method.downcase) do |req|
|
|
69
|
+
req.body = @data
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
# check for web applications in IIS
|
|
4
|
+
# Note: this is only supported in windows 2012 and later
|
|
5
|
+
module Inspec::Resources
|
|
6
|
+
class IisApp < Inspec.resource(1)
|
|
7
|
+
name 'iis_app'
|
|
8
|
+
desc 'Tests IIS application configuration on windows. Supported in server 2012+ only'
|
|
9
|
+
example "
|
|
10
|
+
describe iis_app('/myapp', 'Default Web Site') do
|
|
11
|
+
it { should exist }
|
|
12
|
+
it { should have_application_pool('MyAppPool') }
|
|
13
|
+
it { should have_protocols('http') }
|
|
14
|
+
it { should have_site_name('Default Web Site') }
|
|
15
|
+
it { should have_physical_path('C:\\inetpub\\wwwroot\\myapp') }
|
|
16
|
+
it { should have_path('\\My Application') }
|
|
17
|
+
end
|
|
18
|
+
"
|
|
19
|
+
|
|
20
|
+
def initialize(path, site_name)
|
|
21
|
+
@path = path
|
|
22
|
+
@site_name = site_name
|
|
23
|
+
@cache = nil
|
|
24
|
+
@inspec = inspec
|
|
25
|
+
|
|
26
|
+
# verify that this resource is only supported on Windows
|
|
27
|
+
return skip_resource 'The `iis_app` resource is not supported on your OS.' unless inspec.os.windows?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def application_pool
|
|
31
|
+
iis_app[:application_pool]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def protocols
|
|
35
|
+
iis_app[:protocols]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def site_name
|
|
39
|
+
iis_app[:site_name]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def path
|
|
43
|
+
iis_app[:path]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def physical_path
|
|
47
|
+
iis_app[:physical_path]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def exists?
|
|
51
|
+
!iis_app[:path].empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def has_site_name?(site_name)
|
|
55
|
+
iis_app[:site_name] == site_name
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def has_application_pool?(application_pool)
|
|
59
|
+
iis_app[:application_pool] == application_pool
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def has_path?(path)
|
|
63
|
+
iis_app[:path] == path
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def has_physical_path?(physical_path)
|
|
67
|
+
iis_app[:physical_path] == physical_path
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def has_protocol?(protocol)
|
|
71
|
+
iis_app[:protocols].include?(protocol)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def to_s
|
|
75
|
+
"iis_app '#{@site_name}#{@path}'"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def iis_app
|
|
81
|
+
return @cache unless @cache.nil?
|
|
82
|
+
command = "Import-Module WebAdministration; Get-WebApplication -Name '#{@path}' -Site '#{@site_name}' | Select-Object * | ConvertTo-Json"
|
|
83
|
+
cmd = @inspec.command(command)
|
|
84
|
+
|
|
85
|
+
begin
|
|
86
|
+
app = JSON.parse(cmd.stdout)
|
|
87
|
+
rescue JSON::ParserError => _e
|
|
88
|
+
return {}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# map our values to a hash table
|
|
92
|
+
info = {
|
|
93
|
+
site_name: @site_name,
|
|
94
|
+
path: @path,
|
|
95
|
+
application_pool: app['applicationPool'],
|
|
96
|
+
physical_path: app['PhysicalPath'],
|
|
97
|
+
protocols: app['enabledProtocols'],
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@cache = info unless info.nil?
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/resources/iis_site.rb
CHANGED
|
@@ -121,4 +121,27 @@ module Inspec::Resources
|
|
|
121
121
|
info
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
|
+
|
|
125
|
+
# for compatability with serverspec
|
|
126
|
+
# this is deprecated syntax and will be removed in future versions
|
|
127
|
+
class IisSiteServerSpec < IisSite
|
|
128
|
+
name 'iis_website'
|
|
129
|
+
desc 'Tests IIS site configuration on windows. Deprecated, use `iis_site` instead.'
|
|
130
|
+
example "
|
|
131
|
+
describe iis_website('Default Website') do
|
|
132
|
+
it{ should exist }
|
|
133
|
+
it{ should be_running }
|
|
134
|
+
it{ should be_in_app_pool('Default App Pool') }
|
|
135
|
+
end
|
|
136
|
+
"
|
|
137
|
+
|
|
138
|
+
def initialize(site_name)
|
|
139
|
+
super(site_name)
|
|
140
|
+
warn '[DEPRECATION] `iis_website(site_name)` is deprecated. Please use `iis_site(site_name)` instead.'
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def in_app_pool?(app_pool)
|
|
144
|
+
has_app_pool?(app_pool)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
124
147
|
end
|
data/lib/resources/inetd_conf.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# copyright: 2015, Vulcano Security GmbH
|
|
3
3
|
# author: Christoph Hartmann
|
|
4
4
|
# author: Dominik Richter
|
|
5
|
-
# license: All rights reserved
|
|
6
5
|
|
|
7
6
|
require 'utils/simpleconfig'
|
|
8
7
|
|
|
@@ -22,6 +21,12 @@ module Inspec::Resources
|
|
|
22
21
|
@conf_path = path || '/etc/inetd.conf'
|
|
23
22
|
end
|
|
24
23
|
|
|
24
|
+
# overwrite exec to ensure it works with its
|
|
25
|
+
# TODO: this needs to be fixed in RSpec
|
|
26
|
+
def exec
|
|
27
|
+
read_params['exec']
|
|
28
|
+
end
|
|
29
|
+
|
|
25
30
|
def method_missing(name)
|
|
26
31
|
read_params[name.to_s]
|
|
27
32
|
end
|
|
@@ -37,15 +42,15 @@ module Inspec::Resources
|
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
content = file.content
|
|
40
|
-
if content.empty? && file.
|
|
45
|
+
if content.empty? && !file.empty?
|
|
41
46
|
skip_resource "Can't read file \"#{@conf_path}\""
|
|
42
47
|
return @params = {}
|
|
43
48
|
end
|
|
44
49
|
# parse the file
|
|
45
50
|
conf = SimpleConfig.new(
|
|
46
51
|
content,
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
|
53
|
+
key_values: 6,
|
|
49
54
|
multiple_values: false,
|
|
50
55
|
)
|
|
51
56
|
@params = conf.params
|
data/lib/resources/interface.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# author: Christoph Hartmann
|
|
3
3
|
# author: Dominik Richter
|
|
4
|
+
# author: Aaron Lippold
|
|
4
5
|
|
|
5
6
|
require 'utils/convert'
|
|
6
7
|
|
|
7
8
|
module Inspec::Resources
|
|
8
9
|
class NetworkInterface < Inspec.resource(1)
|
|
9
10
|
name 'interface'
|
|
10
|
-
desc 'Use the interface InSpec audit resource to test basic network adapter properties, such as name, status,
|
|
11
|
+
desc 'Use the interface InSpec audit resource to test basic network adapter properties, such as name, status, and link speed (in MB/sec).'
|
|
11
12
|
example "
|
|
12
13
|
describe interface('eth0') do
|
|
13
14
|
it { should exist }
|
|
@@ -64,7 +65,7 @@ module Inspec::Resources
|
|
|
64
65
|
class LinuxInterface < InterfaceInfo
|
|
65
66
|
def interface_info(iface)
|
|
66
67
|
# will return "[mtu]\n1500\n[type]\n1"
|
|
67
|
-
cmd = inspec.command("find /sys/class/net/#{iface}/ -
|
|
68
|
+
cmd = inspec.command("find /sys/class/net/#{iface}/ -maxdepth 1 -type f -exec sh -c 'echo \"[$(basename {})]\"; cat {} || echo -n' \\;")
|
|
68
69
|
return nil if cmd.exit_status.to_i != 0
|
|
69
70
|
|
|
70
71
|
# parse values, we only recieve values, therefore we threat them as keys
|
|
@@ -121,7 +122,7 @@ module Inspec::Resources
|
|
|
121
122
|
adapter_collection.push(info) if info[:name].casecmp(iface) == 0
|
|
122
123
|
end
|
|
123
124
|
|
|
124
|
-
return nil if adapters.
|
|
125
|
+
return nil if adapters.empty?
|
|
125
126
|
warn "[Possible Error] detected multiple network interfaces with the name #{iface}" if adapters.size > 1
|
|
126
127
|
adapters[0]
|
|
127
128
|
end
|
data/lib/resources/json.rb
CHANGED
|
@@ -12,6 +12,15 @@ module Inspec::Resources
|
|
|
12
12
|
describe json('policyfile.lock.json') do
|
|
13
13
|
its(['cookbook_locks','omnibus','version']) { should eq('2.2.0') }
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
describe json({ command: 'retrieve_data.py --json' }) do
|
|
17
|
+
its('state') { should eq('open') }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe json({ content: '{\"item1\": { \"status\": \"available\" } }' }) do
|
|
21
|
+
its(['item1', 'status']) { should cmp 'available' }
|
|
22
|
+
end
|
|
23
|
+
|
|
15
24
|
"
|
|
16
25
|
|
|
17
26
|
include ObjectTraverser
|
|
@@ -19,21 +28,31 @@ module Inspec::Resources
|
|
|
19
28
|
# make params readable
|
|
20
29
|
attr_reader :params
|
|
21
30
|
|
|
22
|
-
def initialize(
|
|
23
|
-
@
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
def initialize(opts)
|
|
32
|
+
@opts = opts
|
|
33
|
+
if opts.is_a?(Hash)
|
|
34
|
+
if opts.key?(:content)
|
|
35
|
+
@file_content = opts[:content]
|
|
36
|
+
elsif opts.key?(:command)
|
|
37
|
+
@command = inspec.command(opts[:command])
|
|
38
|
+
@file_content = @command.stdout
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
@path = opts
|
|
42
|
+
@file = inspec.file(@opts)
|
|
43
|
+
@file_content = @file.content
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
# check if file is available
|
|
46
|
+
if !@file.file?
|
|
47
|
+
skip_resource "Can't find file \"#{@path}\""
|
|
48
|
+
return @params = {}
|
|
49
|
+
end
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
# check if file is readable
|
|
52
|
+
if @file_content.nil? && !@file.empty?
|
|
53
|
+
skip_resource "Can't read file \"#{@path}\""
|
|
54
|
+
return @params = {}
|
|
55
|
+
end
|
|
37
56
|
end
|
|
38
57
|
|
|
39
58
|
@params = parse(@file_content)
|
|
@@ -61,7 +80,11 @@ module Inspec::Resources
|
|
|
61
80
|
end
|
|
62
81
|
|
|
63
82
|
def to_s
|
|
64
|
-
|
|
83
|
+
if @opts.is_a?(Hash) && @opts.key?(:content)
|
|
84
|
+
'Json content'
|
|
85
|
+
else
|
|
86
|
+
"Json #{@path}"
|
|
87
|
+
end
|
|
65
88
|
end
|
|
66
89
|
end
|
|
67
90
|
end
|
|
@@ -1,30 +1,54 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# author: Christoph Hartmann
|
|
3
3
|
# author: Dominik Richter
|
|
4
|
-
#
|
|
4
|
+
# author: Aaron Lippold
|
|
5
|
+
# author: Adam Leff
|
|
5
6
|
|
|
6
7
|
module Inspec::Resources
|
|
7
8
|
class KernelModule < Inspec.resource(1)
|
|
8
9
|
name 'kernel_module'
|
|
9
|
-
desc 'Use the kernel_module InSpec audit resource to test kernel modules on
|
|
10
|
+
desc 'Use the kernel_module InSpec audit resource to test kernel modules on
|
|
11
|
+
Linux platforms. These parameters are located under /lib/modules. Any submodule
|
|
12
|
+
may be tested using this resource.
|
|
13
|
+
|
|
14
|
+
The `kernel_module` resource can also verify if a kernel module is `blacklisted`
|
|
15
|
+
or if a module is disabled via a fake install using the `bin_true` or `bin_false`
|
|
16
|
+
method.'
|
|
17
|
+
|
|
10
18
|
example "
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
|
|
20
|
+
describe kernel_module('video') do
|
|
21
|
+
it { should be_loaded }
|
|
22
|
+
it { should_not be_disabled }
|
|
23
|
+
it { should_not be_blacklisted }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe kernel_module('sstfb') do
|
|
27
|
+
it { should_not be_loaded }
|
|
28
|
+
it { should be_disabled }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe kernel_module('floppy') do
|
|
32
|
+
it { should be_blacklisted }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe kernel_module('dhcp') do
|
|
36
|
+
it { should_not be_loaded }
|
|
37
|
+
end
|
|
14
38
|
"
|
|
15
39
|
|
|
16
40
|
def initialize(modulename = nil)
|
|
17
41
|
@module = modulename
|
|
18
|
-
|
|
19
42
|
# this resource is only supported on Linux
|
|
20
43
|
return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
|
|
21
44
|
end
|
|
22
45
|
|
|
23
46
|
def loaded?
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
if inspec.os.redhat? || inspec.os.name == 'fedora'
|
|
48
|
+
lsmod_cmd = '/sbin/lsmod'
|
|
49
|
+
else
|
|
50
|
+
lsmod_cmd = 'lsmod'
|
|
51
|
+
end
|
|
28
52
|
|
|
29
53
|
# get list of all modules
|
|
30
54
|
cmd = inspec.command(lsmod_cmd)
|
|
@@ -36,8 +60,51 @@ module Inspec::Resources
|
|
|
36
60
|
!found.nil?
|
|
37
61
|
end
|
|
38
62
|
|
|
63
|
+
def disabled?
|
|
64
|
+
!modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/(true|false)}).nil?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def blacklisted?
|
|
68
|
+
!modprobe_output.match(/^blacklist\s+#{@module}/).nil? || disabled_via_bin_true? || disabled_via_bin_false?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def version
|
|
72
|
+
cmd = inspec.command("#{modinfo_cmd_for_os} -F version #{@module}")
|
|
73
|
+
cmd.exit_status.zero? ? cmd.stdout.delete("\n") : nil
|
|
74
|
+
end
|
|
75
|
+
|
|
39
76
|
def to_s
|
|
40
77
|
"Kernel Module #{@module}"
|
|
41
78
|
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def modprobe_output
|
|
83
|
+
@modprobe_output ||= inspec.command("#{modprobe_cmd_for_os} --showconfig").stdout
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def modinfo_cmd_for_os
|
|
87
|
+
if inspec.os.redhat? || inspec.os.name == 'fedora'
|
|
88
|
+
'/sbin/modinfo'
|
|
89
|
+
else
|
|
90
|
+
'modinfo'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def modprobe_cmd_for_os
|
|
95
|
+
if inspec.os.redhat? || inspec.os.name == 'fedora'
|
|
96
|
+
'/sbin/modprobe'
|
|
97
|
+
else
|
|
98
|
+
'modprobe'
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def disabled_via_bin_true?
|
|
103
|
+
!modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/true}).nil?
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def disabled_via_bin_false?
|
|
107
|
+
!modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/false}).nil?
|
|
108
|
+
end
|
|
42
109
|
end
|
|
43
110
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# author: Richard Nixon
|
|
3
|
+
# author: Christoph Hartmann
|
|
4
|
+
|
|
5
|
+
require 'openssl'
|
|
6
|
+
require 'hashie/mash'
|
|
7
|
+
|
|
8
|
+
module Inspec::Resources
|
|
9
|
+
class RsaKey < Inspec.resource(1)
|
|
10
|
+
name 'key_rsa'
|
|
11
|
+
desc 'public/private RSA key pair test'
|
|
12
|
+
example "
|
|
13
|
+
describe rsa_key('/etc/pki/www.mywebsite.com.key') do
|
|
14
|
+
its('public_key') { should match /BEGIN RSA PUBLIC KEY/ }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe rsa_key('/etc/pki/www.mywebsite.com.key', 'passphrase') do
|
|
18
|
+
it { should be_private }
|
|
19
|
+
it { should be_public }
|
|
20
|
+
end
|
|
21
|
+
"
|
|
22
|
+
|
|
23
|
+
def initialize(keypath, passphrase = nil)
|
|
24
|
+
@key_path = keypath
|
|
25
|
+
@key_file = inspec.file(@key_path)
|
|
26
|
+
@key = nil
|
|
27
|
+
@passphrase = passphrase
|
|
28
|
+
|
|
29
|
+
return skip_resource "Unable to find key file #{@key_path}" unless @key_file.exist?
|
|
30
|
+
|
|
31
|
+
begin
|
|
32
|
+
@key = OpenSSL::PKey.read(@key_file.content, @passphrase)
|
|
33
|
+
rescue OpenSSL::PKey::RSAError => _
|
|
34
|
+
return skip_resource "Unable to load key file #{@key_path}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def public?
|
|
39
|
+
return if @key.nil?
|
|
40
|
+
@key.public?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def public_key
|
|
44
|
+
return if @key.nil?
|
|
45
|
+
@key.public_key.to_s
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def private?
|
|
49
|
+
return if @key.nil?
|
|
50
|
+
@key.private?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def private_key
|
|
54
|
+
return if @key.nil?
|
|
55
|
+
@key.to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def key_length
|
|
59
|
+
return if @key.nil?
|
|
60
|
+
@key.public_key.n.num_bytes * 8
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def to_s
|
|
64
|
+
"rsa_key #{@key_path}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# copyright: 2015, Vulcano Security GmbH
|
|
3
3
|
# author: Christoph Hartmann
|
|
4
4
|
# author: Dominik Richter
|
|
5
|
-
# license: All rights reserved
|
|
6
5
|
|
|
7
6
|
require 'utils/simpleconfig'
|
|
8
7
|
|
|
@@ -35,7 +34,7 @@ module Inspec::Resources
|
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
content = file.content
|
|
38
|
-
if content.empty? && file.
|
|
37
|
+
if content.empty? && !file.empty?
|
|
39
38
|
skip_resource "Can't read file \"#{@conf_path}\""
|
|
40
39
|
return @params = {}
|
|
41
40
|
end
|
|
@@ -43,8 +42,8 @@ module Inspec::Resources
|
|
|
43
42
|
# parse the file
|
|
44
43
|
conf = SimpleConfig.new(
|
|
45
44
|
content,
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
|
46
|
+
key_values: 3,
|
|
48
47
|
multiple_values: true,
|
|
49
48
|
)
|
|
50
49
|
@params = conf.params
|
data/lib/resources/login_def.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# copyright: 2015, Vulcano Security GmbH
|
|
3
3
|
# author: Christoph Hartmann
|
|
4
4
|
# author: Dominik Richter
|
|
5
|
-
# license: All rights reserved
|
|
6
5
|
|
|
7
6
|
require 'utils/simpleconfig'
|
|
8
7
|
|
|
@@ -47,7 +46,7 @@ module Inspec::Resources
|
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
content = file.content
|
|
50
|
-
if content.empty? && file.
|
|
49
|
+
if content.empty? && !file.empty?
|
|
51
50
|
skip_resource "Can't read file \"#{@conf_path}\""
|
|
52
51
|
return @params = {}
|
|
53
52
|
end
|
|
@@ -55,7 +54,7 @@ module Inspec::Resources
|
|
|
55
54
|
# parse the file
|
|
56
55
|
conf = SimpleConfig.new(
|
|
57
56
|
content,
|
|
58
|
-
|
|
57
|
+
assignment_regex: /^\s*(\S+)\s+(\S*)\s*$/,
|
|
59
58
|
multiple_values: false,
|
|
60
59
|
)
|
|
61
60
|
@params = conf.params
|
data/lib/resources/mount.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# author: Christoph Hartmann
|
|
3
3
|
# author: Dominik Richter
|
|
4
|
+
# author: Joseph Benden
|
|
4
5
|
|
|
5
6
|
require 'utils/simpleconfig'
|
|
6
7
|
|
|
@@ -18,13 +19,12 @@ module Inspec::Resources
|
|
|
18
19
|
its('options') { should include 'nodev' }
|
|
19
20
|
end
|
|
20
21
|
"
|
|
21
|
-
include MountParser
|
|
22
|
-
|
|
23
22
|
attr_reader :file
|
|
24
23
|
|
|
25
24
|
def initialize(path)
|
|
26
25
|
@path = path
|
|
27
|
-
|
|
26
|
+
@mount_manager = mount_manager_for_os
|
|
27
|
+
return skip_resource 'The `mount` resource is not supported on your OS yet.' if @mount_manager.nil?
|
|
28
28
|
@file = inspec.backend.file(@path)
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -49,12 +49,42 @@ module Inspec::Resources
|
|
|
49
49
|
line = mounted.stdout.lines.to_a.last if mounted.stdout.lines.count > 1
|
|
50
50
|
|
|
51
51
|
# parse content if we are on linux
|
|
52
|
-
@mount_options ||= parse_mount_options(line)
|
|
52
|
+
@mount_options ||= @mount_manager.parse_mount_options(line)
|
|
53
53
|
@mount_options[name]
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def to_s
|
|
57
57
|
"Mount #{@path}"
|
|
58
58
|
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def mount_manager_for_os
|
|
63
|
+
os = inspec.os
|
|
64
|
+
if os.linux?
|
|
65
|
+
LinuxMounts.new(inspec)
|
|
66
|
+
elsif ['freebsd'].include?(os[:family])
|
|
67
|
+
BsdMounts.new(inspec)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
class MountsInfo
|
|
73
|
+
attr_reader :inspec
|
|
74
|
+
def initialize(inspec)
|
|
75
|
+
@inspec = inspec
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def parse_mount_options(_mount_line, _compatibility = false)
|
|
79
|
+
raise NotImplementedError
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class LinuxMounts < MountsInfo
|
|
84
|
+
include LinuxMountParser
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class BsdMounts < MountsInfo
|
|
88
|
+
include BsdMountParser
|
|
59
89
|
end
|
|
60
90
|
end
|