Skip to content

Commit 4e33311

Browse files
authored
Merge pull request #17 from dev-sec/chris-rock/lint
Lint project
2 parents 7753815 + 79f6f75 commit 4e33311

20 files changed

Lines changed: 254 additions & 229 deletions

.rubocop.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
AllCops:
3+
Exclude:
4+
- vendor/**/*
5+
TargetRubyVersion: 1.9
6+
Documentation:
7+
Enabled: false
8+
AlignParameters:
9+
Enabled: true
10+
HashSyntax:
11+
Enabled: true
12+
LineLength:
13+
Enabled: false
14+
EmptyLinesAroundBlockBody:
15+
Enabled: false
16+
MethodLength:
17+
Max: 40
18+
NumericLiterals:
19+
MinDigits: 10
20+
Metrics/BlockLength:
21+
Max: 35
22+
Metrics/CyclomaticComplexity:
23+
Max: 10
24+
Metrics/PerceivedComplexity:
25+
Max: 10
26+
Metrics/AbcSize:
27+
Max: 30
28+
Style/FileName:
29+
Enabled: false
30+
Style/WordArray:
31+
Enabled: false

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
language: ruby
3+
cache: bundler
4+
rvm:
5+
- 2.3.3
6+
7+
bundler_args: --without integration
8+
script: bundle exec rake

Gemfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
gem 'inspec'
3+
gem 'rake'
4+
gem 'rack', '1.6.4'
5+
gem 'inspec', '~> 1'
6+
gem 'rubocop', '~> 0.44.0'
7+
gem 'highline', '~> 1.6.0'
8+
9+
group :tools do
10+
gem 'github_changelog_generator', '~> 1.12.0'
11+
end

Rakefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env rake
2+
# encoding: utf-8
3+
4+
require 'rake/testtask'
5+
require 'rubocop/rake_task'
6+
7+
# Rubocop
8+
desc 'Run Rubocop lint checks'
9+
task :rubocop do
10+
RuboCop::RakeTask.new
11+
end
12+
13+
# lint the project
14+
desc 'Run robocop linter'
15+
task lint: [:rubocop]
16+
17+
# run tests
18+
task default: [:lint, 'test:check']
19+
20+
namespace :test do
21+
# run inspec check to verify that the profile is properly configured
22+
task :check do
23+
dir = File.join(File.dirname(__FILE__))
24+
sh("bundle exec inspec check #{dir}")
25+
end
26+
end
27+
28+
# Automatically generate a changelog for this project. Only loaded if
29+
# the necessary gem is installed. By default its picking up the version from
30+
# inspec.yml. You can override that behavior with s`rake changelog to=1.2.0`
31+
begin
32+
require 'yaml'
33+
metadata = YAML.load_file('inspec.yml')
34+
v = ENV['to'] || metadata['version']
35+
puts "Generate changelog for version #{v}"
36+
require 'github_changelog_generator/task'
37+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
38+
config.future_release = v
39+
end
40+
rescue LoadError
41+
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
42+
end

controls/check-block.rb

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
# encoding: utf-8
12
# All checks from http://docs.openstack.org/security-guide/block-storage/checklist.html
23

34
cinder_conf_dir = '/etc/cinder'
45
cinder_conf_file = "#{cinder_conf_dir}/cinder.conf"
56

67
control 'check-block-01' do
7-
88
title 'Cinder config files should be owned by root user and cinder group.'
9-
109
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-01-is-user-group-ownership-of-config-files-set-to-root-cinder'
1110

1211
describe file(cinder_conf_file) do
@@ -25,13 +24,10 @@
2524
it { should be_owned_by 'root' }
2625
its('group') { should eq 'cinder' }
2726
end
28-
2927
end
3028

3129
control 'check-block-02' do
32-
3330
title 'Strict permissions should be set for all Cinder config files.'
34-
3531
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-02-are-strict-permissions-set-for-configuration-files'
3632

3733
describe file(cinder_conf_file) do
@@ -46,85 +42,67 @@
4642
describe file("#{cinder_conf_dir}/rootwrap.conf") do
4743
its('mode') { should cmp '0640' }
4844
end
49-
5045
end
5146

5247
control 'check-block-03' do
53-
5448
title 'Cinder should use Keystone for authentication.'
55-
5649
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-03-is-keystone-used-for-authentication'
5750

5851
# nil is acceptable as keystone is default value
5952
describe ini(cinder_conf_file) do
60-
its(['DEFAULT','auth_strategy']) { should be_nil.or eq "keystone" }
53+
its(['DEFAULT', 'auth_strategy']) { should be_nil.or eq 'keystone' }
6154
end
62-
6355
end
6456

6557
control 'check-block-04' do
66-
6758
title 'Cinder should communicate with Keystone using TLS.'
68-
6959
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-04-is-tls-enabled-for-authentication'
7060

7161
describe ini(cinder_conf_file) do
72-
its(['keystone_authtoken','auth_uri']) { should match /^https:/ }
73-
62+
its(['keystone_authtoken', 'auth_uri']) { should match(/^https:/) }
7463
# nil is acceptable as false is the default value
75-
its(['keystone_authtoken','insecure']) { should be_nil.or eq "False" }
64+
its(['keystone_authtoken', 'insecure']) { should be_nil.or eq 'False' }
7665
end
77-
7866
end
7967

8068
control 'check-block-05' do
81-
8269
title 'Cinder should communicate with Nova using TLS.'
83-
8470
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-05-does-cinder-communicate-with-nova-over-tls'
8571

8672
# nil is acceptable as false is the default value
8773
describe ini(cinder_conf_file) do
88-
its(['DEFAULT','nova_api_insecure']) { should be_nil.or eq "False" }
74+
its(['DEFAULT', 'nova_api_insecure']) { should be_nil.or eq 'False' }
8975
end
90-
9176
end
9277

