inspec 0.35.0 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +83 -2
  3. data/Gemfile +6 -0
  4. data/Rakefile +3 -55
  5. data/docs/README.md +20 -0
  6. data/docs/cli.rst +6 -0
  7. data/docs/dsl_inspec.md +245 -0
  8. data/docs/dsl_resource.md +93 -0
  9. data/docs/inspec_and_friends.md +102 -0
  10. data/docs/matchers.md +136 -0
  11. data/docs/plugin_kitchen_inspec.html.md +55 -0
  12. data/docs/profiles.md +271 -0
  13. data/docs/resources.rst +1 -1
  14. data/docs/shell.md +150 -0
  15. data/inspec.gemspec +1 -1
  16. data/lib/bundles/inspec-compliance/api.rb +28 -18
  17. data/lib/bundles/inspec-compliance/cli.rb +19 -27
  18. data/lib/fetchers/git.rb +4 -0
  19. data/lib/fetchers/local.rb +16 -1
  20. data/lib/fetchers/mock.rb +4 -0
  21. data/lib/fetchers/url.rb +40 -12
  22. data/lib/inspec/base_cli.rb +4 -0
  23. data/lib/inspec/cli.rb +6 -8
  24. data/lib/inspec/control_eval_context.rb +8 -0
  25. data/lib/inspec/dependencies/{vendor_index.rb → cache.rb} +5 -4
  26. data/lib/inspec/dependencies/dependency_set.rb +8 -14
  27. data/lib/inspec/dependencies/requirement.rb +10 -20
  28. data/lib/inspec/dependencies/resolver.rb +2 -2
  29. data/lib/inspec/dsl.rb +9 -0
  30. data/lib/inspec/fetcher.rb +1 -1
  31. data/lib/inspec/objects/test.rb +8 -2
  32. data/lib/inspec/plugins/fetcher.rb +11 -12
  33. data/lib/inspec/plugins/resource.rb +3 -0
  34. data/lib/inspec/profile.rb +60 -14
  35. data/lib/inspec/profile_context.rb +28 -7
  36. data/lib/inspec/resource.rb +17 -2
  37. data/lib/inspec/rspec_json_formatter.rb +80 -35
  38. data/lib/inspec/runner.rb +42 -18
  39. data/lib/inspec/shell.rb +5 -16
  40. data/lib/inspec/version.rb +1 -1
  41. data/lib/resources/apache_conf.rb +1 -1
  42. data/lib/resources/gem.rb +1 -0
  43. data/lib/resources/oneget.rb +1 -0
  44. data/lib/resources/os.rb +1 -1
  45. data/lib/resources/package.rb +3 -1
  46. data/lib/resources/pip.rb +1 -1
  47. data/lib/resources/ssl.rb +9 -11
  48. metadata +15 -15
  49. data/docs/dsl_inspec.rst +0 -259
  50. data/docs/dsl_resource.rst +0 -90
  51. data/docs/inspec_and_friends.rst +0 -85
  52. data/docs/matchers.rst +0 -137
  53. data/docs/profiles.rst +0 -169
  54. data/docs/readme.rst +0 -105
  55. data/docs/shell.rst +0 -130
  56. data/docs/template.rst +0 -51
