← Back to Pull requests

feat(ecds): distribute WAF rules and RuleData via ECDS #547

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 27, 2026 17:36 UTC
Author

What

Replace HTTP rule polling and Istio WasmPlugin provisioning with authenticated Envoy ECDS delivery of complete WAF configurations, including RuleData.

Why

The polling path depends on a process-local rule cache populated by the leader and requires cache-token renewal inside plugin configuration. ECDS moves subscription and delivery into Envoy, lets every operator replica serve accepted configurations, and updates rules without restarting Gateway pods.

Changes

  • Deterministic RuleSet assembly and content hashes, accepted metadata in RuleSet/Engine status, and a separate all-replica publisher that reconstructs and verifies accepted content before serving it.

  • Gateway-scoped EnvoyFilter attachment, native RBAC bootstrap policy, Google gRPC file-based ServiceAccount credentials, TokenReview authentication, per-Engine authorization, stream revalidation and resource limits.

  • A shared TLS listener for ECDS and digest-addressed WASM assets, including asset requests over HTTP/1.1 and HTTP/2. Module bytes remain remote HTTPS references with SHA-256 verification, not inline ECDS bytes or Gateway mounts.

  • Versioned rule/data payloads, host-filesystem-free aggregate validation, directive/Include guards, delivery-size checks before Engine acceptance, bounded cold-readiness waiting and bounded NACK recovery.

  • Bundled-module build/release plumbing, Helm/RBAC/CRD changes, reconciler and transport tests, and a one-command KIND demo with the real plugin.

  • Retain the disabled legacy HTTP server, token/prerequisite helpers and ignored spec.ruleSetCacheServer; no second active rule-delivery mode.
  • This is the implementation previously collected in fork PR #3, rebased onto upstream main at 88cc6b0. All 77 implementation commits are signed and signed off. The architecture proposal in #542 remains separate: neither architecture commit is included in this branch. The original fork branch/PR is left intact.

    Verification

    Passed on rebased HEAD 76c9438, using the Makefile's Istio 1.31.1 default:

  • go test ./internal/... ./api/... ./cmd/... ./test/framework/... -count=1 -timeout 180s (includes controller envtest).

  • go test -race ./internal/xds ./internal/ecds/render ./internal/rulesets/... -count=1 -timeout 180s.

  • go build ./... and manager build with -tags 'no_fs_access coraza.no_memoize'.

  • go vet -tags integration ./... and git diff --check.

  • Range comparison preserves the implementation patches; the only changed patch context is an upstream workflow action-pin update. Upstream's current image/dependency pins are retained.
  • Previously verified on the source branch (5de300a), not rerun after this rebase: a from-scratch KIND demo with the real module (/ → 200, evilmonkey → 403, RuleData evildata → 403), and live RuleData reload without a Gateway restart.

    Dependency and release limitations

    The current companion plugin pin (31bca96) is unpublished. The demo requires a local ECDS-aware plugin worktree:

    make demo WASM_PLUGIN_DIR=/path/to/coraza-proxy-wasm-ecds
    

    The committed 8-byte WASM fixture is for developer builds/tests, not request enforcement. Demo/release images must bundle the real module. Release publishing requires a published compatible plugin artifact and the pinned version/digest/source repository variables; this PR does not publish that dependency. The current plugin and JSON/CRS-alias contract are temporary and will be replaced separately from the operator-side ECDS transport and acceptance logic.

    The WASM API change is breaking within v1alpha1: OCI image/imagePullSecret fields are removed in favor of paired url/sha256. There is no legacy-image migration preflight. Coordinated CA rotation/certificate reuse, complete external-host trust/allowlist support, mixed-release module rollover, HA soak/chaos and OpenShift verification remain follow-on work; OLM is outside this MVP. Engine Ready means accepted/provisioned, not proxy ACK or ongoing WAF health.

    Deferred review findings

    Recorded for follow-up after the MVP merge, unchanged by this rebase:

    1. Include crs/<file>.conf guard/validation-filesystem documentation mismatch.
    2. SecDataset backtick content can be over-rejected by directive scanning.
    3. Stale /dev/null comment where the validation trailer uses /dev/stdout.
    4. Startup envelope estimation assumes filenames without JSON escaping; actual rendered-size checks still protect delivery.
    5. Persistent consumer NACKs/retry exhaustion have no CRD-visible signal, notably for typoed embedded-file references. Logs/metrics and last-known-good/bootstrap behavior are not proof that the new configuration is active.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Rule updates are delivered to Gateways over ECDS without requiring Gateway restarts.
    The operator includes a default WASM module; custom modules can be configured with an HTTPS URL and SHA-256 digest.
    RuleSets can explicitly allow or reject empty assembled rules. Engine and RuleSet status now report accepted configuration and content.
    Helm supports generated or externally provided serving certificates.
    Bug Fixes
    Validation rejects reserved RuleData filenames and unsafe rule includes.
    Documentation
    * Upgrade guidance covers CRD updates and migration to URL-and-digest module configuration. Legacy cache-server settings are retained but ignored.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Review follow-up (cffc58b)

  • Security: ECDS now registers only the authenticated state-of-the-world stream. The generated unary and delta RPCs previously bypassed the stream interceptor, TokenReview, per-Engine authorization and node.id pinning; they now return Unimplemented.

  • Retry correctness: NACK retry versions are derived from the last response nonce (with a live-snapshot fallback), not from Envoy's version_info (which is the previously accepted version). Stale-retry serialization remains in place.

  • Rejected-content handling: markRulesInvalid clears RuleSet.status.acceptedContent only when the rejected hash matches the accepted hash. Engine accepted-record clearing on InvalidRuleSet is unchanged by design.

  • Serving certificates: release/static manifests are rendered with tls.generate=false and no private key; Helm installs reuse an existing generated Secret via lookup.

  • Other fixes: BumpRejected/Replace serialization, NACK counter CAS, bearer-token cap, bounded/deduplicated revalidation, HTTP Range/HEAD, Makefile shell/timeout fixes, and all lint findings.

  • Tests/checks: unit/envtest, race, build/vet, Helm validation and pinned golangci-lint pass.
  • Remaining explicit deferrals: OLM/OperatorHub installs still lack the serving Secret (unpublished path; OPP remains red), and auth-failure rate limiting remains a follow-up. See the PR discussion summary for the per-thread assessment.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: redhat-chai-bot Review duration: 2487m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #547"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%