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