Merge branch 'master' into 15572-new-install-docs
[arvados.git] / doc / install / install-keep-web.html.textile.liquid
1 ---
2 layout: default
3 navsection: installguide
4 title: Install Keep-web server
5 ...
6 {% comment %}
7 Copyright (C) The Arvados Authors. All rights reserved.
8
9 SPDX-License-Identifier: CC-BY-SA-3.0
10 {% endcomment %}
11
12 # "Introduction":#introduction
13 # "Configure DNS":#introduction
14 # "Configure anonymous user token.yml":#update-config
15 # "Update nginx configuration":#update-nginx
16 # "Install keep-web package":#install-packages
17 # "Start the service":#start-service
18 # "Restart the API server and controller":#restart-api
19 # "Confirm working installation":#confirm-working
20
21 h2(#introduction). Introduction
22
23 The Keep-web server provides read/write HTTP (WebDAV) access to files stored in Keep.  This makes it easy to access files in Keep from a browser, or mount Keep as a network folder using WebDAV support in various operating systems. It serves public data to unauthenticated clients, and serves private data to clients that supply Arvados API tokens. It can be installed anywhere with access to Keep services, typically behind a web proxy that provides TLS support. See the "godoc page":http://godoc.org/github.com/curoverse/arvados/services/keep-web for more detail.
24
25 h2(#dns). Configure DNS
26
27 It is important to properly configure the keep-web service to so it does not open up cross-site-scripting (XSS) attacks.  A HTML file can be stored in collection.  If an attacker causes a victim to visit that HTML file through Workbench, it will be rendered by the browser.  If all collections are served at the same domain, the browser will consider collections as coming from the same origin and thus have access to the same browsing data (such as API token), enabling malicious Javascript in the HTML file to access Arvados as the victim.
28
29 There are two approaches to mitigate this.
30
31 # The service can tell the browser that all files should go to download instead of in-browser preview, except in situations where an attacker is unlikely to be able to gain access to anything they didn't already have access to.
32 # Each each collection served by @keep-web@ is served on its own virtual host.  This allows for file with executable content to be displayed in-browser securely.  The virtual host embeds the collection uuid or portable data hash in the hostname.  For example, a collection with uuid @xxxxx-4zz18-tci4vn4fa95w0zx@ could be served as @xxxxx-4zz18-tci4vn4fa95w0zx.collections.ClusterID.example.com@ .  The portable data hash @dd755dbc8d49a67f4fe7dc843e4f10a6+54@ could be served at @dd755dbc8d49a67f4fe7dc843e4f10a6-54.collections.ClusterID.example.com@ .  This requires "wildcard DNS record":https://en.wikipedia.org/wiki/Wildcard_DNS_record and "wildcard TLS certificate.":https://en.wikipedia.org/wiki/Wildcard_certificate
33
34 h3. Collections download URL
35
36 Downloads links will served from the the URL in @Services.WebDAVDownload.ExternalURL@ .  The collection uuid or PDH is put in the URL path.
37
38 If blank, serve links to WebDAV with @disposition=attachment@ query param.  Unlike preview links, browsers do not render attachments, so there is no risk of XSS.
39
40 If @WebDAVDownload@ is blank, and @WebDAV@ has a single origin (not wildcard, see below), then Workbench will show an error page
41
42 <pre>
43     Services:
44       WebDAVDownload:
45         ExternalURL: https://download.ClusterID.example.com
46 </pre>
47
48 h3. Collections preview URL
49
50 Collections will be served using the URL pattern in @Services.WebDAV.ExternalURL@ .  If blank, use @Services.WebDAVDownload.ExternalURL@ instead, and disable inline preview.  If both are empty, downloading collections from workbench will be impossible.
51
52 h4. In their own subdomain
53
54 Collections can be served from their own subdomain:
55
56 <pre>
57     Services:
58       WebDAV:
59         ExternalURL: https://*.collections.ClusterID.example.com
60 </pre>
61
62 h4. Under the main domain
63
64 Alternately, they can go under the main domain by including @--@:
65
66 <pre>
67     Services:
68       WebDAV:
69         ExternalURL: https://*--collections.ClusterID.example.com
70 </pre>
71
72 h4. From a single domain
73
74 Serve preview links from a single domain, setting uuid or pdh in the path (similar to downloads).  This configuration only allows previews of public data or collection-sharing links, because these use the anonymous user token or the token is already embedded in the URL.  Authenticated requests will always result in file downloads from @Services.WebDAVDownload.ExternalURL@.
75
76 <pre>
77     Services:
78       WebDAV:
79         ExternalURL: https://collections.ClusterID.example.com
80 </pre>
81
82 h2(#update-config). Configure anonymous user token
83
84 {% assign railscmd = "bundle exec ./script/get_anonymous_user_token.rb --get" %}
85 {% assign railsout = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" %}
86 If you intend to use Keep-web to serve public data to anonymous clients, configure it with an anonymous token. Use the following command on the <strong>API server</strong> to create an anonymous user token. {% include 'install_rails_command' %}
87
88 <notextile>
89 <pre><code>    Users:
90       AnonymousUserToken: "{{railsout}}"
91 </code></pre>
92 </notextile>
93
94 Set @Users.AnonymousUserToken: ""@ (empty string) or leave it out if you do not want to serve public data.
95
96 h2. Set InternalURL
97
98 <pre>
99     Services:
100       WebDAV:
101         InternalURL:
102           "http://collections.ClusterID.example.com:9002": {}
103 </pre>
104
105 h3. Update nginx configuration
106
107 Put a reverse proxy with SSL support in front of keep-web.  Keep-web itself runs on the port 25107 (or whatever is specified in @Services.Keepproxy.InternalURL@) the reverse proxy runs on port 443 and forwards requests to Keepproxy.
108
109 Use a text editor to create a new file @/etc/nginx/conf.d/keep-web.conf@ with the following configuration. Options that need attention are marked with “TODO”.
110
111 <notextile><pre>
112 upstream keep-web {
113   server                127.0.0.1:<span class="userinput">9002</span>;
114 }
115
116 server {
117   listen                <span class="userinput">[TODO: your public IP address]</span>:443 ssl;
118   server_name           download.<span class="userinput">ClusterID</span>.example.com
119                         collections.<span class="userinput">ClusterID</span>.example.com
120                         *.collections.<span class="userinput">ClusterID</span>.example.com
121                         ~.*--collections.<span class="userinput">ClusterID</span>.example.com;
122
123   proxy_connect_timeout 90s;
124   proxy_read_timeout    300s;
125
126   ssl                   on;
127   ssl_certificate       <span class="userinput">/TODO/YOUR/PATH/TO/cert.pem</span>;
128   ssl_certificate_key   <span class="userinput">/TODO/YOUR/PATH/TO/cert.key</span>;
129
130   location / {
131     proxy_pass          http://keep-web;
132     proxy_set_header    Host            $host;
133     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
134
135     client_max_body_size    0;
136     proxy_http_version      1.1;
137     proxy_request_buffering off;
138   }
139 }
140 </pre></notextile>
141
142 {% include 'notebox_begin' %}
143 If you restrict access to your Arvados services based on network topology -- for example, your proxy server is not reachable from the public internet -- additional proxy configuration might be needed to thwart cross-site scripting attacks that would circumvent your restrictions.
144
145 Normally, Keep-web accepts requests for multiple collections using the same host name, provided the client's credentials are not being used. This provides insufficient XSS protection in an installation where the "anonymously accessible" data is not truly public, but merely protected by network topology.
146
147 In such cases -- for example, a site which is not reachable from the internet, where some data is world-readable from Arvados's perspective but is intended to be available only to users within the local network -- the downstream proxy should configured to return 401 for all paths beginning with "/c="
148 {% include 'notebox_end' %}
149
150 h2. Install Keep-web package
151
152 Typically Keep-web runs on the same host as Keepproxy.
153
154 h3. Centos 7
155
156 <notextile>
157 <pre><code># <span class="userinput">yum install keep-web</span>
158 </code></pre>
159 </notextile>
160
161 h3. Debian and Ubuntu
162
163 <notextile>
164 <pre><code># <span class="userinput">apt-get install keep-web</span>
165 </code></pre>
166 </notextile>
167
168 h2(#start-service). Start the service
169
170 If your system uses systemd, the keep-web service should already be set up. Start it and check its status:
171
172 <notextile>
173 <pre><code># <span class="userinput">systemctl restart keep-web</span>
174 # <span class="userinput">systemctl status keep-web</span>
175 &#x25cf; keep-web.service - Arvados Keep web gateway
176    Loaded: loaded (/lib/systemd/system/keep-web.service; enabled)
177    Active: active (running) since Sat 2019-08-10 10:33:21 UTC; 3 days ago
178      Docs: https://doc.arvados.org/
179  Main PID: 4242 (keep-web)
180    CGroup: /system.slice/keep-web.service
181            └─4242 /usr/bin/keep-web
182 [...]
183 </code></pre>
184 </notextile>
185
186 h2(#restart-api). Restart the API server and controller
187
188 After adding WebDAV to the Services section, make sure the cluster config file is up to date on the API server host, and restart the API server and controller processes to ensure the changes are applied.
189
190 <notextile>
191 <pre><code># <span class="userinput">systemctl restart nginx arvados-controller</span>
192 </code></pre>
193 </notextile>
194
195 h2(#confirm-working). Confirm working installation
196
197 Adjust for your configuration.
198
199 <pre>
200 $ curl -H "Authorization: Bearer $system_root_token" https://download.ClusterID.example.com/c=59389a8f9ee9d399be35462a0f92541c-53/_/hello.txt
201 </pre>
202
203 <pre>
204 $ curl -H "Authorization: Bearer $system_root_token" https://collections.ClusterID.example.com/c=59389a8f9ee9d399be35462a0f92541c-53/_/hello.txt
205 </pre>
206
207 <pre>
208 $ curl -H "Authorization: Bearer $system_root_token" https://59389a8f9ee9d399be35462a0f92541c-53.collections.ClusterID.example.com/hello.txt
209 </pre>