2016-09-06 11:30:06 +00:00
# Demos
demos :
- demo : 0 : intro
2016-09-13 11:08:13 +00:00
title : InSpec Introduction
2016-09-06 11:30:06 +00:00
desc : |
2016-09-06 14:32:24 +00:00
Welcome to the interactive InSpec demo. You will learn how to use the command line and shell and get an introduction to all aspects of the language.
2016-09-06 11:30:06 +00:00
To navigate this demo, type `next` to move forward and `prev` to move back.
2016-09-06 14:32:24 +00:00
Use `clear` to clear the terminal screen.
2016-09-06 11:30:06 +00:00
- demo : 1 : inspec-help
2016-09-13 11:08:13 +00:00
title : InSpec Help
2016-09-06 11:30:06 +00:00
desc : |
InSpec is called via
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec
```
2016-09-13 11:08:13 +00:00
2016-09-06 14:32:24 +00:00
Try it out! You will see the help menu. You can also view it with :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec help
```
- demo : 1 : inspec-help-cmd
2016-09-13 11:08:13 +00:00
title : InSpec Help Subcommands
2016-09-06 11:30:06 +00:00
desc : |
This list of subcommands may be intimidating at first. It is easy to get help on any of these commands via `inspec help <COMMAND>`. Let's try it out for a few :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec help version
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
inspec help detect
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
inspec help exec
```
- demo : 1 : inspec-version
2016-09-13 11:08:13 +00:00
title : InSpec Version
2016-09-06 11:30:06 +00:00
desc : |
The easiest subcommand is `inspec version`. It tells you which version of InSpec is running.
- demo : 1 : inspec-check
2016-09-13 11:08:13 +00:00
title : InSpec Check
2016-09-06 11:30:06 +00:00
desc : |
2016-09-06 14:32:24 +00:00
The most frequent use of InSpec is to execute profiles. You can find the `examples/profile` in the InSpec repository. Before executing it for the first time, let's verify if it is valid profile
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec check examples/profile
2016-09-06 11:30:06 +00:00
```
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
This command is not only used for syntax testing and linting, but can also provide information on valid profiles including its version and control overview.
- demo : 1 : inspec-exec
2016-09-13 11:08:13 +00:00
title : InSpec Exec
2016-09-06 11:30:06 +00:00
desc : |
Let's try testing some profiles! To run the profile and test the local machine, type :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile
2016-09-06 11:30:06 +00:00
```
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
The result is shown in the report.
- demo : 1 : inspec-exec-ssh
2016-09-13 11:08:13 +00:00
title : InSpec Exec SSH
2016-09-06 11:30:06 +00:00
desc : |
InSpec can also test your remote machines! Let's assume there is node `host.node` registered with SSH configured for user `bob` with a keyfile in the current directory (`bob.rsa`). You can run the same profile against this node via :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile -t ssh://bob@host.node -i bob.rsa
2016-09-06 11:30:06 +00:00
```
- demo : 1 : inspec-exec-ssh-long
2016-09-13 11:08:13 +00:00
title : InSpec Exec SSH (More Options)
2016-09-06 11:30:06 +00:00
desc : |
The wonderful `-t` option (or `--target`) is a shorthand for specifying all fields separately :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile -b ssh --host host.node --user bob -i bob.rsa
2016-09-06 11:30:06 +00:00
```
2016-09-13 11:08:13 +00:00
2016-09-06 14:32:24 +00:00
For more options try :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec help exec
```
- demo : 1 : inspec-exec-winrm
2016-09-13 11:08:13 +00:00
title : InSpec Exec WinRm
2016-09-06 11:30:06 +00:00
desc : |
We can also scan Windows machines. Let's assume `windows.node` is configured with WinRM access for user `alice` with a password `pass`. The command will now read :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile -t winrm://alice:pass@windows.node
2016-09-06 11:30:06 +00:00
```
- demo : 1 : inspec-exec-winrm-ssl
2016-09-13 11:08:13 +00:00
title : InSpec Exec WinRm SSL
2016-09-06 11:30:06 +00:00
desc : |
The previous example is not quite realistic. Most Windows nodes with WinRM are configured to use SSL. Let's assume the user also has a self-signed certificate. It would now read
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile -t winrm://alice:pass@windows.node --ssl --self-signed
2016-09-06 11:30:06 +00:00
```
- demo : 1 : inspec-exec-docker
2016-09-13 11:08:13 +00:00
title : InSpec Exec Docker
2016-09-06 11:30:06 +00:00
desc : |
InSpec also supports scanning containers. Let's try it with Docker and pick a container
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
2016-09-06 14:32:24 +00:00
inspec exec examples/profile -t docker://abcdef123
2016-09-06 11:30:06 +00:00
```
- demo : 1 : inspec-detect
2016-09-13 11:08:13 +00:00
title : InSpec Detect
2016-09-06 11:30:06 +00:00
desc : |
InSpec is able to verify local and remote nodes before running tests. This is a utility command to check connections and get information on the target
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec detect
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
inspec detect -t ssh://bob@host.node -i bob.rsa
```
- demo : 2 : inspec-shell-c
2016-09-13 11:08:13 +00:00
title : InSpec Shell Introduction
2016-09-06 11:30:06 +00:00
desc : |
Let's explore the InSpec shell. It's an integrated utility to test and debug the InSpec language. Before we start it interactively, let's try the command execution mode. It runs code and resources and prints the result.
First, we start with the OS detection :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec shell -c 'os.params'
```
Another example is to test an existing resource :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec shell -c 'sshd_config.Protocol'
```
- demo : 2 : inspec-shell-c-t
2016-09-13 11:08:13 +00:00
title : InSpec Shell with Remotes
2016-09-06 11:30:06 +00:00
desc : |
These commands also work with remote targets
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec shell -c 'sshd_config.Protocol' -t ssh://bob@host.node -i bob.rsa
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
inspec shell -c 'os.params' -t docker://abcdef123
```
- demo : 2 : inspec-shell
2016-09-13 11:08:13 +00:00
title : Interactive InSpec Shell
2016-09-06 11:30:06 +00:00
desc : |
It's time to see the interactive shell! Type
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
inspec shell
```
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
You can still use `next` and `prev` to move between demos. Look at how the shell prompt looks different between the system shell and the inspec shell.
- demo : 2 : inspec-shell-help
2016-09-13 11:08:13 +00:00
title : InSpec Shell Help
2016-09-06 11:30:06 +00:00
desc : |
The greeting of the InSpec shell suggests to run the help command :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
help
```
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
You will not only see the help menu, but also a quick summary of the machine where this is running.
- demo : 2 : inspec-shell-help-resources
2016-09-13 11:08:13 +00:00
title : InSpec Shell Help Resources
2016-09-06 11:30:06 +00:00
desc : |
To get a list of all available resources, you can type :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
help resources
```
- demo : 2 : inspec-shell-help-resource
2016-09-13 11:08:13 +00:00
title : InSpec Shell Help Subcommands
2016-09-06 11:30:06 +00:00
desc : |
To explore any of these resources, you can try :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
help file
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
help command
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
help os
```
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
These 3 resources are the core trinity of all executions. All other resources reference them in some way. They lead of system interactions.
- demo : 2 : inspec-shell-command
2016-09-13 11:08:13 +00:00
title : InSpec Shell Commands
2016-09-06 11:30:06 +00:00
desc : |
To use any of these resources, you can call it and its arguments. Try these examples :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
command('uname -a').stdout
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
file('/proc/cpuinfo').owner
2016-09-13 11:08:13 +00:00
```
```
2016-09-06 11:30:06 +00:00
sshd_config.params
```
- demo : 2 : inspec-shell-describe
2016-09-13 11:08:13 +00:00
title : InSpec Shell - Describe Block
2016-09-06 11:30:06 +00:00
desc : |
`describe` blocks are used to create simple checks. We will create a test that verifies a file's access permissions.
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
describe file('/root') do
it { should exist }
its('mode') { should cmp '0750'}
end
```
- demo : 2 : inspec-shell-control
2016-09-13 11:08:13 +00:00
title : Inspec Shell - Full Control
2016-09-06 11:30:06 +00:00
desc : |
Tests can be combined in controls, which offer more context. They are mainly used for policy/compliance testing :
2016-09-13 11:08:13 +00:00
2016-09-06 11:30:06 +00:00
```
control "id" do
title "Check permissions on /root!"
impact 0.5
describe file('/root') do
its('mode') { should cmp '0750'}
end
end
```
parts :
- part : InSpec commandline
demos :
- 1 : inspec-help
- 1 : inspec-help-cmd
- 1 : inspec-version
- 1 : inspec-check
- 1 : inspec-exec
- 1 : inspec-exec-ssh
- 1 : inspec-exec-ssh-long
- 1 : inspec-exec-winrm
- 1 : inspec-exec-winrm-ssl
- 1 : inspec-exec-docker
- 1 : inspec-detect
- part : InSpec shell
demos :
- 2 : inspec-shell-c
- 2 : inspec-shell-c-t
- 2 : inspec-shell-help
- 2 : inspec-shell-help-resources
- 2 : inspec-shell-help-resource
- 2 : inspec-shell-command
- 2 : inspec-shell-describe
- 2 : inspec-shell-control
# - part: Profiles