Files
haproxy-manager-base/coraza-spoa/README.md
T
rootandClaude Opus 5.5 4a453df83e
Build and push coraza-spoa / Build-and-Push (push) Successful in 5m42s
coraza-spoa: Coraza engine v3.8.1 (security), SecArgumentsLimit 65536, RC-only publish branch
Security update of the WAF engine. coraza-spoa v0.7.1 pins
github.com/corazawaf/coraza/v3 v3.7.0, which is affected by the v3.8.x
advisories; several are bypasses of rules WHP enforces, reproduced in WHP's
WAF regression net on v3.7.0:

- GHSA-pc5q-qfxp-ggqv jsDecode octal: Log4Shell with ${ } as \44\173 ... \175
  escapes is not seen by the enforced 944150.
- GHSA-5gj4-9gm7-2fx2 JSON key collision: LFI in {"a.b":..} shadowed by a
  later {"a":{"b":..}} (or a case/duplicate collision) is not seen by 930120.
- GHSA-x26q-wvhg-fh4m ProcessURI: a raw 0x7f in the query drops ALL ARGS_GET.
- GHSA-w253-m66g-rx24: the LAST Content-Type picked the body processor.

Dockerfile: keep coraza-spoa v0.7.1 and CRS (coraza-coreruleset v4.25.0)
unchanged; upgrade only the engine in place (ARG CORAZA_VERSION=v3.8.1,
go get, verified against go.sum/sum.golang.org). The build fails unless
`go version -m` shows exactly that version in the binary.

config.yaml: Coraza 3.8 enforces SecArgumentsLimit (default 1000) on
urlencoded/JSON bodies and the query string and never inspects arguments
past it. With the default, "1000 filler args + LFI in arg 1001" bypassed
930120 on 3.8.1 (it is blocked on 3.7.0). Upstream's mitigation (deny rules
200004/200005) is in Coraza's own coraza.conf-recommended, not in the one
coraza-coreruleset v4.25.0 embeds (the @coraza.conf-recommended we load).
Set SecArgumentsLimit 65536 (= SecRequestBodyLimit / 2: no accepted body can
reach it, so every argument is inspected as on 3.7) and add 209620/209621:
deny in enforce / log in detect_only if arguments were ever dropped
(ARGUMENTS_LIMIT_REACHED, 3.8-only variable, so it lives in the image).

