inspec 2.0.45 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -20
- data/docs/dsl_inspec.md +1 -1
- data/docs/inspec_and_friends.md +9 -2
- data/docs/matchers.md +1 -1
- data/docs/plugin_kitchen_inspec.md +1 -0
- data/docs/profiles.md +8 -2
- data/docs/resources/docker.md.erb +4 -4
- data/docs/resources/docker_container.md.erb +2 -3
- data/docs/resources/docker_image.md.erb +2 -2
- data/docs/resources/os.md.erb +18 -18
- data/docs/shell.md +7 -5
- data/inspec.gemspec +1 -1
- data/lib/inspec/backend.rb +1 -0
- data/lib/inspec/base_cli.rb +2 -2
- data/lib/inspec/dependencies/requirement.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/mysql_session.rb +29 -15
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184c03135e14f8d3cf287e8fed443c9fda98953a
|
4
|
+
data.tar.gz: 5d55d1635cd382e22a0f5114137549b43d63cefb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2996dd2613e5f390a2f1e4faefb61cde1c758222ea11b30f591526aa15412b6ad613b26464065dd114900749c5352f9856e6344fcbab02a4d8c66a938290533e
|
7
|
+
data.tar.gz: 7f42ef8a7a61e277c85d6db8302f9ade44f21a2ebbf94ebef118e2bdd39013754e610b89d68c936d524452e4abcb93b2151af76983063feb15d8354a17f78b45
|
data/CHANGELOG.md
CHANGED
@@ -1,36 +1,50 @@
|
|
1
1
|
# Change Log
|
2
2
|
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
|
3
|
-
<!-- latest_release 2.0
|
4
|
-
## [v2.0
|
3
|
+
<!-- latest_release 2.1.0 -->
|
4
|
+
## [v2.1.0](https://github.com/chef/inspec/tree/v2.1.0) (2018-03-15)
|
5
5
|
|
6
6
|
#### Enhancements
|
7
|
-
-
|
7
|
+
- Pin to new Train version and update InSpec defaults [#2827](https://github.com/chef/inspec/pull/2827) ([jquick](https://github.com/jquick))
|
8
8
|
<!-- latest_release -->
|
9
9
|
|
10
|
-
<!-- release_rollup since=2.0.
|
11
|
-
### Changes since 2.0.
|
10
|
+
<!-- release_rollup since=2.0.45 -->
|
11
|
+
### Changes since 2.0.45 release
|
12
|
+
|
13
|
+
#### Bug Fixes
|
14
|
+
- Write version_constraints as an array for inspec.lock [#2619](https://github.com/chef/inspec/pull/2619) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.0.48 -->
|
15
|
+
|
16
|
+
#### Enhancements
|
17
|
+
- Pin to new Train version and update InSpec defaults [#2827](https://github.com/chef/inspec/pull/2827) ([jquick](https://github.com/jquick)) <!-- 2.1.0 -->
|
18
|
+
- quote password when generating mysql command string [#2685](https://github.com/chef/inspec/pull/2685) ([tolland](https://github.com/tolland)) <!-- 2.0.47 -->
|
12
19
|
|
13
20
|
#### Merged Pull Requests
|
14
|
-
-
|
15
|
-
-
|
16
|
-
|
21
|
+
- Sort file list for unit tests [#2812](https://github.com/chef/inspec/pull/2812) ([eramoto](https://github.com/eramoto)) <!-- 2.0.49 -->
|
22
|
+
- Docs: Describe support boundary between RSpec and InSpec [#2753](https://github.com/chef/inspec/pull/2753) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.0.46 -->
|
23
|
+
<!-- release_rollup -->
|
24
|
+
|
25
|
+
<!-- latest_stable_release -->
|
26
|
+
## [v2.0.45](https://github.com/chef/inspec/tree/v2.0.45) (2018-03-08)
|
17
27
|
|
18
28
|
#### Enhancements
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
- Update shadow resource to use FilterTable [#2642](https://github.com/chef/inspec/pull/2642) ([miah](https://github.com/miah))
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
29
|
+
- Fix aws-iam-users pagination [#2761](https://github.com/chef/inspec/pull/2761) ([trickyearlobe](https://github.com/trickyearlobe))
|
30
|
+
- AWS API Pagination fixes [#2762](https://github.com/chef/inspec/pull/2762) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
31
|
+
- Host resource: use bash over netcat in Linux [#2607](https://github.com/chef/inspec/pull/2607) ([jvale](https://github.com/jvale))
|
32
|
+
- Update shadow resource to use FilterTable [#2642](https://github.com/chef/inspec/pull/2642) ([miah](https://github.com/miah))
|
33
|
+
- Create reporter output directory if it does not exist [#2798](https://github.com/chef/inspec/pull/2798) ([jquick](https://github.com/jquick))
|
34
|
+
- Remove os checks from initialize [#2797](https://github.com/chef/inspec/pull/2797) ([miah](https://github.com/miah))
|
35
|
+
- Refine deprecated methods to be consistent with supported fields in shadow file. [#2801](https://github.com/chef/inspec/pull/2801) ([miah](https://github.com/miah))
|
26
36
|
|
27
37
|
#### Bug Fixes
|
28
|
-
-
|
29
|
-
- return 1 as exit code for commands that are not available [#2792](https://github.com/chef/inspec/pull/2792) ([chris-rock](https://github.com/chris-rock))
|
30
|
-
-
|
31
|
-
<!-- release_rollup -->
|
38
|
+
- command resource: Add `exist?` for Alpine Linux [#2768](https://github.com/chef/inspec/pull/2768) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
39
|
+
- return 1 as exit code for commands that are not available [#2792](https://github.com/chef/inspec/pull/2792) ([chris-rock](https://github.com/chris-rock))
|
40
|
+
- Fix http with connection error [#2770](https://github.com/chef/inspec/pull/2770) ([Wing924](https://github.com/Wing924))
|
32
41
|
|
42
|
+
#### Merged Pull Requests
|
43
|
+
- Update name of subnet fixture, fixing 3 failing integration tests [#2765](https://github.com/chef/inspec/pull/2765) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
44
|
+
- iptables resource: Add support for other bin paths [#2783](https://github.com/chef/inspec/pull/2783) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
45
|
+
- Added the missing variable reference [#2794](https://github.com/chef/inspec/pull/2794) ([frezbo](https://github.com/frezbo))
|
33
46
|
<!-- latest_stable_release -->
|
47
|
+
|
34
48
|
## [v2.0.32](https://github.com/chef/inspec/tree/v2.0.32) (2018-03-01)
|
35
49
|
|
36
50
|
#### Bug Fixes
|
@@ -51,7 +65,6 @@
|
|
51
65
|
- virtualization_resource: Fix `NoMethodError` on `nil:NilClass` [#2603](https://github.com/chef/inspec/pull/2603) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
52
66
|
- Docs: Clarify Matchers page to speak about Universal matchers [#2754](https://github.com/chef/inspec/pull/2754) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
53
67
|
- mssql_session - Handling cases where the data is nil [#2752](https://github.com/chef/inspec/pull/2752) ([frezbo](https://github.com/frezbo))
|
54
|
-
<!-- latest_stable_release -->
|
55
68
|
|
56
69
|
## [v2.0.17](https://github.com/chef/inspec/tree/v2.0.17) (2018-02-20)
|
57
70
|
|
data/docs/dsl_inspec.md
CHANGED
@@ -107,7 +107,7 @@ The following test shows how to audit machines running PostgreSQL to ensure that
|
|
107
107
|
```ruby
|
108
108
|
control 'postgres-7' do
|
109
109
|
impact 1.0
|
110
|
-
title
|
110
|
+
title "Don't allow empty passwords"
|
111
111
|
describe postgres_session('user', 'pass').query("SELECT * FROM pg_shadow WHERE passwd IS NULL;") do
|
112
112
|
its('output') { should eq('') }
|
113
113
|
end
|
data/docs/inspec_and_friends.md
CHANGED
@@ -9,8 +9,8 @@ relate to each other.
|
|
9
9
|
|
10
10
|
## RSpec
|
11
11
|
|
12
|
-
RSpec is an awesome framework that is widely used
|
13
|
-
enables test-driven development (TDD) and helps developers to write
|
12
|
+
RSpec is an awesome framework that is widely used by software engineers to test
|
13
|
+
Ruby code. It enables test-driven development (TDD) and helps developers to write
|
14
14
|
better code every day.
|
15
15
|
|
16
16
|
InSpec is built on top of RSpec and uses it as the underlying foundation
|
@@ -40,6 +40,13 @@ control "sshd-11" do
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
+
That said, InSpec is not RSpec. Some key differences:
|
44
|
+
|
45
|
+
* In InSpec, `describe` blocks should not be nested; instead use `control` blocks to describe a higher-level grouping of tests.
|
46
|
+
* The RSpec `shared_example` construct is not supported. Instead, create a simple custom resource that executes repetitious tasks.
|
47
|
+
* InSpec is aimed at compliance practitioners and infrastructure testers, so our focus is providing a few, well-supported, easy-to-use [universal matchers](https://www.inspec.io/docs/reference/matchers/), such as `cmp`. In contrast, RSpec is a tool designed for software engineers. It thus supports a very large range of matchers, to enable testing of software engineering constructs such as exceptions, Object Oriented Programming relationships, and so on.
|
48
|
+
* While InSpec uses parts of the RSpec project and codebase, it is a separate project from InSpec. Rspec's release schedule and feature set are beyond the control of the InSpec team. While it is possible to use many of the RSpec core features within InSpec profiles, InSpec can only guarantee that the features described at [docs.inspec.io](https://docs.inspec.io) will function correctly. Some RSpec core functionality may be removed in future versions of InSpec as needed to ensure stability in the InSpec project.
|
49
|
+
|
43
50
|
## Serverspec
|
44
51
|
|
45
52
|
Serverspec is the first extension of RSpec that enabled
|
data/docs/matchers.md
CHANGED
@@ -18,7 +18,7 @@ The following InSpec-supported universal matchers are available:
|
|
18
18
|
* [`include`](#include) - look for an expected value in a list-valued property
|
19
19
|
* [`match`](#match) - look for patterns in text using regular expressions
|
20
20
|
|
21
|
-
|
21
|
+
See [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about InSpec's built-in matchers.
|
22
22
|
|
23
23
|
## be
|
24
24
|
|
@@ -47,3 +47,4 @@ Use InSpec tests from the local file system:
|
|
47
47
|
inspec_tests:
|
48
48
|
- test/integration/default
|
49
49
|
|
50
|
+
Check out [Detect and correct with Test Kitchen](https://learn.chef.io/modules/detect-correct-kitchen#/) on Learn Chef Rally for a hands-on look at how to use Test Kitchen to run InSpec profiles.
|
data/docs/profiles.md
CHANGED
@@ -29,7 +29,9 @@ where:
|
|
29
29
|
* `files` is the directory with additional files that a profile can access (optional)
|
30
30
|
* `README.md` should be used to explain the profile, its scope, and usage
|
31
31
|
|
32
|
-
See a complete example profile in the InSpec open source repository: https://github.com/chef/inspec/tree/master/examples/profile
|
32
|
+
See a complete example profile in the InSpec open source repository: [https://github.com/chef/inspec/tree/master/examples/profile](https://github.com/chef/inspec/tree/master/examples/profile)
|
33
|
+
|
34
|
+
Also check out [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about how profiles are structured with hands-on examples.
|
33
35
|
|
34
36
|
## inspec.yml
|
35
37
|
|
@@ -111,6 +113,8 @@ and to target all of these examples in a single `inspec.yml` file:
|
|
111
113
|
|
112
114
|
An InSpec profile can bring in the controls and custom resources from another InSpec profile. Additionally, when inheriting the controls of another profile, a profile can skip or even modify those included controls.
|
113
115
|
|
116
|
+
For hands-on examples, check out [Create a custom InSpec profile](https://learn.chef.io/modules/create-a-custom-profile#/) on Learn Chef Rally.
|
117
|
+
|
114
118
|
## Defining the Dependencies
|
115
119
|
|
116
120
|
Before a profile can use controls from another profile, the to-be-included profile needs to be specified in the including profile’s `inspec.yml` file in the `depends` section. For each profile to be included, a location for the profile from where to be fetched and a name for the profile should be included. For example:
|
@@ -298,7 +302,7 @@ See the full example in the InSpec open source repository: https://github.com/ch
|
|
298
302
|
|
299
303
|
# Profile files
|
300
304
|
|
301
|
-
An InSpec profile may contain additional files that can be accessed during tests.
|
305
|
+
An InSpec profile may contain additional files that can be accessed during tests. A profile file enables you to separate the logic of your tests from the data your tests check for, for example, the list of ports you require to be open.
|
302
306
|
|
303
307
|
To access these files, they must be stored in the `files` directory at the root of a profile. They are accessed by their name relative to this folder with `inspec.profile.file(...)`.
|
304
308
|
|
@@ -332,6 +336,8 @@ The tests in `example.rb` can now access this file:
|
|
332
336
|
end
|
333
337
|
end
|
334
338
|
|
339
|
+
For a more complete example that uses a profile file, see [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally.
|
340
|
+
|
335
341
|
# "should" vs. "expect" syntax
|
336
342
|
|
337
343
|
Users familiar with the RSpec testing framework may know that there are two ways to write test statements: `should` and `expect`. The RSpec community decided that `expect` is the preferred syntax. However, InSpec recommends the `should` syntax as it tends to read more easily to those users who are not as technical.
|
@@ -139,7 +139,7 @@ Or execute the profile directly via URL:
|
|
139
139
|
|
140
140
|
### images
|
141
141
|
|
142
|
-
`images` returns information about Docker image as returned by [docker images](https://docs.docker.com/engine/reference/commandline/images/).
|
142
|
+
`images` returns information about a Docker image as returned by [docker images](https://docs.docker.com/engine/reference/commandline/images/).
|
143
143
|
|
144
144
|
describe docker.images do
|
145
145
|
its('ids') { should include 'sha:12b5df59...442b' }
|
@@ -183,9 +183,9 @@ Or execute the profile directly via URL:
|
|
183
183
|
|
184
184
|
### image
|
185
185
|
|
186
|
-
|
187
|
-
|
188
|
-
|
186
|
+
describe docker_container(name: 'an-echo-server') do
|
187
|
+
its('image') { should eq 'busybox:latest' }
|
188
|
+
end
|
189
189
|
|
190
190
|
### repo
|
191
191
|
|
@@ -5,7 +5,7 @@ platform: linux
|
|
5
5
|
|
6
6
|
# docker_container
|
7
7
|
|
8
|
-
Use the `docker_container` InSpec audit resource to test a
|
8
|
+
Use the `docker_container` InSpec audit resource to test a Docker container.
|
9
9
|
|
10
10
|
<br>
|
11
11
|
|
@@ -72,7 +72,7 @@ The `tag` property tests the value of the image tag:
|
|
72
72
|
|
73
73
|
### ports
|
74
74
|
|
75
|
-
The `ports` property tests the value the
|
75
|
+
The `ports` property tests the value the Docker ports:
|
76
76
|
|
77
77
|
its('ports') { should eq '0.0.0.0:1234->1234/tcp' }
|
78
78
|
|
@@ -101,4 +101,3 @@ The `command` property tests the value of the container run command:
|
|
101
101
|
## Matchers
|
102
102
|
|
103
103
|
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
104
|
-
|
@@ -5,7 +5,7 @@ platform: linux
|
|
5
5
|
|
6
6
|
# docker_image
|
7
7
|
|
8
|
-
Use the `docker_image` InSpec audit resource to verify a
|
8
|
+
Use the `docker_image` InSpec audit resource to verify a Docker image.
|
9
9
|
|
10
10
|
<br>
|
11
11
|
|
@@ -70,7 +70,7 @@ The `tag` property tests the value of image tag:
|
|
70
70
|
|
71
71
|
its('tag') { should eq 'latest' }
|
72
72
|
|
73
|
-
### Test a
|
73
|
+
### Test a Docker image
|
74
74
|
|
75
75
|
describe docker_image('alpine:latest') do
|
76
76
|
it { should exist }
|
data/docs/resources/os.md.erb
CHANGED
@@ -13,7 +13,7 @@ Use the `os` InSpec audit resource to test the platform on which the system is r
|
|
13
13
|
|
14
14
|
An `os` resource block declares the platform to be tested. The platform may specified via matcher or control block name. For example, using a matcher:
|
15
15
|
|
16
|
-
describe os
|
16
|
+
describe os.family do
|
17
17
|
it { should eq 'platform_family_name' }
|
18
18
|
end
|
19
19
|
|
@@ -33,19 +33,19 @@ The following examples show how to use this InSpec audit resource.
|
|
33
33
|
|
34
34
|
### Test for RedHat
|
35
35
|
|
36
|
-
describe os
|
36
|
+
describe os.family do
|
37
37
|
it { should eq 'redhat' }
|
38
38
|
end
|
39
39
|
|
40
40
|
### Test for Ubuntu
|
41
41
|
|
42
|
-
describe os
|
42
|
+
describe os.family do
|
43
43
|
it { should eq 'debian' }
|
44
44
|
end
|
45
45
|
|
46
46
|
### Test for Microsoft Windows
|
47
47
|
|
48
|
-
describe os
|
48
|
+
describe os.family do
|
49
49
|
it { should eq 'windows' }
|
50
50
|
end
|
51
51
|
|
@@ -103,28 +103,28 @@ Use the following helpers to test for operating system names, releases, and arch
|
|
103
103
|
it { should eq 'foo' }
|
104
104
|
end
|
105
105
|
|
106
|
-
### os
|
106
|
+
### os.family names
|
107
107
|
|
108
|
-
Use `os
|
108
|
+
Use `os.family` to enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific names to test for specific platforms:
|
109
109
|
|
110
|
-
*
|
111
|
-
*
|
112
|
-
*
|
113
|
-
*
|
114
|
-
*
|
115
|
-
*
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
119
|
-
*
|
110
|
+
* `aix`
|
111
|
+
* `bsd` For platforms that are part of the Berkeley OS family `darwin`, `freebsd`, `netbsd`, and `openbsd`.
|
112
|
+
* `debian`
|
113
|
+
* `hpux`
|
114
|
+
* `linux`. For platforms that are part of the Linux family `alpine`, `amazon`, `arch`, `coreos`, `exherbo`, `fedora`, `gentoo`, and `slackware`.
|
115
|
+
* `redhat`. For platforms that are part of the Redhat family `centos`.
|
116
|
+
* `solaris`. For platforms that are part of the Solaris family `nexentacore`, `omnios`, `openindiana`, `opensolaris`, and `smartos`.
|
117
|
+
* `suse`
|
118
|
+
* `unix`
|
119
|
+
* `windows`
|
120
120
|
|
121
121
|
For example, both of the following tests should have the same result:
|
122
122
|
|
123
|
-
if os
|
123
|
+
if os.family == 'debian'
|
124
124
|
describe port(69) do
|
125
125
|
its('processes') { should include 'in.tftpd' }
|
126
126
|
end
|
127
|
-
elsif os
|
127
|
+
elsif os.family == 'redhat'
|
128
128
|
describe port(69) do
|
129
129
|
its('processes') { should include 'xinetd' }
|
130
130
|
end
|
data/docs/shell.md
CHANGED
@@ -6,12 +6,14 @@ title: InSpec Shell
|
|
6
6
|
|
7
7
|
The InSpec interactive shell is a pry based REPL that can be used to
|
8
8
|
quickly run InSpec controls and tests without having to write it to a
|
9
|
-
file. Its functionality is similar to
|
10
|
-
to exercise the InSpec DSL, its resources, tests and plugins without
|
9
|
+
file. Its functionality is similar to [chef-shell](https://docs.chef.io/chef_shell.html) as it provides a way
|
10
|
+
to exercise the InSpec DSL, its resources, tests, and plugins without
|
11
11
|
having to create a profile or write a test file. See
|
12
12
|
[http://pryrepl.org/](http://pryrepl.org/) for an introduction to what pry is and what it can
|
13
13
|
do.
|
14
14
|
|
15
|
+
See [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally for a hands-on example that uses InSpec shell.
|
16
|
+
|
15
17
|
## Launching the shell
|
16
18
|
|
17
19
|
If you are using InSpec from a platform-specific package (rpm, msi,
|
@@ -25,10 +27,10 @@ $ inspec help shell # This will describe inspec shell usage
|
|
25
27
|
```
|
26
28
|
|
27
29
|
If you wish to connect to a remote machine (called a target within
|
28
|
-
InSpec), you can use the `-t` flag. We support connecting using
|
29
|
-
|
30
|
+
InSpec), you can use the `-t` flag. We support connecting using SSH,
|
31
|
+
WinRM and docker. If no target is provided, we implicitly support the
|
30
32
|
"local" target - i.e. tests running on the current machine running
|
31
|
-
InSpec. For an
|
33
|
+
InSpec. For an SSH connection, use `-i` for specifying SSH key files,
|
32
34
|
and the `--sudo*` commands for requesting a privilege escalation after
|
33
35
|
logging in. For a WinRM connection, use `--path` to change the login
|
34
36
|
path, `--ssl` to use SSL for transport layer encryption.
|
data/inspec.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.required_ruby_version = '>= 2.3'
|
28
28
|
|
29
|
-
spec.add_dependency 'train', '~> 1.
|
29
|
+
spec.add_dependency 'train', '~> 1.2'
|
30
30
|
spec.add_dependency 'thor', '~> 0.19'
|
31
31
|
spec.add_dependency 'json', '>= 1.8', '< 3.0'
|
32
32
|
spec.add_dependency 'method_source', '~> 0.8'
|
data/lib/inspec/backend.rb
CHANGED
data/lib/inspec/base_cli.rb
CHANGED
@@ -76,7 +76,7 @@ module Inspec
|
|
76
76
|
option :create_lockfile, type: :boolean,
|
77
77
|
desc: 'Write out a lockfile based on this execution (unless one already exists)'
|
78
78
|
option :backend_cache, type: :boolean,
|
79
|
-
desc: 'Allow caching for backend command output.'
|
79
|
+
desc: 'Allow caching for backend command output. (default: true)'
|
80
80
|
option :show_progress, type: :boolean,
|
81
81
|
desc: 'Show progress while executing tests.'
|
82
82
|
end
|
@@ -88,7 +88,7 @@ module Inspec
|
|
88
88
|
'show_progress' => false,
|
89
89
|
'color' => true,
|
90
90
|
'create_lockfile' => true,
|
91
|
-
'backend_cache' =>
|
91
|
+
'backend_cache' => true,
|
92
92
|
},
|
93
93
|
shell: {
|
94
94
|
'reporter' => ['cli'],
|
data/lib/inspec/version.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# copyright: 2015, Vulcano Security GmbH
|
3
3
|
|
4
|
+
require 'shellwords'
|
5
|
+
|
4
6
|
module Inspec::Resources
|
5
7
|
class MysqlSession < Inspec.resource(1)
|
6
8
|
name 'mysql_session'
|
@@ -25,21 +27,8 @@ module Inspec::Resources
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def query(q, db = '')
|
28
|
-
|
29
|
-
|
30
|
-
escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
|
31
|
-
|
32
|
-
# run the query
|
33
|
-
command = "mysql -u#{@user} -p#{@pass}"
|
34
|
-
if !@socket.nil?
|
35
|
-
command += " -S #{@socket}"
|
36
|
-
else
|
37
|
-
command += " -h #{@host}"
|
38
|
-
end
|
39
|
-
command += " --port #{@port}" unless @port.nil?
|
40
|
-
command += " #{db} -s -e \"#{escaped_query}\""
|
41
|
-
|
42
|
-
cmd = inspec.command(command)
|
30
|
+
mysql_cmd = create_mysql_cmd(q, db)
|
31
|
+
cmd = inspec.command(mysql_cmd)
|
43
32
|
out = cmd.stdout + "\n" + cmd.stderr
|
44
33
|
if out =~ /Can't connect to .* MySQL server/ || out.downcase =~ /^error/
|
45
34
|
# skip this test if the server can't run the query
|
@@ -56,6 +45,31 @@ module Inspec::Resources
|
|
56
45
|
|
57
46
|
private
|
58
47
|
|
48
|
+
def escape_string(query)
|
49
|
+
Shellwords.escape(query)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_mysql_cmd(q, db = '')
|
53
|
+
# TODO: simple escape, must be handled by a library
|
54
|
+
# that does this securely
|
55
|
+
escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
|
56
|
+
|
57
|
+
# construct the query
|
58
|
+
command = 'mysql'
|
59
|
+
command += " -u#{escape_string(@user)}" unless @user.nil?
|
60
|
+
command += " -p#{escape_string(@pass)}" unless @pass.nil?
|
61
|
+
|
62
|
+
if !@socket.nil?
|
63
|
+
command += " -S #{@socket}"
|
64
|
+
else
|
65
|
+
command += " -h #{@host}"
|
66
|
+
end
|
67
|
+
command += " --port #{@port}" unless @port.nil?
|
68
|
+
command += " #{db}" unless db.empty?
|
69
|
+
command += %{ -s -e "#{escaped_query}"}
|
70
|
+
command
|
71
|
+
end
|
72
|
+
|
59
73
|
def init_fallback
|
60
74
|
# support debian mysql administration login
|
61
75
|
debian = inspec.command('test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf').stdout
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|