Puppet Class: rsyslog::receiver

Defined in:
modules/rsyslog/manifests/receiver.pp

Summary

Setup the rsyslog daemon as a receiver for remote logs.

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • udp_port (Stdlib::Port) (defaults to: 514)

    Listen for UDP syslog on this port

  • tcp_port (Stdlib::Port) (defaults to: 6514)

    Listen for TCP syslog on this port (TLS only)

  • log_retention_days (Integer) (defaults to: 90)

    How long to keep logs in $archive_directory for

  • log_directory (Stdlib::Unixpath) (defaults to: '/srv/syslog')

    Write logs to this directory, parent directory must already exist.

  • archive_directory (Stdlib::Unixpath) (defaults to: '/srv/syslog/archive')

    Archive logs into this directory, it is an error to set this equal to $log_directory and vice versa.

  • tls_auth_mode (Rsyslog::TLS::Auth_mode) (defaults to: 'x509/certvalid')

    Specifies the authentication mode for syslog clients.

  • tls_netstream_driver (Rsyslog::TLS::Driver) (defaults to: 'gtls')

    Rsyslog Network Stream driver to use for TLS support.

  • file_template_property (Enum['fromhost-ip', 'hostname']) (defaults to: 'hostname')

    Property to be used for determining the file name (e.g. /srv/syslog/<property>/syslog.log) of the log file.

  • acme_cert_name (Optional[Stdlib::Fqdn]) (defaults to: undef)

    name for acme-chief cert to use for tls clients

  • ssl_provider (Enum['puppet', 'cfssl', 'acme']) (defaults to: 'puppet')

    Choose to use cfssl or the puppet agent certs



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'modules/rsyslog/manifests/receiver.pp', line 15

class rsyslog::receiver (
    Stdlib::Port                    $udp_port               = 514,
    Stdlib::Port                    $tcp_port               = 6514,
    Integer                         $log_retention_days     = 90,
    Stdlib::Unixpath                $log_directory          = '/srv/syslog',
    Stdlib::Unixpath                $archive_directory      = '/srv/syslog/archive',
    Rsyslog::TLS::Auth_mode         $tls_auth_mode          = 'x509/certvalid',
    Rsyslog::TLS::Driver            $tls_netstream_driver   = 'gtls',
    Enum['fromhost-ip', 'hostname'] $file_template_property = 'hostname',
    Optional[Stdlib::Fqdn]          $acme_cert_name         = undef,
    Enum['puppet', 'cfssl', 'acme'] $ssl_provider           = 'puppet',
) {
    # force acme if we have a acme_cert_name to remain backwards compatible
    $_ssl_provider = ($acme_cert_name =~ NotUndef).bool2str('acme', $ssl_provider)
    if $ssl_provider == 'acme' and $ssl_provider =~ Undef {
        fail('you must set \$acme_cert_name when \$ssl_provider is acme')
    }
    if $tls_netstream_driver == 'gtls' {
        # Unlike rsyslog-openssl (see below), rsyslog-gnutls is available
        # in buster, but on buster systems, we need a newer version of
        # rsyslog due to segfaults (T259780)
        $netstream_package = 'rsyslog-gnutls'
    } else {
        # rsyslog-openssl is available by default in bullseye and later,
        # the package has been backported to component/rsyslog-openssl for
        # buster systems (T324623)
        # component/rsyslog-openssl also incorporated the fix for
        # T259780 (see above), hence component/rsyslog is redundant
        $netstream_package = 'rsyslog-openssl'
    }

    ensure_packages($netstream_package)

    if ($log_directory == $archive_directory) {
        fail("rsyslog log and archive are the same: ${log_directory}")
    }

    # SSL configuration
    case $_ssl_provider {
        'acme': {
            $ca_file   = "/etc/acmecerts/${acme_cert_name}/live/ec-prime256v1.chained.crt"
            $cert_file = "/etc/acmecerts/${acme_cert_name}/live/ec-prime256v1.alt.chained.crt"
            $key_file  = "/etc/acmecerts/${acme_cert_name}/live/ec-prime256v1.key"
        }
        'puppet': {
            puppet::expose_agent_certs { '/etc/rsyslog-receiver':
                provide_private => true,
            }

            $ca_file = '/etc/ssl/certs/wmf-ca-certificates.crt'
            $cert_file = '/etc/rsyslog-receiver/ssl/cert.pem'
            $key_file = '/etc/rsyslog-receiver/ssl/server.key'
        }
        'cfssl': {
            $ssl_paths = profile::pki::get_cert(
                'syslog',
                'rsyslog-receiver',
                {'notify_services' => ['rsyslog-receiver'] })
            $cert_file = $ssl_paths['chained']
            $key_file = $ssl_paths['key']
            $ca_file = '/etc/ssl/certs/wmf-ca-certificates.crt'
        }
        default: { fail("unknown provider: ${ssl_provider}") }
    }

    systemd::service { 'rsyslog-receiver':
        ensure  => present,
        content => template('rsyslog/initscripts/rsyslog_receiver.systemd.erb'),
    }

    file { ['/etc/rsyslog-receiver', '/etc/rsyslog-receiver/conf.d']:
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0500',
    }

    file { '/var/spool/rsyslog-receiver':
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0700',
    }

    file { '/etc/rsyslog-receiver/main.conf':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
        source => 'puppet:///modules/rsyslog/receiver.conf',
    }

    prometheus::rsyslog_exporter { 'receiver':
        listen_port => 9110,
        instance    => 'receiver',
    }

    rsyslog::conf { 'input':
        content  => template("${module_name}/receiver.erb.conf"),
        priority => 10,
        instance => 'receiver',
    }

    logrotate::conf { 'rsyslog_receiver':
        ensure  => present,
        content => template("${module_name}/receiver_logrotate.erb.conf"),
    }

    file { $log_directory:
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { $archive_directory:
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    # Plumb rsync pull from eqiad by codfw centrallog hosts, useful for re-syncing logs
    # inactive (ensure => absent, auto_sync => false)  but kept here to be
    # quickly enabled when needed.
    rsync::quickdatacopy { 'centrallog':
        ensure              => present,
        source_host         => 'centrallog1001.eqiad.wmnet',
        dest_host           => 'centrallog1002.eqiad.wmnet',
        auto_sync           => false,
        module_path         => '/srv',
        server_uses_stunnel => true,
        progress            => true,
    }
}