interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / nginx / conf.d / forge.conf

116 lines · 6555 bytes Raw Blame History
1# /etc/nginx/conf.d/forge.conf on hub (http scope) - INTERPLANE Forge web edge.
2# ForgeInfra, 2026-11-07. Source: spark ~/work/forge/web/infra/nginx/conf.d/forge.conf.
3#
4# forged (seeded Omega) listens on spark 127.0.0.1:18480 only. Spark's tmux session
5# `forged-tunnel` holds `ssh -N -R 127.0.0.1:18480:127.0.0.1:18480 hub`, so the same
6# port on the hub's loopback reaches it. Nothing else on the hub listens on 18480.
7upstream forged {
8 server 127.0.0.1:18480 max_fails=0;
9}
10
11# Visitor address comes from the PROXY header the :443 SNI router adds (www.aienos.com on
12# 4446, interplane.io on 4448). Only POSTs get a key; nginx does not count empty keys, so
13# GET/HEAD are never limited by forge_post.
14map $request_method $forge_post_key {
15 default "";
16 POST $proxy_protocol_addr;
17}
18limit_req_zone $forge_post_key zone=forge_post:10m rate=20r/m;
19
20# A POST that arrived without a PROXY header cannot be rate-limited per client: refuse it.
21map "$request_method:$proxy_protocol_addr" $forge_post_noaddr {
22 default 0;
23 "POST:" 1;
24}
25
26# Downloads (archive, raw, release assets, bundles of imported proposals at
27# /<owner>/<repo>/patches/<id>.bundle): nginx buffers them and spools to
28# /var/lib/nginx/proxy what a slow client has not taken yet (see forge-proxy.conf), so forged is
29# never held by a slow reader. At most 2 at a time per client, 6 in total: forged caps one
30# response at 512 MiB, so the spool stays under 3 GiB of the hub's 6.5 GiB free disk.
31limit_conn_zone $proxy_protocol_addr zone=forge_dl:10m;
32map $host $forge_dl_all_key { default "all"; }
33limit_conn_zone $forge_dl_all_key zone=forge_dl_all:1m;
34
35# Content-Security-Policy (security review P2-3). forged sets its own policy on every response:
36# the page policy, or `sandbox; default-src 'none'; ...` on /raw/. The edge passes it through
37# untouched and adds its own policy (forge-headers.conf) only when forged's would not by itself
38# keep the no-script, same-origin-forms rule: no header at all, or one that is neither a bare
39# `sandbox` (no allow-* tokens) nor has both script-src 'none' and form-action 'self'/'none'.
40# Browsers enforce every CSP header, so the effective policy is never weaker than the edge's.
41# Downloads (the bundle of an imported proposal, /patches/<id>.bundle, included) get a sandbox
42# policy as the fallback, pages the edge page policy.
43map $upstream_http_content_security_policy $forge_csp_sandbox {
44 default 0;
45 "~(^|;) *sandbox *(;|$)" 1;
46}
47map $upstream_http_content_security_policy $forge_csp_noscript {
48 default 0;
49 "~script-src +'none'" 1;
50}
51map $upstream_http_content_security_policy $forge_csp_form {
52 default 0;
53 "~form-action +'(self|none)'" 1;
54}
55map "$forge_csp_sandbox$forge_csp_noscript$forge_csp_form:$uri" $forge_csp_edge {
56 "~^1" "";
57 "~^011:" "";
58 "~^...:(/forge)?/[^/]+/[^/]+/((archive|raw|releases/download)/|patches/[0-9a-f]{16}\.bundle$)"
59 "sandbox; default-src 'none'; img-src 'self'; style-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'";
60 default "default-src 'self'; script-src 'none'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'";
61}
62
63# 2026-11-10 one-interplane (L1058): page reads were unlimited and one crawler family filled the
64# single-request server (about 28 requests a second, 19,677 of the last 20,000 from GoogleOther).
65# All crawlers share one small budget; each visitor address gets its own. Empty keys are not counted.
66map $http_user_agent $forge_bot_key {
67 default "";
68 "~*(bot|crawl|spider|slurp|GoogleOther)" "crawler";
69}
70limit_req_zone $forge_bot_key zone=forge_bots:1m rate=3r/s;
71# Home, Files, and README reads have a separate per-address queue. Match the original
72# request URI because repository homes are routed through the named @forged location.
73map "$host:$request_method:$request_uri" $forge_source_read {
74 default 0;
75 "~^(?:www\.)?interplane\.io:(?:GET|HEAD):/drakestapleton/[A-Za-z0-9][A-Za-z0-9._-]*(?:/?(?:\?|$)|/tree/|/raw/[^?]+/(?i:README)(?:\.[^/?]+)?(?:\?|$))" 1;
76}
77map $forge_source_read $forge_page_addr { 1 $proxy_protocol_addr; default ""; }
78map $forge_source_read $forge_other_addr { 1 ""; default $proxy_protocol_addr; }
79limit_req_zone $forge_page_addr zone=forge_source_pages:10m rate=10r/s;
80limit_req_zone $forge_other_addr zone=forge_other_reads:10m rate=5r/s;
81
82# Smart Git and branch archives stream without the buffered download disk spool.
83limit_conn_zone $proxy_protocol_addr zone=forge_git_client:1m;
84limit_conn_zone $server_name zone=forge_git_streams:1m;
85
86# 2026-11-10 one-interplane (L1058): forged answers one request at a time, so one heavy page held
87# everyone (3 to 20 s waits seen). Pages for visitors who send no cookie are identical for everyone
88# (checked: no Set-Cookie, same bytes twice), so they are kept for 30 s and a stale copy is served
89# while forged is busy or restarting. Any request with a cookie skips the cache entirely.
90# Note: cached hits do not reach forged, so counts taken from forged.log see fewer page reads.
91proxy_cache_path /var/cache/nginx/forge levels=1:2 keys_zone=forge_pages:20m max_size=1g inactive=10m use_temp_path=off;
92# Repository HTML and source reads resolve moving refs at request time.
93map "$http_cookie:$uri" $forge_nocache {
94 ~^:/drakestapleton/[A-Za-z0-9._-]+(?:/?$|/(?:tree|blob|raw)/) 1;
95 ~^: 0;
96 default 1;
97}
98
99# 2026-11-11 open-builds (L1139): forged answers JSON at a page's own address when the request says
100# Accept: application/json (docs/API.md). The cache key was host and address only, so such a request
101# from a visitor with no cookie was answered with the cached HTML page. The key now also carries
102# whether the request asks for JSON, by the same test forged uses (the text application/json).
103map $http_accept $forge_json {
104 default 0;
105 # as forged (server/json.om fjwant): JSON only when the request does not also name text/html
106 "~text/html" 0;
107 "~application/json" 1;
108}
109
110# Historical Git mirror pages share the single forged listener with Explore and repo homes.
111# Count commit-addressed reads across clients. Empty keys leave other requests unaffected.
112map "$request_method:$uri" $forge_git_history_key {
113 default "";
114 "~^(?:GET|HEAD):/(?:forge/)?drakestapleton/git/(?:blob|tree|raw|blame|commits?)/[0-9a-f]{40}(?:/|$)" "git-history";
115}
116limit_conn_zone $forge_git_history_key zone=forge_git_history:1m;