No description
  • Go 95.1%
  • Python 2.9%
  • Dockerfile 0.9%
  • Lua 0.7%
  • Makefile 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
James Luther 37645fce58
All checks were successful
security-scan / security-scan (push) Successful in 1m12s
test / laya (push) Successful in 51s
test / go (push) Successful in 3m12s
Merge pull request 'Document nginx2root as out of WAF reach' (#29) from nginx2root-note into main
Reviewed-on: #29
2026-11-19 13:15:21 +00:00
.forgejo/workflows Build images only when something in them changes 2026-10-27 11:04:49 -05:00
cmd Require at least one gate suite and normalize IPv6 hosts 2026-11-18 21:28:20 -05:00
eval Close the gate's remaining input gaps 2026-11-18 21:24:38 -05:00
integrations Fix the review dashboard's label actions for Grafana 13 2026-10-27 19:00:14 -05:00
internal Add a checkpoint gate that refuses a worse Laya checkpoint 2026-11-18 21:24:38 -05:00
laya Add a checkpoint gate that refuses a worse Laya checkpoint 2026-11-18 21:24:38 -05:00
.dockerignore Build the Laya model server from laya/ as centinela-laya 2026-10-27 10:29:51 -05:00
.gitignore Add a checkpoint gate that refuses a worse Laya checkpoint 2026-11-18 21:24:38 -05:00
.ojoignore Mark the two OJO findings on the config file change as false positives 2026-10-27 12:04:37 -05:00
centinela.example.yaml Read settings from a YAML config file, with per-host settings 2026-10-27 11:42:25 -05:00
DEPLOY.md Tighten the nginx2root note 2026-11-19 08:09:49 -05:00
Dockerfile Build without filesystem access so the image starts under a read-only root 2026-10-02 17:07:55 -05:00
go.mod Upgrade golang.org/x/net for GO-2026-6860, and draw the test token at random 2026-10-27 16:33:36 -05:00
go.sum Upgrade golang.org/x/net for GO-2026-6860, and draw the test token at random 2026-10-27 16:33:36 -05:00
LICENSE Initial commit: Centinela, a WAF grey-zone adjudicator 2026-09-30 09:28:15 -05:00
Makefile Add a checkpoint gate that refuses a worse Laya checkpoint 2026-11-18 21:24:38 -05:00
README.md Tighten the nginx2root note 2026-11-19 08:09:49 -05:00

Centinela

Centinela is a model-driven IPS that sits behind your WAF. Its main job is to adjudicate the WAF's grey zone: run OWASP CRS at a high paranoia level and, instead of blocking on the anomaly score, hand the requests CRS flags to a decision model that answers a fixed set of typed hazard questions. Policy code then decides allow, flag, block, or shun. The result is high-paranoia detection without the false-positive flood that makes high paranoia unusable.

client -> proxy -> WAF (CRS) -> centinela -> app
                     |             |
              anomaly score   shunned? bypass? hard-block? cache? gate?  (µs, no model)
                                   |
                    grey zone (flagged, not certain) -> model -> policy
                                   |
                       allow / flag / block / shun

Centinela deploys two ways: as a forward-auth target behind nginx/Caddy/ Traefik/ModSecurity, or in-path as a reverse proxy where there is no such proxy (e.g. a cloudflared tunnel routing straight to Services) — configure per-host upstream entries under hosts: in CENTINELA_CONFIG (or set CENTINELA_UPSTREAM(S)) and it forwards or blocks, reading the full body. See DEPLOY.md and, for the cluster manifests, gitops-infra/security-apps/centinela/.

On our grey-zone probe set, CRS at paranoia level 3 blocked 51% of benign requests. Adding model adjudication of the grey zone cut that to 10% while detection went up (the model both clears false positives and catches quiet attacks CRS misses). See eval/README.md for the harness, dataset, and full numbers.

The WAF stage

CENTINELA_WAF selects where the WAF verdict comes from:

Value Meaning
embedded Centinela runs OWASP CRS itself, via Coraza in detection-only mode, at CENTINELA_WAF_PARANOIA (1–4). It gets the anomaly score and the matched rules, which it passes to the model as context.
header (default) The proxy's own WAF (ModSecurity, Coraza) reports its anomaly score in CENTINELA_WAF_SCORE_HEADER; /v1/inspect callers can also pass matched rules.
off No WAF signal; the pre-filter alone decides what to escalate.

With a WAF result, the model sees request.waf — the score and each matched rule with what it matched. The battery instructions tell the model to treat those as leads to verify, since CRS fires on apostrophes, passwords, and pasted code. A matched rule is a hint, never a verdict.

Virtual patches

The embedded WAF also loads internal/waf/rules/virtual-patches.conf, Coraza rules for named, widely exploited CVEs. Each adds a critical finding (+5) at any paranoia level and names its CVE, so the model and the decision log see which exploit a request resembles:

Rule CVE
1009618 PHP2Shell (CVE-2026-109618/109619): PHP_SESSION_UPLOAD_PROGRESS field
1044228 Log4Shell (CVE-2021-44228/45046), obfuscated lookups included
1006271 Shellshock (CVE-2014-6271)
1022965 Spring4Shell (CVE-2022-22965)
1005638 Struts S2-045 (CVE-2017-5638): OGNL in Content-Type
1026134 OGNL injection (Confluence CVE-2022-26134, Struts 2)
1042889 Text4Shell (CVE-2022-42889)
1001823 PHP-CGI argument injection (CVE-2012-1823)
1004577 PHP-CGI soft hyphen (CVE-2024-4577)
1029927 Next.js middleware bypass (CVE-2025-29927): any x-middleware-subrequest header
1011497 HTTP2Shell (CVE-2026-111497): request body with Content-Encoding: br
1014938 Java4Shell (CVE-2026-114938): 64+ contiguous Base64 chars with miscounted padding
1031852 OwnTracks Recorder (CVE-2026-131852): printf conversion in fields posted to /pub

Ids are 10 followed by the CVE number. New rules go in that file with an id in 1000000–1099999, the range the WAF reports. With CENTINELA_WAF=header, include the file in your own ModSecurity/Coraza after crs-setup.conf and before the CRS rules.

Virtual patches are a stopgap, not a fix:

  • Java4Shell (1014938, CVE-2026-114938): targets OpenJDK's AVX-512 Base64 decode intrinsic out-of-bounds write across headers, cookies, parameters, XML, multipart part headers and raw request bodies. It does not cover Base64 inside uploaded file contents or MIME whitespace-split values. The real fix is setting -XX:-UseBASE64Intrinsics on the JVM or upgrading to Oracle JDK 17.0.21.1, 21.0.13.1, 25.0.5.1 or 27.0.1.1 (and matching OpenJDK builds).
  • OwnTracks Recorder (1031852, CVE-2026-131852): matches printf format strings in JSON fields or raw bodies posted to /pub (after decoding \u escapes). Location updates sent over MQTT never reach HTTP inspection; upgrade to Recorder 1.0.5.
  • Out of WAF reach: Heartbleed (CVE-2014-0160) is a TLS heartbeat bug (patch OpenSSL where TLS terminates), and Apache httpd's mod_http2 race (CVE-2026-119618) is in HTTP/2 framing (upgrade to 2.4.71 or set Protocols http/1.1).
  • Out of WAF reach, nginx2root (CVE-2026-123007, -123633, -121810, -113425, -123634): nginx bugs in HTTP/2 flow control (-123007) and connection draining (-123633), HTTP/3 streams (-121810), the mail proxy's auth_http (-113425), and the resolver with a variable proxy_pass plus mirror or SSI (-123634). Every trigger is frame, connection, mail or DNS state inside nginx, which neither the WAF nor centinela sees. Upgrade to nginx 1.31.9 or 1.30.7 and restart (a reload keeps the old binary). Until then, set http2 off;, remove quic listeners, bind mail listeners to loopback, and use fixed upstreams instead of variable proxy_pass. The shipped integrations/nginx/centinela.conf enables neither HTTP/2 nor QUIC and proxies only to fixed upstreams (add http2 off; if your http block turns HTTP/2 on).

Local rules and exclusions

CENTINELA_WAF_EXTRA_RULES names a file of your own Coraza directives. The embedded WAF loads it after the virtual patches and before the CRS rules, so it can switch CRS rules off where they misfire (ctl:ruleRemoveById, ctl:ruleRemoveTargetById). Give its rules ids in 1100000–1199999; a rule in that range that matches with a message shows in the decision log like a CRS rule. If the file can't be read or doesn't parse, centinela exits at startup.

For example, Forgejo and Gitea show files such as .gitignore, .htaccess and Dockerfile at /<owner>/<repo>/src/..., which CRS 930130 (restricted files) flags. This turns 930130 off for those views on one host only:

SecRule REQUEST_HEADERS:Host "@streq git.example.org" "id:1100001,phase:1,pass,nolog,chain"
  SecRule REQUEST_FILENAME "@rx ^/[^/]+/[^/]+/(?:src|raw|blame|commits|media)/" "t:none,ctl:ruleRemoveById=930130"

The gate: what reaches the model

CENTINELA_GATE decides which requests are escalated (default grey under CENTINELA_WAF=embedded, else suspicious):

  • grey — requests whose WAF score is at or above CENTINELA_GREY_MIN, or anything the cheap pre-filter flags (the floor: it catches score-0 recon like /phpmyadmin that CRS ignores). A score below CENTINELA_GREY_MIN that the pre-filter does not flag passes without a model call.
  • suspicious — the pre-filter (substring/encoding checks), or any positive WAF score.
  • always — every request not otherwise short-circuited.

CENTINELA_WAF_HARD_BLOCK (0 = off) refuses without a model call at or above a chosen WAF score, for evidence too strong to be worth adjudicating.

Binary request bodies score far above any attack: a git fetch or an image push can reach several hundred. In the config file, hosts.<host>.hard_block_exempt takes all or a list of /pattern entries (and waf.hard_block_exempt takes entries across hosts); in the environment, CENTINELA_WAF_HARD_BLOCK_EXEMPT lists the endpoints the hard block leaves alone, as comma-separated [host]/pattern entries (setting the variable replaces hard_block_exempt in hosts: as a whole):

CENTINELA_WAF_HARD_BLOCK_EXEMPT=git.example.org/*/*/git-upload-pack,git.example.org/*/*/git-receive-pack,git.example.org/v2/*/*/blobs/uploads/*,/hooks/*
  • The host is matched exactly, ignoring case and port. Without one (/hooks/*) the entry applies to every host; a bare host (files.example.org, or hard_block_exempt: all under hosts:) exempts all of its paths.
  • The pattern is matched against the whole decoded path. * matches within one path segment, ? one character, [a-z] a class.
  • An exempt request is exempt from the hard block only. It is still scored and still goes through the gate to the model, which can block it. To skip inspection altogether use hosts.<host>.bypass (per host) or bypass / CENTINELA_BYPASS_PREFIXES (every host).

Why it is fast

Most requests never reach the model. Checks run cheapest first:

  1. Shunned client. A client that earned a shun verdict is refused by IP for CENTINELA_SHUN_TTL. With CENTINELA_SHUN_ON_VERDICT=false a shun verdict is applied as a block, so one false positive costs one request rather than every request for the TTL; pair it with CENTINELA_SHUN_AFTER, or nothing shuns. So is one that had CENTINELA_SHUN_AFTER requests blocked within CENTINELA_SHUN_WINDOW: a scanner rarely sends one request bad enough for a shun, but it sends many that are each worth a block. Blocks by the model (in time or late), from the verdict cache and by the hard block all count; a block because the model was unavailable does not.
    • IP blocklist. A client on a CENTINELA_IP_BLOCKLIST list is refused next, bypass paths included.
    • Rate limit. After the bypass prefixes, a client past CENTINELA_RATE_LIMIT requests in CENTINELA_RATE_WINDOW gets 429 with Retry-After until the window ends.
  2. Bypass prefixes. Health checks and static paths are skipped. Top-level bypass (CENTINELA_BYPASS_PREFIXES) applies to every host; hosts.<host>.bypass in the config file applies only to that host, so an admin path like /ghost/ skips checks on the blog without opening /ghost/ on every other host.
  3. WAF. In embedded mode CRS scores the request (this is the one stage that reads the full headers and body).
  4. Hard block. An overwhelming WAF score is refused here, no model call.
  5. Verdict cache. The cache key hashes everything the model sees and the WAF findings, not the client IP, so scanners that repeat a payload across IPs hit the cache.
  6. Gate. As above — only the grey zone (or flagged requests) go on.
  7. Model call. One request asks every hazard question in parallel, with a hard CENTINELA_BUDGET deadline. If the model errors, the request is allowed (CENTINELA_FAIL_OPEN=true) or refused (false). If it misses the deadline, the request gets the same answer but the call is left to finish in the background for up to ten budgets: the late verdict is cached, a shun blocks that client from its next request on, and the training log gets its line. At most CENTINELA_QUEUE_DEPTH calls run past their budget at once; beyond that a miss is abandoned.

In CENTINELA_MODE=async the model is never on the request path. Escalated requests are allowed immediately and assessed in the background. A resulting shun blocks that client from its next request on. Use async mode when the model's latency is too high for inline use.

Operator endpoints

CENTINELA_ADMIN_LISTEN (default 127.0.0.1:9108) is a second listener for the operator. It accepts loopback addresses only, so it is reachable from inside the pod or host and never through the proxied listener.

Path
GET /debug/vars counters
POST /unshun?client=<address> lift a shun and clear that client's blocked-request and recon counts
/authz, POST /v1/inspect the engine's own endpoints, for trying a request by hand

In proxy mode the main listener serves only /healthz and the proxied apps: it faces the internet, and /v1/inspect takes the client address from its caller.

The image has no shell or HTTP client, so the binary is its own client:

# without CENTINELA_STATE_URL each replica keeps its own shun list, so ask
# every pod; with it, one pod is enough
for p in $(kubectl -n centinela get pods -o name); do
  kubectl -n centinela exec "$p" -- /centinela unshun 203.0.113.9
done

It prints {"client":"203.0.113.9","was_shunned":true} per pod and logs client unshunned. A verdict already cached for a request stays cached: the same request is refused again until CENTINELA_CACHE_TTL passes, but no longer shuns.

Decision log

Every decision can be logged as one JSON line (msg="decision"). CENTINELA_LOG_DECISIONS chooses which:

Level Logged Use
blocked (default) refusals and failures quiet production log
escalated also every allowed request that showed a signal: anything past the gate, and anything the gate passed with a WAF score above 0 reviewing false allows
all every request, bypassed and clean ones included an access log, for short sessions

Rate-limited requests are the exception at every level: one client rate limited line per client per window.

Field Meaning
id per request; a review-queued allow and its late review verdict share it
verdict, source what was decided and by which stage
reasons hazards at or over the policy's thresholds
scores the model's three strongest hazards and its severity, whether or not any reached a threshold; kept with cached verdicts
waf_score, rules the CRS anomaly score and up to 12 matched rule ids
ms time from request arrival to the decision; for a late verdict, how long after
status in proxy mode, the HTTP status the client received (the upstream's, or Centinela's own 403/429), logged when response headers go out so websockets and streams are recorded at once; absent on /authz and /v1/inspect
client, method, host, path the request. Query strings, headers and bodies are not logged unless CENTINELA_LOG_DETAILS is on
country the client's country code from CENTINELA_COUNTRY_HEADER (Cloudflare's CF-IPCountry; XX unknown, T1 Tor), when the request has one. The model never sees it
query, ua, matched with CENTINELA_LOG_DETAILS=true, on every decision that is not an allow: the query string (up to 1 KiB), the user agent (256 bytes), and for each WAF rule that matched, its id and the text it matched (200 bytes, up to 12 rules)

CENTINELA_LOG_DETAILS is for reviewing what refused requests asked for. It is off by default because a refused request's query string or matched text can hold a token or password the client sent; allowed requests never log these fields.

To find false allows at escalated, look at verdict=allow lines with a high waf_score or a scores entry just under the policy's flag threshold.

Two Grafana dashboards read this log from Loki: an overview, and a review dashboard for drilling into the clients, paths and requests behind each count. See integrations/grafana.

Client checks

Three checks judge the client rather than a single payload. None cost a model call, and all are off until configured.

IP blocklist. CENTINELA_IP_BLOCKLIST is a comma-separated list of files and http(s) URLs, each holding one address or CIDR per line (# and ; start a comment, so Spamhaus DROP and FireHOL netsets load as published):

CENTINELA_IP_BLOCKLIST=/etc/centinela/blocklist.txt,https://www.spamhaus.org/drop/drop.txt
  • Every source is re-read each CENTINELA_IP_BLOCKLIST_REFRESH (default 1h). A source that fails, or answers with something that holds no addresses, keeps its previous contents.
  • A missing file stops startup. A URL that cannot be fetched at startup is logged and retried, so a feed's outage does not take the service down; until it loads, that feed blocks nothing.
  • A listed client gets 403 with source ip-reputation.

Rate limit. CENTINELA_RATE_LIMIT is the number of requests one client may make per CENTINELA_RATE_WINDOW (default 1m).

  • Requests under a bypass prefix are not counted. CENTINELA_RATE_LIMIT_EXEMPT takes comma-separated addresses and CIDRs that are never limited (monitoring, CI runners, your own networks).
  • Over the limit the proxy answers 429 with Retry-After; the forward-auth endpoint answers 403, the only refusal an auth subrequest carries. The source is rate-limit.
  • Each client is logged once per window when it first goes over (client rate limited), not once per refused request.
  • Windows are fixed. Counts are per instance and in memory, so with several replicas a client can make up to the limit on each, unless CENTINELA_STATE_URL shares them (see Shared state below).

Recon detection (proxy mode). CENTINELA_RECON_404_AFTER (default 0, off) shuns a client for CENTINELA_SHUN_TTL once that many distinct paths (host+path) it requested came back 404 or 410 from the upstream within CENTINELA_RECON_404_WINDOW (default 1m). Scanners probing for /wp-login.php, /.env and similar paths on sites that do not have them get shut out without per-site rules or model calls.

  • Each shun logs client shunned with reason=recon and not_found=N, and increments centinela_recon_shuns on /debug/vars.
  • Not counted: requests Centinela refused; repeats of a path already counted in the window; paths browsers and crawlers request unprompted (favicon*, robots.txt, ads.txt, app-ads.txt, browserconfig.xml, humans.txt, manifest.json, site.webmanifest, /.well-known/*, /apple-touch-icon*, /sitemap*); requests with a Sec-Fetch-Dest other than document, iframe or frame (page subresources, so broken images on a page cannot get a reader shunned); and CENTINELA_RATE_LIMIT_EXEMPT networks.
  • POST /unshun clears the client's recorded misses along with its shun.

Shared state. With CENTINELA_STATE_URL=valkey://host:6379 (or redis://, optionally [[user]:password@] and /db), shuns, the blocked-request counts behind CENTINELA_SHUN_AFTER, the distinct missing-path sets behind CENTINELA_RECON_404_AFTER and the rate-limit counts are kept in Valkey, so every replica pointed at it enforces the same shun list and the same limits.

  • Needs Valkey 7.0 or Redis 7.0 or later (PEXPIRE ... NX). Keys start with centinela: and all carry a TTL.
  • Each check gets 50 ms. If Valkey fails, the replica uses its own memory, as if no URL were set, and tries Valkey again every 5 s. It logs the outage once and once on recovery, and counts failures in centinela_shared_state_errors. A shun made during an outage holds for its TTL, but only on that replica.
  • An unreachable Valkey at startup is logged, not fatal.
  • The verdict cache stays per instance.

All three checks trust CENTINELA_CLIENT_IP_HEADER. A request that arrives without a client address is neither listed, limited nor counted.

Backends

CENTINELA_BACKEND Endpoint Notes
laya (default) POST /v1/systemone on a self-hosted Laya server Same wire format and questions as typesafe, no key required. A small encoder fine-tuned on this battery and retrained on production traffic: fast enough for the default budget, and recognises recon.
typesafe POST https://api.typesafe.ai/v1/systemone (Jev) Nouls per hazard + a severity Score. Needs TYPESAFE_API_KEY. Adds a network round trip; pin a versioned model ID once thresholds are tuned.

All backends ask the same battery, defined in internal/decider/decider.go: sqli, xss, command_injection, path_traversal, ssrf, recon, and a four-level severity. Tune thresholds separately for each backend.

The Laya backend

laya-centinela-r4 is Laya multilingual (mmBERT-base, 322M parameters) fine-tuned on the exact questions internal/decider/typesafe.go sends. internal/decider/testdata/questions.json pins that wording: if the test fails, the checkpoint no longer matches the battery and needs retraining. Serve it with the centinela-laya image built from laya/, which bakes the checkpoint in, and keep CENTINELA_LAYA_MODEL=multilingual: that server answers any model name, but other names take a slower path. The checkpoint needs max_len 2048, since request states run to about 1,600 tokens. This repository builds both images independently: centinela tags v* (.forgejo/workflows/build.yml, skipping laya/-only pushes) and colibrisec/centinela-laya tags laya-v* (.forgejo/workflows/laya.yml, running only when laya/ changes).

r4 continues from r2 with 4,499 candidates from the production training log labelled by a Qwen teacher with host context (711 held out, 3,788 merged with r2's 10,971 cases for 14,759 in total). On the 711 held-out production requests (balanced policy, against teacher labels) it detects 96.4% of attacks (r2: 72.6%), flags or blocks 0.6% of benign requests (r2: 42.3%), and allows all 135 Forgejo file views (r2: 2 of 135). On GPU it answers in 33 ms p50 / 151 ms p90. It recognises reconnaissance (/.env, /.git/config), which the default policy flags rather than blocks, so on the 68-record eval (PL3, counting blocks) it blocks 21 of 29 attacks (72.4%) against r2's 24 (82.8%) at the same 17.9% false-positive rate, with one SQLi login-bypass regression (admin'-- flagged). See laya/README.md for the full breakdown and the r5 backlog.

Earlier rounds: round one was 3,090 cases from SecureAI-SE/http-attack-requests (CC-BY-4.0) and notesbymuneeb/ai-waf-dataset (MIT), labelled through this pipeline by Qwen 27B. Round two added CSIC 2010 normal traffic, Qwen-verified AI-WAF benign rows and SR-BH 2020 attacks (CC0), 10,971 cases in total. The 68 eval records were never trained on.

Training log

CENTINELA_TRAIN_LOG=/path/train.jsonl appends one JSON line per model call (- writes to stdout). Cache hits and requests the gate lets through are not recorded. Each record has a timestamp, the request's id (matching its decision log line, so a reviewer's label or response outcome joins directly to the model input), the request fingerprint, the state exactly as the model received it, the model's seven answers (hazards and severity), the policy, the verdict and its reasons, and the model latency. The client IP is never written.

The state includes the request body excerpt and the values CRS matched, so the file can hold passwords and personal data. It is created owner-only and stops growing at CENTINELA_TRAIN_LOG_MAX_BYTES. Keep it off unless you are collecting a training window, and decide where it is stored and for how long before turning it on.

Reviewer labels

review.listen (CENTINELA_REVIEW_LISTEN, off by default, e.g. 0.0.0.0:9110) starts a review listener serving POST /v1/labels (and GET /healthz) for the Grafana review dashboard. It requires CENTINELA_REVIEW_TOKEN as a bearer token; the token is environment-only (refused in the config file) and must be at least 32 characters, or startup fails.

Each row of the dashboard's Requests table has False positive (false_positive) and Should be blocked (should_block) actions, each behind a confirmation, that call Centinela through a Grafana Infinity data source (uid: centinela-labels) from Grafana's server inside the cluster. Only users signed in to Grafana can label, and nothing new faces the internet.

A label carries the row's id, host, path, method, client, verdict, source, status, reasons and scores as URL query parameters (a JSON body is also accepted), so it stands on its own even for requests the model never saw. The server sets ts and reads reviewer from the X-Grafana-User header, which the dashboard's actions fill with ${__user.login}. Grafana 13 needs the vizActionsAuth feature toggle for these actions to show. Each label is appended to review.labels (CENTINELA_LABELS) as one JSON line. With several replicas give each pod its own file next to the training log, through the environment variable so Kubernetes fills in the pod name: CENTINELA_LABELS=/var/lib/centinela/labels-$(POD_NAME).jsonl. Each label is also logged as msg="label", which the review dashboard's Labels panel lists. Labels change nothing live; they are input for retraining.

Policies

CENTINELA_POLICY selects strict, balanced or monitor (internal/policy/policy.go). A hazard at or above FlagAt is flagged. At or above ActAt it triggers its action: recon flags, command_injection shuns, and every other hazard blocks. Severity can escalate a hazard that has already fired, but it never blocks on its own.

The thresholds are starting points, not calibrated values. Run monitor against real traffic, review the decision log lines, then switch to enforcing.

Proxy integrations

Proxy How Body inspected?
nginx auth_request → /authz (nginx) no
Caddy forward_auth after coraza_waf (Caddyfile) no
Traefik forwardAuth middleware after the WAF middleware (file, k8s) optional (forwardBody)
Apache / any ModSecurity with Lua SecRuleScript after CRS → /v1/inspect (modsecurity) yes, plus CRS anomaly score

Every integration places Centinela after the WAF, so requests the WAF already blocks never cost a model call.

Run

Centinela reads its settings from the YAML file named by CENTINELA_CONFIG. To try it in front of an app listening on port 8080, write centinela.yaml:

upstream: http://127.0.0.1:8080 # proxy mode: forward allowed requests here
budget: 1s
log:
  decisions: all
waf:
  mode: embedded
backends:
  laya:
    url: http://127.0.0.1:8000/v1/systemone

Start the Laya model server and Centinela, then send requests through port 9107:

docker run --rm --gpus all -p 8000:8000 git.colibrisec.org/colibrisec/centinela-laya:latest
CENTINELA_CONFIG=centinela.yaml make run

curl -i localhost:9107/                            # 200 from the app
curl -i "localhost:9107/item?id=1'+or+'1'='1"      # 403: the model blocks it as SQL injection
curl -s localhost:9108/debug/vars | jq 'with_entries(select(.key|startswith("centinela")))'

Without a GPU, run Laya with -e LAYA_DEVICE=cpu instead of --gpus all; answers take about a second. To use TypeSafe's hosted Jev, set backend: typesafe and put TYPESAFE_API_KEY in the environment. For forward-auth mode, leave out upstream and point your proxy at /authz (see Proxy integrations). centinela.example.yaml is a production-shaped file with every section, including per-host settings.

Any environment variable that is set overrides the matching file key, and the file overrides the default, so environment-only deployments work unchanged. Lists (bypass, rate_limit.exempt, ip_blocklist.sources, waf.hard_block_exempt) are YAML lists in the file and comma-separated in the environment. Unknown keys are startup errors, and a bad value names its key and file. Secrets (CENTINELA_STATE_URL, TYPESAFE_API_KEY, CENTINELA_LAYA_API_KEY, CENTINELA_REVIEW_TOKEN) are environment-only and refused in the file.

A hosts: map in the file gives each host (matched case-insensitively, without a port) its own upstream, bypass prefixes and hard_block_exempt (all, or a list of /pattern entries). Setting CENTINELA_UPSTREAMS or CENTINELA_WAF_HARD_BLOCK_EXEMPT in the environment replaces that part of hosts: as a whole.

Variable File key Default
CENTINELA_CONFIG — unset (path to YAML config file)
CENTINELA_LISTEN listen 127.0.0.1:9107 (unix:/path.sock supported)
CENTINELA_ADMIN_LISTEN admin_listen 127.0.0.1:9108 (loopback only; off disables)
CENTINELA_UPSTREAM upstream unset (fallback upstream URL in proxy mode)
CENTINELA_UPSTREAMS hosts.<host>.upstream unset (host=url,...; overrides hosts: upstreams)
CENTINELA_PROXY_MAX_BODY limits.proxy_max_body 1048576 (bytes buffered for inspection in proxy mode)
CENTINELA_BACKEND backend laya (typesafe)
CENTINELA_MODE mode inline (async)
CENTINELA_GATE gate grey with embedded WAF, else suspicious (always)
CENTINELA_WAF waf.mode header (embedded, off)
CENTINELA_WAF_PARANOIA waf.paranoia 3 (embedded CRS level 1–4)
CENTINELA_WAF_MAX_BODY waf.max_body 131072 (bytes CRS inspects)
CENTINELA_WAF_EXTRA_RULES waf.extra_rules unset (file of Coraza directives loaded before CRS's rules)
CENTINELA_GREY_MIN grey_min 1 (lowest WAF score escalated)
CENTINELA_WAF_HARD_BLOCK waf.hard_block 0 (off; WAF score that blocks with no model call)
CENTINELA_WAF_HARD_BLOCK_EXEMPT waf.hard_block_exempt, hosts.<host>.hard_block_exempt unset ([host]/pattern entries the hard block skips)
CENTINELA_POLICY policy strict
CENTINELA_BUDGET budget 150ms
CENTINELA_FAIL_OPEN fail_open true
CENTINELA_CACHE_TTL / _SIZE cache.ttl / cache.size 10m / 50000
CENTINELA_SHUN_TTL shun.ttl 15m
CENTINELA_SHUN_AFTER / _SHUN_WINDOW shun.after / shun.window 0 (off) / 1m (blocked requests from one client that earn a shun)
CENTINELA_RECON_404_AFTER / _RECON_404_WINDOW recon.not_found_after / recon.window 0 (off) / 1m (distinct 404/410 paths from one client in proxy mode that earn a shun)
CENTINELA_SHUN_ON_VERDICT shun.on_verdict true (false: one model verdict blocks the request but never shuns; only CENTINELA_SHUN_AFTER does)
CENTINELA_MAX_BODY / _MAX_FIELD limits.max_body / limits.max_field 4096 / 1024 bytes
CENTINELA_WORKERS async.workers 8 (async)
CENTINELA_QUEUE_DEPTH async.queue_depth 1024 (async queue; inline, model calls running past the budget)
CENTINELA_CLIENT_IP_HEADER client_ip_header X-Real-IP
CENTINELA_COUNTRY_HEADER country_header CF-IPCountry (country code logged with each decision; empty disables)
CENTINELA_LOG_DECISIONS log.decisions blocked (escalated, all)
CENTINELA_LOG_DETAILS log.details false (true adds query string, user agent and WAF matches to non-allow decisions)
CENTINELA_IP_BLOCKLIST ip_blocklist.sources unset (files and URLs of addresses/CIDRs to refuse)
CENTINELA_IP_BLOCKLIST_REFRESH ip_blocklist.refresh 1h
CENTINELA_RATE_LIMIT / _RATE_WINDOW rate_limit.requests / rate_limit.window 0 (off) / 1m (requests per client per window)
CENTINELA_RATE_LIMIT_EXEMPT rate_limit.exempt unset (addresses/CIDRs never rate limited)
CENTINELA_STATE_URL env only (secret) unset (valkey:// URL to share shuns and counts between replicas)
CENTINELA_WAF_SCORE_HEADER waf.score_header X-WAF-Score
CENTINELA_BYPASS_PREFIXES bypass (+ hosts.<host>.bypass) /healthz,/favicon.ico
CENTINELA_LAYA_URL / _LAYA_MODEL backends.laya.url / backends.laya.model http://127.0.0.1:8000/v1/systemone / multilingual
CENTINELA_LAYA_API_KEY env only (secret) unset (sent as a bearer token when set)
CENTINELA_TYPESAFE_URL / _TYPESAFE_MODEL backends.typesafe.url / backends.typesafe.model https://api.typesafe.ai/v1/systemone / jev-latest
TYPESAFE_API_KEY env only (secret) unset (required when CENTINELA_BACKEND=typesafe)
CENTINELA_REVIEW_LISTEN review.listen off (address serving POST /v1/labels, e.g. 0.0.0.0:9110)
CENTINELA_REVIEW_TOKEN env only (secret) unset (required with review.listen; bearer token, at least 32 characters)
CENTINELA_LABELS review.labels off (path to JSONL file where reviewer labels are appended)
CENTINELA_TRAIN_LOG / _TRAIN_LOG_MAX_BYTES train_log.path / train_log.max_bytes off / 1073741824

Planned

  • Reviewed exceptions. Reviewer labels (false_positive / should_block) are now recorded from the Grafana review dashboard to review.labels. Next, a false_positive label will also create a narrow live exception (host, path, hazard, and the CRS rule and field when the WAF caused it) in Valkey with an expiry, downgrading only that hazard on matching requests while still sending them to the model.
  • Scheduled retraining. A periodic job will join recorded reviewer labels to the training logs, fine-tune the next checkpoint, gate it on centinela-eval plus every labeled example, and open the laya and gitops PRs for a human to merge. Exceptions the new checkpoint handles on its own will be retired.
  • Learned missing-path areas and response-driven recon labels. Learn each host's missing areas automatically from upstream responses, and use 404/410 outcomes as recon labels when retraining.
  • Training log to stdout, minimized. Today the training log is a file holding the full model input, which is what the current retraining round needs. The intended end state is to write it to stdout for the cluster's log pipeline, with the state minimized first (password-like and other sensitive values masked or dropped) so request bodies do not flow into log storage as-is.

Known limits

  • The request is attacker-written model input. The battery tells the model to judge the contents of request and never to follow instructions written inside it. Prompt injection aimed at the classifier is still possible, which is why the WAF stays in front and the model only adds blocks on top of it.
  • Anyone who can reach /v1/inspect can supply a client_ip, and so can get arbitrary IPs shunned. In proxy mode it is served only on the loopback admin listener. In forward-auth deployments, keep CENTINELA_LISTEN on loopback, a unix socket, or a network policy that admits only the proxy.
  • A shun follows the address, not the user. Verdicts are reached before any authentication, so a page that makes a visitor's browser send payload-looking requests to a host behind Centinela gets that visitor's address shunned, on every host. CENTINELA_SHUN_ON_VERDICT=false raises the cost from one request to CENTINELA_SHUN_AFTER of them; it does not remove it.
  • Forward auth does not send the request body in nginx or Caddy. Use the ModSecurity hook when body inspection matters.
  • Only per-request hazards are covered. Credential stuffing and other rate-based abuse need state across requests, and belong in a rate limiter.
  • The verdict cache lives in memory. Each replica keeps its own. Shuns and counts do too unless CENTINELA_STATE_URL is set.
  • Build with -tags no_fs_access (the Makefile and Dockerfile do). Without it Coraza needs a writable temp directory at startup and the binary exits under a read-only root filesystem.

License

GPL-2.0