9378
control 'check-block-06' do
94-
9579
title 'Cinder should communicate with Glance using TLS.'
96-
9780
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-06-does-cinder-communicate-with-glance-over-tls'
9881

9982
describe ini(cinder_conf_file) do
10083
# nil is acceptable as the glance endpoint may be sourced from Keystone based on the value of glance_catalog_info
101-
its(['DEFAULT','glance_api_servers']) { should be_nil.or match /^https:/ }
102-
84+
its(['DEFAULT', 'glance_api_servers']) { should be_nil.or match(/^https:/) }
10385
# nil is acceptable as false is the default value
104-
its(['DEFAULT','glance_api_insecure']) { should be_nil.or eq "False" }
86+
its(['DEFAULT', 'glance_api_insecure']) { should be_nil.or eq 'False' }
10587
end
10688
end
10789

10890
control 'check-block-07' do
109-
11091
title 'Cinder should use secure NAS permissions.'
111-
11292
ref 'http://docs.openstack.org/security-guide/block-storage/checklist.html#check-block-07-is-nas-operating-in-a-secure-environment'
11393

11494
cinder_conf = ini(cinder_conf_file)
11595

11696
only_if do
117-
cinder_conf.value(['DEFAULT','nas_host']) != nil
97+
cinder_conf.value(['DEFAULT', 'nas_host']).nil?
11898
end
11999

120100
describe ini(cinder_conf_file) do
121101
# nil is acceptable as auto is the default value
122-
its(['DEFAULT','nas_secure_file_permissions']) { should be_nil.or eq("True").or eq("auto") }
123-
102+
its(['DEFAULT', 'nas_secure_file_permissions']) { should be_nil.or eq('True').or eq('auto') }
124103
# nil is acceptable as auto is the default value
125-
its(['DEFAULT','nas_secure_file_operations']) { should be_nil.or eq("True").or eq("auto") }
104+
its(['DEFAULT', 'nas_secure_file_operations']) { should be_nil.or eq('True').or eq('auto') }
126105
end
127-
128106
end
129107

130108
control 'check-block-08' do
@@ -135,6 +113,6 @@
135113

136114
describe ini(cinder_conf_file) do
137115
# nil is acceptable as 114688 is the default value
138-
its(['DEFAULT','osapi_max_request_body_size']) { should be_nil.or be >= 114688 }
116+
its(['DEFAULT', 'osapi_max_request_body_size']) { should be_nil.or be >= 114688 }
139117
end
140118
end

controls/check-compute.rb

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
# encoding: utf-8
12
# All checks from http://docs.openstack.org/security-guide/compute/checklist.html
23

34
nova_conf_dir = '/etc/nova'
45
nova_conf_file = "#{nova_conf_dir}/nova.conf"
56

67
control 'check-compute-01' do
7-
88
title 'Nova config files should be owned by root user and nova group.'
9-
109
ref 'http://docs.openstack.org/security-guide/compute/checklist.html#check-compute-01-is-user-group-ownership-of-config-files-set-to-root-nova'
1110

1211
describe file(nova_conf_file) do
@@ -28,9 +27,7 @@
2827
end
2928

3029
control 'check-compute-02' do
31-
3230
title 'Strict permissions should be set for all Nova config files.'
33-
3431
ref 'http://docs.openstack.org/security-guide/compute/checklist.html#check-compute-02-are-strict-permissions-set-for-configuration-files'
3532

3633
describe file(nova_conf_file) do
@@ -48,41 +45,33 @@
4845
end
4946

5047
control 'check-compute-03' do
51-
5248
title 'Nova should use Keystone for authentication.'
53-
5449
ref 'http://docs.openstack.org/security-guide/compute/checklist.html#check-compute-03-is-keystone-used-for-authentication'
5550

5651
describe ini(nova_conf_file) do
5752
# nil is acceptable as "keystone" is the default value
58-
its(['DEFAULT','auth_strategy']) { should be_nil.or eq "keystone" }
53+
its(['DEFAULT', 'auth_strategy']) { should be_nil.or eq 'keystone' }
5954
end
6055
end
6156

6257
control 'check-compute-04' do
63-
6458
title 'Nova should communicate with Keystone using TLS.'
65-
6659
ref 'http://docs.openstack.org/security-guide/compute/checklist.html#check-compute-04-is-secure-protocol-used-for-authentication'
6760

6861
describe ini(nova_conf_file) do
69-
its(['keystone_authtoken','auth_uri']) { should match /^https:/ }
70-
62+
its(['keystone_authtoken', 'auth_uri']) { should match(/^https:/) }
7163
# nil is acceptable as false is the default value
72-
its(['keystone_authtoken','insecure']) { should be_nil.or eq "False" }
64+
its(['keystone_authtoken', 'insecure']) { should be_nil.or eq 'False' }
7365
end
7466
end
7567

7668
control 'check-compute-05' do
77-
7869
title 'Nova should communicate with Glance using TLS.'
79-
8070
ref 'http://docs.openstack.org/security-guide/compute/checklist.html#check-compute-05-does-nova-communicate-with-glance-securely'
8171

8272
describe ini(nova_conf_file) do
83-
its(['glance','api_servers']) { should match /^https:/ }
84-
73+
its(['glance', 'api_servers']) { should match(/^https:/) }
8574
# nil is acceptable as false is the default value
86-
its(['glance','api_insecure']) { should be_nil.or eq "False" }
75+
its(['glance', 'api_insecure']) { should be_nil.or eq 'False' }
8776
end
8877
end

0 commit comments

Comments
 (0)