|
4 | 4 | #
|
5 | 5 | # Copyright (c) 2016 Inversoft, All Rights Reserved.
|
6 | 6 |
|
7 |
| -# Validate the attributes |
8 |
| -if node['security_guide']['users'].length == 0 || node['security_guide']['monit'].attribute?('alert_email') == false |
9 |
| - Chef::Application.fatal!('You must specify at least one user and an alert email for Monit') |
10 |
| -end |
11 |
| - |
12 |
| -apt_update 'Update the apt cache daily' do |
13 |
| - frequency 86_400 |
14 |
| - action :periodic |
15 |
| -end |
16 |
| - |
17 |
| -# Create the ordinary users |
18 |
| -node['security_guide']['users'].each do |user| |
19 |
| - user user.username do |
20 |
| - home "/home/#{user.username}" |
21 |
| - manage_home true |
22 |
| - shell '/bin/bash' |
23 |
| - password user.password |
24 |
| - end |
25 |
| - |
26 |
| - # Add the ordinary user to the sudo group |
27 |
| - group node['security_guide']['sudo_group'] do |
28 |
| - action :modify |
29 |
| - members user.username |
30 |
| - append true |
31 |
| - end |
32 |
| - |
33 |
| - # Setup SSH key's for the ordinary user |
34 |
| - directory "/home/#{user.username}/.ssh" do |
35 |
| - owner user.username |
36 |
| - group user.username |
37 |
| - mode '0700' |
38 |
| - action :create |
39 |
| - end |
40 |
| - file "/home/#{user.username}/.ssh/authorized_keys" do |
41 |
| - content user.public_key |
42 |
| - owner user.username |
43 |
| - group user.username |
44 |
| - mode '0600' |
45 |
| - end |
46 |
| -end |
47 |
| - |
48 |
| -# Disable rot user's password |
49 |
| -user 'root' do |
50 |
| - password '!' |
51 |
| - action :modify |
52 |
| -end |
53 |
| - |
54 |
| -# Install all the security packages |
55 |
| -package 'libpam-cracklib' |
56 |
| -package 'libpam-google-authenticator' |
57 |
| -package 'ntp' |
58 |
| -package 'monit' |
59 |
| -package 'ruby' |
60 |
| - |
61 |
| -# Configure the Debian answers for the iptables-persistent package |
62 |
| -ruby_block 'debconf-iptables-persistent' do |
63 |
| - block do |
64 |
| - `echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections` |
65 |
| - `echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections` |
66 |
| - end |
67 |
| - action :create |
68 |
| -end |
69 |
| -package 'iptables-persistent' |
70 |
| - |
71 |
| -# Install the SSH server configuration file |
72 |
| -cookbook_file '/etc/ssh/sshd_config' do |
73 |
| - source 'sshd_config' |
74 |
| - owner 'root' |
75 |
| - group 'root' |
76 |
| - mode '0644' |
77 |
| -end |
78 |
| - |
79 |
| -# Install the PAM SSH configuration file for two-factor authentication |
80 |
| -cookbook_file '/etc/pam.d/sshd' do |
81 |
| - source 'sshd' |
82 |
| - owner 'root' |
83 |
| - group 'root' |
84 |
| - mode '0644' |
85 |
| -end |
86 |
| - |
87 |
| -# Install the IPTables IPv4 configuration file |
88 |
| -cookbook_file '/etc/iptables/rules.v4' do |
89 |
| - source 'rules.v4' |
90 |
| - owner 'root' |
91 |
| - group 'root' |
92 |
| - mode '0644' |
93 |
| -end |
94 |
| - |
95 |
| -# Install the PAM password module for strong passwords |
96 |
| -cookbook_file '/etc/pam.d/common-password' do |
97 |
| - source 'common-password' |
98 |
| - owner 'root' |
99 |
| - group 'root' |
100 |
| - mode '0644' |
101 |
| -end |
102 |
| - |
103 |
| -# Install the Monit configuration for generating alerts on SSH logins |
104 |
| -cookbook_file '/etc/monit/conf.d/ssh-logins' do |
105 |
| - source 'ssh-logins' |
106 |
| - owner 'root' |
107 |
| - group 'root' |
108 |
| - mode '0600' |
109 |
| -end |
110 |
| - |
111 |
| -# Install the main Monit configuration file that sends the emails |
112 |
| -template '/etc/monit/monitrc' do |
113 |
| - source 'monitrc.erb' |
114 |
| - owner 'root' |
115 |
| - group 'root' |
116 |
| - mode '0600' |
117 |
| -end |
118 |
| - |
119 |
| -# Install the Monit script to send alerts to Slack and Pushover |
120 |
| -template '/etc/monit/monit-slack-pushover.rb' do |
121 |
| - source 'monit-slack-pushover.rb.erb' |
122 |
| - owner 'root' |
123 |
| - group 'root' |
124 |
| - mode '0700' |
125 |
| -end |
126 |
| - |
127 |
| -# Restart all the services |
128 |
| -service 'ssh' do |
129 |
| - action :restart |
130 |
| -end |
131 |
| -service 'netfilter-persistent' do |
132 |
| - action :restart |
133 |
| -end |
134 |
| -service 'monit' do |
135 |
| - action :restart |
136 |
| -end |
| 7 | +include_recipe '2016_security_guide::users' |
| 8 | +include_recipe '2016_security_guide::strong-passwords' |
| 9 | +include_recipe '2016_security_guide::iptables' |
| 10 | +include_recipe '2016_security_guide::sshd' |
| 11 | +if node['security_guide']['two_factor_enabled'] |
| 12 | + include_recipe '2016_security_guide::two-factor' |
| 13 | +end |
| 14 | +include_recipe '2016_security_guide::monit' |
0 commit comments