Skip to content

Commit f0de429

Browse files
committed
project start
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
0 parents  commit f0de429

File tree

9 files changed

+333
-0
lines changed

9 files changed

+333
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/.librarian
2+
**/.tmp
3+
**/Puppetfile.lock
4+
Gemfile.lock
5+
Berksfile.lock

.rubocop.yml

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

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rvm:
2+
- 1.9.3
3+
- 2.0.0
4+
language: ruby

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# encoding: utf-8
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rake'
6+
gem 'serverspec', '~> 2.17.0'
7+
gem 'rubocop', '~> 0.31'
8+
gem 'highline', '~> 1.7.0'

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Tests for PHP hardening
2+
3+
This is currently in development! Please come back later.
4+
5+
6+
## Standalone Usage
7+
8+
You can target the integration tests to any host were you have ssh access
9+
10+
rake -T gives you a list of suites you can run (well ignore directories which are obviously not suites for now)
11+
12+
```
13+
± rake -T
14+
rake serverspec:data_bags # Run serverspec suite data_bags
15+
rake serverspec:default # Run serverspec suite default
16+
```
17+
18+
run it with:
19+
20+
```
21+
bundle install
22+
23+
# default user and ssh-key
24+
25+
bundle exec rake serverspec:default target_host=<name-or-ip-of-target-server>
26+
27+
# or with user, host, password
28+
29+
ASK_LOGIN_PASSWORD=true bundle exec rake serverspec:default target_host=192.168.1.222 user=stack
30+
```
31+
32+
add `format=html|json` to get a report.html or report.json document
33+
34+
35+
## License
36+
37+
Licensed under the Apache License, Version 2.0 (the "License");
38+
you may not use this file except in compliance with the License.
39+
You may obtain a copy of the License at
40+
41+
http://www.apache.org/licenses/LICENSE-2.0
42+
43+
Unless required by applicable law or agreed to in writing, software
44+
distributed under the License is distributed on an "AS IS" BASIS,
45+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46+
See the License for the specific language governing permissions and
47+
limitations under the License.

Rakefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# encoding: utf-8
2+
3+
require 'rake'
4+
require 'rspec/core/rake_task'
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 cookbook
14+
desc 'Run linters'
15+
task :run_all_linters => [:rubocop] # rubocop:disable Style/HashSyntax
16+
task :default => :run_all_linters # rubocop:disable Style/HashSyntax
17+
18+
# Serverspec tests
19+
suites = Dir.glob('*').select { |entry| File.directory?(entry) }
20+
21+
class ServerspecTask < RSpec::Core::RakeTask
22+
attr_accessor :target
23+
24+
def spec_command
25+
if target.nil?
26+
puts 'specify either env TARGET_HOST or target_host='
27+
exit 1
28+
end
29+
30+
cmd = super
31+
"env TARGET_HOST=#{target} STANDALONE_SPEC=true #{cmd} --format documentation --no-profile"
32+
end
33+
end
34+
35+
namespace :serverspec do
36+
suites.each do |suite|
37+
desc "Run serverspec suite #{suite}"
38+
ServerspecTask.new(suite.to_sym) do |t|
39+
t.rspec_opts = '--no-color --format html --out report.html' if ENV['format'] == 'html'
40+
t.rspec_opts = '--no-color --format json --out report.json' if ENV['format'] == 'json'
41+
t.target = ENV['TARGET_HOST'] || ENV['target_host']
42+
t.ruby_opts = "-I #{suite}/serverspec"
43+
t.pattern = "#{suite}/serverspec/*_spec.rb"
44+
end
45+
end
46+
end