data/docs/readme.rst DELETED
@@ -1,105 +0,0 @@
1
- =====================================================
2
- InSpec Documentation
3
- =====================================================
4
-
5
- InSpec a collection of resources and matchers to test the compliance of your nodes. This documentation provides an introduction to this mechanism and shows how to write custom tests.
6
-
7
- Introduction
8
- -----------------------------------------------------
9
-
10
- At first, we add our tests to the ``test`` folder. Each test file must end with ``_spec.rb``:
11
-
12
- .. code-block:: bash
13
-
14
- mkdir test
15
- touch test/example_spec.rb
16
-
17
- We add a control to this file, to check the ``/tmp`` path in our system:
18
-
19
- .. code-block:: ruby
20
-
21
- # encoding: utf-8
22
-
23
- control "cis-fs-2.1" do # A unique ID for this control
24
- impact 0.7 # The criticality, if this control fails.
25
- title "Create separate /tmp partition" # A human-readable title
26
- desc "An optional description..."
27
- tag mygroup: "tag" # A tag can be a simple value or
28
- tag "tag" # can have a more complex key/value pair.
29
- ref "name", url: "http://..." # A reference to a document, uri: is optional
30
- describe file('/tmp') do # The actual test
31
- it { should be_mounted }
32
- end
33
- end
34
-
35
-
36
- Let's add another spec for checking the SSH server configuration:
37
-
38
- .. code-block:: bash
39
-
40
- touch test/sshd_spec.rb
41
-
42
- It will contain:
43
-
44
- .. code-block:: ruby
45
-
46
- # encoding: utf-8
47
-
48
- # Skip all controls, if SSH doesn't exist on the system
49
- only_if do
50
- command('sshd').exist?
51
- end
52
-
53
- control "sshd-11" do
54
- impact 1.0
55
- title "Server: Set protocol version to SSHv2"
56
- desc "Set the SSH protocol version to 2. Don't use legacy
57
- insecure SSHv1 connections anymore."
58
- tag security: "openssh-server"
59
- ref "Document A-12"
60
-
61
- describe sshd_config do
62
- its('Protocol') { should eq('2') }
63
- end
64
- end
65
-
66
- control "sshd-7" do
67
- impact 1.0
68
- title "Server: Do not permit root-based login with password."
69
- desc "To reduce the potential to gain full privileges
70
- of a system in the course of an attack (by either misconfiguration
71
- or vulnerabilities), do not allow login as root with password"
72
- tag security: "openssh-server"
73
- ref "Document A-12"
74
-
75
- describe sshd_config do
76
- its('PermitRootLogin') { should match(/no|without-password/) }
77
- end
78
- end
79
-
80
-
81
- Now, we are ready to run the tests locally:
82
-
83
- bundle exec bin/inspec exec demo/test/example_spec.rb
84
-
85
- .. code-block:: bash
86
-
87
- # run tests individually
88
- $ inspec exec test/example_spec.rb
89
- $ inspec exec test/sshd_spec.rb
90
-
91
- # if you want to run all test located within the directory
92
- $ inspec exec ./test
93
-
94
-
95
- Stability Index
96
- -----------------------------------------------------
97
-
98
- Every available InSpec resource will indicate its stability. As InSpec matures, certain parts are more reliable than others. Brand new features are likely to be redesigned and marked as such.
99
-
100
- The stability indices are as follows:
101
-
102
- * ``Stability: Deprecated`` - This features will be removed in future versions, because its known for being problematic. Do not rely on it.
103
- * ``Stability: Experimental`` - New features may change or are removed in future versions
104
- * ``Stability: Stable`` - API is well established and proofed. Maintaining compatibility is a high priority
105
- * ``Stability: Locked`` - Only security and performance fixes are allowed
data/docs/shell.rst DELETED
@@ -1,130 +0,0 @@
1
- =====================================================
2
- InSpec Shell Usage
3
- =====================================================
4
-
5
- The InSpec interactive shell is a pry based REPL that can be used to quickly run InSpec controls and tests without having to write it to a file. Its functionality is similar to ``chef shell`` - it provides a way to exercise the InSpec DSL, its resources, tests and plugins without having to create a profile or write a test file. See http://pryrepl.org/ for an introduction to what pry is and what it can do.
6
-
7
-
8
- Launching the shell
9
- -----------------------------------------------------
10
-
11
- If you are using InSpec from a platform-specific package (rpm, msi, etc.) or from a chef prepared shell in ChefDK, you can directly launch InSpec shell against your local machine using the following. See https://docs.chef.io/install_dk.html#set-system-ruby for details.
12
-
13
- .. code-block:: bash
14
-
15
- $ inspec shell
16
- $ inspec help shell # This will describe inspec shell usage
17
-
18
- If you wish to connect to a remote machine (called a target within InSpec), you can use the ``-t`` flag. We support connecting using ssh, WinRm and docker. If no target is provided, we implicitly support the "local" target - i.e. tests running on the current machine running InSpec. For an ssh connection, use ``-i`` for specifying ssh key files, and the ``--sudo*`` commands for requesting a privelege escalation after logging in. For a WinRM connection, use ``--path`` to change the login path, ``--ssl`` to use SSL for transport layer encryption.
19
-
20
- .. code-block:: bash
21
-
22
- $ inspec shell -t ssh://root@192.168.64.2:11022 # Login to remote machine using ssh as root.
23
- $ inspec shell -t ssh://user@hostname:1234 -i /path/to/user_key # Login to hostname on port 1234 as user using given ssh key.
24
- $ inspec shell -t winrm://UserName:Password@windowsmachine:1234 # Login to windowsmachine over WinRM as UserName.
25
- $ inspec shell -t docker://container_id # Login to a docker container.
26
-
27
-
28
- Using Ruby in InSpec shell
29
- -----------------------------------------------------
30
-
31
- Since InSpec shell is pry based, you may treat the shell as an interactive Ruby session. You may write Ruby expressions and evaluate them. Source high-lighting, automatic indentation and command history (using the up and down arrow keys) are available to make your experience more delightful. You can exit the shell using ``exit``.
32
-
33
- .. code-block:: bash
34
-
35
- $ inspec shell
36
- Welcome to the interactive InSpec Shell
37
- To find out how to use it, type: help
38
-
39
- inspec> 1 + 2
40
- => 3
41
- inspec> exit
42
-
43
-
44
- Using InSpec DSL in InSpec shell
45
- -----------------------------------------------------
46
-
47
- InSpec shell will automatically evaluate the result of every command as if it were a test file. If you type in a Ruby command that is not an InSpec control or test, the shell will evaluate it as if it were a regular ruby command.
48
-
49
- Bare InSpec resources are instantiated and their help text is presented. You may also access the resource contents or other matchers that they define. Run ``help <resource>`` to get more help on using a particular resource or see the InSpec resources documentation online.
50
-
51
- .. code-block:: bash
52
-
53
- $ inspec shell
54
- Welcome to the interactive InSpec Shell
55
- To find out how to use it, type: help
56
-
57
- inspec> file('/Users/ksubramanian').directory?
58
- => true
59
- inspec> os_env('HOME')
60
- => Environment variable HOME
61
- inspec> os_env('HOME').content
62
- => /Users/ksubramanian
63
- inspec> exit
64
-
65
- InSpec tests are immediately executed.
66
-
67
-
68
- .. code-block:: bash
69
-
70
- inspec> describe file('/Users') # Empty test.
71
- Summary: 0 successful, 0 failures, 0 skipped
72
- inspec> describe file('/Users') do # Test with one check.
73
- inspec> it { should exist }
74
- inspec> end
75
- ✔ File /Users should exist
76
-
77
- Summary: 1 successful, 0 failures, 0 skipped
78
-
79
-
80
- All tests in a control are immediately executed as well. If a control is redefined in the shell, the old control's tests are destroyed and replaced with the redefinition and the control is re-run.
81
-
82
- .. code-block:: bash
83
-
84
- inspec> control 'my_control' do
85
- inspec> describe os_env('HOME') do
86
- inspec> its('content') { should eq '/Users/ksubramanian' }
87
- inspec> end
88
- inspec> end
89
- ✔ my_control: Environment variable HOME content should eq "/Users/ksubramanian"
90
-
91
- Summary: 1 successful, 0 failures, 0 skipped
92
-
93
- Syntax errors are illegal tests are also detected and reported.
94
-
95
-
96
- .. code-block:: bash
97
-
98
- inspec> control 'foo' do
99
- inspec> thisisnonsense
100
- inspec> end
101
- NameError: undefined local variable or method `thisisnonsense' for #<#<Class:0x007fd63b571f98>:0x007fd639825cc8>
102
- from /usr/local/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers.rb:967:in `method_missing'
103
- inspec> control 'foo' do
104
- inspec> describe file('wut') do
105
- inspec> its('thismakesnosense') { should cmp 'fail' }
106
- inspec> end
107
- inspec> end
108
- ✖ foo: File wut thismakesnosense (undefined method `thismakesnosense' for File wut:Inspec::Resource::Registry::File)
109
-
110
- Summary: 0 successful, 1 failures, 0 skipped
111
-
112
-
113
- Running a single InSpec command
114
- -----------------------------------------------------
115
-
116
- If you wish to run a single InSpec command and fetch its results, you may use the ``-c`` flag. This is similar to using ``bash -c``.
117
-
118
- .. code-block:: bash
119
- $ inspec shell -c 'describe file("/Users/ksubramanian") do it { should exist } end'
120
-
121
- Target: local://
122
-
123
- ✔ File /Users/ksubramanian should exist
124
-
125
- Summary: 1 successful, 0 failures, 0 skipped
126
-
127
-
128
- .. code-block:: bash
129
- $ inspec shell --format json -c 'describe file("/Users/ksubramanian") do it { should exist } end'
130
- {"version":"0.30.0","profiles":{"":{"supports":[],"controls":{"(generated from in_memory.rb:1 5aab65c33fb1f133d9244017958eef64)":{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":" rule = rule_class.new(id, profile_id, {}) do\n res = describe(*args, &block)\n end\n","source_location":{"ref":"/Users/ksubramanian/repo/chef/inspec/lib/inspec/profile_context.rb","line":184},"results":[{"status":"passed","code_desc":"File /Users/ksubramanian should exist","run_time":0.000747,"start_time":"2016-08-16 11:41:40 -0400"}]}},"groups":{"in_memory.rb":{"title":null,"controls":["(generated from in_memory.rb:1 5aab65c33fb1f133d9244017958eef64)"]}},"attributes":[]}},"other_checks":[],"summary":{"duration":0.001078,"example_count":1,"failure_count":0,"skip_count":0}}
data/docs/template.rst DELETED
@@ -1,51 +0,0 @@
1
- resource_name
2
- =====================================================
3
- Use the ``resource_name`` audit resource to xxxxx.
4
-
5
- Syntax
6
- -----------------------------------------------------
7
- A ``resource_name`` audit resource block declares xxxxx. For example:
8
-
9
- .. code-block:: ruby
10
-
11
- describe xxxxx(xxxxx) do
12
- it { should xxxxx }
13
- end
14
-
15
- where
16
-
17
- * ``xxxxx`` must specify xxxxx
18
- * xxxxx
19
- * ``xxxxx`` is a valid matcher for this audit resource
20
-
21
- Matchers
22
- -----------------------------------------------------
23
- This audit resource has the following matchers.
24
-
25
- xxxxx
26
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
27
- The ``xxxxx`` matcher tests if xxxxx. For example:
28
-
29
- .. code-block:: ruby
30
-
31
- it { should xxxxx }
32
-
33
- xxxxx
34
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
35
- The ``xxxxx`` matcher tests if xxxxx. For example:
36
-
37
- .. code-block:: ruby
38
-
39
- it { should xxxxx }
40
-
41
- Examples
42
- -----------------------------------------------------
43
- The following examples show how to use this audit resource in a recipe.
44
-
45
- **xxxxx**
46
-
47
- xxxxx
48
-
49
- **xxxxx**
50
-
51
- xxxxx