Puppet Class: profile::trafficserver::tls

Defined in:
modules/profile/manifests/trafficserver/tls.pp

Overview

class profile::trafficserver::tls

Class that sets up a Traffic Server TLS terminator instance.

Parameters:

  • user (String) (defaults to: hiera('profile::trafficserver::tls::user', 'trafficserver'))
  • port (Stdlib::Port) (defaults to: hiera('profile::trafficserver::tls::port', 443))
  • network_settings (Optional[Trafficserver::Network_settings]) (defaults to: hiera('profile::trafficserver::tls::network_settings', undef))
  • http_settings (Optional[Trafficserver::HTTP_settings]) (defaults to: hiera('profile::trafficserver::tls::http_settings', undef))
  • h2_settings (Optional[Trafficserver::H2_settings]) (defaults to: hiera('profile::trafficserver::tls::h2_settings', undef))
  • tls_settings (Trafficserver::Inbound_TLS_settings) (defaults to: hiera('profile::trafficserver::tls::inbound_tls_settings'))
  • enable_xdebug (Boolean) (defaults to: hiera('profile::trafficserver::tls::enable_xdebug', false))
  • mapping_rules (Array[TrafficServer::Mapping_rule]) (defaults to: hiera('profile::trafficserver::tls::mapping_rules', []))
  • log_formats (Array[TrafficServer::Log_format]) (defaults to: hiera('profile::trafficserver::tls::log_formats', []))
  • log_filters (Array[TrafficServer::Log_filter]) (defaults to: hiera('profile::trafficserver::tls::log_filters', []))
  • logs (Array[TrafficServer::Log]) (defaults to: hiera('profile::trafficserver::tls::logs', []))
  • parent_rules (Array[TrafficServer::Parent_rule]) (defaults to: hiera('profile::trafficserver::tls::parent_rules'))
  • prometheus_exporter_port (Wmflib::UserIpPort) (defaults to: hiera('profile::trafficserver::tls::prometheus_exporter_port', 9322))
  • unified_certs (Optional[Array[String]]) (defaults to: hiera('profile::trafficserver::tls::unified_certs', undef))
  • unified_acme_chief (Boolean) (defaults to: hiera('profile::trafficserver::tls::unified_acme_chief', false))
  • websocket_support (Boolean) (defaults to: hiera('profile::trafficserver::tls::websocket_support', false))
  • ocsp_proxy (Optional[String]) (defaults to: hiera('http_proxy'))
  • systemd_hardening (Boolean) (defaults to: hiera('profile::trafficserver::tls::systemd_hardening', true))
  • available_unified_certs (Hash[String, Trafficserver::TLS_certificate]) (defaults to: hiera('profile::trafficserver::tls::available_unified_certs'))
  • public_tls_unified_cert_vendor (String) (defaults to: hiera('public_tls_unified_cert_vendor'))
  • extra_certs (Optional[Hash[String, Trafficserver::TLS_certificate]]) (defaults to: hiera('profile::trafficserver::tls::extra_certs', undef))
  • conftool_service (String) (defaults to: hiera('profile::trafficserver::tls::conftool_service', 'ats-tls'))
  • res_track_memory (Optional[Integer[0,2]]) (defaults to: lookup('profile::trafficserver::tls::res_track_memory', {'default_value' => undef}))
  • atsmtail_progs (Stdlib::Absolutepath) (defaults to: lookup('profile::trafficserver::tls::atsmtail_tls_progs', {'default_value' => '/etc/atsmtail-tls'}))
  • atsmtail_port (Wmflib::UserIpPort) (defaults to: lookup('profile::trafficserver::tls::atsmtail_tls_port', {'default_value' => 3905}))


5
6
7
8
9
10
11
12
13
14
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'modules/profile/manifests/trafficserver/tls.pp', line 5

