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