norcaster-envoy
A filter for an Envoy your platform team already runs. Before Envoy sends an app's AI request to the provider, the filter asks Norcaster for a decision. Norcaster answers from the app's rules and keeps a record of every answer. Envoy then calls the AI provider itself. The apps are not changed: they keep sending to Envoy, and your provider keys stay where they are.
| Norcaster's decision | What Envoy does |
|---|---|
| allow | Sends the request to the provider as it is, byte for byte. |
| hide | Sends the version Norcaster returned, with the sensitive data hidden. |
| block | Does not call the provider. The caller gets an error that names the decision and the record. |
With answer checks on for a route, Envoy also asks Norcaster about the provider's answer, its text and the tool calls it asks for, before the caller gets it. They are off unless you turn them on.
The filter is an Envoy external processor (ext_proc): a small gRPC service that runs beside
Envoy. Envoy hands it each request and acts on its answer.
Status: on PyPI as norcaster-envoy, and as a container image for amd64 and arm64,
ghcr.io/norcaster/norcaster-envoy:0.2.1, signed (see Verify the image).
Tested with Envoy 1.40.2.
What the record shows
The app asked Norcaster before it called the provider. Here Envoy asks on the app's behalf. With answer checks on, Envoy also asked about the provider's answer before the caller got it; that record is kept under the request's.
What it does not show:
- What Envoy sent afterwards. Norcaster does not see the provider call. The record holds a SHA-256 of what was checked, so you can compare it with what your own systems logged.
- That every request was checked. Only requests that pass through this Envoy, on a route where the filter is on, are. A request that goes to the provider another way (another proxy, a direct call, a route where the filter is turned off) is not checked and leaves no record.
- That the text asked about was the provider's whole answer, or what the app did with it. With answer checks on, the record shows what Envoy asked about. Some parts of an answer are not read; see Answer checks.
- That every answer was checked. Answers are checked only on routes where answer checks are on, and not when the request itself was let through without a check, or the provider answered with an error.
If you need a record that nothing reached the provider unchecked, send the app's traffic through the Norcaster gateway instead.
The request is sent to Norcaster to be checked. If your data may not leave your network, this filter does not change that; a Norcaster you host yourself does.
Set up
You need a Norcaster key with the runs:write scope, and the id of each app in Norcaster.
-
Run the filter beside Envoy, in the same pod or on the same host, from its image:
docker pull ghcr.io/norcaster/norcaster-envoy:0.2.1
There is no
latesttag: pin the version, or better its digest, and verify the image before you run it.Run it with the key in its environment. It listens on
127.0.0.1:9002, so it shares Envoy's network: in Kubernetes as a second container in Envoy's pod; with plain Docker like this:docker run --network container:<your envoy container> --read-only \ -e NORCASTER_API_KEY -e NORCASTER_API_URL=https://api.norcaster.com \ ghcr.io/norcaster/norcaster-envoy:0.2.1
Without the image:
pip install norcaster-envoy(it brings the Norcaster SDK,norcaster), thenpython -m norcaster_envoy. From a checkout of the Norcaster repository:pip install ./sdk/python ./packages/norcaster-envoy, or build the image from its root withdocker build -f packages/norcaster-envoy/Dockerfile -t norcaster-envoy .. -
Add the filter to Envoy.
examples/envoy.yamlis a whole working config: an OpenAI route and an Anthropic route, the filter, and its gRPC cluster. It comes in the package's source distribution on PyPI:pip download --no-deps --no-binary norcaster-envoy norcaster-envoy==0.2.1 tar -xzf norcaster_envoy-0.2.1.tar.gz norcaster_envoy-0.2.1/examples
The parts that matter are the
envoy.filters.http.ext_procfilter (before the router) and, on each route, the app it belongs to:typed_per_filter_config: envoy.filters.http.ext_proc: "@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExtProcPerRoute overrides: grpc_initial_metadata: - key: x-norcaster-app value: "<the app's id>"
-
Send one request through Envoy. The response carries
x-norcaster-decision: allowandx-norcaster-receipt-id. The same request is in the app's records in Norcaster, marked Checked. If the headers are missing, the filter is not on for that route.
Settings
The filter reads its settings from the environment. Anything missing or wrong stops it before it
listens, with a log line Norcaster filter not started: and what is wrong. Envoy then refuses the
requests (see If the filter is not running).
| Environment variable | Default | What it is |
|---|---|---|
NORCASTER_API_KEY |
none, required | The Norcaster key, with the runs:write scope. Pass it from your secret store; never write it in a file you share. |
NORCASTER_API_URL |
https://api.norcaster.com |
Your Norcaster address. |
NORCASTER_WHEN_UNREACHABLE |
block |
block or let_through. See When Norcaster can't be reached. |
NORCASTER_TIMEOUT |
10 |
Seconds to wait for Norcaster's answer. Keep Envoy's message_timeout above it. |
NORCASTER_APPS_FILE |
none | The apps file: which provider key belongs to which app. See below. |
NORCASTER_ENVOY_ADDRESS |
127.0.0.1:9002 |
Where the filter listens. Change it only on a private network: the port has no TLS and receives whole prompts. |
Which app a request belongs to
Each request is checked against one app's rules and recorded under that app. The filter finds the app in this order, and never guesses:
-
The route's app, set in Envoy's config as above. Apps can't set or change it. To use one app for every route of an Envoy, set it once on the filter's
grpc_serviceasinitial_metadata(commented out in the example); a route's own app still wins. Namex-norcaster-apponce in each place: Envoy passes on only the last value of a key it is given twice. -
The provider key the request carries, through the apps file. For one route that serves several apps, each with its own provider key:
{ "provider_keys": [ {"name": "Support assistant", "sha256": "<SHA-256 of the provider key>", "app": "<the app's id>"} ] }
The file holds the key's SHA-256, never the key. Print it with
python -m norcaster_envoy fingerprint(ordocker run -i ghcr.io/norcaster/norcaster-envoy:0.2.1 fingerprint) and give the key on standard input. The key is read fromAuthorization: Bearer,x-api-keyorapi-key. It is hashed on arrival, never logged, and still goes to the provider as it was. The apps file is read only for routes with no app of their own.
A request that can't be tied to an app is refused: HTTP 403, x-norcaster-decision: not_checked, code no_app. Norcaster is not asked and the provider is not called. The same goes
for keys of two different apps on one request.
What is checked
Two kinds of request, streamed or not:
- OpenAI chat completions:
POST …/chat/completions(this covers Azure OpenAI too). The conversation: system prompt, user messages, earlier answers, tool calls and tool results. A request with a predicted output (prediction) is refused: OpenAI gets its text, usually the same file a message holds, and a check doesn't read it. - Anthropic messages:
POST …/v1/messages. The system prompt and the conversation. Thinking the provider signed is not checked and is sent on as it was. - Images, documents and audio in either: they meet the app's rules for them (allow, warn, block, size and type limits), as on the Norcaster gateway. Norcaster gets a description of each inline one (its SHA-256, size, media type and pixel size), never the file, and does not read what it shows; the record lists each one as not read. A hide never changes a file. A large file counts toward Envoy's buffer limit (below).
Any other request the filter sees is refused with HTTP 400 and is not sent: embeddings, the Responses API, token counting, a path with a trailing slash, and the rest. Norcaster is not asked about them. They are refused so that an app cannot skip the check by calling another route through the same Envoy. The path is read as the app sent it, before any rewrite of yours.
A route that sends no prompt, such as listing models, can be turned off for the filter in Envoy's
config (disabled: true, as in the example). Every route turned off that way is not checked.
Not checked on any request: the model's name and settings, tool definitions. The provider's answer is checked only with answer checks on; without them, a streamed answer streams to the caller as before, and the check runs before the request is sent.
Also refused, before Norcaster is asked: a body that is not JSON, a compressed body, a JSON body that names a field twice (the provider might read the other one), and a body Envoy did not send in full.
Answer checks
Off unless you turn them on. With them on for a route, Envoy also sends the filter the provider's whole answer and holds it until Norcaster has decided. The filter asks about it under the request's check, and the caller gets the answer only after that.
Turn them on for a route with a processing_mode override next to the route's app, as the
example shows (commented out on the /openai/ route):
overrides:
grpc_initial_metadata:
- key: x-norcaster-app
value: "<the app's id>"
processing_mode:
request_header_mode: SEND
request_body_mode: BUFFERED
request_trailer_mode: SKIP
response_header_mode: SEND
response_body_mode: BUFFERED
response_trailer_mode: SKIP
Keep all six lines. An override replaces the whole processing_mode, and a mode it leaves out is
Envoy's default: for the request body, NONE, so the request would never reach the filter. The
filter refuses such a request with HTTP 400 and it is not sent. For every route of an Envoy, set
response_body_mode: BUFFERED in the filter's own processing_mode instead.
The filter reads, for each request, which parts Envoy says it will send. response_body_mode: BUFFERED turns answer checks on, NONE leaves them off, and any other mode (STREAMED,
FULL_DUPLEX_STREAMED and the rest) is refused: Envoy would hand the caller the answer before it
was checked. Nothing else turns them on, and an app can't turn them off.
The app's rules in Norcaster must cover answers. If they don't, Norcaster refuses the answer check
(output_rules_off) and the answer is withheld (HTTP 503).
What is read: the answer's text, and each tool call it asks for (the tool's name and its arguments) before the app gets it, and so before any tool runs:
- OpenAI chat completions: the message's text, its
tool_callsof type function and the olderfunction_call. A tool call of any other type, an answer in audio, and an answer with more than one choice are withheld. - Anthropic messages: the text blocks and the
tool_useblocks (name and input).
Not read: images, reasoning and thinking, refusals, tools the provider runs itself (they ran before the answer came back), and the tool definitions in the request. The answer is checked as JSON, or as a stream of events. On hide, the caller gets Norcaster's text and each tool call's hidden arguments, still JSON of the same shape, with the tool's name unchanged.
Refused before anything is sent, with answer checks on: a request for more than one answer
(n above 1), and an OpenAI request for an answer in audio (modalities other than text, or
audio). A check could not read those answers.
Compression. The filter removes accept-encoding from the request on these routes, so the
provider answers uncompressed and the caller gets it uncompressed. Only that header changes. An
answer that is compressed anyway is withheld.
Streamed answers (stream: true) are held. The caller gets nothing until the provider has
finished and Norcaster has decided; then the status, the headers and every event arrive at once.
On hide, only the events that held hidden text or arguments change; every other event keeps the
provider's bytes. A block is a JSON error, not a stream, and the app's OpenAI or Anthropic client
raises it. The OpenAI and Anthropic clients wait up to 10 minutes for an answer by default; the
example route allows 300 seconds.
What the caller gets. The request's headers stay; these are added for the answer:
x-norcaster-answer-decision:allow,hideorblock;uncheckedfor an answer let through without a check;no_textfor an answer with neither text nor a tool call (not asked about);unreachable,refusedornot_checkedfor an answer that was withheld.x-norcaster-answer-receipt-id: the record's id in Norcaster, when Norcaster answered.x-norcaster-answer-unchecked-id: the id of an answer let through without a check.
| The answer | The caller gets | x-norcaster-answer-decision |
|---|---|---|
| Norcaster's decision was allow | The provider's answer, byte for byte | allow |
| Norcaster's decision was hide | The answer with Norcaster's version in it, its Content-Length to match | hide |
| Norcaster's decision was block | 400, the answer withheld | block |
Norcaster can't be reached (setting block) |
503, the answer withheld | unreachable |
Norcaster can't be reached (setting let_through) |
The provider's answer, untouched; reported later | unchecked |
| Norcaster refused: the rate limit | 429, with Retry-After, the answer withheld |
refused |
| Norcaster refused: the app is stopped | 403, the answer withheld | refused |
Norcaster refused: anything else (output_rules_off, a wrong key…) |
503, the answer withheld | refused |
| The answer can't be read (not JSON or events, compressed, audio…) | 400, the answer withheld | not_checked |
| Neither text nor a tool call | The provider's answer, untouched | no_text |
| The request was let through without a check | The provider's answer, untouched | none |
| The provider answered with an error | The provider's error, untouched | none |
| The answer is larger than Envoy's buffer | 500 from Envoy, none of the answer | none |
An error about the answer is in the provider's own format, as for a request, with "about": "answer" in its norcaster part:
{
"error": {
"message": "Norcaster's decision on the model's answer was block (contextual_block). A secret or access credential was detected in the message. The answer was withheld. Receipt: 5b2f0c1e-0a51-4c1b-9d8e-3f7a2c6d9e10.",
"type": "invalid_request_error",
"code": "contextual_block"
},
"norcaster": {"about": "answer", "decision": "block", "receipt_id": "5b2f0c1e-0a51-4c1b-9d8e-3f7a2c6d9e10", "code": "contextual_block"}
}
The request's check id never leaves the filter: the answer is asked about in the same call, so neither the caller nor the provider sees it or can set it.
What the caller gets
On every response the filter saw, also on errors:
x-norcaster-decision:allow,hideorblock;uncheckedfor a request let through without a check;unreachable,refusedornot_checkedfor a request that was not sent.x-norcaster-receipt-id: the record's id in Norcaster, when Norcaster answered.x-norcaster-unchecked-id: the id of a request let through without a check.
With answer checks on, the answer's own headers too; see Answer checks.
A block is HTTP 400, in the provider's own error format so that the app's OpenAI or Anthropic client shows the message. The provider is not called:
{
"error": {
"message": "Norcaster's decision was block (contextual_block). A secret or access credential was detected in the message. The provider was not called. Receipt: d8d96f4f-dbec-4ab9-9792-2a0919d2c0c5.",
"type": "invalid_request_error",
"code": "contextual_block"
},
"norcaster": {
"decision": "block",
"receipt_id": "d8d96f4f-dbec-4ab9-9792-2a0919d2c0c5",
"code": "contextual_block",
"reason": "A secret or access credential was detected in the message.",
"suggestion": "Replace the credential with a descriptive placeholder such as <API_KEY> or <TOKEN>, then ask about the surrounding code or error. Rotate it if it was live."
}
}
The error never repeats what was blocked. Other refusals, in the same format:
| What happened | Status | x-norcaster-decision |
|---|---|---|
| Norcaster's decision was block | 400 | block |
Norcaster can't be reached (setting block) |
503 | unreachable |
| Norcaster refused: too much content | 413 | refused |
| Norcaster refused: the rate limit | 429, with Retry-After |
refused |
| Norcaster refused: the app is stopped | 403 | refused |
| Norcaster refused: a wrong key, a missing scope, an unknown app | 503 | refused |
| No app for the request | 403 | not_checked |
| A request the filter does not check, or can't read | 400 | not_checked |
| Envoy is not set to hold the request (its modes, below) | 400 | not_checked |
| The filter is down or does not answer in time | 503, empty body, no headers | (Envoy's own) |
| The request is larger than Envoy's buffer | 413 | (Envoy's own) |
What your own logs get
- Envoy's access log can carry the decision and the record's id from the response headers. The
example config logs
norcaster=%RESP(X-NORCASTER-DECISION)% receipt=%RESP(X-NORCASTER-RECEIPT-ID)% unchecked=%RESP(X-NORCASTER-UNCHECKED-ID)%, and the same three for the answer (answer=,answer_receipt=,answer_unchecked=);%RESPONSE_CODE_DETAILS%saysnorcaster_block,norcaster_not_checked,norcaster_answer_blockand so on for a refusal. - The filter's log has one line per request: the decision, the record's id, the code and the
reason, the app and how it was found, the kind of request and how long it took. With answer
checks on, a second line per answer, starting
about=answer, with how long the filter took from the answer's arrival. Never the content or a key.
When Norcaster can't be reached
"Can't be reached" means no connection, no answer within NORCASTER_TIMEOUT, or an error on
Norcaster's side.
By default the request is blocked: HTTP 503, the provider is not called.
NORCASTER_WHEN_UNREACHABLE=let_through sends the request on instead. Every request that is let
through is recorded, each time:
- A warning in the filter's log, with the request's id and its SHA-256.
- In the
x-norcaster-decision: uncheckedandx-norcaster-unchecked-idresponse headers, and so in Envoy's access log. - In Norcaster, once it answers again: the next check that succeeds reports what was let through, and it shows in the app's records as Let through without a check. When the filter stops, it tries once more to report what is still waiting.
The record holds a SHA-256 of the request, when it happened and why. It never holds the request itself. No rule ran on a request that was let through, and it is not counted as a check.
With answer checks on, the setting applies to the answer too. By default the answer is withheld
(HTTP 503); the provider had already answered. With let_through the caller gets the answer
untouched, with x-norcaster-answer-decision: unchecked and its id, and Norcaster records it under
the request it answers. An answer to a request that was itself let through is not asked about:
there is no check to ask it under.
Know these limits before you turn it on:
- A request that is let through goes to the provider as the app wrote it. Nothing is hidden.
- Requests waiting to be reported are kept in the filter's memory. If the filter ends before Norcaster answers again, its own log line is the only record.
- At most 10,000 wait at a time per filter. Past that, requests are blocked.
- A refusal from Norcaster always blocks, whatever the setting: a wrong or revoked key, a missing scope, a stopped app, the rate limit, or more than 1,000,000 characters.
If the filter is not running
What Envoy does when the filter is down, or does not answer in time, is set in Envoy's config, not by the filter. Nothing the filter does can record a request Envoy sends without asking it. Keep these as the example has them:
failure_mode_allow: false. Withtrue, Envoy sends requests to the provider unchecked and with no record in Norcaster whenever the filter is down, slow or failing. The only traces are Envoy's ownext_proc.failure_mode_allowedcounter and a missingx-norcaster-decisionin its access log.message_timeoutaboveNORCASTER_TIMEOUT(the example: 11 s against 10 s). If Envoy gives up first, the caller gets Envoy's error andNORCASTER_WHEN_UNREACHABLEnever applies.processing_modeas in the example: the request headers, the whole request body (BUFFERED), and the response headers; the answerNONEorBUFFERED(answer checks). A route's override lists all six modes. The filter reads Envoy's modes on each request and refuses one that Envoy would not hold for the decision, and a body it did not get in full.observability_modeoff. In that mode Envoy sends requests on without waiting for the filter; the filter then asks Norcaster nothing and logs an error.- The filter before any other filter that changes the request body, and before the router.
- No
disabled: trueon a route that carries prompts, and no per-routefailure_mode_allow.
With these, a request while the filter is down gets HTTP 503 from Envoy and is not sent. After the filter comes back, Envoy reaches it again on the next request.
After any change to Envoy's config, send one request and look for x-norcaster-decision.
Limits to know
- Each check draws on the Norcaster key's rate limit, the same one as requests through Norcaster's gateway: 600 a minute by default, shared by all of one person's keys, or by one service account's or agent's keys. One key for every app behind an Envoy shares that limit: 10 requests a second for all of them together. Over the limit, Norcaster refuses and the request is blocked with HTTP 429. Like gatewayed requests, checks don't count toward the plan's monthly request limit yet.
- Each request waits for Norcaster's answer before the provider is called. Measured on one machine against a local Norcaster: about 13 ms added for a short prompt and 22 ms for a 6.5 KB conversation (p50), of which about 2 to 3 ms is the filter and the hops to it; the rest is the check. A hosted Norcaster adds the network round trip.
- Envoy holds the whole request body while it is checked. The example allows 4 MiB
(
per_connection_buffer_limit_bytes); a larger request gets HTTP 413 from Envoy and is not sent. With answer checks on, Envoy holds the whole answer under the same limit; a larger answer gets HTTP 500 from Envoy and none of it reaches the caller. A streamed answer's events are much larger than its text: 4 MiB holds roughly 14,000 tokens of a streamed OpenAI answer and 35,000 of an Anthropic one (estimated from the events' size). A route raises both limits withrequest_body_buffer_limit. The filter takes up to 64 MiB; keep Envoy's limits at or below it. - Answer checks add the provider's whole time to a streamed answer's first word, and a second
check. The answer check is asked once the provider has finished, so Envoy's
message_timeoutdoes not include the provider's time; the route'stimeoutdoes. - The Responses API is not covered.
POST /v1/responsesis refused, as every route the filter does not check. - Run the filter on loopback, beside Envoy. Its gRPC port has no TLS and receives whole prompts.
Verify the image
Norcaster's release workflow builds and signs each release of the image. The signature is made without a key: a Sigstore certificate for that workflow's GitHub identity, recorded in the public Rekor log. Verify a pulled image with cosign 2.6 or later:
cosign verify ghcr.io/norcaster/norcaster-envoy:0.2.1 \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp '^https://github\.com/norcaster/norcaster/\.github/workflows/release-envoy\.yml@refs/tags/norcaster-envoy-v'
The image is built for linux/amd64 and linux/arm64. Its signed index also lists BuildKit's
SPDX SBOM and the build's SLSA provenance:
docker buildx imagetools inspect ghcr.io/norcaster/norcaster-envoy:0.2.1 --format '{{ json .SBOM }}'
The Norcaster SDK in the image is the published norcaster release, byte for byte: the release
workflow checks that before it builds. Before a release is pushed, each platform is scanned and a
fixable critical vulnerability stops it, and the tests below run against the image behind Envoy.
Develop
The tests need Docker for the Envoy tests (they are skipped without it) and the SDK from this
repository (sdk/python). From this folder:
PYTHONPATH=src:../../sdk/python/src uv run --isolated --no-project --python 3.12 \
--with-requirements docker/requirements.txt --with "pytest>=7" --with "pyyaml>=6" \
python -m pytest -q
test/test_service.py and test/test_answers.py drive the filter over a real gRPC connection the
way Envoy does, without and with answer checks. test/test_envoy.py runs Envoy 1.40.2 in Docker
with examples/envoy.yaml, as it is and with its answer checks turned on,
against a stand-in provider and a stand-in Norcaster; set NORCASTER_ENVOY_TEST_IMAGE to run the
filter from a built image. docker/lock.sh regenerates the image's hash-pinned requirements.
Metadata
Release files for norcaster-envoy 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| norcaster_envoy-0.2.1.tar.gz | 65.7 kB | Without provenance | Details for norcaster_envoy-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| norcaster_envoy-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for norcaster_envoy-0.2.1-py3-none-any.whl |
Total release size: 101.3 kB
Release files / norcaster_envoy-0.2.1.tar.gz
| Download URL | norcaster_envoy-0.2.1.tar.gz |
|---|---|
| Size | 65.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d1e9d23b9fe0f2e9eca6f088789c02d5cd0f694bc919da0e0d000bcf70e5dac
|
|
BLAKE2b-256 checksum How to use checksums |
bffe6e6b294b0ba5851b6d666a3bebd3e25e4f742b9d6031f4b13dc32f026e99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Release files / norcaster_envoy-0.2.1-py3-none-any.whl
| Download URL | norcaster_envoy-0.2.1-py3-none-any.whl |
|---|---|
| Size | 35.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6d585bd1580d5133499ae18d600f017e1fb0e5223a0e3aa8d4b490ea76416fa
|
|
BLAKE2b-256 checksum How to use checksums |
1339c52417b6d44e9e6e3cb56c5a5eccb9e15d4cffff1c04f23e7a8fce2ceee7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Security for norcaster-envoy 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.