Top Banner
Building Security Into Your Workflow with InSpec Mandi Walls | [email protected]
39

InSpec Workflow for DevOpsDays Riga 2017

Jan 29, 2018

Download

Software

Mandi Walls
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: InSpec Workflow for DevOpsDays Riga 2017

Building Security Into Your Workflow with InSpec

Mandi Walls | [email protected]

Page 2: InSpec Workflow for DevOpsDays Riga 2017

HI!

• Mandi Walls

• Technical Community Manager for Chef, EMEA

[email protected]

• @lnxchk

• Adam Leff – Community Lead for InSpec @adamleff

Page 3: InSpec Workflow for DevOpsDays Riga 2017

EVERY business is a software business

We’re going to be a software

company with airplanes.– CIO, Alaska Airlines

Page 4: InSpec Workflow for DevOpsDays Riga 2017
Page 5: InSpec Workflow for DevOpsDays Riga 2017

Motivation

Page 6: InSpec Workflow for DevOpsDays Riga 2017

Product Ideas and Features

Security Review

Production

Page 7: InSpec Workflow for DevOpsDays Riga 2017

http://mspmentor.net/msp-mentor/botched-server-install-results-214-million-hipaa-breach-fine

Page 8: InSpec Workflow for DevOpsDays Riga 2017

https://www.darkreading.com/attacks-breaches/wannacry-forces-honda-to-take-production-plant-offline-/d/d-id/1329192

Page 9: InSpec Workflow for DevOpsDays Riga 2017

Equifax

"This vulnerability was disclosed back in March. There were clear and

simple instructions of how to remedy the situation. The responsibility is

then on companies to have procedures in place to follow such advice

promptly.”

- Bas van Schaik, a product manager and researcher at Semmle, an

analytics security firm, via Wired

https://www.wired.com/story/equifax-breach-no-excuse/

Page 10: InSpec Workflow for DevOpsDays Riga 2017

What We Have Here Is A Communications Problem

Page 11: InSpec Workflow for DevOpsDays Riga 2017
Page 12: InSpec Workflow for DevOpsDays Riga 2017

What Is InSpec

Page 13: InSpec Workflow for DevOpsDays Riga 2017

InSpec

• Human-readable specification language for tests related to security and

compliance

• Includes facilities for creating, sharing, and reusing profiles

• Extensible language so you can build your own rules for your

applications and systems

• Command-line tools for plugging into your existing workflows / build

servers

• Integrates with Test Kitchen for fast-feedback local testing by developers

Page 14: InSpec Workflow for DevOpsDays Riga 2017

SSH Example

• If your security team sends you a directive:

SSH supports two different protocol versions. The

original version, SSHv1, was subject to a number

of security issues. All systems must use SSHv2

instead to avoid these issues.

Page 15: InSpec Workflow for DevOpsDays Riga 2017

How Do You Go About Fixing It?

• Identify the file and file location to check your systems

• Figure out some sort of incantation

Do we check it first or just push a new one everywhere?

• What’s the plan for the currently used images?

Rebuild?

Remediate at instantiation?

• Maybe you’re using a configuration management solution for these types

of changes? Did your change get tested before it goes to all your

systems?

Page 16: InSpec Workflow for DevOpsDays Riga 2017

Lifecycle

• When you get a mandate from security, how often is it checked?

• Single big scan, report mailed out with a “due date”?

• Yearly or twice-yearly massive scans with remediation firedrills?

Page 17: InSpec Workflow for DevOpsDays Riga 2017

Using InSpec

Page 18: InSpec Workflow for DevOpsDays Riga 2017

Find It!

• http://inspec.io/

• Open Source!

• The “spec” is a hint

Page 19: InSpec Workflow for DevOpsDays Riga 2017

Check that sshd_config

describe sshd_config do

impact 1.0

title 'SSH Version 2'

desc <<-EOF

SSH supports two different protocol versions. The original version, SSHv1, was subject to a

number of security issues. Please use SSHv2 instead to avoid these.

EOF

its('Protocol') { should cmp 2 }

end

Page 20: InSpec Workflow for DevOpsDays Riga 2017

Resources

• InSpec includes built-in resources for common services, system

files, and configurations

See http://inspec.io/docs/reference/resources/ for the current list!

• Built-in resources work on several platforms of Linux. There are

also Windows-specifics

• A resource has characteristics that can be verified for your

requirements, and Matchers that work with those characteristics

Page 21: InSpec Workflow for DevOpsDays Riga 2017

Check that sshd_config

describe sshd_config do

impact 1.0

title 'SSH Version 2'

desc <<-EOF

SSH supports two different protocol versions. The original version, SSHv1, was subject to a

number of security issues. Please use SSHv2 instead to avoid these.

EOF

its('Protocol') { should cmp 2 }

end

Page 22: InSpec Workflow for DevOpsDays Riga 2017

• Resources take the “grep for x” out of the testing phase

• Parsers included in the InSpec software do the work for you

• It’s built off the premises of rSpec, and meant to be human

readable

Page 23: InSpec Workflow for DevOpsDays Riga 2017

its.... should...

• it { should exist }

• it { should be_installed }

• it { should be_enabled }

• its('max_log_file') { should cmp 6 }

• its('exit_status') { should eq 0 }

• its('gid') { should eq 0 }

Page 24: InSpec Workflow for DevOpsDays Riga 2017

Run It

• InSpec is command line

Installs on your workstation as a ruby gem or as part of the ChefDK

