inspec-mongodb-resources 7.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f936269f07ea1c3b9a47bd6c48579da4107636e51aa4d3c6f310f3b3fbf0b159
4
+ data.tar.gz: 5aeb283297dc475839c9e18e5def998d3627126d24e962c08bb18be780c156c5
5
+ SHA512:
6
+ metadata.gz: 17074ba489dbabf65b1de2dca80ece3ba66864062e72e2ae29dc1262821f010b62f82892b558a29637fcb9aac640d25e9a7ff42f2bd93aea061d0ca0503eb066
7
+ data.tar.gz: 4de2696aff1ac731995ae081e5011ac747a19bd0f6d4b0dc53fdba941c14ec405f6a302220eaf58d0fd42b63fe12d06d1ec7d5a6c9c4a10b42e6c914c81a17e5
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gem "inspec", git: "https://github.com/inspec/inspec", branch: "inspec-7"
5
+ gem "inspec-bin", git: "https://github.com/inspec/inspec", branch: "inspec-7"
6
+
7
+ gemspec
8
+
9
+ group :test do
10
+ gem "byebug"
11
+ gem "chefstyle"
12
+ gem "minitest"
13
+ gem "m"
14
+ gem "mocha"
15
+ gem "rake"
16
+ gem "simplecov"
17
+ gem "simplecov_json_formatter"
18
+ end
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # inspec-mongodb-resources
2
+
3
+ Mongodb InSpec Resources in a Gem
4
+
5
+ This repository contains the InSpec Mongodb resources, formerly contained in InSpec Core. In InSpec 7+, these resources are available in a gem, `inspec-mongodb-resources`.
6
+
7
+ ## Usage
8
+
9
+ To use this resource pack, add this dependency to your inspec.yml :
10
+
11
+ ```yaml
12
+ depends:
13
+ - name: inspec-mongodb-resources
14
+ gem: inspec-mongodb-resources
15
+ ```
16
+
@@ -0,0 +1,46 @@
1
+ # As plugins are usually packaged and distributed as a RubyGem,
2
+ # we have to provide a .gemspec file, which controls the gembuild
3
+ # and publish process. This is a fairly generic gemspec.
4
+
5
+ # It is traditional in a gemspec to dynamically load the current version
6
+ # from a file in the source tree. The next three lines make that happen.
7
+ lib = File.expand_path("lib", __dir__)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require "inspec-mongodb-resources/version"
10
+
11
+ Gem::Specification.new do |spec|
12
+ # Importantly, all InSpec plugins must be prefixed with `inspec-` (most
13
+ # plugins) or `train-` (plugins which add new connectivity features).
14
+ spec.name = "inspec-mongodb-resources"
15
+
16
+ # It is polite to namespace your plugin under InspecPlugins::YourPluginInCamelCase
17
+ spec.version = InspecPlugins::MongodbResources::VERSION
18
+ spec.authors = ["InSpec Core Maintainers"]
19
+ spec.email = ["inspec@progress.com"]
20
+ spec.summary = "InSpec mongodb Resources in a Gem"
21
+ spec.description = "Contains InSpec 7.0+ resources fo interacting with Mongodb Resources."
22
+ spec.homepage = "https://github.com/inspec/inspec-mongodb-resources"
23
+ spec.license = "Apache-2.0"
24
+
25
+ # Though complicated-looking, this is pretty standard for a gemspec.
26
+ # It just filters what will actually be packaged in the gem (leaving
27
+ # out tests, etc)
28
+ spec.files = %w{
29
+ README.md inspec-mongodb-resources.gemspec Gemfile inspec.yml
30
+ } + Dir.glob(
31
+ "lib/**/*", File::FNM_DOTMATCH
32
+ ).reject { |f| File.directory?(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.required_ruby_version = ">= 3.1.0"
36
+
37
+ # If you rely on any other gems, list them here with any constraints.
38
+ # This is how `inspec plugin install` is able to manage your dependencies.
39
+ # For example, perhaps you are writing a thing that talks to AWS, and you
40
+ # want to ensure you have `aws-sdk` in a certain version.
41
+
42
+ # This plugin uses InSpec 7 Resource Pack Plugins
43
+ spec.add_dependency "inspec-core", ">= 7.0"
44
+
45
+ spec.add_dependency "mongo", "= 2.21.3" # 2.14 introduces a broken symlink in mongo-2.14.0/spec/support/ocsp
46
+ end
data/inspec.yml ADDED
@@ -0,0 +1,10 @@
1
+ name: inspec-mongodb-resources
2
+ title: Inspec Mongodb Resources
3
+ maintainer: InSpec Core Maintainers
4
+ copyright: Progress Software Corporation
5
+ copyright_email: inspec@progress.com
6
+ license: Apache-2.0
7
+ summary: Inspec Mongodb Resources in a Gem
8
+ version: 7.1.2
9
+ supports:
10
+ platform: os
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ # Plugin Definition file
3
+ # The purpose of this file is to declare to InSpec what plugin_types (capabilities)
4
+ # are included in this plugin, and provide activator that will load them as needed.
5
+
6
+ # It is important that this file load successfully and *quickly*.
7
+ # Your plugin's functionality may never be used on this InSpec run; so we keep things
8
+ # fast and light by only loading heavy things when they are needed.
9
+
10
+ # Presumably this is light
11
+ require "inspec-mongodb-resources/version"
12
+
13
+ # The InspecPlugins namespace is where all plugins should declare themselves.
14
+ # The "Inspec" capitalization is used throughout the InSpec source code; yes, it's
15
+ # strange.
16
+ module InspecPlugins
17
+ # Pick a reasonable namespace here for your plugin. A reasonable choice
18
+ # would be the CamelCase version of your plugin gem name.
19
+ # inspec-test-resources => TestResources
20
+ module MongodbResources
21
+ # This simple class handles the plugin definition, so calling it simply Plugin is OK.
22
+ # Inspec.plugin returns various Classes, intended to be superclasses for various
23
+ # plugin components. Here, the one-arg form gives you the Plugin Definition superclass,
24
+ # which mainly gives you access to the activator / plugin_type DSL.
25
+ # The number '2' says you are asking for version 2 of the plugin API. If there are
26
+ # future versions, InSpec promises plugin API v2 will work for at least two more InSpec
27
+ # major versions.
28
+ class Plugin < ::Inspec.plugin(2)
29
+ # Internal machine name of the plugin. InSpec will use this in errors, etc.
30
+ plugin_name :"inspec-mongodb-resources"
31
+
32
+ # Define a new Resource Pack.
33
+ resource_pack :"inspec-mongodb-resources" do
34
+ # This file will load the resources implicitly via the superclass
35
+ require "inspec-mongodb-resources/resource_pack"
36
+
37
+ # Having loaded our functionality, return a class that represents the plugin.
38
+ # Reserved for future use.
39
+ InspecPlugins::MongodbResources::ResourcePack
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require "inspec/resource"
3
+
4
+ module InspecPlugins::MongodbResources
5
+ # This class will provide the actual CLI implementation.
6
+ # Its superclass is provided by another call to Inspec.plugin,
7
+ # this time with two args. The first arg specifies we are requesting
8
+ # version 2 of the Plugins API. The second says we are making a Resource
9
+ # Pack plugin component, so please make available any DSL needed
10
+ # for that.
11
+ class ResourcePack < Inspec.plugin(2, :resource_pack)
12
+ # TBD
13
+ # load_timing :early <-- isn't that implicit in the rewuire statements
14
+ # train relationship declarations? <-- that should be in the gemspec
15
+ end
16
+ end
File without changes
@@ -0,0 +1,67 @@
1
+ class Mongodb < Inspec.resource(1)
2
+ name "mongodb"
3
+ supports platform: "unix"
4
+ supports platform: "windows"
5
+
6
+ desc "The 'mongodb' resource is a helper for the 'mongodb_conf' & 'mongodb_session' resources. Please use those instead."
7
+
8
+ attr_reader :conf_path
9
+
10
+ def initialize
11
+ case inspec.os[:family]
12
+ when "debian", "fedora", "redhat", "linux", "suse"
13
+ init_linux
14
+ when "darwin"
15
+ init_macos
16
+ when "windows"
17
+ init_windows
18
+ end
19
+ end
20
+
21
+ def resource_id
22
+ @conf_path
23
+ end
24
+
25
+ def to_s
26
+ "MongoDB"
27
+ end
28
+
29
+ private
30
+
31
+ def init_linux
32
+ @conf_path = "/etc/mongod.conf"
33
+ end
34
+
35
+ def init_macos
36
+ @conf_path = "/usr/local/etc/mongod.conf"
37
+ end
38
+
39
+ def init_windows
40
+ dir = "C:\\Program Files\\MongoDB\\Server"
41
+ @version = version_from_dir(dir)
42
+ unless @version.to_s.empty?
43
+ @conf_path = "#{dir}\\#{@version}\\bin\\mongod.cfg"
44
+ end
45
+ end
46
+
47
+ def version_from_dir(dir)
48
+ dirs = inspec.command("Get-ChildItem -Path \"#{dir}\" -Name").stdout
49
+ entries = dirs.lines.count
50
+ case entries
51
+ when 0
52
+ warn "Could not determine version of installed MongoDB by inspecting #{dir}"
53
+ nil
54
+ when 1
55
+ dir_to_version(dirs)
56
+ else
57
+ warn "Multiple versions of MongoDB installed or incorrect base dir #{dir}"
58
+ first = dir_to_version(dirs.lines.first)
59
+ warn "Using the first version found: #{first}"
60
+ first
61
+ end
62
+ end
63
+
64
+ def dir_to_version(dir)
65
+ dir.chomp.split("/").last
66
+ end
67
+ end
@@ -0,0 +1,42 @@
1
+ require "inspec/resources/json"
2
+ require "inspec-mongodb-resources/resources/mongodb"
3
+
4
+ class MongodbConf < ::Inspec::Resources::JsonConfig
5
+ name "mongodb_conf"
6
+ supports platform: "unix"
7
+ supports platform: "windows"
8
+ 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."
9
+ example <<~EXAMPLE
10
+ describe mongodb_conf do
11
+ its(["storage", "dbPath"]) { should eq "/var/lib/mongodb" }
12
+ its(["net", "port"]) { should eq 27017 }
13
+ end
14
+ EXAMPLE
15
+
16
+ def initialize(conf_path = nil)
17
+ @conf_path = conf_path || inspec.mongodb.conf_path
18
+
19
+ if @conf_path.nil?
20
+ return skip_resource "MongoDB conf path is not set."
21
+ end
22
+
23
+ super(@conf_path)
24
+ end
25
+
26
+ # set resource_id to "" if system is not able to determine the @conf_path
27
+ def resource_id
28
+ @conf_path || "mongodb_conf"
29
+ end
30
+
31
+ private
32
+
33
+ def parse(content)
34
+ YAML.load(content)
35
+ rescue => e
36
+ raise Inspec::Exceptions::ResourceFailed, "Unable to parse `mongod.conf` or `mongod.cfg` file: #{e.message}"
37
+ end
38
+
39
+ def resource_base_name
40
+ "MongoDB Configuration"
41
+ end
42
+ end
@@ -0,0 +1,96 @@
1
+ require "mongo"
2
+
3
+ class Lines
4
+ attr_reader :params
5
+
6
+ def initialize(raw, desc, exit_status = nil)
7
+ @params = raw
8
+ @desc = desc
9
+ @exit_status = exit_status
10
+ end
11
+
12
+ def to_s
13
+ @desc
14
+ end
15
+ end
16
+
17
+ class MongodbSession < Inspec.resource(1)
18
+ name "mongodb_session"
19
+ supports platform: "unix"
20
+ supports platform: "windows"
21
+
22
+ desc "Use the mongodb_session InSpec audit resource to run MongoDB command against a MongoDB Database."
23
+ example <<~EXAMPLE
24
+ # default values:
25
+ # host: "127.0.0.1"
26
+ # port: "27017"
27
+ # auth_source - default to database name
28
+ # auth_mech - :scram
29
+
30
+ describe mongodb_session(user: "foo", password: "bar", database: "test").query(usersInfo: "ian").params["users"].first["roles"].first do
31
+ its(["role"]) { should eq "readWrite" }
32
+ end
33
+ EXAMPLE
34
+ attr_reader :user, :host, :port, :database, :params
35
+
36
+ def initialize(opts = {})
37
+ @user = opts[:user] || nil
38
+ @password = opts[:password] || nil
39
+ @host = opts[:host] || "127.0.0.1"
40
+ @port = opts[:port] || "27017"
41
+ @database = opts[:database] || nil
42
+ @auth_mech = opts[:auth_mech] || :scram
43
+ @auth_source = opts[:auth_source] || @database
44
+ @ssl = opts[:ssl] || false
45
+ @ssl_cert = opts[:ssl_cert] || nil
46
+ @ssl_key = opts[:ssl_key] || nil
47
+ @ssl_ca_cert = opts[:ssl_ca_cert] || nil
48
+ @auth_mech_properties = opts[:auth_mech_properties] || {}
49
+ @client = nil
50
+
51
+ fail_resource "Can't run MongoDB checks without authentication." unless user && @password
52
+ fail_resource "You must provide a database name for the session." unless database
53
+
54
+ create_session
55
+ end
56
+
57
+ def query(command)
58
+ raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
59
+
60
+ Lines.new(@client.command(command).documents.first, "MongoDB query: #{command}")
61
+ rescue => e
62
+ raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command Error: #{e.message}"
63
+ end
64
+
65
+ def resource_id
66
+ "mongodb_session:User:#{@user}:Host:#{@host}:Database:#{@database}"
67
+ end
68
+
69
+ private
70
+
71
+ def create_session
72
+ raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
73
+
74
+ options = { user: "#{user}",
75
+ password: "#{@password}",
76
+ database: "#{database}",
77
+ auth_source: "#{@auth_source}",
78
+ auth_mech: @auth_mech,
79
+ }
80
+ options[:auth_mech_properties] = @auth_mech_properties unless @auth_mech_properties.empty?
81
+ options[:ssl] = @ssl
82
+ options[:ssl_key] = @ssl_key unless @ssl_key.nil?
83
+ options[:ssl_cert] = @ssl_cert unless @ssl_cert.nil?
84
+ options[:ssl_ca_cert] = @ssl_ca_cert unless @ssl_ca_cert.nil?
85
+
86
+ # 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
87
+ # 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
88
+ # 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.
89
+ # Once we get the latest version working we can remove logger level set here.
90
+ Mongo::Logger.logger.level = Logger::INFO
91
+ @client = Mongo::Client.new([ "#{host}:#{port}" ], options)
92
+
93
+ rescue => e
94
+ raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command. Error: #{e.message}"
95
+ end
96
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ # This file simply makes it easier for CI engines to update
3
+ # the version stamp, and provide a clean way for the gemspec
4
+ # to learn the current version.
5
+ module InspecPlugins
6
+ module MongodbResources
7
+ VERSION = "7.1.2"
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # This file is known as the "entry point."
2
+ # This is the file InSpec will try to load if it
3
+ # thinks your plugin is installed.
4
+
5
+ # The *only* thing this file should do is setup the
6
+ # load path, then load the plugin definition file.
7
+
8
+ # Next two lines simply add the path of the gem to the load path.
9
+ # This is not needed when being loaded as a gem; but when doing
10
+ # plugin development, you may need it. Either way, it's harmless.
11
+ libdir = File.dirname(__FILE__)
12
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
13
+
14
+ require "inspec-mongodb-resources/plugin"
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspec-mongodb-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.1.2
5
+ platform: ruby
6
+ authors:
7
+ - InSpec Core Maintainers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: inspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.21.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.21.3
41
+ description: Contains InSpec 7.0+ resources fo interacting with Mongodb Resources.
42
+ email:
43
+ - inspec@progress.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - README.md
50
+ - inspec-mongodb-resources.gemspec
51
+ - inspec.yml
52
+ - lib/inspec-mongodb-resources.rb
53
+ - lib/inspec-mongodb-resources/plugin.rb
54
+ - lib/inspec-mongodb-resources/resource_pack.rb
55
+ - lib/inspec-mongodb-resources/resources/.gitkeep
56
+ - lib/inspec-mongodb-resources/resources/mongodb.rb
57
+ - lib/inspec-mongodb-resources/resources/mongodb_conf.rb
58
+ - lib/inspec-mongodb-resources/resources/mongodb_session.rb
59
+ - lib/inspec-mongodb-resources/version.rb
60
+ homepage: https://github.com/inspec/inspec-mongodb-resources
61
+ licenses:
62
+ - Apache-2.0
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.1.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.3.27
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: InSpec mongodb Resources in a Gem
83
+ test_files: []