AI Gateway Security Model
This page describes what Elchi AI Gateway protects and how: where each secret is stored and where it goes, who can reach the sockets and ports on the edge, what a client can and cannot forge, and what ends up in logs. Each section ends with how to check it on a running system.
What the supervisor is, and what it is not
elchi-ai-gateway is a supervisor. It renders the configuration for the engine, runs the Agent Router extproc as its child process, answers the consumer-key checks and writes usage and logs. It is not in the request path of the LLM traffic: Envoy's ext_proc filters connect directly to the extproc's Unix socket. Envoy's ext_authz filters connect to the supervisor's own authorization socket for keyed gateways (see Request-path isolation).
Consequences:
- A request never passes through a TCP port of the supervisor. Every connection from Envoy to the gateway uses a Unix socket in
/run/elchi-ai-gateway. - The supervisor's own HTTP server (
127.0.0.1:9002:/healthz,/readyz,/configz,/metrics) binds to loopback. Binding anywhere else needs the explicit--allow-non-loopbackflag. - The AI
ext_procfilter and both authorization phases are fail-closed (failure_mode_allow: false). If the gateway is down, requests fail. They are never forwarded without authorization or without the provider credential. The MCP result scan fails closed on a gateway whose sensitive-data policy blocks a type, and fails open where the policy only flags.
Where secrets live and travel
| Secret | Stored in the control plane | Shown by the API | Reaches the edge as | Never |
|---|---|---|---|---|
| Provider credentials (API keys, AWS/GCP credentials, Azure Entra client secret) | Mongo ai_gateway_configs, sealed with a key derived from ELCHI_JWT_SECRET | Masked: every secret field reads ***REDACTED*** | 00-providers.yaml in conf.d, then the rendered bundle in /run/elchi-ai-gateway/bundle (0600) | Sent to an edge that does not report an installed AI gateway |
Consumer virtual keys (sk-elchi-…) | SHA-256 hash only (sha256:<hex>) and a short prefix for display | The full key once, in the answer to the create call; afterwards only id and prefix | 00-consumers.yaml with hashes only | Stored or pushed in clear |
| MCP server URL and shared credential | Sealed together with the provider key | Masked | Envoy resources only: a GenericSecret (elchi-aigw-mcp_<server>_cred) over SDS, injected by Envoy's credential_injector | Written to conf.d |
| Request-log content key | Private key in the control plane; only the public recipient goes out | Not shown | spec.capture.recipients (an age X25519 public key) | Present on the edge as a private key |
| ClickHouse DSN (edge) | Not in the control plane | — | /etc/elchi/elchi-ai-gateway/config.yaml, mode 0600, owner elchi | Inherited by the extproc process |
What each row means in practice:
- Without
ELCHI_JWT_SECRETthe AI gateway is off. The controller logsAI gateway disabled: ELCHI_JWT_SECRET is empty, every/api/v3/ai-gatewayendpoint answers503, and nothing is deployed. - A masked secret is kept only for the same destination. When you save a provider with the masked value unchanged, the stored secret is kept only if the provider's endpoint, type, path and API version are the same. If you point a provider at a new host, you must enter the key again. Otherwise an editor could send a stored key to a host of their choice.
- Only edges that run the gateway get the set. A deploy targets the project's connected clients whose registration reports
ai_gateway_version. A client without the gateway never receives provider credentials. - Removing the AI gateway removes the credentials from the edges.
DELETE /api/v3/ai-gatewaysends every edge an empty configuration. A client that is offline at that moment receives it when it connects again. - The supervisor never shows credentials.
/configzlists providers as{name, type, credentials: "[REDACTED]"}, and the MCP session seed is never shown. - The ClickHouse DSN stays with the supervisor. The extproc inherits only a fixed allowlist of environment variables (
OTEL_*,GOOGLE_*,AWS_*,AZURE_*,SSL_CERT_*, the proxy variables,PATH,HOME,TMPDIR,TZ,LANG). It never inheritsELCHI_AI_GATEWAY_*.
Verify: GET /api/v3/ai-gateway/providers?project=<id> shows ***REDACTED*** in every set secret. On the edge, ls -l /etc/elchi/elchi-ai-gateway/conf.d shows the files as -rw------- elchi elchi. The client page's AI Gateway tab also lists them with their mode.
Resources a user cannot claim
The AI gateway generates its Envoy resources and keeps them in step with its configuration. The controller refuses a user's create or update that would claim them. It answers with the error reserved for the AI gateway, which names the reason:
| Refused | Why |
|---|---|
A resource name starting with elchi-aigw-, or equal to elchi-ai-gateway or starting with elchi-ai-gateway- | A later deploy generates that name and would collide with yours. |
general.metadata.managed_by set on your own resource | Only the feature that generates a resource sets it. The AI reconciler would take the resource for its own. |
Envoy metadata under the namespace aigateway.envoy.io | The extproc reads the provider name from this namespace and injects that provider's credential. A user cluster to any host tagged with a provider's name would be sent that provider's key. |
A resource saved before this guard existed may keep the aigateway.envoy.io metadata it already has. It cannot change that metadata.
Generated resources (managed_by: elchi-ai-gateway) can be changed only by the AI gateway itself. A manual edit is refused with this resource is generated and kept by the AI gateway: change it on the AI Gateway page. A backup import also leaves them out (elchi-aigw-* names, aigateway.envoy.io metadata). The next deploy or Sync generates them again.
Request-path isolation
On every edge the gateway uses these sockets:
| Socket | Served by | Used by | Mode |
|---|---|---|---|
/run/elchi-ai-gateway/extproc.sock | the extproc | Envoy's AI ext_proc filter (router level and the upstream chain) | 0775, set by the extproc |
/run/elchi-ai-gateway/authz.sock | the supervisor | Envoy's two ext_authz phases, the MCP result scan, the AI listeners' access logs | 0660, set by the supervisor |
/run/elchi-ai-gateway/mcp.sock | the extproc's MCP proxy | Envoy's /mcp routes | set by the extproc |
How Envoy is allowed in, and nobody else:
- The unit runs as
User=elchi Group=elchi. RuntimeDirectory=elchi-ai-gatewaywithRuntimeDirectoryMode=2750: the directory is setgid, so the sockets in it belong to groupelchi. Other users cannot enter it at all.- Envoy's user is a member of the
elchigroup. The installer runsusermod -aG elchi <envoy-user>(defaultenvoyuser, set with--envoy-user=). If that user does not exist, the installer warns:add Envoy's user to the elchi group manually or the UDS will be unreachable. UMask=0007keeps what the service creates closed to "other".
The unit is hardened as follows: NoNewPrivileges, an empty CapabilityBoundingSet, ProtectSystem=strict, ProtectHome, PrivateTmp, PrivateDevices, ProtectProc=invisible, SystemCallFilter=@system-service, and RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6. The only writable path is ReadWritePaths=/var/lib/elchi/ai-gateway, which holds the extproc binaries, the Files-API id seed and the last-good configuration. conf.d and config.yaml are read-only to the service. The extproc runs as the same user and parses untrusted request bodies, so it must not be able to rewrite its own configuration. InaccessiblePaths hides the agent's and the WAF's secrets from the gateway (/etc/elchi/config.yaml, /var/lib/elchi/.elchi_client_id, /etc/elchi/elchi-shield).
Verify: ls -ld /run/elchi-ai-gateway shows drwxr-s--- elchi elchi. id envoyuser lists elchi. Use your Envoy user's name if it differs.
The extproc admin port (9064)
The extproc opens an admin server (metrics and health, no authentication) on port 9064 on every interface. It has no bind-address option. The gateway closes the port to everything except loopback with its own nftables table, inet elchi_ai_gateway:
chain input {
type filter hook input priority -10; policy accept;
iif != "lo" tcp dport 9064 drop
}
- Plain Linux: the installer writes the table to
/etc/elchi/elchi-ai-gateway/firewall.nft. It loads the table at boot fromelchi-ai-gateway-firewall.service(beforenetwork-pre.target) and again on every gateway start (ExecStartPre=-+nft -f …). With--no-firewallit writes nothing. Withoutnftit warns:close port 9064 to non-loopback traffic yourself.--print-firewallprints the rules this host would get and exits. - Elchi OS: the same rule lives in
/usr/lib/elchi/elchi-ai-gateway.nft. It holds whether the host firewall is on or off. The gateway does not start without it: itsExecStartPre=+/usr/lib/elchi/elchi-ai-gateway-guard openhas no-prefix. The firewall sync restores the table when something flushed it.
Verify: sudo nft list table inet elchi_ai_gateway. From another host, curl http://<edge>:9064/ must not connect.
The MCP egress (127.0.0.1:10088)
While a project has MCP servers, every AI listener carries a last entry, <listener>-mcp, on 127.0.0.1:10088. The extproc sends every MCP tool call there. The call carries the consumer's name and a user's own token, and Envoy adds the server's shared credential. Its filter chain accepts only sources in 127.0.0.0/8. A listener port of 10088 is refused. An MCP server URL that points to the edge's own ports is refused (10088, 9001–9003, 9064, 6060 and the proxy admin range 30000–39999 on a loopback or unspecified host).
The port is guarded in both directions:
| Plain Linux (installer rule) | Elchi OS | |
|---|---|---|
| Who may connect to 10088 | Only processes running as the gateway's user elchi. Everyone else gets reject with tcp reset. | Only the gateway service's own processes, matched by its cgroup (system.slice/elchi-ai-gateway.service), not by user. The WAF and the agent also run as elchi and cannot connect. Everyone else gets a reset. |
| Who may answer from 10088 | Only Envoy's user (--envoy-user, default envoyuser). SYN-ACKs from any other socket are dropped. | Only envoyuser. Other SYN-ACKs are dropped. |
| When the connect rule exists | Always, from the table | Added by elchi-ai-gateway-guard open at each gateway start, removed by … closed at each stop. While the gateway is stopped, nobody can connect. |
The installer's output rules, written with numeric user ids:
chain output {
type filter hook output priority -10; policy accept;
ip daddr 127.0.0.1 tcp dport 10088 meta skuid != <elchi-uid> reject with tcp reset
ip saddr 127.0.0.1 tcp sport 10088 meta skuid <envoy-uid> accept
ip saddr 127.0.0.1 tcp sport 10088 tcp flags & (syn | ack) == syn | ack drop
ip saddr 127.0.0.1 tcp sport 10088 meta skuid != <envoy-uid> drop
}
The SYN-ACK rule exists for a reason. A SYN-ACK sent as a syncookie has no socket, so a user match never sees it. Envoy's own SYN-ACKs are accepted first and every other one is dropped.
If Envoy's user does not exist when you install, only the connect side is guarded. The installer warns: … not found, so any user may answer from the port — re-run the installer once Envoy's user exists.
An edge whose gateway is older than v0.4.0 has no firewall on this port. As long as any client of the project reports such a version, no listener of the project serves /mcp. GET /api/v3/ai-gateway/mcp-readiness names those edges, and the MCP servers tab shows them.
Verify (Elchi OS): sudo nft list table inet elchi_ai_gateway shows a socket cgroupv2 level 2 "system.slice/elchi-ai-gateway.service" accept rule in chain mcp_egress while the gateway runs. If the rule could not be added, the journal of elchi-ai-gateway-guard says the MCP egress stays closed (no rule for system.slice/elchi-ai-gateway.service).
The WAF and the AI gateway on Elchi OS
On Elchi OS (0.8.0 and later) Shield and the AI gateway both run as the agent's user and both parse what clients send. They cannot read each other:
- Shield's unit has
InaccessiblePaths=covering the gateway's configuration and store:/etc/elchi/elchi-ai-gateway,/var/lib/elchi/ai-gateway,/var/lib/elchi-persist/ai-gateway, plus the agent's/etc/elchi/config.yaml,/etc/elchi/setup.yamland/etc/elchi/environment. - The gateway's unit hides the WAF's files and the agent's secrets:
/etc/elchi/elchi-shield,/var/lib/elchi-persist/shield,/etc/elchi/config.yaml,/etc/elchi/setup.yaml,/etc/elchi/environment,/var/lib/elchi/.elchi_client_id. - Both run with
PrivatePIDs=yes: each sees only its own processes. Neither can reach the other's files or environment through/proc/<pid>/root.ProtectProc=invisiblealone hides only other users' processes, and both run as the same user.
Redaction and what the logs carry
| Protection | How |
|---|---|
| No prompts in the journal | The extproc always runs with -enableRedaction=true. Without it, its debug logs carry full prompts and completions. Raising the log level cannot turn redaction off. |
| No pprof server | The extproc always gets DISABLE_PPROF=1. Otherwise the upstream binary opens pprof on 127.0.0.1:6060. The supervisor's own /debug/pprof exists only with --pprof. |
| No inherited telemetry endpoint | The extproc's OpenTelemetry environment is set explicitly (OTEL_TRACES_EXPORTER, the traces endpoint, AI_GATEWAY_TRACING_SEMCONV=gen_ai). An OTEL_EXPORTER_OTLP_ENDPOINT inherited from the unit would otherwise ship spans with full content elsewhere. Without a request-log receiver, traces are off (OTEL_TRACES_EXPORTER=none) and content capture is off. |
| Loopback-only receiver | The request-log receiver (127.0.0.1:9003, OTLP/gRPC) receives content unredacted, so it refuses any non-loopback address at start. |
| Content encrypted on the edge | A gateway at capture level full keeps prompts and completions only redacted, truncated and age-encrypted to the project's recipient. Only the control plane holds the private key. Reading content is Owner/Admin only, never cached by the browser, and each view is audited (VIEW_AI_GATEWAY_REQUEST_CONTENT). Removing the AI gateway with shred=true destroys the key, and captured content can never be read again. See Request Log. |
| Decisions without values | The decision log (elchi_ai_gateway_decisions) stores the sensitive-data types and counts of a denial or a flag, never the values. The policy test endpoint answers with types and offsets, never values. Its sample is neither logged nor audited. |
Header spoofing protections
A client cannot choose its gateway, its consumer, its model route or its provider key through headers:
| Header | What a client sends | What happens |
|---|---|---|
x-elchi-ai-gateway | Anything | Each gateway's virtual host overwrites it with its own gateway name (OVERWRITE_IF_EXISTS_OR_ADD) before any AI filter runs. The gateway is chosen by Host, never by this header. |
x-elchi-consumer | Anything | Removed on every gateway by the same header mutation. On keyed gateways only the authorization sets it, after a key matched. Otherwise a client could bill another consumer. |
x-ai-eg-model | Anything | Removed. The extproc sets it from the request body. |
x-elchi-aigw-unrouted | Anything | Removed. A client can never choose the cluster of the unrouted route. |
authorization, x-api-key, api-key, x-goog-api-key | The consumer key | On a keyed gateway, all four are removed once the key is accepted. The provider gets the gateway's own credential, never the client's key. |
x-elchi-provider-key | A client's own provider key (only where credentialOverride is enabled) | The first AI filter moves it into dynamic metadata and removes the header before any other filter, log or provider sees it. |
Before the request leaves for the provider, the upstream chain also removes x-elchi-ai-gateway and x-elchi-consumer. A provider learns neither the gateway nor the consumer. MCP servers never see the client's elchi key or the consumer header.
Two Host-matching details matter for security. Each AI listener's route contains only the gateways bound to that listener, so a Host header cannot reach a gateway that another listener serves. The AI HCM also sets strip_trailing_host_dot: true: a keyed gateway's host written with a trailing dot (llm.example.com.) still matches that gateway instead of falling through to the listener's open default.
Roles in the control plane
| Action | Who |
|---|---|
| Read providers (masked), gateways, consumers (keys by id and prefix), MCP servers, listeners, usage, provider status | Any member of the project |
| Every change, Sync, removal; provider model list/check/try; MCP tool discovery | Owner or Admin who is a member of the project |
Edge status and files (/status, /files) | Owner or Admin. The client must be a connected client of that project. |
| Request log, its content, erasure; decision log; MCP call log | Owner or Admin |
A non-admin gets 403 only Admin and Owner can manage the AI gateway. The full list is in the REST API reference.