Improve kpartx rule
[mirror/dsa-puppet.git] / modules / debian_org / manifests / init.pp
1 # == Class: debian_org
2 #
3 # Stuff common to all debian.org servers
4 #
5 class debian_org {
6         include debian_org::apt
7
8         if $systemd {
9                 include systemd
10                 $servicefiles = 'present'
11         } else {
12                 $servicefiles = 'absent'
13         }
14
15         # the virtual facter needs virt-what on jessie to work
16         if versioncmp($::lsbmajdistrelease, '9') < 0 {
17                 package { 'virt-what': ensure => installed }
18         } else {
19                 package { 'virt-what': ensure => purged }
20         }
21
22         $samhain_recipients = hiera('samhain_recipients')
23         $root_mail_alias = hiera('root_mail_alias')
24
25         package { [
26                         'klogd',
27                         'sysklogd',
28                         'rsyslog',
29                         'os-prober',
30                         'apt-listchanges',
31                         'mlocate',
32                 ]:
33                 ensure => purged,
34         }
35         package { [
36                         'debian.org',
37                         'debian.org-recommended',
38                         'dsa-munin-plugins',
39                         'userdir-ldap',
40                 ]:
41                 ensure => installed,
42                 tag    => extra_repo,
43         }
44         file { '/etc/ssh/ssh_known_hosts':
45                 ensure  => present,
46                 replace => false,
47                 mode    => '0644',
48                 source  => 'puppet:///modules/debian_org/basic-ssh_known_hosts'
49         }
50
51         if versioncmp($::lsbmajdistrelease, '8') >= 0 {
52                 $rubyfs_package = 'ruby-filesystem'
53         } else {
54                 $rubyfs_package = 'libfilesystem-ruby1.9'
55         }
56         package { [
57                         'apt-utils',
58                         'bash-completion',
59                         'dnsutils',
60                         'less',
61                         'lsb-release',
62                         $rubyfs_package,
63                         'mtr-tiny',
64                         'nload',
65                         'pciutils',
66                         'lldpd',
67                 ]:
68                 ensure => installed,
69         }
70
71         munin::check { [
72                         'cpu',
73                         'entropy',
74                         'forks',
75                         'interrupts',
76                         'iostat',
77                         'irqstats',
78                         'load',
79                         'memory',
80                         'open_files',
81                         'open_inodes',
82                         'processes',
83                         'swap',
84                         'uptime',
85                         'vmstat',
86                 ]:
87         }
88
89         if getfromhash($site::nodeinfo, 'broken-rtc') {
90                 package { 'fake-hwclock':
91                         ensure => installed,
92                         tag    => extra_repo,
93                 }
94         }
95
96         package { 'molly-guard':
97                 ensure => installed,
98         }
99         file { '/etc/molly-guard/run.d/10-check-kvm':
100                 mode    => '0755',
101                 source  => 'puppet:///modules/debian_org/molly-guard/10-check-kvm',
102                 require => Package['molly-guard'],
103         }
104         file { '/etc/molly-guard/run.d/15-acquire-reboot-lock':
105                 mode    => '0755',
106                 source  => 'puppet:///modules/debian_org/molly-guard/15-acquire-reboot-lock',
107                 require => Package['molly-guard'],
108         }
109
110         augeas { 'inittab_replicate':
111                 context => '/files/etc/inittab',
112                 changes => [
113                         'set ud/runlevels 2345',
114                         'set ud/action respawn',
115                         'set ud/process "/usr/bin/ud-replicated -d"',
116                 ],
117                 notify  => Exec['init q'],
118         }
119
120
121         file { '/etc/facter':
122                 ensure  => directory,
123                 purge   => true,
124                 force   => true,
125                 recurse => true,
126                 source  => 'puppet:///files/empty/',
127         }
128         file { '/etc/facter/facts.d':
129                 ensure => directory,
130         }
131         file { '/etc/facter/facts.d/debian_facts.yaml':
132                 content => template('debian_org/debian_facts.yaml.erb')
133         }
134         file { '/etc/timezone':
135                 source => 'puppet:///modules/debian_org/timezone',
136                 notify => Exec['dpkg-reconfigure tzdata -pcritical -fnoninteractive'],
137         }
138         if $::hostname == handel {
139                 include puppetmaster::db
140                 $dbpassword = $puppetmaster::db::password
141         }
142         file { '/etc/puppet/puppet.conf':
143                 content => template('debian_org/puppet.conf.erb'),
144                 mode => '0440',
145                 group => 'puppet',
146         }
147         file { '/etc/default/puppet':
148                 source => 'puppet:///modules/debian_org/puppet.default',
149         }
150         file { '/etc/systemd':
151                 ensure  => directory,
152                 mode => '0755',
153         }
154         file { '/etc/systemd/system':
155                 ensure  => directory,
156                 mode => '0755',
157         }
158         file { '/etc/systemd/system/ud-replicated.service':
159                 ensure => $servicefiles,
160                 source => 'puppet:///modules/debian_org/ud-replicated.service',
161                 notify => Exec['systemctl daemon-reload'],
162         }
163         if $systemd {
164                 file { '/etc/systemd/system/multi-user.target.wants/ud-replicated.service':
165                         ensure => 'link',
166                         target => '../ud-replicated.service',
167                         notify => Exec['systemctl daemon-reload'],
168                 }
169         }
170         file { '/etc/systemd/system/puppet.service':
171                 ensure => 'link',
172                 target => '/dev/null',
173                 notify => Exec['systemctl daemon-reload'],
174         }
175         file { '/etc/systemd/system/proc-sys-fs-binfmt_misc.automount':
176                 ensure => 'link',
177                 target => '/dev/null',
178                 notify => Exec['systemctl daemon-reload'],
179         }
180
181         concat { '/etc/cron.d/dsa-puppet-stuff': }
182         concat::fragment { 'dsa-puppet-stuff---header':
183                 target => '/etc/cron.d/dsa-puppet-stuff',
184                 order  => '000',
185                 content  => @(EOF)
186                         ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
187                         SHELL=/bin/bash
188                         MAILTO=root
189                         PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/nagios/plugins
190                         | EOF
191         }
192         concat::fragment { 'dsa-puppet-stuff---all':
193                 target => '/etc/cron.d/dsa-puppet-stuff',
194                 order  => '010',
195                 content => template('debian_org/dsa-puppet-stuff.cron.erb'),
196                 require => Package['debian.org'],
197         }
198         file { '/etc/ldap/ldap.conf':
199                 require => Package['debian.org'],
200                 content  => template('debian_org/ldap.conf.erb'),
201         }
202         file { '/etc/pam.d/common-session':
203                 require => Package['debian.org'],
204                 content => template('debian_org/pam.common-session.erb'),
205         }
206         file { '/etc/pam.d/common-session-noninteractive':
207                 require => Package['debian.org'],
208                 content => template('debian_org/pam.common-session-noninteractive.erb'),
209         }
210         file { '/etc/rc.local':
211                 mode   => '0755',
212                 content => template('debian_org/rc.local.erb'),
213                 notify => Exec['service rc.local restart'],
214         }
215         file { '/etc/dsa':
216                 ensure => directory,
217                 mode   => '0755',
218         }
219         file { '/etc/dsa/cron.ignore.dsa-puppet-stuff':
220                 source  => 'puppet:///modules/debian_org/dsa-puppet-stuff.cron.ignore',
221                 require => Package['debian.org']
222         }
223         file { '/etc/nsswitch.conf':
224                 mode   => '0755',
225                 source => 'puppet:///modules/debian_org/nsswitch.conf',
226         }
227
228         file { '/etc/profile.d/timeout.sh':
229                 mode   => '0555',
230                 source => 'puppet:///modules/debian_org/etc.profile.d/timeout.sh',
231         }
232         file { '/etc/zsh':
233                 ensure => directory,
234         }
235         file { '/etc/zsh/zprofile':
236                 mode   => '0444',
237                 source => 'puppet:///modules/debian_org/etc.zsh/zprofile',
238         }
239         file { '/etc/environment':
240                 content => "",
241                 mode => '0440',
242         }
243         file { '/etc/default/locale':
244                 content => "",
245                 mode => '0444',
246         }
247
248         # set mmap_min_addr to 4096 to mitigate
249         # Linux NULL-pointer dereference exploits
250         site::sysctl { 'mmap_min_addr':
251                 ensure => absent
252         }
253         site::sysctl { 'perf_event_paranoid':
254                 key   => 'kernel.perf_event_paranoid',
255                 value => '2',
256         }
257         site::sysctl { 'puppet-vfs_cache_pressure':
258                 key   => 'vm.vfs_cache_pressure',
259                 value => '10',
260         }
261         site::alternative { 'editor':
262                 linkto => '/usr/bin/vim.basic',
263         }
264         site::alternative { 'view':
265                 linkto => '/usr/bin/vim.basic',
266         }
267         mailalias { 'samhain-reports':
268                 ensure    => present,
269                 recipient => $samhain_recipients,
270                 require   => Package['debian.org']
271         }
272         mailalias { 'root':
273                 ensure    => present,
274                 recipient => $root_mail_alias,
275                 require   => Package['debian.org']
276         }
277
278         file { '/usr/local/bin/check_for_updates':
279                 source => 'puppet:///modules/debian_org/check_for_updates',
280                 mode   => '0755',
281                 owner  => root,
282                 group  => root,
283         }
284         file { '/usr/local/bin/dsa-is-shutdown-scheduled':
285                 source  => 'puppet:///modules/debian_org/dsa-is-shutdown-scheduled',
286                 mode    => '0555',
287         }
288
289         exec { 'dpkg-reconfigure tzdata -pcritical -fnoninteractive':
290                 path        => '/usr/bin:/usr/sbin:/bin:/sbin',
291                 refreshonly => true
292         }
293         exec { 'service puppetmaster restart':
294                 refreshonly => true
295         }
296         exec { 'service rc.local restart':
297                 refreshonly => true
298         }
299         exec { 'init q':
300                 refreshonly => true
301         }
302
303         exec { 'systemctl daemon-reload':
304                 refreshonly => true,
305                 onlyif  => "test -x /bin/systemctl"
306         }
307
308         exec { 'systemd-tmpfiles --create --exclude-prefix=/dev':
309                 refreshonly => true,
310                 onlyif  => "test -x /bin/systemd-tmpfiles"
311         }
312
313         tidy { '/var/lib/puppet/clientbucket/':
314                 age      => '2w',
315                 recurse  => 9,
316                 type     => ctime,
317                 matches  => [ 'paths', 'contents' ],
318                 schedule => weekly
319         }
320
321         file { '/root/.bashrc':
322                 source => 'puppet:///modules/debian_org/root-dotfiles/bashrc',
323         }
324         file { '/root/.profile':
325                 source => 'puppet:///modules/debian_org/root-dotfiles/profile',
326         }
327         file { '/root/.selected_editor':
328                 source => 'puppet:///modules/debian_org/root-dotfiles/selected_editor',
329         }
330         file { '/root/.screenrc':
331                 source => 'puppet:///modules/debian_org/root-dotfiles/screenrc',
332         }
333         file { '/root/.tmux.conf':
334                 source => 'puppet:///modules/debian_org/root-dotfiles/tmux.conf',
335         }
336         file { '/root/.vimrc':
337                 source => 'puppet:///modules/debian_org/root-dotfiles/vimrc',
338         }
339
340         if versioncmp($::lsbmajdistrelease, '9') >= 0 { # older puppets do facts as strings.
341                 if $::processorcount > 1 {
342                         package { 'irqbalance': ensure => installed }
343                 }
344         }
345
346
347         # https://www.decadent.org.uk/ben/blog/bpf-security-issues-in-debian.html
348         site::sysctl { 'unprivileged_bpf_disabled':
349                 key   => 'kernel.unprivileged_bpf_disabled',
350                 value => '1',
351         }
352
353         # Disable kpartx udev rules
354         file { '/etc/udev/rules.d/60-kpartx.rules':
355                 ensure => $has_lib_udev_rules_d_60_kpartx_rules ? { true  => 'present', default => 'absent' },
356                 content => "",
357                 mode => '0444',
358         }
359 }