port 6081 is redirected
[mirror/dsa-puppet.git] / modules / roles / manifests / snapshot_web.pp
1 class roles::snapshot_web {
2         include apache2
3         include apache2::rewrite
4
5         # snapshot abusers
6         #  61.69.254.110 - 20180705, mirroring with wget
7         # 20180821 large amount of requests way too fast from some amazon AWS instances
8         #  18.185.157.46
9         #  18.194.174.202
10         #  18.184.181.169
11         #  18.184.5.230
12         #  18.194.137.96
13         #  18.197.147.183
14         #  3.120.39.137
15         #  3.120.41.69
16         #  35.158.129.130
17         #  52.59.199.25
18         #  52.59.228.158
19         #  52.59.245.42
20         #  52.59.253.41
21         #  52.59.71.13
22         # 20180821 mirroring
23         #  99.137.191.34
24         # 20181110 crawler
25         #  51.15.215.91
26         @ferm::rule { 'dsa-snapshot-abusers':
27                 prio  => "005",
28                 rule  => "saddr (61.69.254.110 18.128.0.0/9 3.120.0.0/14 35.156.0.0/14 52.58.0.0/15 99.137.191.34 51.15.215.91) DROP",
29         }
30
31         ensure_packages ( [
32                 "libapache2-mod-wsgi",
33                 ], {
34                 ensure => 'installed',
35         })
36
37         apache2::site { '020-snapshot.debian.org':
38                 site   => 'snapshot.debian.org',
39                 content => template('roles/snapshot/snapshot.debian.org.conf.erb')
40         }
41
42         case $::hostname {
43                 'lw07': {
44                         $ipv4addr        = '185.17.185.185'
45                         $ipv6addr        = '2001:1af8:4020:b030:deb::185'
46                         $ipv6addr_apache = '2001:1af8:4020:b030:deb::187'
47                 }
48                 'sallinen': {
49                         $ipv4addr        = '193.62.202.27'
50                         $ipv6addr        = '2001:630:206:4000:1a1a:0:c13e:ca1b'
51                         $ipv6addr_apache = '2001:630:206:4000:1a1a:0:c13e:ca1a'
52                 }
53                 default: {
54                         fail ( "unknown host $::hostname for snapshot_web." )
55                 }
56         }
57
58         @ferm::rule { 'dsa-snapshot-connlimit':
59                 domain => '(ip ip6)',
60                 prio  => "005",
61                 rule  => "proto tcp mod state state (NEW) daddr (${ipv4addr} ${ipv6addr})  mod multiport destination-ports (80 443) mod connlimit connlimit-above 3 DROP;
62                           proto tcp mod state state (NEW)                                                dport 6081                 mod connlimit connlimit-above 3 DROP;
63                            ",
64         }
65
66         # varnish cache
67         ###############
68         @ferm::rule { 'dsa-nat-snapshot-varnish-v4':
69                 table => 'nat',
70                 chain => 'PREROUTING',
71                 rule  => "proto tcp daddr ${ipv4addr} dport 80 REDIRECT to-ports 6081",
72         }
73
74         varnish::config { 'default':
75                 listen  => [
76                         ':6081',
77                         "[$ipv6addr]:80"
78                         ],
79                 backend => 'file,/var/lib/varnish/varnish_storage.bin,8G',
80                 content => template('roles/snapshot/snapshot.debian.org.vcl.erb'),
81         }
82
83         # the ipv6 port 80 is owned by varnish
84         file { '/etc/apache2/ports.conf':
85                 content  => @("EOF"),
86                         Listen 0.0.0.0:80
87                         Listen [$ipv6addr_apache]:80
88                         | EOF
89                 require => Package['apache2'],
90                 notify  => Service['apache2'],
91         }
92
93         # haproxy ssl termination
94         #########################
95         include haproxy
96         file { '/etc/haproxy/haproxy.cfg':
97                 content => template('roles/snapshot/haproxy.cfg.erb'),
98                 require => Package['haproxy'],
99                 notify  => Service['haproxy'],
100         }
101         ssl::service { 'snapshot.debian.org':
102                 notify  => Service['haproxy'],
103                 key => true,
104         }
105 }