Puppet Class: dynamicproxy

Defined in:
modules/dynamicproxy/manifests/init.pp

Overview

Parameters:

  • k8s_vip_fqdn (Optional[Stdlib::Fqdn]) (defaults to: undef)
  • k8s_vip_fqdn_port (Optional[Stdlib::Port]) (defaults to: undef)
  • luahandler (Any)
  • redis_maxmemory (Any) (defaults to: '512MB')
  • ssl_settings (Any) (defaults to: undef)
  • ssl_certificate_name (Any) (defaults to: false)
  • notfound_servers (Any) (defaults to: [])
  • redis_replication (Any) (defaults to: undef)
  • error_enabled (Any) (defaults to: false)
  • error_config (Any) (defaults to: { title => 'Wikimedia Cloud Services Error', logo => '/.error/wmcs-logo.png', logo_2x => '/.error/wmcs-logo-2x.png', logo_width => 120, logo_height => 137, logo_alt => 'Wikimedia Cloud Services', logo_link => 'https://wikitech.wikimedia.org/wiki/Portal:Cloud_VPS', favicon => 'https://wikitech.wikimedia.org/static/favicon/wikitech.ico', })
  • error_description (Any) (defaults to: 'Our servers are currently experiencing a technical problem. This is probably temporary and should be fixed soon. Please try again later.')
  • error_details (Any) (defaults to: undef)
  • banned_ips (Any) (defaults to: [])
  • banned_description (Any) (defaults to: 'You have been banned from accessing this service.')
  • noproxy_description (Any) (defaults to: 'No proxy is configured for this host name. Please see <a href="https://wikitech.wikimedia.org/wiki/Help:Proxy">our documentation on Wikitech</a> for more information on configuring a proxy.')
  • web_domain (Any) (defaults to: undef)
  • blocked_user_agent_regex (Any) (defaults to: 'TweetmemeBot')
  • blocked_referer_regex (Any) (defaults to: '')
  • https_upgrade (Any) (defaults to: false)
  • use_acme_chief (Boolean) (defaults to: false)
  • xff_fqdns (Optional[Array[Stdlib::Fqdn]]) (defaults to: undef)


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
# File 'modules/dynamicproxy/manifests/init.pp', line 15

