Elffuss BraidHub

utopia-ia/elffuss-code public

deploy-sandbox.sh: leave the sandbox folder readable by the web server

mktemp -d makes the staging folder 700 and rsync -a carried that mode onto
x2/v1/ on the server, so nginx could not enter it and both documents were
404 with 'Permission denied'. The stage is now 755 with 644 documents, and
step 3 checks the modes on the server. x2_deploy's fake rsync copies modes
like the real one, and D6 asserts 755/644 (it fails on the previous script).

nginx.conf.example follows the live vhost: its own access log with the
truncated address (elffuss_anon), and the port 80 redirect inside a location
so certbot's nginx authenticator can still renew over HTTP-01.
Changesetda97708d0aaf8f500d87bc0ded79bbb08a79324110be9879b1bb1a6ae7cf3b8b
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-12 12:40 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-12 12:40 +02:00
Parentsc8095cfbfb2b

Browse the files at this changeset

3 files changed

modified deploy-sandbox.sh +12 −1
@@ -46,7 +46,11 @@
4646 DOCS=(sandbox.html exthost-iframe.html)
4747 STAGE=$(mktemp -d)
4848 trap 'rm -rf "$STAGE"' EXIT
49-for f in "${DOCS[@]}"; do cp "sandbox/x2/v1/$f" "$STAGE/$f"; done
49+# mktemp -d crea la carpeta con 700 y rsync -a copia ese modo a x2/v1/ del
50+# servidor: nginx (otro usuario) no podría ni entrar y los dos documentos
51+# darían 404 con «Permission denied» en el log de errores
52+chmod 755 "$STAGE"
53+for f in "${DOCS[@]}"; do cp "sandbox/x2/v1/$f" "$STAGE/$f"; chmod 644 "$STAGE/$f"; done
5054 ssh -i "$KEY" "$HOST" "mkdir -p '$DEST/x2/v1'"
5155 rsync -a --delete -e "ssh -i $KEY" "$STAGE/" "$HOST:$DEST/x2/v1/"
5256
@@ -58,4 +62,11 @@
5862 diff <(printf '%s\n' "$EXPECTED") <(printf '%s\n' "$REMOTE") >&2 || true
5963 exit 1
6064 fi
65+# y que el servidor web los pueda leer: la carpeta 755 y los documentos 644
66+MODES=$(ssh -i "$KEY" "$HOST" "cd '$DEST/x2/v1' && stat -c '%a %n' . ${DOCS[*]}")
67+if [ "$MODES" != "$(printf '755 .\n644 sandbox.html\n644 exthost-iframe.html')" ]; then
68+ echo "✗ permisos en el servidor (se esperaba 755 la carpeta y 644 los documentos):" >&2
69+ printf '%s\n' "$MODES" >&2
70+ exit 1
71+fi
6172 echo "recinto en el servidor y verificado; mira sus cabeceras con: X2_SANDBOX=$ORIGIN node tests/x2_headers.mjs"
modified sandbox/x2/nginx.conf.example +10 −4
@@ -16,12 +16,15 @@
1616 # the manifest names.
1717
1818 server {
19- listen 443 ssl http2;
19+ listen 443 ssl; # http2 is per socket: set it where the other vhosts on :443 do
2020 server_name x2.utopiaia.com;
2121 ssl_certificate /etc/letsencrypt/live/x2.utopiaia.com/fullchain.pem;
2222 ssl_certificate_key /etc/letsencrypt/live/x2.utopiaia.com/privkey.pem;
2323 root /var/www/x2.utopiaia.com;
24- access_log off; # the sandbox keeps no log of who loaded it
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;
2528 autoindex off;
2629 server_tokens off;
2730
@@ -46,8 +49,11 @@
4649 server {
4750 listen 80;
4851 server_name x2.utopiaia.com;
49- access_log off;
50- return 301 https://$host$request_uri;
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; }
5157 }
5258
5359 # In the server block of Code (code.elffuss.com), for the verified vendor
modified tests/x2_deploy.mjs +10 −1
@@ -63,6 +63,11 @@
6363 const cmd = process.argv.at(-1).replaceAll('/var/www/', SERVER);
6464 const dir = (/cd '([^']+)'/.exec(cmd) || /mkdir -p '([^']+)'/.exec(cmd) || [])[1];
6565 if (/^mkdir -p/.test(cmd)) { fs.mkdirSync(dir, { recursive: true }); process.exit(0); }
66+ // stat -c '%a %n' NAMES: the octal mode of each, as GNU stat prints it
67+ if (/stat -c '%a %n'/.test(cmd)) {
68+ for (const n of cmd.split("stat -c '%a %n' ")[1].trim().split(/\s+/)) console.log((fs.statSync(path.join(dir, n)).mode & 0o777).toString(8) + ' ' + n);
69+ process.exit(0);
70+ }
6671 if (/sha256sum/.test(cmd)) {
6772 if (!fs.existsSync(dir)) process.exit(1);
6873 const globs = /find \./.test(cmd) ? null : ((/sha256sum ([^"|;&]+)/.exec(cmd) || [])[1] || '').trim().split(/\s+/);
@@ -85,7 +90,9 @@
8590 const src = a.at(-2), dst = a.at(-1).replace(/^[^:]*:/, '').replaceAll('/var/www/', SERVER);
8691 fs.mkdirSync(dst, { recursive: true });
8792 const files = names || fs.readdirSync(src).filter(f => fs.statSync(path.join(src, f)).isFile());
88- for (const f of files) { const to = path.join(dst, f); if (a.includes('--ignore-existing') && fs.existsSync(to)) continue; fs.copyFileSync(path.join(src, f), to); }
93+ for (const f of files) { const to = path.join(dst, f); if (a.includes('--ignore-existing') && fs.existsSync(to)) continue; fs.copyFileSync(path.join(src, f), to); fs.chmodSync(to, fs.statSync(path.join(src, f)).mode & 0o777); }
94+ // rsync -a SRC/ DEST/ gives DEST the mode of SRC (a mktemp -d folder is 700)
95+ if (a.includes('-a') && !names) fs.chmodSync(dst, fs.statSync(src).mode & 0o777);
8996 if (a.includes('--delete') && !names) for (const f of fs.readdirSync(dst)) if (!files.includes(f)) fs.rmSync(path.join(dst, f), { recursive: true });
9097 }
9198 for (const [name, fn] of [['ssh', fakeSsh], ['rsync', fakeRsync]]) exe(name, `#!/usr/bin/env node\n(${fn.toString()})(${JSON.stringify(log)}, ${JSON.stringify(server + '/')});\n`);
@@ -152,6 +159,8 @@
152159 && r.calls.some(c => c.startsWith('rsync ') && c.endsWith(':/var/www/x2.utopiaia.com/x2/v1/'))
153160 && fs.existsSync(sbxProd) && JSON.stringify(fs.readdirSync(sbxProd).sort()) === JSON.stringify(['exthost-iframe.html', 'sandbox.html'])
154161 && /X2_SANDBOX=https:\/\/x2\.utopiaia\.com node tests\/x2_headers\.mjs/.test(r.out), r.out.slice(-300));
162+const modes = fs.existsSync(sbxProd) ? [sbxProd, ...['sandbox.html', 'exthost-iframe.html'].map(f => path.join(sbxProd, f))].map(p => (fs.statSync(p).mode & 0o777).toString(8)).join(' ') : 'missing';
163+ok('D6 the web server can read what it uploaded: folder 755, documents 644 (rsync -a of a mktemp folder left 700 and both 404)', modes === '755 644 644', modes);
155164
156165 // D7
157166 const live = (env = {}) => spawnSync('node', [path.join(repo, 'vendor/vscode-ext2/check-output.mjs'), '--live', path.join(repo, 'web')], { encoding: 'utf8', env: { ...process.env, ...env } }).status;