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,69 +0,0 @@
|
|
1
|
-
module Inspec::Resources
|
2
|
-
class Mongodb < Inspec.resource(1)
|
3
|
-
name "mongodb"
|
4
|
-
supports platform: "unix"
|
5
|
-
supports platform: "windows"
|
6
|
-
|
7
|
-
desc "The 'mongodb' resource is a helper for the 'mongodb_conf' & 'mongodb_session' resources. Please use those instead."
|
8
|
-
|
9
|
-
attr_reader :conf_path
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
case inspec.os[:family]
|
13
|
-
when "debian", "fedora", "redhat", "linux", "suse"
|
14
|
-
init_linux
|
15
|
-
when "darwin"
|
16
|
-
init_macos
|
17
|
-
when "windows"
|
18
|
-
init_windows
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def resource_id
|
23
|
-
@conf_path
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_s
|
27
|
-
"MongoDB"
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def init_linux
|
33
|
-
@conf_path = "/etc/mongod.conf"
|
34
|
-
end
|
35
|
-
|
36
|
-
def init_macos
|
37
|
-
@conf_path = "/usr/local/etc/mongod.conf"
|
38
|
-
end
|
39
|
-
|
40
|
-
def init_windows
|
41
|
-
dir = "C:\\Program Files\\MongoDB\\Server"
|
42
|
-
@version = version_from_dir(dir)
|
43
|
-
unless @version.to_s.empty?
|
44
|
-
@conf_path = "#{dir}\\#{@version}\\bin\\mongod.cfg"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def version_from_dir(dir)
|
49
|
-
dirs = inspec.command("Get-ChildItem -Path \"#{dir}\" -Name").stdout
|
50
|
-
entries = dirs.lines.count
|
51
|
-
case entries
|
52
|
-
when 0
|
53
|
-
warn "Could not determine version of installed MongoDB by inspecting #{dir}"
|
54
|
-
nil
|
55
|
-
when 1
|
56
|
-
dir_to_version(dirs)
|
57
|
-
else
|
58
|
-
warn "Multiple versions of MongoDB installed or incorrect base dir #{dir}"
|
59
|
-
first = dir_to_version(dirs.lines.first)
|
60
|
-
warn "Using the first version found: #{first}"
|
61
|
-
first
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def dir_to_version(dir)
|
66
|
-
dir.chomp.split("/").last
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require "inspec/resources/json"
|
2
|
-
require "inspec/resources/mongodb"
|
3
|
-
|
4
|
-
module Inspec::Resources
|
5
|
-
class MongodbConf < JsonConfig
|
6
|
-
name "mongodb_conf"
|
7
|
-
supports platform: "unix"
|
8
|
-
supports platform: "windows"
|
9
|
-
desc "Use the mongodb_conf InSpec audit resource to test the contents of the configuration file for MongoDB, typically located at `/etc/mongod.conf` or `C:\\Program Files\\MongoDB\\Server\\<version>\\bin\\mongod.cfg`, depending on the platform."
|
10
|
-
example <<~EXAMPLE
|
11
|
-
describe mongodb_conf do
|
12
|
-
its(["storage", "dbPath"]) { should eq "/var/lib/mongodb" }
|
13
|
-
its(["net", "port"]) { should eq 27017 }
|
14
|
-
end
|
15
|
-
EXAMPLE
|
16
|
-
|
17
|
-
def initialize(conf_path = nil)
|
18
|
-
@conf_path = conf_path || inspec.mongodb.conf_path
|
19
|
-
|
20
|
-
if @conf_path.nil?
|
21
|
-
return skip_resource "MongoDB conf path is not set."
|
22
|
-
end
|
23
|
-
|
24
|
-
super(@conf_path)
|
25
|
-
end
|
26
|
-
|
27
|
-
# set resource_id to "" if system is not able to determine the @conf_path
|
28
|
-
def resource_id
|
29
|
-
@conf_path || "mongodb_conf"
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def parse(content)
|
35
|
-
YAML.load(content)
|
36
|
-
rescue => e
|
37
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to parse `mongod.conf` or `mongod.cfg` file: #{e.message}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def resource_base_name
|
41
|
-
"MongoDB Configuration"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require "mongo"
|
2
|
-
|
3
|
-
module Inspec::Resources
|
4
|
-
class Lines
|
5
|
-
attr_reader :params
|
6
|
-
|
7
|
-
def initialize(raw, desc, exit_status = nil)
|
8
|
-
@params = raw
|
9
|
-
@desc = desc
|
10
|
-
@exit_status = exit_status
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
@desc
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class MongodbSession < Inspec.resource(1)
|
19
|
-
name "mongodb_session"
|
20
|
-
supports platform: "unix"
|
21
|
-
supports platform: "windows"
|
22
|
-
|
23
|
-
desc "Use the mongodb_session InSpec audit resource to run MongoDB command against a MongoDB Database."
|
24
|
-
example <<~EXAMPLE
|
25
|
-
# default values:
|
26
|
-
# host: "127.0.0.1"
|
27
|
-
# port: "27017"
|
28
|
-
# auth_source - default to database name
|
29
|
-
# auth_mech - :scram
|
30
|
-
|
31
|
-
describe mongodb_session(user: "foo", password: "bar", database: "test").query(usersInfo: "ian").params["users"].first["roles"].first do
|
32
|
-
its(["role"]) { should eq "readWrite" }
|
33
|
-
end
|
34
|
-
EXAMPLE
|
35
|
-
attr_reader :user, :host, :port, :database, :params
|
36
|
-
|
37
|
-
def initialize(opts = {})
|
38
|
-
@user = opts[:user] || nil
|
39
|
-
@password = opts[:password] || nil
|
40
|
-
@host = opts[:host] || "127.0.0.1"
|
41
|
-
@port = opts[:port] || "27017"
|
42
|
-
@database = opts[:database] || nil
|
43
|
-
@auth_mech = opts[:auth_mech] || :scram
|
44
|
-
@auth_source = opts[:auth_source] || @database
|
45
|
-
@ssl = opts[:ssl] || false
|
46
|
-
@ssl_cert = opts[:ssl_cert] || nil
|
47
|
-
@ssl_key = opts[:ssl_key] || nil
|
48
|
-
@ssl_ca_cert = opts[:ssl_ca_cert] || nil
|
49
|
-
@auth_mech_properties = opts[:auth_mech_properties] || {}
|
50
|
-
@client = nil
|
51
|
-
|
52
|
-
fail_resource "Can't run MongoDB checks without authentication." unless user && @password
|
53
|
-
fail_resource "You must provide a database name for the session." unless database
|
54
|
-
|
55
|
-
create_session
|
56
|
-
end
|
57
|
-
|
58
|
-
def query(command)
|
59
|
-
raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
|
60
|
-
|
61
|
-
Lines.new(@client.command(command).documents.first, "MongoDB query: #{command}")
|
62
|
-
rescue => e
|
63
|
-
raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command Error: #{e.message}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def resource_id
|
67
|
-
"mongodb_session:User:#{@user}:Host:#{@host}:Database:#{@database}"
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def create_session
|
73
|
-
raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
|
74
|
-
|
75
|
-
options = { user: "#{user}",
|
76
|
-
password: "#{@password}",
|
77
|
-
database: "#{database}",
|
78
|
-
auth_source: "#{@auth_source}",
|
79
|
-
auth_mech: @auth_mech,
|
80
|
-
}
|
81
|
-
options[:auth_mech_properties] = @auth_mech_properties unless @auth_mech_properties.empty?
|
82
|
-
options[:ssl] = @ssl
|
83
|
-
opitons[:ssl_key] = @ssl_key unless @ssl_key.nil?
|
84
|
-
options[:ssl_cert] = @ssl_cert unless @ssl_cert.nil?
|
85
|
-
options[:ssl_ca_cert] = @ssl_ca_cert unless @ssl_ca_cert.nil?
|
86
|
-
|
87
|
-
# Setting the logger level to INFO as mongo gem version 2.13.2 is using DEBUG as the log level Ref: https://github.com/mongodb/mongo-ruby-driver/blob/v2.13.2/lib/mongo/logger.rb#L79
|
88
|
-
# Latest version of the mongo gem don't have this issue as it set to INFO level Ref: https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/logger.rb#L82
|
89
|
-
# We pinned the version to 2.13.2 as the latest version of the mongo gem has broken symlink https://jira.mongodb.org/browse/RUBY-2546 which causes omnibus build failure.
|
90
|
-
# Once we get the latest version working we can remove logger level set here.
|
91
|
-
Mongo::Logger.logger.level = Logger::INFO
|
92
|
-
@client = Mongo::Client.new([ "#{host}:#{port}" ], options)
|
93
|
-
|
94
|
-
rescue => e
|
95
|
-
raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command. Error: #{e.message}"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,353 +0,0 @@
|
|
1
|
-
require "inspec/resources/command"
|
2
|
-
require "inspec/utils/filter"
|
3
|
-
require "hashie/mash"
|
4
|
-
|
5
|
-
module Inspec::Resources
|
6
|
-
class Podman < Inspec.resource(1)
|
7
|
-
# Resource requires an internal name.
|
8
|
-
name "podman"
|
9
|
-
|
10
|
-
# Restrict to only run on the below platforms (if none were given,
|
11
|
-
# all OS's and cloud API's supported)
|
12
|
-
supports platform: "unix"
|
13
|
-
|
14
|
-
desc "A resource to retrieve information about podman"
|
15
|
-
|
16
|
-
example <<~EXAMPLE
|
17
|
-
describe podman.containers do
|
18
|
-
its('images') { should include "docker.io/library/ubuntu:latest" }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe podman.images do
|
22
|
-
its('names') { should_not include "docker.io/library/ubuntu:latest" }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe podman.pods do
|
26
|
-
its("ids") { should include "95cadbb84df71e6374fceb3fd89ee3b8f2c7e1a831062cd9cea7d0e3e4b1dbcc" }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe podman.info.host do
|
30
|
-
its("os") { should eq "linux"}
|
31
|
-
end
|
32
|
-
|
33
|
-
describe podman.version do
|
34
|
-
its("Client.Version") { should eq "4.1.0"}
|
35
|
-
end
|
36
|
-
|
37
|
-
podman.containers.ids.each do |id|
|
38
|
-
# call podman inspect for a specific container id
|
39
|
-
describe podman.object(id) do
|
40
|
-
its("State.OciVersion") { should eq "1.0.2-dev" }
|
41
|
-
its("State.Running") { should eq true}
|
42
|
-
end
|
43
|
-
end
|
44
|
-
EXAMPLE
|
45
|
-
|
46
|
-
def containers
|
47
|
-
PodmanContainerFilter.new(parse_containers)
|
48
|
-
end
|
49
|
-
|
50
|
-
def images
|
51
|
-
PodmanImageFilter.new(parse_images)
|
52
|
-
end
|
53
|
-
|
54
|
-
def networks
|
55
|
-
PodmanNetworkFilter.new(parse_networks)
|
56
|
-
end
|
57
|
-
|
58
|
-
def pods
|
59
|
-
PodmanPodFilter.new(parse_pods)
|
60
|
-
end
|
61
|
-
|
62
|
-
def volumes
|
63
|
-
PodmanVolumeFilter.new(parse_volumes)
|
64
|
-
end
|
65
|
-
|
66
|
-
def version
|
67
|
-
return @version if defined?(@version)
|
68
|
-
|
69
|
-
sub_cmd = "version --format json"
|
70
|
-
output = run_command(sub_cmd)
|
71
|
-
@version = Hashie::Mash.new(JSON.parse(output))
|
72
|
-
rescue JSON::ParserError => _e
|
73
|
-
Hashie::Mash.new({})
|
74
|
-
end
|
75
|
-
|
76
|
-
def info
|
77
|
-
return @info if defined?(@info)
|
78
|
-
|
79
|
-
sub_cmd = "info --format json"
|
80
|
-
output = run_command(sub_cmd)
|
81
|
-
@info = Hashie::Mash.new(JSON.parse(output))
|
82
|
-
rescue JSON::ParserError => _e
|
83
|
-
Hashie::Mash.new({})
|
84
|
-
end
|
85
|
-
|
86
|
-
# returns information about podman objects
|
87
|
-
def object(id)
|
88
|
-
return @inspect if defined?(@inspect)
|
89
|
-
|
90
|
-
output = run_command("inspect #{id} --format json")
|
91
|
-
data = JSON.parse(output)
|
92
|
-
data = data[0] if data.is_a?(Array)
|
93
|
-
@inspect = Hashie::Mash.new(data)
|
94
|
-
rescue JSON::ParserError => _e
|
95
|
-
Hashie::Mash.new({})
|
96
|
-
end
|
97
|
-
|
98
|
-
def to_s
|
99
|
-
"Podman"
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
|
104
|
-
# Calls the run_command method to get all podman containers and parse the command output.
|
105
|
-
# Returns the parsed command output.
|
106
|
-
def parse_containers
|
107
|
-
labels = %w{ID Image ImageID Command CreatedAt RunningFor Status Pod Ports Size Names Networks Labels Mounts}
|
108
|
-
parse_json_command(labels, "ps -a --no-trunc --size")
|
109
|
-
end
|
110
|
-
|
111
|
-
# Calls the run_command method to get all podman images and parse the command output.
|
112
|
-
# Returns the parsed command output.
|
113
|
-
def parse_images
|
114
|
-
labels = %w{ID Repository Tag Size Digest CreatedAt CreatedSince History}
|
115
|
-
parse_json_command(labels, "images -a --no-trunc")
|
116
|
-
end
|
117
|
-
|
118
|
-
# Calls the run_command method to get all podman network list and parse the command output.
|
119
|
-
# Returns the parsed command output.
|
120
|
-
def parse_networks
|
121
|
-
labels = %w{ID Name Driver Labels Options IPAMOptions Created Internal IPv6Enabled DNSEnabled NetworkInterface Subnets}
|
122
|
-
parse_json_command(labels, "network ls --no-trunc")
|
123
|
-
end
|
124
|
-
|
125
|
-
# Calls the run_command method to get all podman pod list and parse the command output.
|
126
|
-
# Returns the parsed command output.
|
127
|
-
def parse_pods
|
128
|
-
sub_cmd = "pod ps --no-trunc --format json"
|
129
|
-
output = run_command(sub_cmd)
|
130
|
-
parse(output)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Calls the run_command method to get all podman volume list and parse the command output.
|
134
|
-
# Returns the parsed command output.
|
135
|
-
def parse_volumes
|
136
|
-
sub_cmd = "volume ls --format json"
|
137
|
-
output = run_command(sub_cmd)
|
138
|
-
parse(output)
|
139
|
-
end
|
140
|
-
|
141
|
-
# Runs the given podman command on the host machine on which podman is installed
|
142
|
-
# Returns the command output or raises the command execution error.
|
143
|
-
def run_command(subcommand)
|
144
|
-
result = inspec.command("podman #{subcommand}")
|
145
|
-
if result.stderr.empty?
|
146
|
-
result.stdout
|
147
|
-
else
|
148
|
-
raise "Error while running command \'podman #{subcommand}\' : #{result.stderr}"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def parse_json_command(labels, subcommand)
|
153
|
-
# build command
|
154
|
-
format = labels.map { |label| "\"#{label}\": {{json .#{label}}}" }
|
155
|
-
raw = inspec.command("podman #{subcommand} --format '{#{format.join(", ")}}'").stdout
|
156
|
-
output = []
|
157
|
-
|
158
|
-
raw.each_line do |entry|
|
159
|
-
# convert all keys to lower_case to work well with ruby and filter table
|
160
|
-
row = JSON.parse(entry).map do |key, value|
|
161
|
-
[key.downcase, value]
|
162
|
-
end.to_h
|
163
|
-
|
164
|
-
# ensure all keys are there
|
165
|
-
row = ensure_keys(row, labels)
|
166
|
-
output.push(row)
|
167
|
-
end
|
168
|
-
|
169
|
-
output
|
170
|
-
rescue JSON::ParserError => _e
|
171
|
-
warn "Could not parse `podman #{subcommand}` output"
|
172
|
-
[]
|
173
|
-
end
|
174
|
-
|
175
|
-
def ensure_keys(entry, labels)
|
176
|
-
labels.each do |key|
|
177
|
-
entry[key.downcase] = nil unless entry.key?(key.downcase)
|
178
|
-
end
|
179
|
-
entry
|
180
|
-
end
|
181
|
-
|
182
|
-
# Method to parse JDON content.
|
183
|
-
# Returns: Parsed data.
|
184
|
-
def parse(content)
|
185
|
-
require "json" unless defined?(JSON)
|
186
|
-
output = JSON.parse(content)
|
187
|
-
parsed_output = []
|
188
|
-
output.each do |entry|
|
189
|
-
entry = entry.map do |k, v|
|
190
|
-
[k.downcase, v]
|
191
|
-
end.to_h
|
192
|
-
parsed_output << entry
|
193
|
-
end
|
194
|
-
parsed_output
|
195
|
-
rescue => e
|
196
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to parse command JSON output: #{e.message}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# class for podman.containers plural resource
|
201
|
-
class PodmanContainerFilter
|
202
|
-
filter = FilterTable.create
|
203
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
204
|
-
filter.register_column(:commands, field: "command")
|
205
|
-
.register_column(:ids, field: "id")
|
206
|
-
.register_column(:created_at, field: "createdat")
|
207
|
-
.register_column(:images, field: "image")
|
208
|
-
.register_column(:names, field: "names")
|
209
|
-
.register_column(:status, field: "status")
|
210
|
-
.register_column(:image_ids, field: "image_id")
|
211
|
-
.register_column(:labels, field: "labels", style: :simple)
|
212
|
-
.register_column(:mounts, field: "mounts")
|
213
|
-
.register_column(:networks, field: "networks")
|
214
|
-
.register_column(:pods, field: "pod")
|
215
|
-
.register_column(:ports, field: "ports")
|
216
|
-
.register_column(:sizes, field: "size")
|
217
|
-
.register_column(:running_for, field: "running_for")
|
218
|
-
.register_custom_matcher(:running?) do |x|
|
219
|
-
x.where { status.downcase.start_with?("up") }
|
220
|
-
end
|
221
|
-
filter.install_filter_methods_on_resource(self, :containers)
|
222
|
-
|
223
|
-
attr_reader :containers
|
224
|
-
def initialize(containers)
|
225
|
-
@containers = containers
|
226
|
-
end
|
227
|
-
|
228
|
-
def to_s
|
229
|
-
"Podman Containers"
|
230
|
-
end
|
231
|
-
|
232
|
-
def resource_id
|
233
|
-
"Podman Containers"
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
# class for podman.images plural resource
|
238
|
-
class PodmanImageFilter
|
239
|
-
filter = FilterTable.create
|
240
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
241
|
-
filter.register_column(:ids, field: "id")
|
242
|
-
.register_column(:repositories, field: "repository")
|
243
|
-
.register_column(:tags, field: "tag")
|
244
|
-
.register_column(:sizes, field: "size")
|
245
|
-
.register_column(:digests, field: "digest")
|
246
|
-
.register_column(:created_at, field: "createdat")
|
247
|
-
.register_column(:created_since, field: "createdsince")
|
248
|
-
.register_column(:history, field: "history")
|
249
|
-
filter.install_filter_methods_on_resource(self, :images)
|
250
|
-
|
251
|
-
attr_reader :images
|
252
|
-
def initialize(images)
|
253
|
-
@images = images
|
254
|
-
end
|
255
|
-
|
256
|
-
def to_s
|
257
|
-
"Podman Images"
|
258
|
-
end
|
259
|
-
|
260
|
-
def resource_id
|
261
|
-
"Podman Images"
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
class PodmanNetworkFilter
|
266
|
-
filter = FilterTable.create
|
267
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
268
|
-
.register_column(:ids, field: "id")
|
269
|
-
.register_column(:names, field: "name")
|
270
|
-
.register_column(:drivers, field: "driver")
|
271
|
-
.register_column(:network_interfaces, field: "networkinterface")
|
272
|
-
.register_column(:created, field: "created")
|
273
|
-
.register_column(:subnets, field: "subnets")
|
274
|
-
.register_column(:ipv6_enabled, field: "ipv6enabled")
|
275
|
-
.register_column(:internal, field: "internal")
|
276
|
-
.register_column(:dns_enabled, field: "dnsenabled")
|
277
|
-
.register_column(:ipam_options, field: "ipamoptions")
|
278
|
-
.register_column(:options, field: "options")
|
279
|
-
.register_column(:labels, field: "labels")
|
280
|
-
filter.install_filter_methods_on_resource(self, :networks)
|
281
|
-
|
282
|
-
attr_reader :networks
|
283
|
-
def initialize(networks)
|
284
|
-
@networks = networks
|
285
|
-
end
|
286
|
-
|
287
|
-
def to_s
|
288
|
-
"Podman Networks"
|
289
|
-
end
|
290
|
-
|
291
|
-
def resource_id
|
292
|
-
"Podman Networks"
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
class PodmanPodFilter
|
297
|
-
filter = FilterTable.create
|
298
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
299
|
-
.register_column(:ids, field: "id")
|
300
|
-
.register_column(:cgroups, field: "cgroup")
|
301
|
-
.register_column(:containers, field: "containers")
|
302
|
-
.register_column(:created, field: "created")
|
303
|
-
.register_column(:infraids, field: "infraid")
|
304
|
-
.register_column(:names, field: "name")
|
305
|
-
.register_column(:namespaces, field: "namespace")
|
306
|
-
.register_column(:networks, field: "networks")
|
307
|
-
.register_column(:status, field: "status")
|
308
|
-
.register_column(:labels, field: "labels")
|
309
|
-
filter.install_filter_methods_on_resource(self, :pods)
|
310
|
-
|
311
|
-
attr_reader :pods
|
312
|
-
def initialize(pods)
|
313
|
-
@pods = pods
|
314
|
-
end
|
315
|
-
|
316
|
-
def to_s
|
317
|
-
"Podman Pods"
|
318
|
-
end
|
319
|
-
|
320
|
-
def resource_id
|
321
|
-
"Podman Pods"
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
class PodmanVolumeFilter
|
326
|
-
filter = FilterTable.create
|
327
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
328
|
-
.register_column(:names, field: "name")
|
329
|
-
.register_column(:drivers, field: "driver")
|
330
|
-
.register_column(:mountpoints, field: "mountpoint")
|
331
|
-
.register_column(:createdat, field: "createdat")
|
332
|
-
.register_column(:labels, field: "labels")
|
333
|
-
.register_column(:scopes, field: "scope")
|
334
|
-
.register_column(:options, field: "options")
|
335
|
-
.register_column(:mountcount, field: "mountcount")
|
336
|
-
.register_column(:needscopyup, field: "needscopyup")
|
337
|
-
.register_column(:needschown, field: "needschown")
|
338
|
-
filter.install_filter_methods_on_resource(self, :volumes)
|
339
|
-
|
340
|
-
attr_reader :volumes
|
341
|
-
def initialize(volumes)
|
342
|
-
@volumes = volumes
|
343
|
-
end
|
344
|
-
|
345
|
-
def to_s
|
346
|
-
"Podman Volumes"
|
347
|
-
end
|
348
|
-
|
349
|
-
def resource_id
|
350
|
-
"Podman Volumes"
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require "inspec/resources/podman"
|
2
|
-
require_relative "docker_object"
|
3
|
-
|
4
|
-
# Change module if required
|
5
|
-
module Inspec::Resources
|
6
|
-
class PodmanContainer < Inspec.resource(1)
|
7
|
-
include Inspec::Resources::DockerObject
|
8
|
-
name "podman_container"
|
9
|
-
supports platform: "unix"
|
10
|
-
|
11
|
-
desc "Inspec core resource to retrieve information about podman container"
|
12
|
-
|
13
|
-
example <<~EXAMPLE
|
14
|
-
describe podman_container("sweet_mendeleev") do
|
15
|
-
it { should exist }
|
16
|
-
it { should be_running }
|
17
|
-
its("id") { should eq "591270d8d80d26671fd6ed622f367fbe19004d16e3b519c292313feb5f22e7f7" }
|
18
|
-
its("image") { should eq "docker.io/library/nginx:latest" }
|
19
|
-
its("labels") { should include "maintainer"=>"NGINX Docker Maintainers <docker-maint@nginx.com>" }
|
20
|
-
its("ports") { should eq nil }
|
21
|
-
end
|
22
|
-
|
23
|
-
describe podman_container(id: "591270d8d80d2667") do
|
24
|
-
it { should exist }
|
25
|
-
it { should be_running }
|
26
|
-
end
|
27
|
-
EXAMPLE
|
28
|
-
|
29
|
-
def initialize(opts = {})
|
30
|
-
skip_resource "The `podman_container` resource is not yet available on your OS." unless inspec.os.unix?
|
31
|
-
|
32
|
-
# if a string is provided, we expect it is the name
|
33
|
-
if opts.is_a?(String)
|
34
|
-
@opts = { name: opts }
|
35
|
-
else
|
36
|
-
@opts = opts
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def running?
|
41
|
-
status.downcase.start_with?("up") if object_info.entries.length == 1
|
42
|
-
end
|
43
|
-
|
44
|
-
def status
|
45
|
-
object_info.status[0] if object_info.entries.length == 1
|
46
|
-
end
|
47
|
-
|
48
|
-
def labels
|
49
|
-
object_info.labels
|
50
|
-
end
|
51
|
-
|
52
|
-
def ports
|
53
|
-
object_info.ports[0] if object_info.entries.length == 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def command
|
57
|
-
return unless object_info.entries.length == 1
|
58
|
-
|
59
|
-
object_info.commands[0]
|
60
|
-
end
|
61
|
-
|
62
|
-
def image
|
63
|
-
object_info.images[0] if object_info.entries.length == 1
|
64
|
-
end
|
65
|
-
|
66
|
-
def resource_id
|
67
|
-
object_info.ids[0] || @opts[:id] || @opts[:name] || ""
|
68
|
-
end
|
69
|
-
|
70
|
-
def to_s
|
71
|
-
name = @opts[:name] || @opts[:id]
|
72
|
-
"Podman Container #{name}"
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def object_info
|
78
|
-
return @info if defined?(@info)
|
79
|
-
|
80
|
-
opts = @opts
|
81
|
-
@info = inspec.podman.containers.where { names == opts[:name] || (!id.nil? && !opts[:id].nil? && (id == opts[:id] || id.start_with?(opts[:id]))) }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|