Articles

Programmable edge rules and replayable trace testing without Nginx or Cloudflare

Block scrapers, rate-limit routes, verify JWTs and validate JSON Schema requests at the gateway without waking idle VMs, then test rule sets deterministically with versioned `gregale edge rule trace` JSON scenarios.

Updated

Enforce rate limits, JWT checks, IP/country blocks, CORS, JSON Schema validation, and request rewrites at the gateway—and test rules deterministically with replayable JSON scenarios before breaking live traffic. Refused requests never wake your microVM or consume compute.

Why gateway rules fail in typical PaaS stacks

On most platforms, adding request throttling, path validation, or IP allowlists forces you either to stitch together an external Cloudflare/Nginx proxy in front of your PaaS or write middleware in application code—meaning abusive scrapers, malformed uploads, and preflight OPTIONS requests still wake cold containers and burn billable RAM before being rejected. And editing regex or firewall rules directly in production risks locking out real users.

Programmable edge rules that protect idle apps

Gregale evaluates edge rules at the gateway before waking your app, in a strict cheapest-first pipeline (route, maintenance, redirect, rewrite, headers, cors, ip, geo, jwt, limit, throttle, waf, validate, challenge, cache, async, and budget):

sh
# Rate-limit searches across all app hosts without waking VMs on 429s
gregale edge rule create --app my-api --kind throttle \
  --match-host @app --match-path '/search/**' \
  --throttle-requests-per-second 5 --throttle-burst 10

# Share reusable office IP lists across apps and apply temporary 2h scraper blocks
gregale edge rule-list create office-ips --kind ip --item 203.0.113.0/24 --item 2001:db8::1
gregale edge rule create --app my-api --kind ip --match-host @app --match-path '/**' \
  --ip-deny 192.0.2.0/24 --expires-in 2h --name "block scraper"
  • Bypass-resistant normalization: Security gates (ip, geo, jwt, limit, throttle, validate, waf, challenge) normalize . / .. traversal segments, double slashes, case, ; path parameters, and X-HTTP-Method-Override headers before matching.
  • Draft 2020-12 JSON validation: validate rules enforce JSON schemas and unique case-insensitive object property keys (422 request_validation_failed) before bytes reach Go or ASP.NET handlers.
  • Safe rollout and instant rollback: Deploy risky rules in mode: log (gregale edge rule review), guard concurrent updates with If-Match ETags, and revert any mistake with gregale edge rule rollback --app my-api --to 12.
Rule limit per appFreeHobbyProScale
Total edge rules525100500
geo rules1525100
throttle rules1525100
cache rules01520

Replayable edge-rule trace testing

Instead of guessing how overlapping rules interact, replay exact requests locally against live app or project-environment rules via versioned scenario files:

sh
gregale edge rule trace --config trace.json

Trace scenarios (version: 1, up to 2 MiB config and 1 MiB body or body_base64) support repeated headers, simulated client_ip / country, and --project / --environment scopes without sending customer payloads to external logs or mutating production state. Whenever an outcome depends on live runtime state—such as a token bucket counter, cached response, or live JWKS fetch—the trace explicitly stops as incomplete instead of guessing.

Tradeoffs and boundaries

Edge rules apply to public hosts and automatically inherit @app security rules onto PR previews, whereas internal service-to-service traffic (*.internal), scheduled crons, queues, and direct invocations skip public edge rules (so internal auth remains your app's responsibility). Features such as jwt, ip, cache, and challenge require Hobby or higher, waf requires Pro+, and retry/circuit_breaker/async rules are gated per account.

See Edge rules, Reusable edge-rule trace scenarios, Security, Cache public API responses at the edge without waking your app, and Gregale pricing.

Questions

Do requests refused by edge rules wake a parked Gregale app?

No. ip, geo, jwt, limit, throttle, validate, waf and challenge rules run at the gateway in cheapest-first order, refusing blocked traffic before waking your microVM.

How can I test edge rule changes before applying them to production?

Deploy rules first in mode: log, inspect matched samples with gregale edge rule review, and run deterministic dry-runs against live rules using gregale edge rule trace --config trace.json.

Can I undo a broken edge rule change immediately?

Yes. Every change creates a versioned snapshot (gregale edge rule history) that you can restore in one command with gregale edge rule rollback.