default/serverspec/phpconf_spec.rb

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# encoding: utf-8
2+
# Copyright 2015, Dominik Richter
3+
# License: Apache v2
4+
5+
require 'spec_helper'
6+
7+
describe 'PHP config parameters' do
8+
# Some things we don't do:
9+
# * safe_mode
10+
# reason: deprecated
11+
# see: http://php.net/manual/de/features.safe-mode.php
12+
13+
# Base configuration
14+
15+
context php_config('open_basedir') do
16+
its(:value) { should eq '/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/' }
17+
end
18+
19+
# Time / Memory Quota
20+
21+
context php_config('max_execution_time') do
22+
its(:value) { should eq 30 }
23+
end
24+
25+
context php_config('max_input_nesting_level') do
26+
its(:value) { should eq 64 }
27+
end
28+
29+
context php_config('memory_limit') do
30+
its(:value) { should eq '128M' }
31+
end
32+
33+
context php_config('post_max_size') do
34+
its(:value) { should eq '8M' }
35+
end
36+
37+
# PHP Capabilities
38+
39+
# TODO: do we have a recommended minimum-set?
40+
context php_config('disable_functions') do
41+
its(:value) { should eq 'php_uname, getmyuid, getmypid, passthru, leak, listen, diskfreespace, tmpfile, link, ignore_user_abord, shell_exec, dl, set_time_limit, exec, system, highlight_file, source, show_source, fpaththru, virtual, posix_ctermid, posix_getcwd, posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, posix, _getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, posix_setpgid, posix_setsid, posix_setuid, posix_times, posix_ttyname, posix_uname, proc_open, proc_close, proc_get_status, proc_nice, proc_terminate, phpinfo' }
42+
end
43+
44+
# TODO: do we have a recommended minimum-set?
45+
context php_config('disable_classes') do
46+
its(:value) { should eq '...' }
47+
end
48+
49+
context php_config('register_globals') do
50+
its(:value) { should eq 'Off' }
51+
end
52+
53+
context php_config('expose_php') do
54+
its(:value) { should eq 'Off' }
55+
end
56+
57+
context php_config('enable_dl') do
58+
its(:value) { should eq 'Off' }
59+
end
60+
61+
context php_config('default_charset') do
62+
its(:value) { should eq 'utf-8' }
63+
end
64+
65+
context php_config('default_mimetype') do
66+
its(:value) { should eq 'text/html' }
67+
end
68+
69+
# removed as of PHP5.4, so...
70+
# remove these test?
71+
context php_config('magic_quotes_gpc') do
72+
its(:value) { should eq nil}
73+
end
74+
context php_config('magic_quotes_sybase') do
75+
its(:value) { should eq nil}
76+
end
77+
78+
# # removed // how to test this?
79+
# context php_config('magic_quotes_runtime') do
80+
# its(:value) { should eq 'Off'}
81+
# end
82+
83+
# Upload / Open
84+
85+
context php_config('allow_url_fopen') do
86+
its(:value) { should eq 'Off' }
87+
end
88+
89+
context php_config('allow_url_include') do
90+
its(:value) { should eq 'Off' }
91+
end
92+
93+
context php_config('file_uploads') do
94+
its(:value) { should eq 'Off' }
95+
end
96+
97+
# Alternative: restrict upload maximum to prevent
98+
# system overload:
99+
# upload_tmp_dir = /var/php_tmp
100+
# upload_max_filezize = 10M
101+
102+
# Log // Information Disclosure
103+
104+
context php_config('display_errors') do
105+
its(:value) { should eq 'Off' }
106+
end
107+
108+
context php_config('display_startup_errors') do
109+
its(:value) { should eq 'Off' }
110+
end
111+
112+
context php_config('log_errors') do
113+
its(:value) { should eq 'On' }
114+
end
115+
116+
# Session Handling
117+
118+
context php_config('session.save_path') do
119+
its(:value) { should eq '/var/lib/php' }
120+
end
121+
122+
context php_config('session.cookie_httponly') do
123+
its(:value) { should eq 1 }
124+
end
125+
126+
# Mail
127+
128+
context php_config('mail.add_x_header') do
129+
its(:value) { should eq 'Off' }
130+
131+
end

default/serverspec/spec_helper.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# encoding: utf-8
2+
#
3+
# Copyright 2014, Deutsche Telekom AG
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
if ENV['STANDALONE_SPEC']
19+
20+
require 'serverspec'
21+
require 'pathname'
22+
require 'net/ssh'
23+
require 'highline/import'
24+
25+
set :backend, :ssh
26+
27+
RSpec.configure do |c|
28+
29+
if ENV['ASK_SUDO_PASSWORD']
30+
c.sudo_password = ask('Enter sudo password: ') { |q| q.echo = false }
31+
else
32+
c.sudo_password = ENV['SUDO_PASSWORD']
33+
end
34+
35+
options = {}
36+
37+
if ENV['ASK_LOGIN_PASSWORD']
38+
options[:password] = ask("\nEnter login password: ") { |q| q.echo = false }
39+
else
40+
options[:password] = ENV['LOGIN_PASSWORD']
41+
end
42+
43+
if ENV['ASK_LOGIN_USERNAME']
44+
options[:user] = ask("\nEnter login username: ") { |q| q.echo = false }
45+
else
46+
options[:user] = ENV['LOGIN_USERNAME'] || ENV['user'] || Etc.getlogin
47+
end
48+
49+
if options[:user].nil?
50+
puts 'specify login user env LOGIN_USERNAME= or user='
51+
exit 1
52+
end
53+
54+
c.host = ENV['TARGET_HOST']
55+
c.ssh_options = options.merge(Net::SSH::Config.for(c.host))
56+
57+
end
58+
59+
else
60+
require 'serverspec'
61+
62+
set :backend, :exec
63+
end

0 commit comments

Comments
 (0)