Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install inspec from source #168

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
11 changes: 11 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ suites:
token: <%= ENV['COMPLIANCE_ACCESSTOKEN'] %>
owner: admin
profiles: *profiles

- name: inspec_package # compliance direct reporting
run_list:
- recipe[audit::default]
attributes:
audit:
inspec_package_source: 'https://packages.chef.io/stable/el/6/inspec-1.4.1-1.el6.x86_64.rpm'
inspec_package_libpath: '/opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.4.1/lib'
profiles:
- name: ssh-hardening
url: https://github.com/dev-sec/tests-ssh-hardening
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

# Used in cases where the desired install of inspec is via package instead of gem
# Default to false, set to true if needed. Setting to true will skip the inspec recipe and use inspec_package recipe
default['audit']['inspec_package'] = false
default['audit']['inspec_package_source'] = nil
default['audit']['inspec_package_libpath'] = nil

# collector possible values: chef-server, chef-compliance, chef-visibility, chef-server-visibility, json-file
# chef-visibility requires inspec version 0.27.1 or above
Expand Down
6 changes: 6 additions & 0 deletions libraries/compliance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# load all the inspec and compliance bundle requirements
def load_inspec_libs

if node['audit']['inspec_package_source']
libpath = node['audit']['inspec_package_libpath']
$LOAD_PATH.unshift(libpath) unless $LOAD_PATH.include?(libpath)
end

require 'inspec'
if Inspec::VERSION != node['audit']['inspec_version'] && node['audit']['inspec_version'] !='latest'
Chef::Log.warn "Wrong version of inspec (#{Inspec::VERSION}), please "\
Expand Down
5 changes: 3 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if node['audit']['inspec_package']
if node['audit']['inspec_package_source']
include_recipe 'audit::inspec_package'
else
include_recipe 'audit::inspec'
load_audit_handler
end

load_audit_handler
14 changes: 8 additions & 6 deletions recipes/inspec_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

chef_ingredient 'inspec' do
version node['audit']['inspec_version'] if node['audit']['inspec_version'] != 'latest'
accept_license true
action :upgrade
package 'inspec' do
source "/tmp/#{File.basename(node['audit']['inspec_package_source'])}"
action :nothing
end

load_inspec_libs
remote_file "/tmp/#{File.basename(node['audit']['inspec_package_source'])}" do
source node['audit']['inspec_package_source']
notifies :upgrade, 'package[inspec]', :immediately
end

load_audit_handler
load_inspec_libs