Elffuss BraidHub

utopia-ia/elffuss-code public

main · 3.3 KiBRawPermalink
1# nginx for the level 2 extension sandbox of Elffuss Code, on x2.utopiaia.com:
2# another registrable domain than code.elffuss.com (web/js/ext2/config.js and
3# sandbox/x2/headers.json name this origin; deploy-sandbox.sh refuses any
4# other). Its folder is /var/www/x2.utopiaia.com, the one deploy-sandbox.sh
5# fills, owned by the user that deploys. Generate the two header snippets with
6#
7# node sandbox/x2/headers.mjs --nginx
8#
9# and save them as /etc/nginx/snippets/x2-sandbox.conf and x2-exthost.conf.
10# Order (README, "Extensions that run code"): main's deploy.sh protecting
11# vendor/x2/ first (deploy-vendor.sh refuses until it does), x2.utopiaia.com
12# resolving to the server that serves Code and its certificate, this vhost
13# and Code's vendor location (at the end of this file), nginx -t and reload,
14# deploy-sandbox.sh, deploy-vendor.sh, and deploy.sh last: it publishes
15# config.js naming this sandbox, and refuses while the server lacks the bundle
16# the manifest names.
17
18server {
19 listen 443 ssl; # http2 is per socket: set it where the other vhosts on :443 do
20 server_name x2.utopiaia.com;
21 ssl_certificate /etc/letsencrypt/live/x2.utopiaia.com/fullchain.pem;
22 ssl_certificate_key /etc/letsencrypt/live/x2.utopiaia.com/privkey.pem;
23 root /var/www/x2.utopiaia.com;
24 # its own log, with the address truncated (log_format elffuss_anon of the
25 # server's conf.d/elffuss-zones.conf): no record of who loaded it
26 access_log /var/log/nginx/x2.utopiaia.com.access.log elffuss_anon;
27 error_log /var/log/nginx/x2.utopiaia.com.error.log;
28 autoindex off;
29 server_tokens off;
30
31 # the sandbox document: only with no query string at all
32 location = /x2/v1/sandbox.html {
33 if ($args != "") { return 404; }
34 include snippets/x2-sandbox.conf;
35 try_files $uri =404;
36 }
37
38 # the extension-host document: only the exact query the library builds
39 location = /x2/v1/exthost-iframe.html {
40 if ($args !~ "^parentOrigin=https%3A%2F%2Fx2\.utopiaia\.com&vscodeWebWorkerExtHostId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") { return 404; }
41 include snippets/x2-exthost.conf;
42 try_files $uri =404;
43 }
44
45 # nothing else exists on this host
46 location / { return 404; }
47}
48
49server {
50 listen 80;
51 server_name x2.utopiaia.com;
52 access_log /var/log/nginx/x2.utopiaia.com.access.log elffuss_anon;
53 # in a location, not at server level: a server-level return runs before
54 # certbot's nginx authenticator gets to answer the HTTP-01 challenge, and the
55 # certificate would stop renewing
56 location / { return 301 https://$host$request_uri; }
57}
58
59# In the server block of Code (code.elffuss.com), for the verified vendor
60# bundle that deploy-vendor.sh uploads (never compressed again on the way, so
61# the browser checks the exact bytes of the manifest):
62#
63# location ^~ /vendor/x2/ {
64# default_type application/octet-stream;
65# gzip off;
66# add_header Cache-Control "public, max-age=31536000, immutable";
67# add_header X-Content-Type-Options nosniff always;
68# }
69#
70# No `always` on Cache-Control: nginx then adds it only to successful
71# responses. With `always`, a 404 for a build that is not there yet would be
72# cached as immutable for a year, and since the buildId is a content hash,
73# uploading the same bytes later would not help those browsers.
74#
75# Code's host must never serve /x2/ (the sandbox documents live outside web/,
76# so deploy.sh never uploads them).