Workflow: a push to coraza-release/** publishes ONLY :<coraza-spoa/VERSION>-rc
and :<sha> (never :latest), for a staged per-host rollout through WHP's coraza
image pin. Not release/**: that prefix also triggers the edge image build.
main keeps publishing :latest (+ :<version> + :<sha>). New coraza-spoa/VERSION
2026.11.1.

Do not merge until the staged rollout is done: merging moves :latest, which
apply-coraza-waf-mode.sh pulls on every unpinned host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-27 21:38:57 -08:00

115 lines
6.1 KiB
Markdown

# coraza-spoa sidecar
A sidecar container that runs [Coraza-SPOA](https://github.com/corazawaf/coraza-spoa) as a WAF engine for `haproxy-manager`. HAProxy consults it per-request via the SPOE/SPOP protocol; Coraza evaluates the request against OWASP CRS rules and tells HAProxy whether to allow or block.
## Design constraints
- **`haproxy-manager` does NOT depend on this sidecar.** The base image works standalone (used in other projects and home networks) without WAF. SPOE config in the generated `haproxy.cfg` is opt-in via an env var on `haproxy-manager`.
- **Fail-open when the sidecar is unhealthy.** `option set-on-error continue` in the HAProxy SPOE config means request flow continues uninspected if coraza-spoa is unreachable, rather than 503-ing customer traffic.
- **Detect-only globally; enforce explicitly.** See `overrides.conf` for the day-one enforce list. Most CRS rules log without blocking until we've tuned per-customer false positives.
## Deployment shape
Two containers per host, both on the `client-net` docker network:
```
haproxy-manager (existing) — ports 80, 443, 8000
│ SPOE TCP/9000 → reach coraza-spoa by container DNS
▼
coraza-spoa (this image)
port 9000 (SPOE) — NOT exposed on host; internal network only
/var/log/coraza — bind-mounted to host for AI Monitor consumption
```
Typical `docker run`:
```bash
mkdir -p /var/log/coraza
chown 65532:65532 /var/log/coraza # distroless nonroot UID
docker run -d \
--name coraza-spoa \
--network client-net \
--restart unless-stopped \
-v /var/log/coraza:/var/log/coraza \
your-registry.example.com/cloud-hosting-platform/coraza-spoa:latest
```
Then on the `haproxy-manager` container, add the env var:
```
-e HAPROXY_CORAZA_SPOE_BACKEND=coraza-spoa:9000
```
The haproxy-manager template engine sees the env var and renders the SPOE config block pointing at this sidecar. Without the env var, no SPOE blocks render — the haproxy-manager image's behavior is unchanged.
## Files
| File | Purpose |
|---|---|
| `Dockerfile` | Multi-stage build (golang:1.25 → distroless), pinned to upstream coraza-spoa tag |
| `config.yaml` | SPOA listener config + one named application `haproxy` |
| `overrides.conf` | Day-one enforce list (`ctl:ruleEngine=On` for high-confidence rule IDs) |
| `README.md` | This file |
## Audit log
`/var/log/coraza/audit.log` — JSON, one event per line, RelevantOnly (only requests that triggered ≥1 rule are logged). AI Monitor should be configured to tail this on each host.
Entries include rule IDs, matched patterns, request metadata, and action taken (`log` for detect-only, `deny` for enforced). Use the JSON `action` field to filter blocked vs. observed.
## Upgrading the pin
CRS rules are bundled into the coraza-spoa binary at build time, so the CRS version is whatever ships with the pinned coraza-spoa tag. To upgrade:
1. Check upstream releases: <https://github.com/corazawaf/coraza-spoa/releases>
2. Skim the CHANGELOG for new/changed rules in the `overrides.conf` ID ranges.
3. Bump `ARG CORAZA_SPOA_VERSION` in the Dockerfile.
4. The Coraza ENGINE is pinned separately (`ARG CORAZA_VERSION`, upgraded in place with `go get`; the build fails if the
binary does not embed it). Move it together with WHP's WAF regression net (`scripts/tests/waf-regression` +
`scripts/tests/coraza-body-parse-harness` go.mod in the WHP repo), which must pass on the new engine first.
5. Bump `coraza-spoa/VERSION` (YYYY.MM.N) and push a `coraza-release/<anything>` branch: CI publishes ONLY
`:<VERSION>-rc` and `:<sha>` (never `:latest`). Roll it out host by host with WHP's coraza image pin
(`/etc/whp/coraza-image`, then `container-manager.sh recreate coraza-spoa`).
6. Only after the staged rollout, merge to `main`: CI then publishes `:latest` + `:<VERSION>` + `:<sha>`. Moving
`:latest` IS a fleet-wide rollout: `apply-coraza-waf-mode.sh` pulls `:latest` on every WAF mode apply on unpinned hosts.
## Tuning false positives
When a legitimate request triggers a blocked rule, the audit log shows the rule ID. Two ways to silence it:
1. **Per-rule exception** in `overrides.conf`: `SecRuleRemoveById <id>` (full disable) or `SecRuleRemoveTargetById <id> "<target>"` (targeted exception).
2. **Drop from the enforce list**: remove the rule's ID range from the `ctl:ruleEngine=On` overrides; it falls back to detect-only.
After tuning, push the change — CI rebuilds, then `recreate coraza-spoa` on each host to apply.
## Multi-arch (linux/amd64 + linux/arm64)
The image is built for both platforms **without QEMU**: the two Go stages are
`FROM --platform=$BUILDPLATFORM` (the in-house `golang:1.25` mirror is amd64-only,
which is enough) and the binary is cross-compiled with
`CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH`. The catalog-extractor runs at
build time on the build platform; its JSON output is architecture-neutral. Only the
final distroless stage is per target platform. The amd64 image content is
byte-identical to the pre-multi-arch build (measured: same rootfs tree, same
`/coraza-spoa` sha256).
CI (`.gitea/workflows/build-push-coraza.yaml`, one job on the trusted x86 runner):
amd64 and arm64 are each pushed **by digest, untagged, to both registries**
(Gitea + GHCR; the same digest lands in both), then
`scripts/assemble-multiarch-index.sh` creates `:latest` in each registry with
`docker buildx imagetools create` from `<repo>@<amd64>` and `<repo>@<arm64>`.
The arm64 step is `continue-on-error`; when it fails the tag is published
amd64-only, as before, and the arm64 digest is only ever taken from the current
run's step output (a previous build's arm64 is never re-attached).
Attestations: buildx provenance is kept per platform. A by-digest push with
attestations is a small per-platform index (image + `attestation-manifest`);
`imagetools create` over two of them yields one index with all four entries
(amd64, its attestation, arm64, its attestation), each attestation still pointing
at its own platform manifest; `imagetools inspect --format '{{json .Provenance}}'`
shows both. Nothing flattens or drops them.
Local rehearsal (no real registry is touched): `scripts/e2e-coraza-multiarch.sh`
(usage in its header).