Puppet Class: dynamicproxy

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

Overview

Parameters:

  • ssl_settings (Array[String])
  • supported_zones (Hash[String, Dynamicproxy::Zone])
  • redis_primary (Optional[Stdlib::Fqdn])
  • banned_ips (Array[Stdlib::IP::Address])
  • blocked_user_agent_regex (String)
  • blocked_referer_regex (String)
  • xff_fqdns (Array[Stdlib::Fqdn])
  • rate_limit_requests (Integer)
  • redis_maxmemory (String[1]) (defaults to: '512MB')


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

class dynamicproxy (
    Array[String]                    $ssl_settings,
    Hash[String, Dynamicproxy::Zone] $supported_zones,
    Optional[Stdlib::Fqdn]           $redis_primary,
    Array[Stdlib::IP::Address]       $banned_ips,
    String                           $blocked_user_agent_regex,
    String                           $blocked_referer_regex,
    Array[Stdlib::Fqdn]              $xff_fqdns,
    Integer                          $rate_limit_requests,
    String[1]                        $redis_maxmemory = '512MB',
) {
    $acme_certs = $supported_zones.values.map |Dynamicproxy::Zone $zone| { $zone['acmechief_cert'] }.unique

    acme_chief::cert { $acme_certs:
        puppet_rsc => Exec['nginx-reload'],
    }

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

    $redis_port = '6379'
    if $redis_primary and !($redis_primary in [$::facts['hostname'], $::facts['fqdn']]) {
        $slaveof = "${redis_primary} ${redis_port}"
    } else {
        $slaveof = undef
    }

    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',
        },
    }

    # Monitoring!
    prometheus::redis_exporter { '6379': }

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

    logrotate::conf { 'nginx':
        ensure => present,
        source => 'puppet:///modules/dynamicproxy/logrotate',
    }

    systemd::timer::job { 'dynamicproxy_logrotate':
        ensure      => present,
        description => 'Logrotation for Dynamic Proxy',
        user        => 'root',
        command     => '/usr/sbin/logrotate /etc/logrotate.conf',
        interval    => {'start' => 'OnCalendar', 'interval' => '*-*-* 00/1:00:00'}
    }

    file { '/etc/nginx/nginx.conf':
        ensure  => file,
        content => template('dynamicproxy/nginx.conf.erb'),
        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',
    }

    mediawiki::errorpage {
        default:
            favicon     => 'https://wikitech.wikimedia.org/static/favicon/wikitech.ico',
            pagetitle   => 'Wikimedia Cloud Services Error',
            logo_src    => '/.error/wmcs-logo.png',
            logo_srcset => '/.error/wmcs-logo-2x.png 2x',
            logo_width  => 120,
            logo_height => 137,
            logo_alt    => 'Wikimedia Cloud Services',
            logo_link   => 'https://wikitech.wikimedia.org/wiki/Portal:Cloud_VPS',
            footer      => "<p>${::facts['networking']['fqdn']}</p>",
            owner       => 'www-data',
            group       => 'www-data',
            mode        => '0444';

        '/var/www/error/errorpage.html':
            content => '<p>Our servers are currently experiencing a technical problem. This is probably temporary and should be fixed soon. Please try again later.</p>';
        '/var/www/error/banned.html':
            content => '<p>You have been banned from accessing this service.</p>';
        '/var/www/error/noproxy.html':
            content => '<p>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.</p>';
        '/var/www/error/ratelimit.html':
            content => '<p>You are trying to access this service too fast.</p>';
        '/var/www/error/unreachable.html':
            content => '<p>This web service cannot be reached. Please contact a maintainer of this project.</p><p>Maintainers can find troubleshooting instructions from <a href="https://wikitech.wikimedia.org/wiki/Help:Proxy">our documentation on Wikitech</a>.</p>';
    }

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

    $supported_zones.each |String[1] $name, Dynamicproxy::Zone $zone| {
        $fqdn = $name.regsubst('(.+)\.', '\\1')
        nginx::site { $fqdn:
            content => template('dynamicproxy/nginx-site.conf.erb'),
        }
    }

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

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

    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',
    }
}