Files
bchanot 7be94d4ce6 chore(docker): R2 application image with the Rust core — wasm stage, precompressed module, CSP proof on the image
Dockerfile stage 0 (rust:1.99.0-bookworm, wasm32 target, wasm-bindgen-cli
at the builder's pinned version, cargo cache mounts) builds the shipped
module with scripts/wasm-build.sh (WASM_BUILD_SHIPPED_ONLY=1); the Node
stage copies packages/core-wasm (manifest + pkg/); the runner gzips the
module and nginx serves it with gzip_static (application/wasm, 1,180,153
bytes raw, 372,275 served). docker/csp-proof/app-image.sh runs the real
image behind the DEPLOY.md CSP in headless Chromium: with
'wasm-unsafe-eval' a report is created and a zone click is applied by the
core with no script or wasm violation; without it the editor shows the
degraded notice, stays put and leaves the draft untouched; /login,
/app/account and / never request the module (15/15 checks).
2026-10-14 00:45:51 +02:00

41 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# R2 proof (review VI.2 R2, D-R13): the application image boots under the production CSP of
# DEPLOY.md. With 'wasm-unsafe-eval' the editor runs the Rust core (new report, zone click);
# without it the editor shows the degraded state and /login stays usable; /login and
# /app/account never request the core module. Runs the real image (SHEET_BUNDLE=draft) behind
# the image's own nginx with the header added, and drives headless Chromium.
#
# CHROME=/path/to/chrome PLAYWRIGHT_NODE_MODULES=/path/to/node_modules \
# bash docker/csp-proof/app-image.sh
#
# PLAYWRIGHT_NODE_MODULES: a node_modules holding playwright-core, outside the repository
# (no project dependency); the driver runs from a temporary directory linked to it.
#
# Result recorded in docs/development/RUST.md (R2 section).
set -euo pipefail
cd "$(dirname "$0")/../.."
work="$(mktemp -d)"
csp_line="$(grep -m1 '^add_header Content-Security-Policy' DEPLOY.md | sed -E 's/^add_header Content-Security-Policy "(.*)" always;$/\1/')"
without_csp="${csp_line/ \'wasm-unsafe-eval\'/}"
with_csp="${without_csp/script-src \'self\'/script-src \'self\' \'wasm-unsafe-eval\'}"
for variant in without with; do
if [ "$variant" = without ]; then csp="$without_csp"; else csp="$with_csp"; fi
sed "s/\${PORT}/8080/; s|^ # SPA fallback| add_header Content-Security-Policy \"$csp\" always;\n # SPA fallback|; s|^ add_header Cache-Control \"public, max-age=31536000, immutable\";| add_header Cache-Control \"public, max-age=31536000, immutable\";\n add_header Content-Security-Policy \"$csp\" always;|" docker/nginx.conf > "$work/csp-$variant.conf"
done
docker build --build-arg SHEET_BUNDLE=draft -t faunosteo:r2-csp-proof . >/dev/null 2>&1
cleanup() { docker rm -f faunosteo_r2csp_without faunosteo_r2csp_with >/dev/null 2>&1 || true; }
trap cleanup EXIT
cleanup
for variant in without with; do
port=8093
[ "$variant" = with ] && port=8094
docker run -d --rm --name "faunosteo_r2csp_$variant" -p "127.0.0.1:$port:8080" \
--entrypoint nginx \
-v "$work/csp-$variant.conf:/etc/nginx/conf.d/default.conf:ro" \
faunosteo:r2-csp-proof -g 'daemon off;' >/dev/null
done
sleep 1.5
cp docker/csp-proof/app-image.mjs "$work/"
ln -s "${PLAYWRIGHT_NODE_MODULES:?set PLAYWRIGHT_NODE_MODULES}" "$work/node_modules"
node "$work/app-image.mjs"