security(shared-httpd): remove cgid/lua/include/actions/dav/userdir + exec-surface build gate #59

Open
jknapp wants to merge 5 commits from sec/shared-httpd-exec-surface-2026-11-22 into trunk
pull from: sec/shared-httpd-exec-surface-2026-11-22
Owner

What / why

shared-httpd is the one Apache that serves every shared_httpd tenant. Everything it executes runs as the shared apache user, which can read every tenant's world-readable files. Measured on the live canary: tenants could run code as apache via SSI, CGI and Lua. WHP PR #346 (template + server-scope drop-in, merged as 2dc62a79b) closes most of it by config, but config cannot close what a tenant binds with RewriteRule ... [H=<handler>] or [P] (mod_rewrite sets the handler in the fixup phase, after any config section) nor a nested tenant <If>: those are closed only by removing the module from the image. Hence: mod_lua/cgid/include/actions/dav/userdir (first commits) and, in the latest commit, status, info and every proxy module the platform does not use.

Modules removed (exact list)

  • exec / files: cgid cgi include actions lua dav dav_fs dav_lock userdir (RPM mod_lua uninstalled; the rest are httpd-core .so files deleted)
  • status: status (server-status), info (server-info)
  • proxy: proxy_http proxy_ajp proxy_ftp proxy_connect proxy_scgi proxy_uwsgi proxy_wstunnel proxy_fdpass proxy_express proxy_hcheck, lbmethod_bybusyness lbmethod_bytraffic lbmethod_heartbeat (+ the unloaded mod_heartbeat/mod_heartmonitor .so)
  • unused: suexec dbd authn_dbd authz_dbd cache cache_disk cache_socache socache_dbm socache_memcache socache_redis

Kept (WHP renders them): proxy proxy_fcgi proxy_balancer lbmethod_byrequests slotmem_shm socache_shmcb(SSL) ssl rewrite headers expires deflate brotli ... (full required list in the gate). Stays loaded and unaddressed by this PR (not requested, flagged in the notes below): authnz_fcgi ext_filter dumpio echo.