class dynamicproxy (
    Optional[Stdlib::Fqdn] $k8s_vip_fqdn = undef,
    Optional[Stdlib::Port] $k8s_vip_fqdn_port = undef,
    $luahandler,
    $redis_maxmemory          = '512MB',
    $ssl_settings             = undef,
    $ssl_certificate_name     = false,
    $notfound_servers         = [],
    $redis_replication        = undef,
    $error_enabled            = false,
    $error_config             = {
        title       => 'Wikimedia Cloud Services Error',
        logo        => '/.error/wmcs-logo.png',
        logo_2x     => '/.error/wmcs-logo-2x.png',
        logo_width  => 120,
        logo_height => 137,
        logo_alt    => 'Wikimedia Cloud Services',
        logo_link   => 'https://wikitech.wikimedia.org/wiki/Portal:Cloud_VPS',
        favicon     => 'https://wikitech.wikimedia.org/static/favicon/wikitech.ico',
    },
    $error_description        = 'Our servers are currently experiencing a technical problem. This is probably temporary and should be fixed soon. Please try again later.',
    $error_details            = undef,
    $banned_ips               = [],
    $banned_description       = 'You have been banned from accessing this service.',
    $noproxy_description      = 'No proxy is configured for this host name.
    Please see <a href="https://wikitech.wikimedia.org/wiki/Help:Proxy">our documentation on Wikitech</a> for more information on configuring a proxy.',
    $web_domain               = undef,
    $blocked_user_agent_regex = 'TweetmemeBot', # T73120 - misbehaving crawler
    $blocked_referer_regex    = '',
    $https_upgrade            = false,
    Boolean $use_acme_chief   = false,
    Optional[Array[Stdlib::Fqdn]] $xff_fqdns = undef,
) {
    if $ssl_certificate_name != false and $ssl_settings == undef {
        fail('ssl_certificate_name set but ssl_settings not set')
    }

    $resolver = join($::nameservers, ' ')

    $redis_port = '6379'
    if $redis_replication and $redis_replication[$::hostname] {
        $slave_host = $redis_replication[$::hostname]
        $slaveof = "${slave_host} ${redis_port}"
    }

    redis::instance { $redis_port:
        settings => {
            # Protected by iptables  / ferm rules from elsewhere
            # We need to allow this so we can replicate
            bind           => '0.0.0.0',
            appendonly     => 'yes',
            appendfilename => "${::hostname}-${redis_port}.aof",
            maxmemory      => $redis_maxmemory,
            slaveof        => $slaveof,
            dir            => '/var/lib/redis',
        },
    }

    class { '::nginx':
        variant => 'extras',
    }

    # For logrotate to work on both timing and size, it must run hourly
    logrotate::conf { 'nginx':
        ensure => present,
        source => 'puppet:///modules/dynamicproxy/logrotate',
    }

    file { '/etc/cron.daily/logrotate':
        ensure => absent,
    }

    file {'/etc/cron.hourly/logrotate':
        ensure => file,
        source => 'puppet:///modules/dynamicproxy/logrotate.cron',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { '/etc/nginx/nginx.conf':
        ensure  => file,
        content => template('dynamicproxy/nginx.conf'),
        require => Package['nginx-common'],
        notify  => Service['nginx'],
    }

    file { [
        '/var/www/',
        '/var/www/error',
    ]:
        ensure => directory,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0444',
    }

    file { '/var/www/error/wmcs-logo.png':
        ensure => file,
        source => 'puppet:///modules/dynamicproxy/wmcs-logo.png',
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0444',
    }

    file { '/var/www/error/wmcs-logo-2x.png':
        ensure => file,
        source => 'puppet:///modules/dynamicproxy/wmcs-logo-2x.png',
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0444',
    }

    # Clean up legacy logo files. Can be removed after files have been purged.
    file { '/var/www/error/labs-logo.png':
        ensure => absent,
    }
    file { '/var/www/error/labs-logo-2x.png':
        ensure => absent,
    }

    mediawiki::errorpage { '/var/www/error/errorpage.html':
        favicon     => $error_config['favicon'],
        pagetitle   => $error_config['title'],
        logo_src    => $error_config['logo'],
        logo_srcset => "${error_config['logo_2x']} 2x",
        logo_width  => $error_config['logo_width'],
        logo_height => $error_config['logo_height'],
        logo_alt    => $error_config['logo_alt'],
        logo_link   => $error_config['logo_link'],
        content     => "<p>${error_description}</p>",
        footer      => $error_details,
        owner       => 'www-data',
        group       => 'www-data',
        mode        => '0444',
    }

    mediawiki::errorpage { '/var/www/error/banned.html':
        favicon     => $error_config['favicon'],
        pagetitle   => $error_config['title'],
        logo_src    => $error_config['logo'],
        logo_srcset => "${error_config['logo_2x']} 2x",
        logo_width  => $error_config['logo_width'],
        logo_height => $error_config['logo_height'],
        logo_alt    => $error_config['logo_alt'],
        logo_link   => $error_config['logo_link'],
        content     => "<p>${banned_description}</p>",
        owner       => 'www-data',
        group       => 'www-data',
        mode        => '0444',
    }

    mediawiki::errorpage { '/var/www/error/noproxy.html':
        favicon     => $error_config['favicon'],
        pagetitle   => $error_config['title'],
        logo_src    => $error_config['logo'],
        logo_srcset => "${error_config['logo_2x']} 2x",
        logo_width  => $error_config['logo_width'],
        logo_height => $error_config['logo_height'],
        logo_alt    => $error_config['logo_alt'],
        logo_link   => $error_config['logo_link'],
        content     => "<p>${noproxy_description}</p>",
        owner       => 'www-data',
        group       => 'www-data',
        mode        => '0444',
    }

    file { '/etc/security/limits.conf':
        ensure  => file,
        source  => 'puppet:///modules/dynamicproxy/limits.conf',
        require => Package['nginx-common'],
        notify  => Service['nginx'],
    }

    nginx::site { 'proxy':
        content => template("dynamicproxy/${luahandler}.conf"),
    }

    file { '/etc/nginx/lua':
        ensure  => directory,
        require => Package['nginx-extras'],
    }

    file { "/etc/nginx/lua/${luahandler}.lua":
        ensure  => file,
        source  => "puppet:///modules/dynamicproxy/${luahandler}.lua",
        require => File['/etc/nginx/lua'],
        notify  => Service['nginx'],
    }

    if $luahandler == 'urlproxy' {
        file { '/etc/nginx/lua/list-proxy-entries.lua':
            ensure  => 'file',
            source  => 'puppet:///modules/dynamicproxy/list-proxy-entries.lua',
            require => [File['/etc/nginx/lua'], Package['lua-json']],
            notify  => Service['nginx'],
        }

        package { 'lua-json':
            ensure => installed,
        }

        nginx::site { 'proxymanager':
            content => template('dynamicproxy/proxymanager.conf.erb'),
            require => File['/etc/nginx/lua/list-proxy-entries.lua'],
        }
    }

    file { '/etc/nginx/lua/resty':
        ensure  => directory,
        require => File['/etc/nginx/lua'],
    }

    file { '/etc/nginx/lua/resty/redis.lua':
        ensure  => file,
        require => File['/etc/nginx/lua/resty'],
        source  => 'puppet:///modules/dynamicproxy/redis.lua',
    }

    # T209709
    nginx::status_site { 'diamond-monitor-proxy': }

    # Also monitor local redis
    include ::redis::client::python
}