inspec-core 6.8.24 → 7.0.38.beta
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/Gemfile +6 -6
- data/etc/deprecations.json +15 -6
- data/lib/inspec/base_cli.rb +3 -0
- data/lib/inspec/cached_fetcher.rb +16 -1
- data/lib/inspec/dependencies/cache.rb +48 -4
- data/lib/inspec/dsl.rb +40 -11
- data/lib/inspec/exceptions.rb +1 -0
- data/lib/inspec/fetcher/gem.rb +99 -0
- data/lib/inspec/fetcher/local.rb +1 -1
- data/lib/inspec/fetcher.rb +1 -0
- data/lib/inspec/file_provider.rb +46 -1
- data/lib/inspec/input_registry.rb +1 -1
- data/lib/inspec/plugin/v2/concerns/gem_spec_helper.rb +30 -0
- data/lib/inspec/plugin/v2/gem_source_manager.rb +43 -0
- data/lib/inspec/plugin/v2/installer.rb +42 -16
- data/lib/inspec/plugin/v2/loader.rb +34 -5
- data/lib/inspec/plugin/v2/plugin_types/resource_pack.rb +8 -0
- data/lib/inspec/plugin/v2.rb +1 -0
- data/lib/inspec/profile.rb +10 -0
- data/lib/inspec/profile_context.rb +10 -0
- data/lib/inspec/reporters/automate.rb +2 -2
- data/lib/inspec/resources/auditd.rb +1 -1
- data/lib/inspec/resources/groups.rb +52 -0
- data/lib/inspec/resources/port.rb +2 -2
- data/lib/inspec/resources/postgres_session.rb +5 -9
- data/lib/inspec/resources/yum.rb +1 -1
- data/lib/inspec/resources.rb +0 -14
- data/lib/inspec/runner.rb +7 -15
- data/lib/inspec/source_reader.rb +2 -0
- data/lib/inspec/ui.rb +1 -0
- data/lib/inspec/utils/deprecation/config_file.rb +39 -3
- data/lib/inspec/utils/deprecation/deprecator.rb +10 -3
- data/lib/inspec/utils/licensing_config.rb +1 -15
- data/lib/inspec/utils/parser.rb +9 -19
- data/lib/inspec/utils/telemetry.rb +1 -3
- data/lib/inspec/version.rb +1 -1
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +2 -4
- data/lib/source_readers/gem.rb +67 -0
- data/lib/source_readers/inspec.rb +1 -1
- metadata +9 -32
- data/lib/inspec/resources/docker.rb +0 -274
- data/lib/inspec/resources/docker_container.rb +0 -116
- data/lib/inspec/resources/docker_image.rb +0 -141
- data/lib/inspec/resources/docker_object.rb +0 -52
- data/lib/inspec/resources/docker_plugin.rb +0 -68
- data/lib/inspec/resources/docker_service.rb +0 -95
- data/lib/inspec/resources/elasticsearch.rb +0 -165
- data/lib/inspec/resources/ibmdb2_conf.rb +0 -65
- data/lib/inspec/resources/ibmdb2_session.rb +0 -78
- data/lib/inspec/resources/mongodb.rb +0 -69
- data/lib/inspec/resources/mongodb_conf.rb +0 -44
- data/lib/inspec/resources/mongodb_session.rb +0 -98
- data/lib/inspec/resources/podman.rb +0 -353
- data/lib/inspec/resources/podman_container.rb +0 -84
- data/lib/inspec/resources/podman_image.rb +0 -108
- data/lib/inspec/resources/podman_network.rb +0 -81
- data/lib/inspec/resources/podman_pod.rb +0 -101
- data/lib/inspec/resources/podman_volume.rb +0 -87
- data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
- data/lib/inspec/resources/rabbitmq_config.rb +0 -56
- data/lib/inspec/resources/ssh_config.rb +0 -215
- data/lib/inspec/resources/ssh_key.rb +0 -124
- data/lib/inspec/resources/sshd_active_config.rb +0 -2
- data/lib/inspec/resources/sshd_config.rb +0 -2
- data/lib/inspec/resources/sybase_conf.rb +0 -41
- data/lib/inspec/resources/sybase_session.rb +0 -124
- data/lib/inspec/utils/deprecated_core_resources_list.rb +0 -25
- data/lib/inspec/utils/podman.rb +0 -24
@@ -1,108 +0,0 @@
|
|
1
|
-
require "inspec/resources/command"
|
2
|
-
require_relative "docker_object"
|
3
|
-
require "inspec/utils/podman"
|
4
|
-
|
5
|
-
module Inspec::Resources
|
6
|
-
class PodmanImage < Inspec.resource(1)
|
7
|
-
include Inspec::Resources::DockerObject
|
8
|
-
include Inspec::Utils::Podman
|
9
|
-
|
10
|
-
name "podman_image"
|
11
|
-
supports platform: "unix"
|
12
|
-
|
13
|
-
desc "InSpec core resource to retrieve information about podman image"
|
14
|
-
|
15
|
-
example <<~EXAMPLE
|
16
|
-
describe podman_image("docker.io/library/busybox") do
|
17
|
-
it { should exist }
|
18
|
-
its("repo_tags") { should include "docker.io/library/busybox:latest" }
|
19
|
-
its("size") { should eq 1636053 }
|
20
|
-
its("resource_id") { should eq "docker.io/library/busybox:latest" }
|
21
|
-
end
|
22
|
-
|
23
|
-
describe podman_image("docker.io/library/busybox:latest") do
|
24
|
-
it { should exist }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe podman_image(repo: "docker.io/library/busybox", tag: "latest") do
|
28
|
-
it { should exist }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe podman_image(id: "3c19bafed223") do
|
32
|
-
it { should exist }
|
33
|
-
end
|
34
|
-
EXAMPLE
|
35
|
-
|
36
|
-
attr_reader :opts, :image_info
|
37
|
-
|
38
|
-
def initialize(opts)
|
39
|
-
skip_resource "The `podman_image` resource is not yet available on your OS." unless inspec.os.unix?
|
40
|
-
opts = { image: opts } if opts.is_a?(String)
|
41
|
-
@opts = sanitize_options(opts)
|
42
|
-
raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running?
|
43
|
-
|
44
|
-
@image_info = get_image_info
|
45
|
-
end
|
46
|
-
|
47
|
-
LABELS = {
|
48
|
-
"id" => "ID",
|
49
|
-
"repo_tags" => "RepoTags",
|
50
|
-
"size" => "Size",
|
51
|
-
"digest" => "Digest",
|
52
|
-
"created_at" => "Created",
|
53
|
-
"version" => "Version",
|
54
|
-
"names_history" => "NamesHistory",
|
55
|
-
"repo_digests" => "RepoDigests",
|
56
|
-
"architecture" => "Architecture",
|
57
|
-
"os" => "Os",
|
58
|
-
"virtual_size" => "VirtualSize",
|
59
|
-
}.freeze
|
60
|
-
|
61
|
-
## This creates all the required properties methods dynamically.
|
62
|
-
LABELS.each do |k, v|
|
63
|
-
define_method(k) do
|
64
|
-
image_info[k.to_s]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def exist?
|
69
|
-
! image_info.empty?
|
70
|
-
end
|
71
|
-
|
72
|
-
def resource_id
|
73
|
-
opts[:id] || opts[:image] || ""
|
74
|
-
end
|
75
|
-
|
76
|
-
def to_s
|
77
|
-
"podman_image #{resource_id}"
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def sanitize_options(opts)
|
83
|
-
opts.merge!(parse_components_from_image(opts[:image]))
|
84
|
-
|
85
|
-
# assume a "latest" tag if we don't have one
|
86
|
-
opts[:tag] ||= "latest"
|
87
|
-
|
88
|
-
# Assemble/reassemble the image from the repo and tag
|
89
|
-
opts[:image] = "#{opts[:repo]}:#{opts[:tag]}" unless opts[:repo].nil?
|
90
|
-
|
91
|
-
opts
|
92
|
-
end
|
93
|
-
|
94
|
-
def get_image_info
|
95
|
-
current_image = opts[:id] || opts[:image] || opts[:repo] + ":" + opts[:tag]
|
96
|
-
json_key_label = generate_go_template(LABELS)
|
97
|
-
podman_inspect_cmd = inspec.command("podman image inspect #{current_image} --format '{#{json_key_label}}'")
|
98
|
-
|
99
|
-
if podman_inspect_cmd.exit_status == 0
|
100
|
-
parse_command_output(podman_inspect_cmd.stdout)
|
101
|
-
elsif podman_inspect_cmd.stderr =~ /failed to find image/
|
102
|
-
{}
|
103
|
-
else
|
104
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to retrieve podman image information for #{current_image}.\nError message: #{podman_inspect_cmd.stderr}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require "inspec/resources/command"
|
2
|
-
require "inspec/utils/podman"
|
3
|
-
module Inspec::Resources
|
4
|
-
class PodmanNetwork < Inspec.resource(1)
|
5
|
-
include Inspec::Utils::Podman
|
6
|
-
|
7
|
-
name "podman_network"
|
8
|
-
|
9
|
-
supports platform: "unix"
|
10
|
-
|
11
|
-
desc "InSpec core resource to retrive information about the given Podman network"
|
12
|
-
|
13
|
-
example <<~EXAMPLE
|
14
|
-
describe podman_network("podman") do
|
15
|
-
it { should exist }
|
16
|
-
end
|
17
|
-
describe podman_network("3a7c94d937d5f3a0f1a9b1610589945aedfbe56207fd5d32fc8154aa1a8b007f") do
|
18
|
-
its("driver") { should eq bridge }
|
19
|
-
end
|
20
|
-
EXAMPLE
|
21
|
-
|
22
|
-
LABELS = {
|
23
|
-
id: "ID",
|
24
|
-
name: "Name",
|
25
|
-
driver: "Driver",
|
26
|
-
labels: "Labels",
|
27
|
-
options: "Options",
|
28
|
-
ipam_options: "IPAMOptions",
|
29
|
-
internal: "Internal",
|
30
|
-
created: "Created",
|
31
|
-
ipv6_enabled: "IPv6Enabled",
|
32
|
-
dns_enabled: "DNSEnabled",
|
33
|
-
network_interface: "NetworkInterface",
|
34
|
-
subnets: "Subnets",
|
35
|
-
}.freeze
|
36
|
-
|
37
|
-
attr_reader :param, :network_info
|
38
|
-
def initialize(param)
|
39
|
-
skip_resource "The `podman_network` resource is not yet available on your OS." unless inspec.os.unix?
|
40
|
-
|
41
|
-
@param = param
|
42
|
-
raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running?
|
43
|
-
|
44
|
-
@network_info = get_network_info
|
45
|
-
end
|
46
|
-
|
47
|
-
## This creates all the required properties methods dynamically.
|
48
|
-
LABELS.each do |k, v|
|
49
|
-
define_method(k) do
|
50
|
-
network_info[k.to_s]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def exist?
|
55
|
-
!network_info.empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
def resource_id
|
59
|
-
id || param || ""
|
60
|
-
end
|
61
|
-
|
62
|
-
def to_s
|
63
|
-
"podman_network #{resource_id}"
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def get_network_info
|
69
|
-
go_template_format = generate_go_template(LABELS)
|
70
|
-
result = inspec.command("podman network inspect #{param} --format '{#{go_template_format}}'")
|
71
|
-
|
72
|
-
if result.exit_status == 0
|
73
|
-
parse_command_output(result.stdout)
|
74
|
-
elsif result.stderr =~ /network not found/
|
75
|
-
{}
|
76
|
-
else
|
77
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to retrieve podman network information for #{param}.\nError message: #{result.stderr}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require "inspec/resources/command"
|
2
|
-
require "inspec/utils/podman"
|
3
|
-
|
4
|
-
module Inspec::Resources
|
5
|
-
class PodmanPod < Inspec.resource(1)
|
6
|
-
include Inspec::Utils::Podman
|
7
|
-
|
8
|
-
name "podman_pod"
|
9
|
-
supports platform: "unix"
|
10
|
-
|
11
|
-
desc "InSpec core resource to retrieve information about podman pod"
|
12
|
-
|
13
|
-
example <<~EXAMPLE
|
14
|
-
describe podman_pod("nginx-frontend") do
|
15
|
-
it { should exist }
|
16
|
-
its("id") { should eq "fcfe4d471cfface0d1b39bce23af7d31ab8736cd68c0360ade0b4afe364f79d4" }
|
17
|
-
its("name") { should eq "nginx-frontend" }
|
18
|
-
its("created_at") { should eq "2022-07-14T15:47:47.978078124+05:30" }
|
19
|
-
its("create_command") { should include "new:nginx-frontend" }
|
20
|
-
its("state") { should eq "Running" }
|
21
|
-
its("hostname") { should eq "" }
|
22
|
-
its("create_cgroup") { should eq true }
|
23
|
-
its("cgroup_parent") { should eq "user.slice" }
|
24
|
-
its("cgroup_path") { should eq "user.slice/user-libpod_pod_fcfe4d471cfface0d1b39bce23af7d31ab8736cd68c0360ade0b4afe364f79d4.slice" }
|
25
|
-
its("create_infra") { should eq true }
|
26
|
-
its("infra_container_id") { should eq "727538044b32a165934729dc2d47d9d5e981b6496aebfad7de470f7e76ea4251" }
|
27
|
-
its("infra_config") { should include "DNSOption" }
|
28
|
-
its("shared_namespaces") { should include "ipc" }
|
29
|
-
its("num_containers") { should eq 2 }
|
30
|
-
its("containers") { should_not be nil }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe podman_pod("non-existing-pod") do
|
34
|
-
it { should_not exist }
|
35
|
-
end
|
36
|
-
EXAMPLE
|
37
|
-
|
38
|
-
attr_reader :pod_info, :pod_id
|
39
|
-
|
40
|
-
def initialize(pod_id)
|
41
|
-
skip_resource "The `podman_pod` resource is not yet available on your OS." unless inspec.os.unix?
|
42
|
-
raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running?
|
43
|
-
|
44
|
-
@pod_id = pod_id
|
45
|
-
@pod_info = get_pod_info
|
46
|
-
end
|
47
|
-
|
48
|
-
LABELS = {
|
49
|
-
"id" => "ID",
|
50
|
-
"name" => "Name",
|
51
|
-
"created_at" => "Created",
|
52
|
-
"create_command" => "CreateCommand",
|
53
|
-
"state" => "State",
|
54
|
-
"hostname" => "Hostname",
|
55
|
-
"create_cgroup" => "CreateCgroup",
|
56
|
-
"cgroup_parent" => "CgroupParent",
|
57
|
-
"cgroup_path" => "CgroupPath",
|
58
|
-
"create_infra" => "CreateInfra",
|
59
|
-
"infra_container_id" => "InfraContainerID",
|
60
|
-
"infra_config" => "InfraConfig",
|
61
|
-
"shared_namespaces" => "SharedNamespaces",
|
62
|
-
"num_containers" => "NumContainers",
|
63
|
-
"containers" => "Containers",
|
64
|
-
}.freeze
|
65
|
-
|
66
|
-
# This creates all the required properties methods dynamically.
|
67
|
-
LABELS.each do |k, _|
|
68
|
-
define_method(k) do
|
69
|
-
pod_info[k.to_s]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def exist?
|
74
|
-
!pod_info.empty?
|
75
|
-
end
|
76
|
-
|
77
|
-
def resource_id
|
78
|
-
pod_id
|
79
|
-
end
|
80
|
-
|
81
|
-
def to_s
|
82
|
-
"Podman Pod #{resource_id}"
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def get_pod_info
|
88
|
-
json_key_label = generate_go_template(LABELS)
|
89
|
-
|
90
|
-
inspect_pod_cmd = inspec.command("podman pod inspect #{pod_id} --format '{#{json_key_label}}'")
|
91
|
-
|
92
|
-
if inspect_pod_cmd.exit_status == 0
|
93
|
-
parse_command_output(inspect_pod_cmd.stdout)
|
94
|
-
elsif inspect_pod_cmd.stderr =~ /no pod with name or ID/
|
95
|
-
{}
|
96
|
-
else
|
97
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to retrieve podman pod information for #{pod_id}.\nError message: #{inspect_pod_cmd.stderr}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require "inspec/resources/command"
|
2
|
-
require "inspec/utils/podman"
|
3
|
-
|
4
|
-
module Inspec::Resources
|
5
|
-
class PodmanVolume < Inspec.resource(1)
|
6
|
-
include Inspec::Utils::Podman
|
7
|
-
|
8
|
-
name "podman_volume"
|
9
|
-
supports platform: "unix"
|
10
|
-
|
11
|
-
desc "InSpec core resource to retrieve information about podman volume"
|
12
|
-
|
13
|
-
example <<~EXAMPLE
|
14
|
-
describe podman_volume("my_volume") do
|
15
|
-
it { should exist }
|
16
|
-
its("name") { should eq "my_volume" }
|
17
|
-
its("driver") { should eq "local" }
|
18
|
-
its("mountpoint") { should eq "/var/home/core/.local/share/containers/storage/volumes/my_volume/_data" }
|
19
|
-
its("created_at") { should eq "2022-07-14T13:21:19.965421792+05:30" }
|
20
|
-
its("labels") { should eq({}) }
|
21
|
-
its("scope") { should eq "local" }
|
22
|
-
its("options") { should eq({}) }
|
23
|
-
its("mount_count") { should eq 0 }
|
24
|
-
its("needs_copy_up") { should eq true }
|
25
|
-
its("needs_chown") { should eq true }
|
26
|
-
end
|
27
|
-
EXAMPLE
|
28
|
-
|
29
|
-
attr_reader :volume_info, :volume_name
|
30
|
-
|
31
|
-
def initialize(volume_name)
|
32
|
-
skip_resource "The `podman_volume` resource is not yet available on your OS." unless inspec.os.unix?
|
33
|
-
raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running?
|
34
|
-
|
35
|
-
@volume_name = volume_name
|
36
|
-
@volume_info = get_volume_info
|
37
|
-
end
|
38
|
-
|
39
|
-
LABELS = {
|
40
|
-
"name" => "Name",
|
41
|
-
"driver" => "Driver",
|
42
|
-
"mountpoint" => "Mountpoint",
|
43
|
-
"created_at" => "CreatedAt",
|
44
|
-
"labels" => "Labels",
|
45
|
-
"scope" => "Scope",
|
46
|
-
"options" => "Options",
|
47
|
-
"mount_count" => "MountCount",
|
48
|
-
"needs_copy_up" => "NeedsCopyUp",
|
49
|
-
"needs_chown" => "NeedsChown",
|
50
|
-
}.freeze
|
51
|
-
|
52
|
-
# This creates all the required properties methods dynamically.
|
53
|
-
LABELS.each do |k, _|
|
54
|
-
define_method(k) do
|
55
|
-
volume_info[k.to_s]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def exist?
|
60
|
-
!volume_info.empty?
|
61
|
-
end
|
62
|
-
|
63
|
-
def resource_id
|
64
|
-
volume_name
|
65
|
-
end
|
66
|
-
|
67
|
-
def to_s
|
68
|
-
"podman_volume #{resource_id}"
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def get_volume_info
|
74
|
-
json_key_label = generate_go_template(LABELS)
|
75
|
-
|
76
|
-
inspect_volume_cmd = inspec.command("podman volume inspect #{volume_name} --format '{#{json_key_label}}'")
|
77
|
-
|
78
|
-
if inspect_volume_cmd.exit_status == 0
|
79
|
-
parse_command_output(inspect_volume_cmd.stdout)
|
80
|
-
elsif inspect_volume_cmd.stderr =~ /inspecting object: no such/
|
81
|
-
{}
|
82
|
-
else
|
83
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to retrieve podman volume information for #{volume_name}.\nError message: #{inspect_volume_cmd.stderr}"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require "inspec/utils/erlang_parser"
|
2
|
-
require "inspec/utils/file_reader"
|
3
|
-
|
4
|
-
module Inspec::Resources
|
5
|
-
class RabbitmqConfig < Inspec.resource(1)
|
6
|
-
name "rabbitmq_conf" # TODO: this is an alias. do we want this?
|
7
|
-
name "rabbitmq_config"
|
8
|
-
supports platform: "unix"
|
9
|
-
desc "Use the rabbitmq_config InSpec resource to test configuration data "\
|
10
|
-
"for the RabbitMQ service located in /etc/rabbitmq/rabbitmq.config on "\
|
11
|
-
"Linux and UNIX platforms."
|
12
|
-
example <<~EXAMPLE
|
13
|
-
describe rabbitmq_config.params('rabbit', 'ssl_listeners') do
|
14
|
-
it { should cmp 5671 }
|
15
|
-
end
|
16
|
-
EXAMPLE
|
17
|
-
|
18
|
-
include FileReader
|
19
|
-
|
20
|
-
def initialize(conf_path = nil)
|
21
|
-
@conf_path = conf_path || "/etc/rabbitmq/rabbitmq.config"
|
22
|
-
@content = read_file_content(@conf_path, allow_empty: true)
|
23
|
-
end
|
24
|
-
|
25
|
-
def params(*opts)
|
26
|
-
opts.inject(read_params) do |res, nxt|
|
27
|
-
res.respond_to?(:key) ? res[nxt] : nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"rabbitmq_config #{@conf_path}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def resource_id
|
36
|
-
@conf_path
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def read_content
|
42
|
-
return @content if defined?(@content)
|
43
|
-
|
44
|
-
@content = read_file_content(@conf_path, allow_empty: true)
|
45
|
-
end
|
46
|
-
|
47
|
-
def read_params
|
48
|
-
return @params if defined?(@params)
|
49
|
-
return @params = {} if read_content.nil?
|
50
|
-
|
51
|
-
@params = ErlangConfigFile.parse(read_content)
|
52
|
-
rescue Parslet::ParseFailed
|
53
|
-
raise "Cannot parse RabbitMQ config: \"#{read_content}\""
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,215 +0,0 @@
|
|
1
|
-
# copyright: 2015, Vulcano Security GmbH
|
2
|
-
|
3
|
-
require "inspec/utils/simpleconfig"
|
4
|
-
require "inspec/utils/file_reader"
|
5
|
-
|
6
|
-
module Inspec::Resources
|
7
|
-
class SshConfig < Inspec.resource(1)
|
8
|
-
name "ssh_config"
|
9
|
-
supports platform: "unix"
|
10
|
-
supports platform: "windows"
|
11
|
-
desc "Use the `ssh_config` InSpec audit resource to test OpenSSH client configuration data located at `/etc/ssh/ssh_config` on Linux and Unix platforms."
|
12
|
-
example <<~EXAMPLE
|
13
|
-
describe ssh_config do
|
14
|
-
its('cipher') { should contain '3des' }
|
15
|
-
its('port') { should eq '22' }
|
16
|
-
its('hostname') { should include('example.com') }
|
17
|
-
end
|
18
|
-
EXAMPLE
|
19
|
-
|
20
|
-
include FileReader
|
21
|
-
|
22
|
-
def initialize(conf_path = nil, type = nil)
|
23
|
-
@conf_path = conf_path || ssh_config_file("ssh_config")
|
24
|
-
typename = (@conf_path.include?("sshd") ? "Server" : "Client")
|
25
|
-
@type = type || "SSH #{typename} configuration #{conf_path}"
|
26
|
-
read_content
|
27
|
-
end
|
28
|
-
|
29
|
-
def content
|
30
|
-
read_content
|
31
|
-
end
|
32
|
-
|
33
|
-
def params(*opts)
|
34
|
-
opts.inject(read_params) do |res, nxt|
|
35
|
-
res.respond_to?(:key) ? res[nxt] : nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def convert_hash(hash)
|
40
|
-
new_hash = {}
|
41
|
-
hash.each { |k, v| new_hash[k.downcase] ||= v }
|
42
|
-
new_hash
|
43
|
-
end
|
44
|
-
|
45
|
-
def method_missing(name)
|
46
|
-
param = read_params[name.to_s.downcase]
|
47
|
-
return nil if param.nil?
|
48
|
-
return param[0] if param.length == 1
|
49
|
-
|
50
|
-
param
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_s
|
54
|
-
"SSH Configuration"
|
55
|
-
end
|
56
|
-
|
57
|
-
def resource_id
|
58
|
-
@conf_path || "SSH Configuration"
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def read_content
|
64
|
-
return @content if defined?(@content)
|
65
|
-
|
66
|
-
@content = read_file_content(@conf_path)
|
67
|
-
end
|
68
|
-
|
69
|
-
def read_params
|
70
|
-
return @params if defined?(@params)
|
71
|
-
return @params = {} if read_content.nil?
|
72
|
-
|
73
|
-
conf =
|
74
|
-
SimpleConfig.new(
|
75
|
-
read_content,
|
76
|
-
assignment_regex: /^\s*(\S+?)\s+(.*?)\s*$/,
|
77
|
-
multiple_values: true
|
78
|
-
)
|
79
|
-
@params = convert_hash(conf.params)
|
80
|
-
end
|
81
|
-
|
82
|
-
def ssh_config_file(type)
|
83
|
-
if inspec.os.windows?
|
84
|
-
programdata = inspec.os_env("programdata").content
|
85
|
-
return "#{programdata}\\ssh\\#{type}"
|
86
|
-
end
|
87
|
-
|
88
|
-
"/etc/ssh/#{type}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class SshdConfig < SshConfig
|
93
|
-
name "sshd_config"
|
94
|
-
supports platform: "unix"
|
95
|
-
supports platform: "windows"
|
96
|
-
desc "Use the sshd_config InSpec audit resource to test configuration data for the Open SSH daemon located at /etc/ssh/sshd_config on Linux and UNIX platforms. sshd---the Open SSH daemon---listens on dedicated ports, starts a daemon for each incoming connection, and then handles encryption, authentication, key exchanges, command execution, and data exchanges."
|
97
|
-
example <<~EXAMPLE
|
98
|
-
describe sshd_config do
|
99
|
-
its('Protocol') { should eq '2' }
|
100
|
-
end
|
101
|
-
EXAMPLE
|
102
|
-
|
103
|
-
def initialize(path = nil)
|
104
|
-
super(path || ssh_config_file("sshd_config"))
|
105
|
-
end
|
106
|
-
|
107
|
-
def to_s
|
108
|
-
"SSHD Configuration"
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def ssh_config_file(type)
|
114
|
-
if inspec.os.windows?
|
115
|
-
programdata = inspec.os_env("programdata").content
|
116
|
-
return "#{programdata}\\ssh\\#{type}"
|
117
|
-
end
|
118
|
-
|
119
|
-
"/etc/ssh/#{type}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
class SshdActiveConfig < SshdConfig
|
124
|
-
name "sshd_active_config"
|
125
|
-
supports platform: "unix"
|
126
|
-
supports platform: "windows"
|
127
|
-
desc "Use the sshd_active_config InSpec audit resource to test configuration data for the Open SSH daemon located at /etc/ssh/sshd_config on Linux and UNIX platforms. sshd---the Open SSH daemon---listens on dedicated ports, starts a daemon for each incoming connection, and then handles encryption, authentication, key exchanges, command execution, and data exchanges."
|
128
|
-
example <<~EXAMPLE
|
129
|
-
describe sshd_active_config do
|
130
|
-
its('Protocol') { should eq '2' }
|
131
|
-
end
|
132
|
-
EXAMPLE
|
133
|
-
|
134
|
-
attr_reader :active_path
|
135
|
-
|
136
|
-
def initialize
|
137
|
-
@active_path = dynamic_sshd_config_path
|
138
|
-
super(@active_path)
|
139
|
-
end
|
140
|
-
|
141
|
-
def to_s
|
142
|
-
"SSHD Active Configuration (active path: #{@conf_path})"
|
143
|
-
end
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
def ssh_config_file(type)
|
148
|
-
if inspec.os.windows?
|
149
|
-
programdata = inspec.os_env("programdata").content
|
150
|
-
return "#{programdata}\\ssh\\#{type}"
|
151
|
-
end
|
152
|
-
|
153
|
-
"/etc/ssh/#{type}"
|
154
|
-
end
|
155
|
-
|
156
|
-
def dynamic_sshd_config_path
|
157
|
-
if inspec.os.windows?
|
158
|
-
script = <<-EOH
|
159
|
-
$sshdPath = (Get-Command sshd.exe).Source
|
160
|
-
if ($sshdPath -ne $null) {
|
161
|
-
Write-Output $sshdPath
|
162
|
-
} else {
|
163
|
-
Write-Error "sshd.exe not found"
|
164
|
-
}
|
165
|
-
EOH
|
166
|
-
sshd_path_result = inspec.powershell(script).stdout.strip
|
167
|
-
sshd_path = "\"#{sshd_path_result}\""
|
168
|
-
if !sshd_path_result.empty? && sshd_path_result != "sshd.exe not found"
|
169
|
-
command_output = inspec.command("sudo #{sshd_path} -dd 2>&1").stdout
|
170
|
-
dynamic_path =
|
171
|
-
command_output
|
172
|
-
.lines
|
173
|
-
.find { |line| line.include?("filename") }
|
174
|
-
&.split("filename")
|
175
|
-
&.last
|
176
|
-
&.strip
|
177
|
-
env_var_name = dynamic_path.match(/__(.*?)__/)[1]
|
178
|
-
if env_var_name?
|
179
|
-
dynamic_path =
|
180
|
-
dynamic_path.gsub(
|
181
|
-
/__#{env_var_name}__/,
|
182
|
-
inspec.os_env(env_var_name).content
|
183
|
-
)
|
184
|
-
end
|
185
|
-
else
|
186
|
-
Inspec::Log.error("sshd.exe not found using PowerShell script block.")
|
187
|
-
return nil
|
188
|
-
end
|
189
|
-
elsif inspec.os.unix?
|
190
|
-
sshd_path = "/usr/sbin/sshd"
|
191
|
-
command_output = inspec.command("sudo #{sshd_path} -dd 2>&1").stdout
|
192
|
-
dynamic_path =
|
193
|
-
command_output
|
194
|
-
.lines
|
195
|
-
.find { |line| line.include?("filename") }
|
196
|
-
&.split("filename")
|
197
|
-
&.last
|
198
|
-
&.strip
|
199
|
-
else
|
200
|
-
Inspec::Log.error(
|
201
|
-
"Unable to determine sshd configuration path on Windows using -T flag."
|
202
|
-
)
|
203
|
-
return nil
|
204
|
-
end
|
205
|
-
|
206
|
-
if dynamic_path.nil? || dynamic_path.empty?
|
207
|
-
Inspec::Log.warn(
|
208
|
-
"No active SSHD configuration found. Using default configuration."
|
209
|
-
)
|
210
|
-
return ssh_config_file("sshd_config")
|
211
|
-
end
|
212
|
-
dynamic_path
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|