Proof WHP does not use the removed modules (grep of WHP origin/main 2dc62a79b)

  • server-status|server-info|balancer-manager|ExtendedStatus: zero hits in code, templates, configs, scripts or the edge (haproxy-manager-base, fleet-manager checked). Only docs: DOCS_FOR_AGENTS/QUICK_REFERENCE.md (curl localhost/server-status, a panel-host cheat sheet; the shared tier never served it: no <Location> exists, stock Alma ships none) and the WHP isolation suite itself (which asserts the opposite).
  • Proxy directives rendered by WHP (panel/internal/vhost/httpdtpl/render.go, shared-vhost-template.tpl, shared-httpd-security.conf, shared-httpd-default-vhost.conf, container-manager.sh recreate_shared_httpd): only SetHandler "proxy:fcgi://host:port", <Proxy "balancer://fpm_*"> + BalancerMember "fcgi://..." + ProxySet lbmethod=byrequests, ProxyFCGISetEnvIf. No ProxyPass, ProxyPassMatch, ProxyTimeout, ProxyErrorOverride, SSLProxy*, ProxyRequests, Cache*, DBD*, SuexecUserGroup. /ping is a mod_rewrite R=204 (no mod_status). Health check = curl -sfk https://localhost/ping.
  • configs/whp-terminal-websocket.conf (proxy_wstunnel/proxy_http) is installed by setup.sh into the panel host's own httpd, not this image.
  • Fleet scan (shared-httpd-image-baseline-2026-11-22.md): zero RewriteRule [P]/[H=/proxy:/fcgi:// in any of the 45 shared sites' .htaccess.
  • .htaccess compat, measured (same fixture on trunk image vs this image, AllowOverride as rendered): 27 directive probes (Cache*, AuthDBD*, AddModuleInfo, Proxy*, ProxyFCGI*, ExtendedStatus, SuexecUserGroup, Digest/DBM/Basic auth, Expires/Header/Brotli ...) answer the same status on both; the only change is RewriteRule ^ http://127.0.0.1:81/ [P] 503 -> 500 (the point). Cache*, Proxy*, Suexec*, ExtendedStatus were already a 500 from a tenant .htaccess.

Independent re-review (2026-11-22, branch 990b379 + comment-only 0ad6b43)

Rebuilt trunk and branch locally from the same base; trunk's httpd -M equals the registry :latest (993b6405) exactly. Branch = trunk minus exactly the 33 listed modules, nothing else; no LoadModule left pointing at a deleted .so; mod_lua RPM gone. Gate test 26/26; WHP suite (main 2dc62a79b) 48/48 on branch (45 + 3 residual notes on trunk); probes 13/13 (and 13/13 EXPECT_OPEN=1 on trunk); arm64 under qemu: both gates OK. Real-render matrix with the WHP Go renderer (4 sites: single FPM, 2- and 3-member balancers, aliases, wildcard primary; real cac-fpm:php83 backends; image run with the recreate_shared_httpd mounts read-only, plus a run with the production hardening flags): ~240 requests (http->https, PATH_INFO, WP pretty URLs, 20 MB POST, gzip, brotli, Expires/Header, basic auth, MultiViews, autoindex, Range, ErrorDocument, dotfile deny, remoteip XFF in the access log, balancer spread, default vhost, /ping, TLS, graceful, stop) identical to trunk except the intended deltas: <IfModule mod_cache.c>-guarded lines now skipped (was a 500, now 200), /cgi-bin/x now the site's own 404 (no ScriptAlias), the Allow: header lists the same methods in a different order, and two startup notices gone.

Changes

  • scripts/httpd-exec-surface-gate.sh: one list (CORE_SO) of banned modules drives remove (uninstall/delete .so, LoadModule lines, global INCLUDES filter, ScriptAlias /cgi-bin/, /var/www/cgi-bin) and check (build fails if: mod_lua RPM present; a banned module in httpd -M; a banned .so on disk; a banned LoadModule line; INCLUDES filter / ScriptAlias / cgi|SSI handler / Options ExecCGI|Includes; a required module not loaded (positive control, includes proxy_balancer, lbmethod_byrequests, slotmem_shm, brotli); httpd -t fails).
  • Dockerfile.shared-httpd: COPY + RUN gate remove && gate check last, LABEL org.whp.httpd-exec-surface="removed".
  • scripts/tests/httpd-exec-surface-gate.test.sh: 26 cases in a throwaway stock-Alma container: negative control, remove+check, idempotent, and each regression caught for its own reason (mod_lua RPM, include / status / info / proxy_http / proxy_wstunnel / proxy_ajp / cache back (loaded), leftover .so (userdir, status, proxy_http), prefork-guarded cgi LoadModule, INCLUDES filter, ScriptAlias, Options +ExecCGI, required rewrite / proxy_fcgi / lbmethod_byrequests / proxy_balancer missing, config does not parse).
  • scripts/tests/httpd-exec-surface-probes.test.sh (new): renders the REAL WHP template + drop-in (WHP_DIR) into the image and probes the holes; EXPECT_OPEN=1 runs it against an unhardened image to prove the probes can see them.
  • build-push.yaml: both new scripts in the Shell-Checks list (shellcheck clean).

Test evidence (local builds, httpd 2.4.63, amd64 + arm64 under qemu)

  1. Gate: build passes, gate OK: ... all required modules loaded; httpd -t passes; httpd -M has none of the banned modules, proxy family = proxy proxy_balancer proxy_fcgi lbmethod_byrequests + slotmem_shm. arm64 (qemu, --platform linux/arm64): same gate OK. Gate test: 26 passed, 0 failed.
  2. WHP suite WHP_TI_IMAGE=<this image> scripts/test-shared-httpd-tenant-isolation.sh (WHP main 2dc62a79b): PASS, 48 assertions, 0 failed; residual notes now: Lua [H=lua-script] closed, nested <If> CGI closed, [H=server-status] closed (on the previous branch image the last one was still "KNOWN RESIDUAL").
  3. Probes (httpd-exec-surface-probes.test.sh): 13 passed, 0 failed. Closed: [H=lua-script], nested <If> ExecCGI+cgi-script, [H=server-status], [H=server-info], nested <If> SetHandler server-status, [P] http:// to an internal 127.0.0.1:81 listener (500, no secret), [P] ws://, [P] ajp:// ftp:// scgi:// uwsgi:// (AH01144 "No protocol handler"); [H=cgi-script]++ExecCGI is closed by the WHP drop-in on both images. Same script on the trunk image (EXPECT_OPEN=1): lua, nested-If CGI, status, info, [P] http:// and [P] ws:// are all reachable.
  4. Real-render matrix (WHP Go httpdtpl.RenderVhostConfig output of the real template, real cac-fpm:php83 backends, two sites, one with a 2-member balancer): httpd -t OK; PHP over FastCGI (SCRIPT_FILENAME/DOCUMENT_ROOT right), WordPress-style rewrite (pretty URL and /), https, http->https 301, gzip (Content-Encoding: gzip), Expires (max-age=2592000), Header set/always set, basic auth (401 / 401 / 200), MultiViews, Options +Indexes, dotfile 403, ErrorDocument, /ping 204 (http, https, /ping/), default-vhost catch-all 403, Docker health command passes, balancer hits both members. Output compared with the trunk image: identical (only the container hostname differs); the new image's error log is quieter (no suEXEC / AH02282 No slotmem from mod_heartmonitor notices).

Still open (module needed by WHP; not fixable by removal)

  • RewriteRule ... fcgi://host:port/... [P] and SetEnv-style abuse of proxy_fcgi from a tenant .htaccess: the WHP drop-in already strips PHP_VALUE/PHP_ADMIN_VALUE (suite section "FPM": a poisoned victim worker is not reproducible). A tenant can still make the shared httpd open a FastCGI connection to any host:port reachable from client-net (other tenants' FPM pools). WHP-side follow-up, not this PR.
  • [H=balancer-manager] renders the Load Balancer Manager page; measured: it lists only balancers of the tenant's own vhost (a victim vhost's balancer://fpm_* is not shown) so nothing cross-tenant leaks. It still shows the server version string.
  • authnz_fcgi, ext_filter, dumpio, echo, data, macro, request, substitute stay loaded; their directives are server/vhost/directory scope (not reachable from .htaccess with the rendered AllowOverride).

What a merge publishes (READ BEFORE MERGING)

build-push.yaml triggers on push to trunk (and manual dispatch with only=). A merge runs the whole workflow (~1h): every image family is rebuilt and each publish job does push-by-digest then assemble-multiarch-index.sh --tag latest (cac :phpNN/:latest, cac-fpm, shared-httpd, shared-ols ...). For this change that means repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:latest is retagged to the hardened image (amd64 required, arm64 best effort; --guard-existing-arm64 fails rather than silently dropping arm64). Merging does NOT touch running hosts.

How hosts consume it: by tag :latest, not digest. scripts/container-manager.sh recreate_shared_httpd does docker pull ...shared-httpd:latest then docker run ... shared-httpd:latest. The nightly image-pull (03:17 host time, Go image-pull job / pull-container-images.sh) only refreshes the local :latest image; a running shared-httpd-NN keeps its old image until it is recreated, but ANY recreate (scale, reconfigure that recreates, manual) after the merge gets the hardened image. Merge only when ready to roll out: there is no way to build this image from the branch without also publishing :latest (a manual dispatch publishes the tag too).

Recommended merge (publishes ONLY shared-httpd): merge with [skip ci] in the merge commit title (as #56/#57/#58 did; verified: those merges started no push run), then run the workflow by hand on trunk with only=shared-httpd (.gitea/scripts/plan-legs.sh -> shared_httpd=true, every other family []/false; Shell-Checks incl. the gate test still runs). A plain merge instead rebuilds and re-tags EVERY family (cac/cac-fpm :phpNN, litespeed, lsphp, shared-ols) from a fresh base, which the nightly image-pull would then spread to customer containers: an unplanned fleet-wide image change unrelated to this PR. If the arm64 leg fails, --guard-existing-arm64 makes the job fail and nothing is re-tagged (allow_amd64_only stays false).

Compat impact

The 2026-11-22 survey of all 45 shared sites (whp01 26, whp02 12, whp03 7) found 0 using ExecCGI/Includes/Lua, 0 .shtml with <!--#include, 0 .cgi/.lua files, 0 server-parsed/INCLUDES filters, no WebDAV, no ~user URLs. The only cgi-ish thing is the WordPress "disable script execution in uploads" idiom (Options -ExecCGI + AddHandler cgi-script ...), which still parses (tested). One behaviour delta: with the module present, such a script file in uploads returned 403; now an unmapped file type (.pl/.py/.sh/.phtml) in that dir is served as static text exactly as if the .htaccess were absent (.php still goes to FPM via the vhost handler). Not executed, but its source is downloadable: same as any non-PHP file. Customers who later want CGI/SSI/WebDAV must use a non-shared tier.

Roll-out plan (needs Josh; no ssh was done here)

Safe order with the WHP-side PR #346:

  1. Merge WHP #346 and release it first (template/drop-in work with or without this image; it is the defence-in-depth layer and ships the test).
  2. Merge this PR (publishes :latest, ~1h build). Confirm the Gitea run is green and docker buildx imagetools inspect ...shared-httpd:latest shows amd64 (+arm64).
  3. Canary first (VM 401 whp-al10-test): pre-tag the running image (see Rollback), container-manager.sh recreate shared-httpd, then docker exec shared-httpd-01 /scripts/httpd-exec-surface-gate.sh check (expect gate OK), httpd -M | grep -E 'cgid|lua|include|actions|dav|userdir|status|info|proxy_(http|ajp|ftp|connect|scgi|uwsgi|wstunnel)|suexec|cache|dbd' (expect nothing), scripts/test-shared-httpd-tenant-isolation.sh against it, and a PHP + rewrite request through the edge.
  4. Then whp03, whp02, sdbees, whp01 one at a time. Recreating shared-httpd-01 is a short outage for every shared_httpd site on that host: pick a quiet window, one host at a time, verify the healthcheck turns healthy (start-period 60s) and a site responds before the next.
  5. After the fleet is on it: in WHP delete the "KNOWN RESIDUAL" notes (template comment, drop-in section 5, the residual branch of the test script). The handler pin and Options lines stay.

Rollback

The registry keeps only what is tagged; untagged digests disappear (every fleet digest except whp03's is already 404 there, see /workspace/shared-httpd-image-baseline-2026-11-22.md). So:

  • Registry (done 2026-11-22 during the re-review): the current :latest index sha256:993b6405210dc082cae08ab0b7c44561d8b439687a77fb0d0169f008bbd25f62 (amd64 + arm64, = whp03's image) is now ALSO tagged shared-httpd:rollback-20261122 (same manifest bytes PUT under a second tag; digest unchanged, :latest untouched). The merge moves :latest only; :rollback-20261122 keeps 993b6405 alive.
  • Per host, BEFORE any recreate/pull of the new image (the old local image becomes dangling on docker pull and image prune deletes it): docker tag <running image ID> repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:rollback-local-20261122 (IDs per host in the baseline doc; whp01 also tag shared-httpd-02's separate April image ID, which runs by bare ID and is not touched by a recreate of -01). Optional: docker save it to /root.
  • Roll back one host to its own old image: docker tag ...:rollback-local-20261122 ...:latest, then run the recreate_shared_httpd docker run line by hand (the function itself does docker pull :latest first, which would fetch the new image again).
  • Roll back the registry for everyone: docker buildx imagetools create -t repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:latest repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:rollback-20261122, then recreate on the affected hosts (they get 993b6405, the last published image, not necessarily the older image they ran before). Reverting the PR and re-running the workflow also works but takes ~1h.

🤖 Generated with Claude Code

https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6

## What / why `shared-httpd` is the one Apache that serves every shared_httpd tenant. Everything it executes runs as the shared `apache` user, which can read every tenant's world-readable files. Measured on the live canary: tenants could run code as `apache` via SSI, CGI and Lua. WHP PR #346 (template + server-scope drop-in, merged as 2dc62a79b) closes most of it by config, but config cannot close what a tenant binds with `RewriteRule ... [H=<handler>]` or `[P]` (mod_rewrite sets the handler in the fixup phase, after any config section) nor a nested tenant `<If>`: those are closed only by **removing the module from the image**. Hence: mod_lua/cgid/include/actions/dav/userdir (first commits) and, in the latest commit, `status`, `info` and every proxy module the platform does not use. ## Modules removed (exact list) - exec / files: `cgid cgi include actions lua dav dav_fs dav_lock userdir` (RPM `mod_lua` uninstalled; the rest are httpd-core `.so` files deleted) - status: `status` (server-status), `info` (server-info) - proxy: `proxy_http proxy_ajp proxy_ftp proxy_connect proxy_scgi proxy_uwsgi proxy_wstunnel proxy_fdpass proxy_express proxy_hcheck`, `lbmethod_bybusyness lbmethod_bytraffic lbmethod_heartbeat` (+ the unloaded `mod_heartbeat`/`mod_heartmonitor` `.so`) - unused: `suexec dbd authn_dbd authz_dbd cache cache_disk cache_socache socache_dbm socache_memcache socache_redis` **Kept** (WHP renders them): `proxy proxy_fcgi proxy_balancer lbmethod_byrequests slotmem_shm socache_shmcb(SSL) ssl rewrite headers expires deflate brotli ...` (full required list in the gate). Stays loaded and unaddressed by this PR (not requested, flagged in the notes below): `authnz_fcgi ext_filter dumpio echo`. ## Proof WHP does not use the removed modules (grep of WHP origin/main 2dc62a79b) - `server-status|server-info|balancer-manager|ExtendedStatus`: zero hits in code, templates, configs, scripts or the edge (haproxy-manager-base, fleet-manager checked). Only docs: `DOCS_FOR_AGENTS/QUICK_REFERENCE.md` (`curl localhost/server-status`, a panel-host cheat sheet; the shared tier never served it: no `<Location>` exists, stock Alma ships none) and the WHP isolation suite itself (which asserts the opposite). - Proxy directives rendered by WHP (`panel/internal/vhost/httpdtpl/render.go`, `shared-vhost-template.tpl`, `shared-httpd-security.conf`, `shared-httpd-default-vhost.conf`, `container-manager.sh recreate_shared_httpd`): only `SetHandler "proxy:fcgi://host:port"`, `<Proxy "balancer://fpm_*">` + `BalancerMember "fcgi://..."` + `ProxySet lbmethod=byrequests`, `ProxyFCGISetEnvIf`. No `ProxyPass`, `ProxyPassMatch`, `ProxyTimeout`, `ProxyErrorOverride`, `SSLProxy*`, `ProxyRequests`, `Cache*`, `DBD*`, `SuexecUserGroup`. `/ping` is a mod_rewrite `R=204` (no mod_status). Health check = `curl -sfk https://localhost/ping`. - `configs/whp-terminal-websocket.conf` (`proxy_wstunnel`/`proxy_http`) is installed by `setup.sh` into the **panel host's own httpd**, not this image. - Fleet scan (`shared-httpd-image-baseline-2026-11-22.md`): zero `RewriteRule [P]`/`[H=`/`proxy:`/`fcgi://` in any of the 45 shared sites' `.htaccess`. - .htaccess compat, measured (same fixture on trunk image vs this image, AllowOverride as rendered): 27 directive probes (Cache*, `AuthDBD*`, `AddModuleInfo`, Proxy*, `ProxyFCGI*`, `ExtendedStatus`, `SuexecUserGroup`, Digest/DBM/Basic auth, Expires/Header/Brotli ...) answer the **same** status on both; the only change is `RewriteRule ^ http://127.0.0.1:81/ [P]` 503 -> 500 (the point). `Cache*`, `Proxy*`, `Suexec*`, `ExtendedStatus` were already a 500 from a tenant `.htaccess`. ## Independent re-review (2026-11-22, branch 990b379 + comment-only 0ad6b43) Rebuilt trunk and branch locally from the same base; trunk's `httpd -M` equals the registry `:latest` (993b6405) exactly. Branch = trunk minus exactly the 33 listed modules, nothing else; no `LoadModule` left pointing at a deleted `.so`; `mod_lua` RPM gone. Gate test 26/26; WHP suite (main 2dc62a79b) 48/48 on branch (45 + 3 residual notes on trunk); probes 13/13 (and 13/13 `EXPECT_OPEN=1` on trunk); arm64 under qemu: both gates OK. Real-render matrix with the WHP Go renderer (4 sites: single FPM, 2- and 3-member balancers, aliases, wildcard primary; real `cac-fpm:php83` backends; image run with the `recreate_shared_httpd` mounts read-only, plus a run with the production hardening flags): ~240 requests (http->https, PATH_INFO, WP pretty URLs, 20 MB POST, gzip, brotli, Expires/Header, basic auth, MultiViews, autoindex, Range, ErrorDocument, dotfile deny, remoteip XFF in the access log, balancer spread, default vhost, `/ping`, TLS, graceful, stop) identical to trunk except the intended deltas: `<IfModule mod_cache.c>`-guarded lines now skipped (was a 500, now 200), `/cgi-bin/x` now the site's own 404 (no ScriptAlias), the `Allow:` header lists the same methods in a different order, and two startup notices gone. ## Changes - `scripts/httpd-exec-surface-gate.sh`: one list (`CORE_SO`) of banned modules drives `remove` (uninstall/delete `.so`, `LoadModule` lines, global INCLUDES filter, `ScriptAlias /cgi-bin/`, `/var/www/cgi-bin`) and `check` (build fails if: mod_lua RPM present; a banned module in `httpd -M`; a banned `.so` on disk; a banned `LoadModule` line; INCLUDES filter / ScriptAlias / cgi|SSI handler / `Options ExecCGI|Includes`; a **required** module not loaded (positive control, includes proxy_balancer, lbmethod_byrequests, slotmem_shm, brotli); `httpd -t` fails). - `Dockerfile.shared-httpd`: COPY + `RUN gate remove && gate check` last, `LABEL org.whp.httpd-exec-surface="removed"`. - `scripts/tests/httpd-exec-surface-gate.test.sh`: 26 cases in a throwaway stock-Alma container: negative control, remove+check, idempotent, and each regression caught **for its own reason** (mod_lua RPM, include / status / info / proxy_http / proxy_wstunnel / proxy_ajp / cache back (loaded), leftover `.so` (userdir, status, proxy_http), prefork-guarded cgi LoadModule, INCLUDES filter, ScriptAlias, `Options +ExecCGI`, required rewrite / proxy_fcgi / lbmethod_byrequests / proxy_balancer missing, config does not parse). - `scripts/tests/httpd-exec-surface-probes.test.sh` (new): renders the REAL WHP template + drop-in (`WHP_DIR`) into the image and probes the holes; `EXPECT_OPEN=1` runs it against an unhardened image to prove the probes can see them. - `build-push.yaml`: both new scripts in the Shell-Checks list (shellcheck clean). ## Test evidence (local builds, httpd 2.4.63, amd64 + arm64 under qemu) 1. **Gate**: build passes, `gate OK: ... all required modules loaded; httpd -t passes`; `httpd -M` has none of the banned modules, proxy family = `proxy proxy_balancer proxy_fcgi lbmethod_byrequests` + `slotmem_shm`. arm64 (qemu, `--platform linux/arm64`): same gate OK. Gate test: 26 passed, 0 failed. 2. **WHP suite** `WHP_TI_IMAGE=<this image> scripts/test-shared-httpd-tenant-isolation.sh` (WHP main 2dc62a79b): **PASS, 48 assertions, 0 failed**; residual notes now: Lua `[H=lua-script]` closed, nested `<If>` CGI closed, `[H=server-status]` closed (on the previous branch image the last one was still "KNOWN RESIDUAL"). 3. **Probes** (`httpd-exec-surface-probes.test.sh`): 13 passed, 0 failed. Closed: `[H=lua-script]`, nested `<If>` ExecCGI+cgi-script, `[H=server-status]`, `[H=server-info]`, nested `<If> SetHandler server-status`, `[P] http://` to an internal 127.0.0.1:81 listener (500, no secret), `[P] ws://`, `[P] ajp:// ftp:// scgi:// uwsgi://` (AH01144 "No protocol handler"); `[H=cgi-script]`+`+ExecCGI` is closed by the WHP drop-in on both images. Same script on the trunk image (`EXPECT_OPEN=1`): lua, nested-If CGI, status, info, `[P] http://` and `[P] ws://` are all reachable. 4. **Real-render matrix** (WHP Go `httpdtpl.RenderVhostConfig` output of the real template, real `cac-fpm:php83` backends, two sites, one with a 2-member balancer): `httpd -t` OK; PHP over FastCGI (`SCRIPT_FILENAME`/`DOCUMENT_ROOT` right), WordPress-style rewrite (pretty URL and `/`), https, http->https 301, gzip (`Content-Encoding: gzip`), Expires (`max-age=2592000`), `Header set/always set`, basic auth (401 / 401 / 200), MultiViews, `Options +Indexes`, dotfile 403, ErrorDocument, `/ping` 204 (http, https, `/ping/`), default-vhost catch-all 403, Docker health command passes, balancer hits both members. Output compared with the trunk image: **identical** (only the container hostname differs); the new image's error log is quieter (no `suEXEC` / `AH02282 No slotmem from mod_heartmonitor` notices). ## Still open (module needed by WHP; not fixable by removal) - `RewriteRule ... fcgi://host:port/... [P]` and `SetEnv`-style abuse of proxy_fcgi from a tenant `.htaccess`: the WHP drop-in already strips `PHP_VALUE`/`PHP_ADMIN_VALUE` (suite section "FPM": a poisoned victim worker is not reproducible). A tenant can still make the shared httpd open a FastCGI connection to any host:port reachable from `client-net` (other tenants' FPM pools). WHP-side follow-up, not this PR. - `[H=balancer-manager]` renders the Load Balancer Manager page; measured: it lists only balancers of the tenant's own vhost (a victim vhost's `balancer://fpm_*` is not shown) so nothing cross-tenant leaks. It still shows the server version string. - `authnz_fcgi`, `ext_filter`, `dumpio`, `echo`, `data`, `macro`, `request`, `substitute` stay loaded; their directives are server/vhost/directory scope (not reachable from `.htaccess` with the rendered `AllowOverride`). ## What a merge publishes (READ BEFORE MERGING) `build-push.yaml` triggers on **push to `trunk`** (and manual dispatch with `only=`). A merge runs the whole workflow (~1h): every image family is rebuilt and each publish job does push-by-digest then `assemble-multiarch-index.sh --tag latest` (cac `:phpNN`/`:latest`, cac-fpm, shared-httpd, shared-ols ...). For this change that means **`repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:latest` is retagged to the hardened image** (amd64 required, arm64 best effort; `--guard-existing-arm64` fails rather than silently dropping arm64). Merging does NOT touch running hosts. How hosts consume it: by **tag `:latest`, not digest**. `scripts/container-manager.sh recreate_shared_httpd` does `docker pull ...shared-httpd:latest` then `docker run ... shared-httpd:latest`. The nightly image-pull (03:17 host time, Go `image-pull` job / `pull-container-images.sh`) only refreshes the local `:latest` image; a running `shared-httpd-NN` keeps its old image until it is recreated, but ANY recreate (scale, reconfigure that recreates, manual) after the merge gets the hardened image. Merge only when ready to roll out: there is no way to build this image from the branch without also publishing `:latest` (a manual dispatch publishes the tag too). **Recommended merge (publishes ONLY shared-httpd):** merge with `[skip ci]` in the merge commit title (as #56/#57/#58 did; verified: those merges started no push run), then run the workflow by hand on `trunk` with `only=shared-httpd` (`.gitea/scripts/plan-legs.sh` -> `shared_httpd=true`, every other family `[]`/`false`; Shell-Checks incl. the gate test still runs). A plain merge instead rebuilds and re-tags EVERY family (cac/cac-fpm `:phpNN`, litespeed, lsphp, shared-ols) from a fresh base, which the nightly image-pull would then spread to customer containers: an unplanned fleet-wide image change unrelated to this PR. If the arm64 leg fails, `--guard-existing-arm64` makes the job fail and nothing is re-tagged (`allow_amd64_only` stays `false`). ## Compat impact The 2026-11-22 survey of all 45 shared sites (whp01 26, whp02 12, whp03 7) found 0 using ExecCGI/Includes/Lua, 0 `.shtml` with `<!--#include`, 0 `.cgi`/`.lua` files, 0 server-parsed/INCLUDES filters, no WebDAV, no `~user` URLs. The only cgi-ish thing is the WordPress "disable script execution in uploads" idiom (`Options -ExecCGI` + `AddHandler cgi-script ...`), which still parses (tested). One behaviour delta: with the module present, such a script file in uploads returned 403; now an unmapped file type (.pl/.py/.sh/.phtml) in that dir is served as static text exactly as if the .htaccess were absent (`.php` still goes to FPM via the vhost handler). Not executed, but its source is downloadable: same as any non-PHP file. Customers who later want CGI/SSI/WebDAV must use a non-shared tier. ## Roll-out plan (needs Josh; no ssh was done here) Safe order with the WHP-side PR #346: 1. Merge WHP #346 and release it first (template/drop-in work with or without this image; it is the defence-in-depth layer and ships the test). 2. Merge this PR (publishes `:latest`, ~1h build). Confirm the Gitea run is green and `docker buildx imagetools inspect ...shared-httpd:latest` shows amd64 (+arm64). 3. Canary first (VM 401 whp-al10-test): pre-tag the running image (see Rollback), `container-manager.sh recreate shared-httpd`, then `docker exec shared-httpd-01 /scripts/httpd-exec-surface-gate.sh check` (expect `gate OK`), `httpd -M | grep -E 'cgid|lua|include|actions|dav|userdir|status|info|proxy_(http|ajp|ftp|connect|scgi|uwsgi|wstunnel)|suexec|cache|dbd'` (expect nothing), `scripts/test-shared-httpd-tenant-isolation.sh` against it, and a PHP + rewrite request through the edge. 4. Then whp03, whp02, sdbees, whp01 one at a time. Recreating `shared-httpd-01` is a short outage for every shared_httpd site on that host: pick a quiet window, one host at a time, verify the healthcheck turns healthy (start-period 60s) and a site responds before the next. 5. After the fleet is on it: in WHP delete the "KNOWN RESIDUAL" notes (template comment, drop-in section 5, the residual branch of the test script). The handler pin and Options lines stay. ## Rollback The registry keeps only what is tagged; untagged digests disappear (every fleet digest except whp03's is already 404 there, see `/workspace/shared-httpd-image-baseline-2026-11-22.md`). So: - **Registry (done 2026-11-22 during the re-review):** the current `:latest` index `sha256:993b6405210dc082cae08ab0b7c44561d8b439687a77fb0d0169f008bbd25f62` (amd64 + arm64, = whp03's image) is now ALSO tagged `shared-httpd:rollback-20261122` (same manifest bytes PUT under a second tag; digest unchanged, `:latest` untouched). The merge moves `:latest` only; `:rollback-20261122` keeps 993b6405 alive. - **Per host, BEFORE any recreate/pull of the new image** (the old local image becomes dangling on `docker pull` and `image prune` deletes it): `docker tag <running image ID> repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:rollback-local-20261122` (IDs per host in the baseline doc; whp01 also tag `shared-httpd-02`'s separate April image ID, which runs by bare ID and is not touched by a recreate of -01). Optional: `docker save` it to /root. - **Roll back one host to its own old image:** `docker tag ...:rollback-local-20261122 ...:latest`, then run the `recreate_shared_httpd` `docker run` line by hand (the function itself does `docker pull :latest` first, which would fetch the new image again). - **Roll back the registry for everyone:** `docker buildx imagetools create -t repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:latest repo.anhonesthost.net/cloud-hosting-platform/shared-httpd:rollback-20261122`, then recreate on the affected hosts (they get 993b6405, the last published image, not necessarily the older image they ran before). Reverting the PR and re-running the workflow also works but takes ~1h. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-23 05:49:20 +00:00
One Apache serves every tenant in shared-httpd and everything it executes runs as
the shared `apache` user. mod_lua cannot be closed from the WHP vhost side
(RewriteRule [H=lua-script] binds the handler after any config pin), so the
modules are removed from the image: scripts/httpd-exec-surface-gate.sh
remove|check, run as the last package step of Dockerfile.shared-httpd. check
fails the build if a banned module is loadable/loaded, the global INCLUDES filter
or a cgi-bin ScriptAlias is configured, httpd -t fails, or a module the platform
needs (rewrite, proxy_fcgi, ssl, headers, ...) is not loaded. Test + CI wiring.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 2 commits 2026-11-23 06:09:11 +00:00
A WHP site with more than one FPM backend is rendered as <Proxy balancer://>
+ BalancerMember + `ProxySet lbmethod=byrequests` (panel/internal/vhost/
httpdtpl/render.go buildProxyBlock), which needs proxy_balancer,
lbmethod_byrequests and slotmem_shm. None of the three was in the required
list, so a future image change dropping them would pass this gate and take
every multi-backend site down. brotli_module was named in the comment but not
in the list. The comment's "status for /ping-style probes" was wrong (/ping is
a mod_rewrite R=204 in the default vhost) and is gone. Also documents that a
later `dnf update` of httpd-core restores the deleted .so / %config files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
The first regression case runs `dnf install -y mod_lua`, and restore() only
copied back /etc/httpd and /usr/lib64/httpd, not the RPM database. Every
later case therefore failed on "RPM mod_lua is installed" and passed whether
or not the check it targets worked: with the LoadModule scan, the leftover-.so
check, the RPM check, or the loaded-module check disabled in the gate, all 15
cases still passed (measured by mutating the gate).

restore() now uninstalls mod_lua, and expect_fail asserts the gate's own
failure message for each case. The include case puts the real .so back so the
module actually loads; a new case uses the stock prefork-guarded `LoadModule
cgi_module` shape (never loaded under event MPM), which only the LoadModule
scan can see; a new positive-control case removes proxy_balancer. Re-run:
17 passed; disabling the LoadModule scan, the .so check, the config grep or
the required-module check now each fail the suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
Author
Owner

Independent review (adversarial). Two fixes are pushed to this branch (2a6e2d5, 0f8407c). One rollout decision is still open (finding 3).

Measured locally. I built Dockerfile.shared-httpd from this branch and from trunk and compared them.

  • httpd -M differs by exactly actions, cgid, dav, dav_fs, dav_lock, include, lua and userdir. Everything else is untouched: proxy_balancer, lbmethod_byrequests, slotmem_shm, brotli, wstunnel and so on are still there.
  • WHP PR #346 test-shared-httpd-tenant-isolation.sh passes against this image: 37 assertions, and "Lua via RewriteRule [H=lua-script] is now closed". Trunk reports the residual.
  • With the current main WHP template and drop-in, this image passes httpd -t and SSI, CGI and Lua are all inert. Only the symlink read remains, which needs #346. Shipping the image before #346 is therefore safe and already useful.
  • Real render matrix: Go RenderVhostConfig, the real drop-ins, real cac-fpm:php84 backends, one single-backend site and one balancer site.
    • These match trunk: php, rewrite, http to https 301, https, deflate, expires and Header, auth_basic 401/200, autoindex, remoteip XFF to REMOTE_ADDR, balancer and /ping 204.
    • This differs from trunk: a tenant .htaccess that uses Action, XBitHack or SSI* gets 500 (it got 200 on trunk). AddHandler server-parsed/cgi-script and AddOutputFilter INCLUDES still parse.
  • arm64: the gate passes under QEMU on almalinux/10-base aarch64.
  • shellcheck is clean.

Findings

  1. (fixed, MEDIUM) The test's first case reinstalls mod_lua, and restore() did not roll back the RPM database. Every later case then failed with "RPM mod_lua is installed", so those cases proved nothing. Disabling the LoadModule scan or the .so check in the gate still left the suite at 15/15. restore() now removes mod_lua, every case asserts its own failure reason, and there are new cases for a prefork-guarded cgi LoadModule and a missing balancer. The suite now runs 17 cases, and mutants of the LoadModule scan, the .so check, the config grep and the required-module check are each caught.
  2. (fixed, MEDIUM) The required-module list was missing proxy_balancer, lbmethod_byrequests and slotmem_shm, which multi-FPM sites use (render.go buildProxyBlock). It was also missing brotli. The comment about "status for /ping" was wrong and has been removed.
  3. (open, MEDIUM, rollout) Any tenant .htaccess that uses Action, XBitHack or SSI* outside <IfModule> answers 500 after the recreate. The 2026-11-22 survey did not grep for these. Before the first prod recreate, run a read-only grep of the shared_httpd docroots for ^\s*(Action|XBitHack|SSI[A-Za-z]+)\b.
  4. (note, LOW) This is the first Shell-Checks step that needs docker and network. Shell-Checks does not gate publishing.
  5. (out of scope, already in the spec) A tenant RewriteRule [P] can reach any FPM backend and any internal HTTP service. Measured: fcgi://<other tenant fpm> was reached and answered "Primary script unknown" because the vhost's ProxyFCGISetEnvIf pins SCRIPT_FILENAME.

Publish and rollout. A push to trunk rebuilds and retags every family: cac:php82-86 and :latest, cac-fpm, litespeed, lsphp, shared-httpd:latest and shared-ols. shared-httpd:latest is pulled only by container-manager.sh recreate_shared_httpd, which runs from the manual CLI or the admin "Pull & Recreate All"/Scale actions. The nightly 03:17 image-pull covers only container_types (cac-fpm), and --restart unless-stopped restarts the old container. So merging publishes the image but rolls nothing out. To avoid the ~1 h rebuild of every family, merge with [skip ci] and then dispatch only=shared-httpd.

Not merged (by instruction).

Independent review (adversarial). Two fixes are pushed to this branch (2a6e2d5, 0f8407c). One rollout decision is still open (finding 3). **Measured locally.** I built `Dockerfile.shared-httpd` from this branch and from trunk and compared them. - `httpd -M` differs by exactly actions, cgid, dav, dav_fs, dav_lock, include, lua and userdir. Everything else is untouched: proxy_balancer, lbmethod_byrequests, slotmem_shm, brotli, wstunnel and so on are still there. - WHP PR #346 `test-shared-httpd-tenant-isolation.sh` passes against this image: 37 assertions, and "Lua via RewriteRule [H=lua-script] is now closed". Trunk reports the residual. - With the *current main* WHP template and drop-in, this image passes `httpd -t` and SSI, CGI and Lua are all inert. Only the symlink read remains, which needs #346. Shipping the image before #346 is therefore safe and already useful. - Real render matrix: Go `RenderVhostConfig`, the real drop-ins, real cac-fpm:php84 backends, one single-backend site and one balancer site. - These match trunk: php, rewrite, http to https 301, https, deflate, expires and Header, auth_basic 401/200, autoindex, remoteip XFF to REMOTE_ADDR, balancer and `/ping` 204. - This differs from trunk: a tenant `.htaccess` that uses `Action`, `XBitHack` or `SSI*` gets **500** (it got 200 on trunk). `AddHandler server-parsed/cgi-script` and `AddOutputFilter INCLUDES` still parse. - arm64: the gate passes under QEMU on almalinux/10-base aarch64. - shellcheck is clean. **Findings** 1. (fixed, MEDIUM) The test's first case reinstalls mod_lua, and `restore()` did not roll back the RPM database. Every later case then failed with "RPM mod_lua is installed", so those cases proved nothing. Disabling the LoadModule scan or the .so check in the gate still left the suite at 15/15. `restore()` now removes mod_lua, every case asserts its own failure reason, and there are new cases for a prefork-guarded cgi LoadModule and a missing balancer. The suite now runs 17 cases, and mutants of the LoadModule scan, the .so check, the config grep and the required-module check are each caught. 2. (fixed, MEDIUM) The required-module list was missing proxy_balancer, lbmethod_byrequests and slotmem_shm, which multi-FPM sites use (`render.go` buildProxyBlock). It was also missing brotli. The comment about "status for /ping" was wrong and has been removed. 3. (open, MEDIUM, rollout) Any tenant `.htaccess` that uses `Action`, `XBitHack` or `SSI*` outside `<IfModule>` answers 500 after the recreate. The 2026-11-22 survey did not grep for these. Before the first prod recreate, run a read-only grep of the shared_httpd docroots for `^\s*(Action|XBitHack|SSI[A-Za-z]+)\b`. 4. (note, LOW) This is the first Shell-Checks step that needs docker and network. Shell-Checks does not gate publishing. 5. (out of scope, already in the spec) A tenant `RewriteRule [P]` can reach any FPM backend and any internal HTTP service. Measured: `fcgi://<other tenant fpm>` was reached and answered "Primary script unknown" because the vhost's ProxyFCGISetEnvIf pins SCRIPT_FILENAME. **Publish and rollout.** A push to trunk rebuilds and retags every family: cac:php82-86 and :latest, cac-fpm, litespeed, lsphp, shared-httpd:latest and shared-ols. shared-httpd:latest is pulled only by `container-manager.sh recreate_shared_httpd`, which runs from the manual CLI or the admin "Pull & Recreate All"/Scale actions. The nightly 03:17 image-pull covers only container_types (cac-fpm), and `--restart unless-stopped` restarts the old container. So merging publishes the image but rolls nothing out. To avoid the ~1 h rebuild of every family, merge with `[skip ci]` and then dispatch `only=shared-httpd`. Not merged (by instruction).
jknapp added 1 commit 2026-11-23 06:47:23 +00:00
A tenant `RewriteRule ^ - [H=server-status|server-info]` binds the handler
after any config section could pin it, and `RewriteRule ... http://x [P]`
proxies to internal addresses (SSRF). Config cannot close those; removing
the modules does. WHP renders only SetHandler proxy:fcgi, <Proxy balancer://>
+ BalancerMember fcgi:// + ProxySet lbmethod=byrequests and
ProxyFCGISetEnvIf, so only proxy, proxy_fcgi, proxy_balancer,
lbmethod_byrequests and slotmem_shm stay.

Removed in addition to the earlier set: status, info, proxy_http, proxy_ajp,
proxy_ftp, proxy_connect, proxy_scgi, proxy_uwsgi, proxy_wstunnel,
proxy_fdpass, proxy_express, proxy_hcheck, lbmethod_bybusyness,
lbmethod_bytraffic, lbmethod_heartbeat (+ mod_heartbeat/heartmonitor .so),
suexec, dbd, authn_dbd, authz_dbd, cache, cache_disk, cache_socache,
socache_dbm, socache_memcache, socache_redis. socache_shmcb stays (SSL).

The gate derives its banned-module regex from one list. Tests: 26 gate
cases (banned status/info/proxy_*/cache back, leftover .so, required
lbmethod_byrequests/balancer missing) and a new live probe script
(scripts/tests/httpd-exec-surface-probes.test.sh) that renders the real WHP
template + drop-in and tries [H=lua-script|server-status|server-info],
nested <If> CGI and [P] http/ws/ajp/ftp/scgi/uwsgi.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-23 07:01:20 +00:00
The comment still described only the first commit's modules (cgid/lua/include/
actions/dav/userdir). It now lists status/info, the unused proxy_* family and
suexec/dbd/cache too, and says plainly that Shell-Checks does not gate the image
jobs: the Dockerfile `gate check` is what blocks a bad image. Comment only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin sec/shared-httpd-exec-surface-2026-11-22:sec/shared-httpd-exec-surface-2026-11-22
git checkout sec/shared-httpd-exec-surface-2026-11-22
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cloud-hosting-platform/cloud-apache-container#59