9957: Refactor keep-web to load config from a file, with legacy support for command...
[arvados.git] / services / keep-web / doc.go
1 // Keep-web provides read-only HTTP access to files stored in Keep. It
2 // serves public data to anonymous and unauthenticated clients, and
3 // serves private data to clients that supply Arvados API tokens. It
4 // can be installed anywhere with access to Keep services, typically
5 // behind a web proxy that supports TLS.
6 //
7 // See http://doc.arvados.org/install/install-keep-web.html.
8 //
9 // Configuration
10 //
11 // The default configuration file location is
12 // /etc/arvados/keep-web/config.json.
13 //
14 // Example configuration file
15 //
16 //   {
17 //     "Client": {
18 //       "APIHost": "zzzzz.arvadosapi.com:443",
19 //       "AuthToken": "",
20 //       "Insecure": false
21 //     },
22 //     "Listen":":1234",
23 //     "AnonymousTokens":["xxxxxxxxxxxxxxxxxxxx"],
24 //     "AttachmentOnlyHost":"",
25 //     "TrustAllContent":false
26 //   }
27 //
28 // Starting the server
29 //
30 // Start a server using the default config file
31 // /etc/arvados/keep-web/config.json:
32 //
33 //   keep-web
34 //
35 // Start a server using the config file /path/to/config.json:
36 //
37 //   keep-web -config /path/to/config.json
38 //
39 // Proxy configuration
40 //
41 // Keep-web does not support SSL natively. Typically, it is installed
42 // behind a proxy like nginx.
43 //
44 // Here is an example nginx configuration.
45 //
46 //      http {
47 //        upstream keep-web {
48 //          server localhost:1234;
49 //        }
50 //        server {
51 //          listen *:443 ssl;
52 //          server_name collections.example.com *.collections.example.com ~.*--collections.example.com;
53 //          ssl_certificate /root/wildcard.example.com.crt;
54 //          ssl_certificate_key /root/wildcard.example.com.key;
55 //          location  / {
56 //            proxy_pass http://keep-web;
57 //            proxy_set_header Host $host;
58 //            proxy_set_header X-Forwarded-For $remote_addr;
59 //          }
60 //        }
61 //      }
62 //
63 // It is not necessary to run keep-web on the same host as the nginx
64 // proxy. However, TLS is not used between nginx and keep-web, so
65 // intervening networks must be secured by other means.
66 //
67 // Anonymous downloads
68 //
69 // The "AnonymousTokens" configuration entry is an array of tokens to
70 // use when clients try to retrieve files without providing their own
71 // Arvados API token.
72 //
73 //   "AnonymousTokens":["xxxxxxxxxxxxxxxxxxxxxxx"]
74 //
75 // See http://doc.arvados.org/install/install-keep-web.html for examples.
76 //
77 // Download URLs
78 //
79 // The following "same origin" URL patterns are supported for public
80 // collections and collections shared anonymously via secret links
81 // (i.e., collections which can be served by keep-web without making
82 // use of any implicit credentials like cookies). See "Same-origin
83 // URLs" below.
84 //
85 //   http://collections.example.com/c=uuid_or_pdh/path/file.txt
86 //   http://collections.example.com/c=uuid_or_pdh/t=TOKEN/path/file.txt
87 //
88 // The following "multiple origin" URL patterns are supported for all
89 // collections:
90 //
91 //   http://uuid_or_pdh--collections.example.com/path/file.txt
92 //   http://uuid_or_pdh--collections.example.com/t=TOKEN/path/file.txt
93 //
94 // In the "multiple origin" form, the string "--" can be replaced with
95 // "." with identical results (assuming the downstream proxy is
96 // configured accordingly). These two are equivalent:
97 //
98 //   http://uuid_or_pdh--collections.example.com/path/file.txt
99 //   http://uuid_or_pdh.collections.example.com/path/file.txt
100 //
101 // The first form (with "--" instead of ".") avoids the cost and
102 // effort of deploying a wildcard TLS certificate for
103 // *.collections.example.com at sites that already have a wildcard
104 // certificate for *.example.com. The second form is likely to be
105 // easier to configure, and more efficient to run, on a downstream
106 // proxy.
107 //
108 // In all of the above forms, the "collections.example.com" part can
109 // be anything at all: keep-web itself ignores everything after the
110 // first "." or "--". (Of course, in order for clients to connect at
111 // all, DNS and any relevant proxies must be configured accordingly.)
112 //
113 // In all of the above forms, the "uuid_or_pdh" part can be either a
114 // collection UUID or a portable data hash with the "+" character
115 // optionally replaced by "-". (When "uuid_or_pdh" appears in the
116 // domain name, replacing "+" with "-" is mandatory, because "+" is
117 // not a valid character in a domain name.)
118 //
119 // In all of the above forms, a top level directory called "_" is
120 // skipped. In cases where the "path/file.txt" part might start with
121 // "t=" or "c=" or "_/", links should be constructed with a leading
122 // "_/" to ensure the top level directory is not interpreted as a
123 // token or collection ID.
124 //
125 // Assuming there is a collection with UUID
126 // zzzzz-4zz18-znfnqtbbv4spc3w and portable data hash
127 // 1f4b0bc7583c2a7f9102c395f4ffc5e3+45, the following URLs are
128 // interchangeable:
129 //
130 //   http://zzzzz-4zz18-znfnqtbbv4spc3w.collections.example.com/foo/bar.txt
131 //   http://zzzzz-4zz18-znfnqtbbv4spc3w.collections.example.com/_/foo/bar.txt
132 //   http://zzzzz-4zz18-znfnqtbbv4spc3w--collections.example.com/_/foo/bar.txt
133 //   http://1f4b0bc7583c2a7f9102c395f4ffc5e3-45--foo.example.com/foo/bar.txt
134 //   http://1f4b0bc7583c2a7f9102c395f4ffc5e3-45--.invalid/foo/bar.txt
135 //
136 // An additional form is supported specifically to make it more
137 // convenient to maintain support for existing Workbench download
138 // links:
139 //
140 //   http://collections.example.com/collections/download/uuid_or_pdh/TOKEN/foo/bar.txt
141 //
142 // A regular Workbench "download" link is also accepted, but
143 // credentials passed via cookie, header, etc. are ignored. Only
144 // public data can be served this way:
145 //
146 //   http://collections.example.com/collections/uuid_or_pdh/foo/bar.txt
147 //
148 // Authorization mechanisms
149 //
150 // A token can be provided in an Authorization header:
151 //
152 //   Authorization: OAuth2 o07j4px7RlJK4CuMYp7C0LDT4CzR1J1qBE5Avo7eCcUjOTikxK
153 //
154 // A base64-encoded token can be provided in a cookie named "api_token":
155 //
156 //   Cookie: api_token=bzA3ajRweDdSbEpLNEN1TVlwN0MwTERUNEN6UjFKMXFCRTVBdm83ZUNjVWpPVGlreEs=
157 //
158 // A token can be provided in an URL-encoded query string:
159 //
160 //   GET /foo/bar.txt?api_token=o07j4px7RlJK4CuMYp7C0LDT4CzR1J1qBE5Avo7eCcUjOTikxK
161 //
162 // A suitably encoded token can be provided in a POST body if the
163 // request has a content type of application/x-www-form-urlencoded or
164 // multipart/form-data:
165 //
166 //   POST /foo/bar.txt
167 //   Content-Type: application/x-www-form-urlencoded
168 //   [...]
169 //   api_token=o07j4px7RlJK4CuMYp7C0LDT4CzR1J1qBE5Avo7eCcUjOTikxK
170 //
171 // If a token is provided in a query string or in a POST request, the
172 // response is an HTTP 303 redirect to an equivalent GET request, with
173 // the token stripped from the query string and added to a cookie
174 // instead.
175 //
176 // Indexes
177 //
178 // Currently, keep-web does not generate HTML index listings, nor does
179 // it serve a default file like "index.html" when a directory is
180 // requested. These features are likely to be added in future
181 // versions. Until then, keep-web responds with 404 if a directory
182 // name (or any path ending with "/") is requested.
183 //
184 // Compatibility
185 //
186 // Client-provided authorization tokens are ignored if the client does
187 // not provide a Host header.
188 //
189 // In order to use the query string or a POST form authorization
190 // mechanisms, the client must follow 303 redirects; the client must
191 // accept cookies with a 303 response and send those cookies when
192 // performing the redirect; and either the client or an intervening
193 // proxy must resolve a relative URL ("//host/path") if given in a
194 // response Location header.
195 //
196 // Intranet mode
197 //
198 // Normally, Keep-web accepts requests for multiple collections using
199 // the same host name, provided the client's credentials are not being
200 // used. This provides insufficient XSS protection in an installation
201 // where the "anonymously accessible" data is not truly public, but
202 // merely protected by network topology.
203 //
204 // In such cases -- for example, a site which is not reachable from
205 // the internet, where some data is world-readable from Arvados's
206 // perspective but is intended to be available only to users within
207 // the local network -- the downstream proxy should configured to
208 // return 401 for all paths beginning with "/c=".
209 //
210 // Same-origin URLs
211 //
212 // Without the same-origin protection outlined above, a web page
213 // stored in collection X could execute JavaScript code that uses the
214 // current viewer's credentials to download additional data from
215 // collection Y -- data which is accessible to the current viewer, but
216 // not to the author of collection X -- from the same origin
217 // (``https://collections.example.com/'') and upload it to some other
218 // site chosen by the author of collection X.
219 //
220 // Attachment-Only host
221 //
222 // It is possible to serve untrusted content and accept user
223 // credentials at the same origin as long as the content is only
224 // downloaded, never executed by browsers. A single origin (hostname
225 // and port) can be designated as an "attachment-only" origin: cookies
226 // will be accepted and all responses will have a
227 // "Content-Disposition: attachment" header. This behavior is invoked
228 // only when the designated origin matches exactly the Host header
229 // provided by the client or downstream proxy.
230 //
231 //   "AttachmentOnlyHost":"domain.example:9999"
232 //
233 // Trust All Content mode
234 //
235 // In TrustAllContent mode, Keep-web will accept credentials (API
236 // tokens) and serve any collection X at
237 // "https://collections.example.com/c=X/path/file.ext".  This is
238 // UNSAFE except in the special case where everyone who is able write
239 // ANY data to Keep, and every JavaScript and HTML file written to
240 // Keep, is also trusted to read ALL of the data in Keep.
241 //
242 // In such cases you can enable trust-all-content mode.
243 //
244 //   "TrustAllContent":true
245 //
246 // When TrustAllContent is enabled, the only effect of the
247 // AttachmentOnlyHost flag is to add a "Content-Disposition:
248 // attachment" header.
249 //
250 //   "AttachmentOnlyHost":"domain.example:9999",
251 //   "TrustAllContent":true
252 //
253 // Depending on your site configuration, you might also want to enable
254 // the "trust all content" setting in Workbench. Normally, Workbench
255 // avoids redirecting requests to keep-web if they depend on
256 // TrustAllContent being enabled.
257 //
258 package main