Skip to main content

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-loopback flag.
  • The AI ext_proc filter 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​

SecretStored in the control planeShown by the APIReaches the edge asNever
Provider credentials (API keys, AWS/GCP credentials, Azure Entra client secret)Mongo ai_gateway_configs, sealed with a key derived from ELCHI_JWT_SECRETMasked: 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 displayThe full key once, in the answer to the create call; afterwards only id and prefix00-consumers.yaml with hashes onlyStored or pushed in clear
MCP server URL and shared credentialSealed together with the provider keyMaskedEnvoy resources only: a GenericSecret (elchi-aigw-mcp_<server>_cred) over SDS, injected by Envoy's credential_injectorWritten to conf.d
Request-log content keyPrivate key in the control plane; only the public recipient goes outNot shownspec.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 elchiInherited by the extproc process

What each row means in practice:

  • Without ELCHI_JWT_SECRET the AI gateway is off. The controller logs AI gateway disabled: ELCHI_JWT_SECRET is empty, every /api/v3/ai-gateway endpoint answers 503, 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-gateway sends every edge an empty configuration. A client that is offline at that moment receives it when it connects again.
  • The supervisor never shows credentials. /configz lists 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 inherits ELCHI_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:

RefusedWhy
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 resourceOnly 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.ioThe 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:

SocketServed byUsed byMode
/run/elchi-ai-gateway/extproc.sockthe extprocEnvoy's AI ext_proc filter (router level and the upstream chain)0775, set by the extproc
/run/elchi-ai-gateway/authz.sockthe supervisorEnvoy's two ext_authz phases, the MCP result scan, the AI listeners' access logs0660, set by the supervisor
/run/elchi-ai-gateway/mcp.sockthe extproc's MCP proxyEnvoy's /mcp routesset by the extproc

How Envoy is allowed in, and nobody else:

  • The unit runs as User=elchi Group=elchi.
  • RuntimeDirectory=elchi-ai-gateway with RuntimeDirectoryMode=2750: the directory is setgid, so the sockets in it belong to group elchi. Other users cannot enter it at all.
  • Envoy's user is a member of the elchi group. The installer runs usermod -aG elchi <envoy-user> (default envoyuser, 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=0007 keeps 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 from elchi-ai-gateway-firewall.service (before network-pre.target) and again on every gateway start (ExecStartPre=-+nft -f …). With --no-firewall it writes nothing. Without nft it warns: close port 9064 to non-loopback traffic yourself. --print-firewall prints 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: its ExecStartPre=+/usr/lib/elchi/elchi-ai-gateway-guard open has 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 10088Only 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 10088Only 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 existsAlways, from the tableAdded 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.yaml and /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=invisible alone hides only other users' processes, and both run as the same user.

Redaction and what the logs carry​

ProtectionHow
No prompts in the journalThe 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 serverThe 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 endpointThe 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 receiverThe 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 edgeA 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 valuesThe 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:

HeaderWhat a client sendsWhat happens
x-elchi-ai-gatewayAnythingEach 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-consumerAnythingRemoved 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-modelAnythingRemoved. The extproc sets it from the request body.
x-elchi-aigw-unroutedAnythingRemoved. A client can never choose the cluster of the unrouted route.
authorization, x-api-key, api-key, x-goog-api-keyThe consumer keyOn 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-keyA 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​

ActionWho
Read providers (masked), gateways, consumers (keys by id and prefix), MCP servers, listeners, usage, provider statusAny member of the project
Every change, Sync, removal; provider model list/check/try; MCP tool discoveryOwner 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 logOwner 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.