]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/frontend.rb
web: Add security.txt
[chef.git] / cookbooks / web / recipes / frontend.rb
1 #
2 # Cookbook:: web
3 # Recipe:: frontend
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 node.default[:memcached][:ip_address] = node.internal_ipaddress || "127.0.0.1"
21
22 include_recipe "memcached"
23 include_recipe "apache"
24 include_recipe "fail2ban"
25 include_recipe "web::rails"
26 include_recipe "web::cgimap"
27
28 web_passwords = data_bag_item("web", "passwords")
29
30 apache_module "alias"
31 apache_module "expires"
32 apache_module "headers"
33 apache_module "proxy"
34 apache_module "proxy_fcgi"
35 apache_module "lbmethod_byrequests"
36 apache_module "lbmethod_bybusyness"
37 apache_module "remoteip"
38 apache_module "reqtimeout"
39 apache_module "rewrite"
40 apache_module "unique_id"
41
42 apache_site "default" do
43   action [:disable]
44 end
45
46 remote_directory "#{node[:web][:base_directory]}/static" do
47   source "static"
48   owner "root"
49   group "root"
50   mode "755"
51   files_owner "root"
52   files_group "root"
53   files_mode "644"
54 end
55
56 template "#{node[:web][:base_directory]}/static/.well-known/security.txt" do
57   source "security.txt.erb"
58   owner "root"
59   group "root"
60   mode "644"
61 end
62
63 remote_file "#{Chef::Config[:file_cache_path]}/cloudflare-ipv4-list" do
64   source "https://www.cloudflare.com/ips-v4"
65   compile_time true
66   ignore_failure true
67 end
68
69 cloudflare_ipv4 = IO.read("#{Chef::Config[:file_cache_path]}/cloudflare-ipv4-list").lines.map(&:chomp)
70
71 remote_file "#{Chef::Config[:file_cache_path]}/cloudflare-ipv6-list" do
72   source "https://www.cloudflare.com/ips-v6"
73   compile_time true
74   ignore_failure true
75 end
76
77 cloudflare_ipv6 = IO.read("#{Chef::Config[:file_cache_path]}/cloudflare-ipv6-list").lines.map(&:chomp)
78
79 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
80   source "https://api.fastly.com/public-ip-list"
81   compile_time true
82   ignore_failure true
83 end
84
85 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
86
87 apache_site "www.openstreetmap.org" do
88   template "apache.frontend.erb"
89   variables :cloudflare => cloudflare_ipv4 + cloudflare_ipv6,
90             :fastly => fastlyips["addresses"] + fastlyips["ipv6_addresses"],
91             :status => node[:web][:status],
92             :secret_key_base => web_passwords["secret_key_base"]
93 end
94
95 template "/etc/logrotate.d/apache2" do
96   source "logrotate.apache.erb"
97   owner "root"
98   group "root"
99   mode "644"
100 end
101
102 fail2ban_filter "apache-request-timeout" do
103   failregex '^<ADDR> .* "-" 408 .*$'
104 end
105
106 fail2ban_jail "apache-request-timeout" do
107   filter "apache-request-timeout"
108   logpath "/var/log/apache2/access.log"
109   ports [80, 443]
110 end
111
112 fail2ban_filter "apache-trackpoints-timeout" do
113   failregex '^<ADDR> .* "GET /api/0\.6/trackpoints\?.*" 408 .*$'
114 end
115
116 fail2ban_jail "apache-trackpoints-timeout" do
117   filter "apache-trackpoints-timeout"
118   logpath "/var/log/apache2/access.log"
119   ports [80, 443]
120   bantime "12h"
121   findtime "30m"
122 end
123
124 fail2ban_filter "apache-notes-search" do
125   failregex '^<ADDR> .* "GET /api/0\.6/notes/search\?q=abcde&.*$'
126 end
127
128 fail2ban_jail "apache-notes-search" do
129   filter "apache-notes-search"
130   logpath "/var/log/apache2/access.log"
131   ports [80, 443]
132 end
133
134 if %w[database_offline database_readonly].include?(node[:web][:status])
135   service "rails-jobs@mailers" do
136     action :stop
137   end
138
139   service "rails-jobs@storage" do
140     action :stop
141   end
142
143   service "rails-jobs@traces" do
144     action :stop
145   end
146 else
147   service "rails-jobs@mailers" do
148     action [:enable, :start]
149     supports :restart => true
150     subscribes :restart, "rails_port[www.openstreetmap.org]"
151     subscribes :restart, "systemd_service[rails-jobs@]"
152   end
153
154   service "rails-jobs@storage" do
155     action [:enable, :start]
156     supports :restart => true
157     subscribes :restart, "rails_port[www.openstreetmap.org]"
158     subscribes :restart, "systemd_service[rails-jobs@]"
159   end
160
161   service "rails-jobs@traces" do
162     action [:enable, :start]
163     supports :restart => true
164     subscribes :restart, "rails_port[www.openstreetmap.org]"
165     subscribes :restart, "systemd_service[rails-jobs@]"
166   end
167 end
168
169 template "/usr/local/bin/deliver-message" do
170   source "deliver-message.erb"
171   owner "rails"
172   group "rails"
173   mode "0700"
174   variables :secret_key_base => web_passwords["secret_key_base"]
175 end