Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/raw-csp-inner.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / test / raw-csp-inner.sh` 96 lines ยท 6336 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Runs INSIDE the throwaway container started by raw-csp.sh. Never run on the hub. 3 set -u 4 PASS=0; FAIL=0 5 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 6 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 7 [ -f /.dockerenv ] || { echo "refusing: not in a container"; exit 2; } 8 export DEBIAN_FRONTEND=noninteractive 9 apt-get update -qq >/dev/null && apt-get install -y -qq nginx libnginx-mod-stream curl git openssl python3 ca-certificates >/dev/null 2>&1 \ 10 || { echo "apt install failed"; exit 2; } 11 echo "container: $(nginx -v 2>&1), $(git --version)" 12 13 # forged execs git with an empty environment as root here; the storage belongs to another uid. 14 printf '[safe]\n\tdirectory = *\n' >> /etc/gitconfig 15 mkdir -p /home/drakestapleton/forge-data 16 (cd /home/drakestapleton/forge-data && setsid /forged > /tmp/forged.log 2>&1 &) 17 D() { curl -s -o /dev/null -w '%{http_code}' --max-time 5 -H 'X-Forge-Base: /' -H 'X-Real-IP: 10.9.9.9' "http://127.0.0.1:18480$1"; } 18 for i in $(seq 1 50); do [ "$(D /drakestapleton)" = 200 ] && break; sleep 0.2; done 19 [ "$(D /drakestapleton)" = 200 ] || { echo "forged did not start"; cat /tmp/forged.log; exit 2; } 20 # Warm forged's cache: every archive and raw blob is built once, and forged allows at most 2 cold 21 # builds in any 60 s site-wide (dl/dl.om dlcold, else 503 + Retry-After). Live is warm already. 22 ROWS=drakestapleton/omega-mv/raw/main/seed/ng/bench/evidence/20261107T0830Z-baseline-v2/x925/rows.txt 23 SVG=drakestapleton/benchmarks-mv/raw/main/assets/chart_multi_model.svg 24 for p in drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz drakestapleton/cuda-crack/archive/refs/heads/main.zip $ROWS $SVG; do 25 for i in $(seq 1 90); do c=$(D /$p); [ "$c" = 200 ] && break; sleep 1; done 26 echo "forged direct warm: $p -> $c after $i tries" 27 done 28 29 # Hub /etc/nginx (certs excluded) + stand-in certs, web roots and the hs.aienos.com upstream. 30 rm -rf /etc/nginx && tar -C /etc -xf /w/etc-nginx.tar 31 for d in aienos.com interplane.io www.aienos.com; do 32 mkdir -p /etc/nginx/certs/$d 33 openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=$d" -addext "subjectAltName=DNS:$d,DNS:www.$d" \ 34 -keyout /etc/nginx/certs/$d/key.pem -out /etc/nginx/certs/$d/fullchain.pem >/dev/null 2>&1 35 cp /etc/nginx/certs/$d/fullchain.pem /usr/local/share/ca-certificates/rawcsp-$d.crt 36 done 37 openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=hs.aienos.com" -addext "subjectAltName=DNS:hs.aienos.com" -keyout /tmp/hs.key -out /tmp/hs.pem >/dev/null 2>&1 38 cp /tmp/hs.pem /usr/local/share/ca-certificates/rawcsp-hs.crt 39 update-ca-certificates >/dev/null 2>&1 40 mkdir -p /var/www/interplane.io/quick-start /var/www/aienos.com/current /var/www/replicate /var/www/si /var/www/aienos-hive /var/log/nginx 41 echo IP-HOME > /var/www/interplane.io/index.html; echo IP-QS > /var/www/interplane.io/quick-start/index.html 42 echo AE-HOME > /var/www/aienos.com/current/index.html; echo AE-404 > /var/www/aienos.com/current/404.html 43 python3 - >/dev/null 2>&1 <<'EOF' & 44 import ssl 45 from http.server import BaseHTTPRequestHandler, HTTPServer 46 class H(BaseHTTPRequestHandler): 47 def log_message(self, *a): pass 48 def do_GET(self): 49 self.send_response(200); self.send_header("Content-Length", "2"); self.end_headers(); self.wfile.write(b"ok") 50 h = HTTPServer(("127.0.0.1", 4443), H) 51 ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER); ctx.load_cert_chain("/tmp/hs.pem", "/tmp/hs.key") 52 h.socket = ctx.wrap_socket(h.socket, server_side=True) 53 h.serve_forever() 54 EOF 55 56 # Old: the P2-1 edge files (which hide forged's CSP) over the hub copy. 57 FILES="conf.d/forge.conf snippets/forge-proxy.conf snippets/forge-headers.conf snippets/forge-archive.conf snippets/aienos-forge.conf sites-enabled/interplane.io" 58 for f in $FILES; do cp /w/old/nginx/$f /etc/nginx/$f; done 59 nginx -t -q && nginx || { echo "old config does not start in container"; nginx -t; exit 2; } 60 sleep 1 61 62 hdrs() { local u=$1 h=${1#https://}; h=${h%%/*}; curl -s -D - -o /dev/null --max-time 30 --resolve "$h:443:127.0.0.1" "$u" | tr -d '\r'; } 63 csp() { printf '%s\n' "$1" | sed -n 's/^[Cc]ontent-[Ss]ecurity-[Pp]olicy: //p'; } 64 n() { printf '%s\n' "$1" | grep -c .; } 65 oneline() { printf %s "$1" | tr '\n' '|'; } 66 67 # forged itself (the source of the policy the edge must keep) 68 h=$(curl -s -D - -o /tmp/raw.body -H 'X-Forge-Base: /' -H 'X-Real-IP: 10.9.9.8' "http://127.0.0.1:18480/$ROWS" | tr -d '\r') 69 c=$(csp "$h") 70 case "$c" in "sandbox;"*) ok "forged direct: raw CSP $c";; *) bad "forged direct: raw CSP '$c' (forged does not send the sandbox): $(oneline "$(printf '%s\n' "$h" | head -1)") $(head -c 300 /tmp/raw.body)"; exit 1;; esac 71 72 for base in https://interplane.io/ https://www.aienos.com/forge/; do 73 c=$(csp "$(hdrs "$base$ROWS")") 74 case "$(n "$c"):$c" in "1:sandbox;"*) bad "old $base: raw already carries forged's sandbox (negative control failed)";; 75 *) ok "old $base: raw rows.txt CSP is the edge's, not forged's: $(oneline "$c")";; esac 76 done 77 78 # New: hub/forge-edge-update.sh installs this tree over the old one. 79 export FORGE_RELOAD="nginx -s reload" 80 bash /infra/hub/forge-edge-update.sh /infra /w/old > /tmp/u.log 2>&1; rc=$? 81 [ $rc = 0 ] && grep -q '^UPDATE OK' /tmp/u.log && ok "new: forge-edge-update.sh applied (nginx -t, reload, live checks)" || { bad "new: update rc=$rc"; cat /tmp/u.log; exit 1; } 82 grep -E '^(ok|FAIL) ' /tmp/u.log | sed 's/^/ /' 83 84 for base in https://interplane.io/ https://www.aienos.com/forge/; do 85 h=$(hdrs "$base$ROWS"); c=$(csp "$h") 86 case "$(n "$c"):$c" in "1:sandbox; default-src 'none'"*) ok "new $base: raw rows.txt: forged's sandbox CSP, alone";; *) bad "new $base: raw rows.txt CSP: $(oneline "$c")";; esac 87 h=$(hdrs "$base$SVG"); c=$(csp "$h") 88 case "$(n "$c"):$c" in "1:sandbox; default-src 'none'"*) ok "new $base: raw svg: forged's sandbox CSP, alone";; *) bad "new $base: raw svg CSP: $(oneline "$c")";; esac 89 printf '%s\n' "$h" | grep -qi '^content-disposition: attachment' && ok "new $base: raw svg Content-Disposition attachment" || bad "new $base: raw svg not an attachment" 90 for p in drakestapleton explore; do 91 c=$(csp "$(hdrs "$base$p")") 92 case "$(n "$c"):$c" in 1:*"script-src 'none'"*"form-action 'self'"*) ok "new $base$p: one CSP, script-src 'none', form-action 'self'";; *) bad "new $base$p CSP: $(oneline "$c")";; esac 93 done 94 done 95 echo "RESULT: $PASS passed, $FAIL failed" 96 [ "$FAIL" = 0 ]