• Can be run locally, test the machine it is executing on

• Or remotely

InSpec will log into the target and run the tests for you

• Also a REPL

https://www.inspec.io/docs/reference/shell/

Page 25: InSpec Workflow for DevOpsDays Riga 2017

Test Any Target

inspec exec test.rb

inspec exec test.rb -i ~/.aws/mandi_eu.pem -t ssh://ec2-

[email protected]

inspec exec test.rb -t winrm://[email protected] --password

super

inspec exec test.rb -t docker://3dda08e75838

Page 26: InSpec Workflow for DevOpsDays Riga 2017

Failures

• InSpec runs with failed tests return a non-zero return code

Profile Summary: 0 successful, 1 failures, 0 skipped

[chef@ip-172-31-29-25 ~]$ echo $?

1

[chef@ip-172-31-29-25 ~]$

• Passing tests have 0 return code

Profile Summary: 1 successful, 0 failures, 0 skipped

[chef@ip-172-31-29-25 ~]$ echo $?

0

[chef@ip-172-31-29-25 ~]$

Page 27: InSpec Workflow for DevOpsDays Riga 2017

Test Kitchen

• InSpec also runs as an included tester in TK

• This gives you fast feedback for local development

• Ensure that new projects are always starting out in compliance

with existing security requirements

• https://www.inspec.io/docs/reference/plugin_kitchen_inspec/

• Include profiles right off github into your .kitchen.yml file

Page 28: InSpec Workflow for DevOpsDays Riga 2017

suites:

- name: default

run_list:

- recipe[osdc-inspec-talk::default]

- recipe[os-hardening]

verifier:

inspec_tests:

- test/smoke/default

- https://github.com/dev-sec/linux-baseline

attributes:

Page 29: InSpec Workflow for DevOpsDays Riga 2017

Profiles

• InSpec profiles allow you to package and share sets of InSpec

tests for your organization or for a specific application set

• Each profile can have multiple test files included

• The test files generally test for one required outcome, but can

look at different objects to meet requirements

• Flexible!

Create your own profiles for specific software you use

Page 30: InSpec Workflow for DevOpsDays Riga 2017

Example – Basic Hardening

• Centos 7.2 host

• Test Kitchen

• os-hardening cookbook from https://supermarket.chef.io

• /dev-sec/linux-baseline InSpec profile from https://supermarket.chef.io

Page 31: InSpec Workflow for DevOpsDays Riga 2017

The Cookbook and the InSpec Profile Work Together

suites:

- name: default

run_list:

- recipe[osdc-inspec-talk::default]

- recipe[os-hardening]

verifier:

inspec_tests:

- test/smoke/default

- https://github.com/dev-sec/linux-baseline

attributes:

Page 32: InSpec Workflow for DevOpsDays Riga 2017

What’s in the os-hardening Cookbook

Page 33: InSpec Workflow for DevOpsDays Riga 2017

Run kitchen test Without Hardening

Profile Summary: 25 successful, 25 failures, 1 skipped

Test Summary: 77 successful, 39 failures, 3 skipped

>>>>>> ------Exception-------

>>>>>> Class: Kitchen::ActionFailed

>>>>>> Message: 1 actions failed.

>>>>>> Verify failed on instance <default-centos-72>. Pleasesee .kitchen/logs/default-centos-72.log for more details

>>>>>> ----------------------

>>>>>> Please see .kitchen/logs/kitchen.log for more details

>>>>>> Also try running `kitchen diagnose --all` for configuration

Page 34: InSpec Workflow for DevOpsDays Riga 2017

Run kitchen test With Hardening

Profile Summary: 50 successful, 0 failures, 1 skipped

Test Summary: 116 successful, 0 failures, 3 skipped

Finished verifying <default-centos-72> (0m11.07s).

-----> Destroying <default-centos-72>...

==> default: Forcing shutdown of VM...

==> default: Destroying VM and associated drives...

Vagrant instance <default-centos-72> destroyed.

Finished destroying <default-centos-72> (0m4.97s).

Finished testing <default-centos-72> (2m37.89s).

-----> Kitchen is finished. (2m39.44s)

Page 35: InSpec Workflow for DevOpsDays Riga 2017

What’s in the linux-baseline Profile

control 'os-02' do

impact 1.0

title 'Check owner and permissions for /etc/shadow'

desc 'Check periodically the owner and permissions for /etc/shadow'

describe file('/etc/shadow') do

it { should exist }

it { should be_file }

it { should be_owned_by 'root' }

its('group') { should eq shadow_group }

it { should_not be_executable }

it { should be_writable.by('owner') }

...

Page 36: InSpec Workflow for DevOpsDays Riga 2017

Over Time

Build a Comprehensive Set of Checks for Your Systems

Run Them Every Time Someone Needs to Make a Change

Make it EASY for Everyone to Use

Page 37: InSpec Workflow for DevOpsDays Riga 2017

Resources

• https://inspec.io

• https://github.com/chef-training/workshops/

• http://www.anniehedgie.com/inspec-basics-1

• http://blog.johnray.io/chef-inspec-and-dirty-cow

• https://blog.chef.io/2017/05/23/inspec-launches-support-cloud-platform-

assessments/

• https://github.com/lnxchk/inspec_fivemins

Page 38: InSpec Workflow for DevOpsDays Riga 2017

October 10 – 11, 2017etc.venues Fenchurch St London

https://chef.io/summits

Page 39: InSpec Workflow for DevOpsDays Riga 2017