Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs-chef-io/content/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
+++
title = "About the Chef InSpec MongoDB resource pack"
draft = false
linkTitle = "MongoDB resource pack"
summary = "Chef InSpec resources for auditing MongoDB databases and configurations."

[cascade]
[cascade.params]
platform = "mongodb"

[menu.mongodb]
title = "About MongoDB resources"
identifier = "inspec/resources/mongodb/about"
parent = "inspec/resources/mongodb"
weight = 10
+++

The Chef InSpec MongoDB resources allow you to audit MongoDB database configurations, user permissions, and security settings.

## Support

The InSpec MongoDB resources are supported in the following InSpec versions:

- InSpec 6 and earlier: MongoDB resources were included in the InSpec core installation
- InSpec 7 and later: MongoDB resources are distributed as the separate `inspec-mongodb-resources` gem

### Add to your InSpec profile

To add this resource pack to an InSpec profile, add the `inspec-mongodb-resources` gem as a dependency in your `inspec.yml` file:

```yaml
depends:
- name: inspec-mongodb-resources
gem: inspec-mongodb-resources
```

## MongoDB resources

{{< inspec_resources_filter >}}

The following Chef InSpec MongoDB resources are available in this resource pack.

{{< inspec_resources section="mongodb" platform="mongodb" >}}
60 changes: 60 additions & 0 deletions docs-chef-io/content/mongodb_conf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
+++
title = "mongodb_conf resource"
draft = false


[menu.mongodb]
title = "mongodb_conf"
identifier = "inspec/resources/mongodb/mongodb_conf.md mongodb_conf resource"
parent = "inspec/resources/mongodb"
+++

Use the `mongodb_conf` Chef 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.

## Syntax

A `mongodb_conf` resource block declares one (or more) settings in the `mongodb.conf` file, and then compares the setting in the configuration file to the value stated in the test:

```ruby
describe mongodb_conf('path') do
its('setting') { should eq 'value' }
end
```

where

- `'setting'` specifies a setting in the `mongodb.conf` file
- `('path')` is the non-default path to the `mongodb.conf` file (optional)
- `should eq 'value'` is the value that is expected

## Examples

The following examples show how to use this Chef InSpec audit resource.

Test the key management configuration options:

```ruby
describe mongodb_conf do
its(["security", "enableEncryption"]) { should eq true }
end
```

Test the port on which MongoDB listens:

```ruby
describe mongodb_conf do
its(["net", "port"]) { should eq 27017 }
end
```

Test the security configuration options:

```ruby
describe mongodb_conf do
its(["security", "authorization"]) { should eq "enabled" }
end
```

## Matchers

{{< readfile file="content/reusable/md/inspec_matchers_link.md" >}}
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
+++
title = "mongodb_session resource"
draft = false
gh_repo = "inspec"
platform = "os"

[menu]
[menu.inspec]
[menu.mongodb]
title = "mongodb_session"
identifier = "inspec/resources/os/mongodb_session.md mongodb_session resource"
parent = "inspec/resources/os"
identifier = "inspec/resources/mongodb/mongodb_session.md mongodb_session resource"
parent = "inspec/resources/mongodb"
+++

Use the `mongodb_session` Chef InSpec audit resource to run MongoDB command against a MongoDB Database.

## Availability

### Install

{{< readfile file="content/inspec/reusable/md/inspec_installation.md" >}}

## Syntax

A `mongodb_session` resource block declares the `user`, `password`, and `database` to use for the session and then the command to be run:

describe mongodb_session(user: "username", password: "password", database: "test").query(key: value) do
its("params") { should match(/expected-result/) }
end
```ruby
describe mongodb_session(user: "username", password: "password", database: "test").query(key: value) do
its("params") { should match(/expected-result/) }
end
```

where

Expand Down Expand Up @@ -85,28 +78,34 @@ This resource uses the [MongoDB Ruby Driver](https://docs.mongodb.com/ruby-drive

The following examples show how to use this Chef InSpec audit resource.

### Test the roles information using the `rolesInfo` command in MongoDB
Test the roles information using the `rolesInfo` command in MongoDB:

describe mongodb_session(user: "foo", password: "bar", database: "test").query(rolesInfo: "dbAdmin").params["roles"].first do
its(["role"]) { should eq "dbAdmin" }
end
```ruby
describe mongodb_session(user: "foo", password: "bar", database: "test").query(rolesInfo: "dbAdmin").params["roles"].first do
its(["role"]) { should eq "dbAdmin" }
end
```

### Test the MongoDB user role
Test the MongoDB user role:

describe mongodb_session(user: "foo", password: "bar", database: "test").query(usersInfo: "foo").params["users"].first["roles"].first do
its(["role"]) { should eq "readWrite" }
end
```ruby
describe mongodb_session(user: "foo", password: "bar", database: "test").query(usersInfo: "foo").params["users"].first["roles"].first do
its(["role"]) { should eq "readWrite" }
end
```

### Test the database parameters
Test the database parameters:

describe mongodb_session(user: "foo", password: "bar", database: "test").query(rolesInfo: "dbAdmin") do
its("params") { should_not be_empty }
its("params") { should include "roles" }
end
```ruby
describe mongodb_session(user: "foo", password: "bar", database: "test").query(rolesInfo: "dbAdmin") do
its("params") { should_not be_empty }
its("params") { should include "roles" }
end
```

## Matchers

{{< readfile file="content/inspec/reusable/md/inspec_matchers_link.md" >}}
{{< readfile file="content/reusable/md/inspec_matchers_link.md" >}}

This resource has the following special matchers.

Expand Down
3 changes: 3 additions & 0 deletions docs-chef-io/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/inspec/inspec-mongodb-resources/docs-chef-io

go 1.17
60 changes: 0 additions & 60 deletions docs/resources/mongodb_conf.md

This file was deleted.