18676: move length check for AnonymousUserToken to lib/config, bring it
[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":#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 access to files stored in Keep using WebDAV and S3 protocols.  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":https://pkg.go.dev/git.arvados.org/arvados.git/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 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 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 <notextile>
43 <pre><code>    Services:
44       WebDAVDownload:
45         ExternalURL: https://<span class="userinput">download.ClusterID.example.com</span>
46 </code></pre>
47 </notextile>
48
49 h3. Collections preview URL
50
51 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.  When wildcard domains configured, credentials are still required to access non-public data.
52
53 h4. In their own subdomain
54
55 Collections can be served from their own subdomain:
56
57 <notextile>
58 <pre><code>    Services:
59       WebDAV:
60         ExternalURL: https://<span class="userinput">*.collections.ClusterID.example.com/</span>
61 </code></pre>
62 </notextile>
63
64 This option is preferred if you plan to access Keep using third-party S3 client software, because it accommodates S3 virtual host-style requests and path-style requests without any special client configuration.
65
66 h4. Under the main domain
67
68 Alternately, they can go under the main domain by including @--@:
69
70 <notextile>
71 <pre><code>    Services:
72       WebDAV:
73         ExternalURL: https://<span class="userinput">*--collections.ClusterID.example.com/</span>
74 </code></pre>
75 </notextile>
76
77 h4. From a single domain
78
79 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 (data accessible by the anonymous user) and collection-sharing links (where the token is already embedded in the URL); it will ignore authorization headers, so a request for non-public data may return "404 Not Found" even if normally valid credentials were provided.
80
81 <notextile>
82 <pre><code>    Services:
83       WebDAV:
84         ExternalURL: https://<span class="userinput">collections.ClusterID.example.com/</span>
85 </code></pre>
86 </notextile>
87
88 Note the trailing slash.
89
90 {% include 'notebox_begin' %}
91 Whether you choose to serve collections from their own subdomain or from a single domain, it's important to keep in mind that they should be served from me same _site_ as Workbench for the inline previews to work.
92
93 Please check "keep-web's URL pattern guide":../api/keep-web-urls.html#same-site to learn more.
94 {% include 'notebox_end' %}
95
96 h2. Set InternalURLs
97
98 <notextile>
99 <pre><code>    Services:
100       WebDAV:
101         InternalURLs:
102           http://<span class="userinput">localhost:9002</span>: {}
103 </code></pre>
104 </notextile>
105
106 h2(#update-config). Configure anonymous user token
107
108 If you intend to use Keep-web to serve public data to anonymous clients, configure it with an anonymous token.
109
110 Generate a random string (>= 32 characters long) and put it in the @config.yml@ file, in the @AnonymousUserToken@ field.
111
112 <notextile>
113 <pre><code>    Users:
114       AnonymousUserToken: <span class="userinput">"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"</span>
115 </code></pre>
116 </notextile>
117
118 Set @Users.AnonymousUserToken: ""@ (empty string) or leave it out if you do not want to serve public data.
119
120 h3. Update nginx configuration
121
122 Put a reverse proxy with SSL support in front of keep-web.  Keep-web itself runs on the port 9002 (or whatever is specified in @Services.WebDAV.InternalURL@) while the reverse proxy runs on port 443 and forwards requests to Keep-web.
123
124 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 in <span class="userinput">red</span>.
125
126 <notextile><pre>
127 upstream keep-web {
128   server                127.0.0.1:<span class="userinput">9002</span>;
129 }
130
131 server {
132   listen                443 ssl;
133   server_name           <span class="userinput">download.ClusterID.example.com</span>
134                         <span class="userinput">collections.ClusterID.example.com</span>
135                         <span class="userinput">*.collections.ClusterID.example.com</span>
136                         <span class="userinput">~.*--collections.ClusterID.example.com</span>;
137
138   proxy_connect_timeout 90s;
139   proxy_read_timeout    300s;
140
141   ssl                   on;
142   ssl_certificate       <span class="userinput">/YOUR/PATH/TO/cert.pem</span>;
143   ssl_certificate_key   <span class="userinput">/YOUR/PATH/TO/cert.key</span>;
144
145   location / {
146     proxy_pass          http://keep-web;
147     proxy_set_header    Host            $host;
148     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
149
150     client_max_body_size    0;
151     proxy_http_version      1.1;
152     proxy_request_buffering off;
153     proxy_max_temp_file_size 0;
154   }
155 }
156 </pre></notextile>
157
158 {% include 'notebox_begin' %}
159 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.
160
161 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.
162
163 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="
164 {% include 'notebox_end' %}
165
166 {% assign arvados_component = 'keep-web' %}
167
168 {% include 'install_packages' %}
169
170 {% include 'start_service' %}
171
172 {% include 'restart_api' %}
173
174 h2(#confirm-working). Confirm working installation
175
176 <notextile><code><pre>
177 $ curl -H "Authorization: Bearer $system_root_token" https://<span class="userinput">download.ClusterID.example.com</span>/c=59389a8f9ee9d399be35462a0f92541c-53/_/hello.txt
178 </code></pre></notextile>
179
180 If wildcard collections domains are configured:
181
182 <notextile><code><pre>
183 $ curl -H "Authorization: Bearer $system_root_token" https://<span class="userinput">59389a8f9ee9d399be35462a0f92541c-53.collections.ClusterID.example.com</span>/hello.txt
184 </code></pre></notextile>
185
186 If using a single collections preview domain:
187
188 <notextile><code><pre>
189 $ curl https://<span class="userinput">collections.ClusterID.example.com</span>/c=59389a8f9ee9d399be35462a0f92541c-53/t=$system_root_token/_/hello.txt
190 </code></pre></notextile>