class profile::trafficserver::tls (
    String $user=hiera('profile::trafficserver::tls::user', 'trafficserver'),
    Stdlib::Port $port=hiera('profile::trafficserver::tls::port', 443),
    Optional[Trafficserver::Network_settings] $network_settings=hiera('profile::trafficserver::tls::network_settings', undef),
    Optional[Trafficserver::HTTP_settings] $http_settings=hiera('profile::trafficserver::tls::http_settings', undef),
    Optional[Trafficserver::H2_settings] $h2_settings=hiera('profile::trafficserver::tls::h2_settings', undef),
    Trafficserver::Inbound_TLS_settings $tls_settings=hiera('profile::trafficserver::tls::inbound_tls_settings'),
    Boolean $enable_xdebug=hiera('profile::trafficserver::tls::enable_xdebug', false),
    Array[TrafficServer::Mapping_rule] $mapping_rules=hiera('profile::trafficserver::tls::mapping_rules', []),
    Array[TrafficServer::Log_format] $log_formats=hiera('profile::trafficserver::tls::log_formats', []),
    Array[TrafficServer::Log_filter] $log_filters=hiera('profile::trafficserver::tls::log_filters', []),
    Array[TrafficServer::Log] $logs=hiera('profile::trafficserver::tls::logs', []),
    Array[TrafficServer::Parent_rule] $parent_rules=hiera('profile::trafficserver::tls::parent_rules'),
    Wmflib::UserIpPort $prometheus_exporter_port=hiera('profile::trafficserver::tls::prometheus_exporter_port', 9322),
    Optional[Array[String]] $unified_certs = hiera('profile::trafficserver::tls::unified_certs', undef),
    Boolean $unified_acme_chief = hiera('profile::trafficserver::tls::unified_acme_chief', false),
    Boolean $websocket_support = hiera('profile::trafficserver::tls::websocket_support', false),
    Optional[String] $ocsp_proxy=hiera('http_proxy'),
    Boolean $systemd_hardening=hiera('profile::trafficserver::tls::systemd_hardening', true),
    Hash[String, Trafficserver::TLS_certificate] $available_unified_certs=hiera('profile::trafficserver::tls::available_unified_certs'),
    String $public_tls_unified_cert_vendor=hiera('public_tls_unified_cert_vendor'),
    Optional[Hash[String, Trafficserver::TLS_certificate]] $extra_certs=hiera('profile::trafficserver::tls::extra_certs', undef),
    String $conftool_service=hiera('profile::trafficserver::tls::conftool_service', 'ats-tls'),
    Optional[Integer[0,2]] $res_track_memory=lookup('profile::trafficserver::tls::res_track_memory', {'default_value' => undef}),
    Stdlib::Absolutepath $atsmtail_progs=lookup('profile::trafficserver::tls::atsmtail_tls_progs', {'default_value' => '/etc/atsmtail-tls'}),
    Wmflib::UserIpPort $atsmtail_port=lookup('profile::trafficserver::tls::atsmtail_tls_port', {'default_value' => 3905}),
){
    $errorpage = {
        title       => 'Wikimedia Error',
        pagetitle   => 'Error',
        logo_link   => 'https://www.wikimedia.org',
        logo_src    => 'https://www.wikimedia.org/static/images/wmf-logo.png',
        logo_srcset => 'https://www.wikimedia.org/static/images/wmf-logo-2x.png 2x',
        logo_width  => '135',
        logo_height => '101',
        logo_alt    => 'Wikimedia',
        # An explanation for these (and more) fields is available here:
        # https://docs.trafficserver.apache.org/en/latest/admin-guide/logging/formatting.en.html
        # Rendered example:
        # Request from 93.184.216.34 via cp1071.eqiad.wmnet, ATS/8.0.3
        # Error: 502, connect failed at 2019-04-04 12:22:08 GMT
        footer      => "<p>If you report this error to the Wikimedia System Administrators, please include the details below.</p><p class='text-muted'><code>Request from %<{X-Client-IP}cqh> via ${::fqdn}, %<{Server}psh><br>Error: %<pssc>, %<prrp> at %<cqtd> %<cqtt> GMT</code></p>",
    }

    $instance_name = 'tls'
    $service_name = "trafficserver-${instance_name}"
    $paths = trafficserver::get_paths(false, $instance_name)
    $tls_lua_script_path = "${paths['sysconfdir']}/lua/tls.lua"
    $tls_material_path = "${paths['sysconfdir']}/tls"
    if !$available_unified_certs[$public_tls_unified_cert_vendor] {
        fail('The specified TLS unified cert vendor is not available')
    }
    $tls_paths = {
        'cert_path'          => $tls_material_path,
        'private_key_path'   => $tls_material_path,
        'ocsp_stapling_path' => $tls_material_path,
    }
    $paths_tls_settings = merge($tls_settings, $tls_paths)

    if !empty($extra_certs) {
        $extra_certs.each |String $extra_cert_name, Trafficserver::TLS_certificate $extra_cert| {
            if $extra_cert['default'] {
                fail("${extra_cert} cannot be the default certificate")
            }
            if !$extra_cert['acme_chief'] {
                fail("${extra_cert} must be an acme-chief managed certificate")
            }
        }
        $available_certs = [$available_unified_certs[$public_tls_unified_cert_vendor]] + values($extra_certs)
    } else {
        $available_certs = [$available_unified_certs[$public_tls_unified_cert_vendor]]
    }
    $inbound_tls_settings = merge($paths_tls_settings, {'certificates' => $available_certs})
    if $inbound_tls_settings['do_ocsp'] == 1 and empty($inbound_tls_settings['ocsp_stapling_path']) {
        fail('The provided Inbound TLS settings are insufficient to ensure prefetched OCSP stapling responses')
    }
    $inbound_tls_settings['certificates'].each |Trafficserver::TLS_certificate $certificate| {
        if $inbound_tls_settings['do_ocsp'] == 1 and empty($certificate['ocsp_stapling_files']) {
            fail('The provided Inbound TLS settings are insufficient to ensure prefetched OCSP stapling responses')
        }
    }

    if $inbound_tls_settings['session_ticket_enable'] == 1 and empty($inbound_tls_settings['session_ticket_filename']) {
        fail('Invalid TLS session ticket settings. Please provide a ticket filename')
    }

    $websocket_arg = bool2str($websocket_support)
    if !empty($http_settings) and $http_settings['keep_alive_enabled_out'] == 1 {
        $keepalive_arg = 'true'  # lint:ignore:quoted_booleans
    } else {
        $keepalive_arg = 'false' # lint:ignore:quoted_booleans
    }

    # Write configuration file for global TLS Lua script
    # TODO: Remove entirely on a following commit
    file { "${tls_lua_script_path}.conf":
        ensure  => absent,
        owner   => root,
        group   => root,
        mode    => '0444',
        content => "lua_websocket_support = ${websocket_arg}\nlua_keepalive_support = ${keepalive_arg}\n",
        notify  => Service[$service_name],
    }

    file { '/usr/local/lib/nagios/plugins/check_tls_lua_conf':
        ensure  => absent,
        owner   => root,
        group   => root,
        mode    => '0555',
        content => "#!/usr/bin/lua\ndofile('${tls_lua_script_path}.conf')\nassert(lua_websocket_support ~= nil)\nprint('OK')\n",
        require => File["${tls_lua_script_path}.conf"],
    }

    nrpe::monitor_service { 'tls_lua_conf':
        ensure       => absent,
        description  => 'TLS Lua configuration file',
        nrpe_command => '/usr/local/lib/nagios/plugins/check_tls_lua_conf',
        require      => File['/usr/local/lib/nagios/plugins/check_tls_lua_conf'],
        notes_url    => 'https://wikitech.wikimedia.org/wiki/ATS',
    }

    systemd::tmpfile { "trafficserver_${instance_name}_secrets_tmpfile":
        content => "d ${paths['secretsdir']} 0700 root root -",
    }

    profile::trafficserver::tls_material { 'unified':
        instance_name      => $instance_name,
        service_name       => $service_name,
        tls_material_path  => $tls_material_path,
        ssl_multicert_path => $paths['ssl_multicert'],
        certs              => $unified_certs,
        acme_chief         => $unified_acme_chief,
        do_ocsp            => num2bool($inbound_tls_settings['do_ocsp']),
        ocsp_proxy         => $ocsp_proxy,
        secrets_fullpath   => $paths['secretsdir'],
    }

    if !empty($extra_certs) {
        $extra_certs_names = keys($extra_certs)

        profile::trafficserver::tls_material { $extra_certs_names:
            instance_name      => $instance_name,
            service_name       => $service_name,
            tls_material_path  => $tls_material_path,
            ssl_multicert_path => $paths['ssl_multicert'],
            acme_chief         => true,
            do_ocsp            => num2bool($inbound_tls_settings['do_ocsp']),
            ocsp_proxy         => $ocsp_proxy,
        }
    }

    if $inbound_tls_settings['session_ticket_enable'] == 1 {
        $ensure_stek = present
        require_package('python3-pystemd')
    } else {
        $ensure_stek = absent
    }

    file { '/usr/local/sbin/ats-stek-manager':
        ensure => $ensure_stek,
        source => 'puppet:///modules/profile/trafficserver/ats_stek_manager.py',
        owner  => root,
        group  => root,
        mode   => '0544',
    }

    systemd::timer::job { "trafficserver_${instance_name}_stek_job":
        ensure      => $ensure_stek,
        description => "trafficserver-${instance_name} STEK manager",
        command     => "/usr/local/sbin/ats-stek-manager ${paths['stekfile']}",
        interval    => [
            {
            'start'    => 'OnCalendar',
            'interval' => '*-*-* 00/8:00:00', # every 8 hours
            },
            {
            'start'    => 'OnBootSec',
            'interval' => '0sec',
            },
        ],
        user        => 'root',
        require     => File['/usr/local/sbin/ats-stek-manager'],
    }

    trafficserver::instance { $instance_name:
        paths                  => $paths,
        conftool_service       => $conftool_service,
        port                   => $port,
        disable_dns_resolution => 1,
        network_settings       => $network_settings,
        http_settings          => $http_settings,
        h2_settings            => $h2_settings,
        inbound_tls_settings   => $inbound_tls_settings,
        enable_xdebug          => $enable_xdebug,
        mapping_rules          => $mapping_rules,
        global_lua_script      => $tls_lua_script_path,
        enable_caching         => false,
        log_formats            => $log_formats,
        log_filters            => $log_filters,
        logs                   => $logs,
        parent_rules           => $parent_rules,
        error_page             => template('mediawiki/errorpage.html.erb'),
        x_forwarded_for        => 1,
        systemd_hardening      => $systemd_hardening,
        res_track_memory       => $res_track_memory,
    }

    trafficserver::lua_script { 'tls':
        source        => 'puppet:///modules/profile/trafficserver/tls.lua',
        unit_test     => 'puppet:///modules/profile/trafficserver/tls_test.lua',
        service_name  => $service_name,
        config_prefix => $paths['sysconfdir'],
    }

    # Monitoring
    profile::trafficserver::monitoring { "trafficserver_${instance_name}_monitoring":
        paths                    => $paths,
        port                     => $port,
        prometheus_exporter_port => $prometheus_exporter_port,
        inbound_tls              => $inbound_tls_settings,
        instance_name            => $instance_name,
        acme_chief               => $unified_acme_chief,
        disable_config_check     => true,
        user                     => $user,
    }

    profile::trafficserver::logs { "trafficserver_${instance_name}_logs":
        instance_name    => $instance_name,
        user             => $user,
        service_name     => $service_name,
        conftool_service => $conftool_service,
        logs             => $logs,
        paths            => $paths,
        atslog_filename  => 'analytics',
    }

    profile::trafficserver::atsmtail { "trafficserver_${instance_name}_atsmtail":
        instance_name  => $instance_name,
        atsmtail_progs => $atsmtail_progs,
        atsmtail_port  => $atsmtail_port,
        wanted_by      => "${service_name}.service",
    }

    mtail::program { 'atstls':
        source      => 'puppet:///modules/mtail/programs/atstls.mtail',
        destination => $atsmtail_progs,
        notify      => Service["atsmtail@${instance_name}"],
    }
}