Browser Access (CORS)
Calling the Models as a Service gateway directly from a browser – pointing a browser-based chat UI at https://<gateway-host> with a MaaS API key – fails out of the box: CORS preflights are rejected (404 or 401, depending on whether the gateway’s route matching or auth chain rejects OPTIONS first), and success responses carry no CORS headers. This page shows the one EnvoyFilter that fixes both.
Prerequisites: cluster-admin access on the MaaS cluster, at least one model deployed (local or external), and a MaaS API key. A key comes from POST /maas-api/v1/api-keys with your OpenShift token.
Status: undocumented and unsupported in RHOAI/Kuadrant docs – but verified end-to-end on a live cluster (2026-09-22, RHOAI 3.5.1 + MaaS from this repo’s setup-maas.sh): all three CORS checks pass and the browser flow was confirmed working. Model-agnostic: the same gateway reconfiguration works for local models, external models, and the /maas-api/* control plane. No AuthPolicy changes – authentication is untouched.
What Has to Happen for CORS to Work
Three things, all on the gateway:
Preflights must be answered before the auth filters run. Browsers never send
Authorizationon a CORS preflight (fetch spec: preflights are credentialless). Without the Lua filter,OPTIONSfails – typically 404 because no HTTPRoute matches the method, or 401 if the auth chain intercepts first:<1> May be 401 with
x-ext-auth-reason: Authentication requiredon some Kuadrant/gateway configurations. Either way, CORS fails.Actual responses must carry CORS headers. A preflight alone is not enough – the browser also validates every real response (
200,401,429, …). Noaccess-control-allow-originon a response means the browser blocks it from JavaScript.Never add a second set of CORS headers. OpenAI-compatible upstreams (LiteLLM-style) often run permissive CORSMiddleware and already emit
access-control-allow-origin(plusaccess-control-allow-credentials: true). Adding another one merges intoaccess-control-allow-origin: *,*, which browsers treat as invalid. Verified on-cluster 2026-09-22 – an unguardedheaders():add()produced exactly that.
How to Reconfigure the Gateway
One EnvoyFilter. A Lua filter inserted FIRST in the gateway’s HTTP filter chain – before the Kuadrant WASM/ext-authz filters – does both jobs: it answers preflights itself (auth never sees them) and adds CORS headers to responses that the upstream did not already decorate. No AuthPolicy changes, no auth touched.
The applied, verified manifest is manifests/99-cors/envoyfilter-cors.yaml in the repo. The block below mirrors it – if the filter changes, update both together.
Apply from the repository root:
Three properties make this work:
operation: INSERT_FIRST– the Lua filter sits ahead of the Kuadrant ext-authz/WASM filters, so preflights are answered before auth can 401 them, and every response that comes back passes through the Luaon_response(including auth-generated 401s, which the upstream never sees).- The
workloadSelectormatches the gateway pods – verify the label withoc get pod -n openshift-ingress --show-labels. The genericistio: ingressgatewaylabel would hit every gateway on the node. - The guard in
on_response– only add CORS headers the upstream did not already send.
On anything shared, pin access-control-allow-origin to the real origin instead of * (both in the preflight respond() and in on_response).
Why Not the Alternatives
- Native
envoy.filters.http.corsfilter (VIRTUAL_HOST/ROUTEtyped_per_filter_configCorsPolicy): works – Istio ships it – but its position in the filter chain is not controllable. If the Kuadrant ext-authz filter is inserted before it, preflights 401 before the cors filter ever sees them. LuaINSERT_FIRSTguarantees ordering. (header_mutationwas also considered: it mutates headers but cannot answer preflights with local replies.) - AuthPolicy with an anonymous rule gated to OPTIONS (
when: predicate: "request.method == 'OPTIONS'"– documented Kuadrant syntax,predicateper the Authorino 1.5.x features doc): only worth it if EnvoyFilters are blocked on your gateway. It is risky: the MaaS AuthPolicy on this setup is Gateway-targeting (maas-gateway-authinopenshift-ingress), and a route-level policy may REPLACE the gateway defaults for that route rather than OR-combine – the CRD says gatewaydefaultsare enforced on “routes that lack a more specific policy attached to”. If it replaces, non-OPTIONS requests have no active authentication rules -> anonymous access -> the route silently opens. If you must, target the specific model HTTPRoute, then MANDATORY: verify an unauthenticated request still returns 401 and roll back (oc delete authpolicy allow-cors-preflight -n <HTTPROUTE_NS>) if it does not. - Authorino response headers (
rules.response.unauthenticated.headers– documented CRD fields): makes the 401 carry CORS headers (error bodies readable in-browser) but NOT success responses – the CRD’sresponse.success.headersare “wrapped as HTTP headers to be injected in the request” (the upstream request, not the client response). Success-response CORS needs the EnvoyFilter or a permissive upstream.
Verify
Then the browser: point the chat UI at https://<HOST> with a MaaS key, click Test connection. Expect “Connected – N model(s)”.
Undo
One resource, one delete. The procedure on this page changed nothing else – auth, routes, and policies are untouched – and nothing re-creates the filter afterwards: setup-maas.sh never applies manifests/99-cors/, and cleanup-maas.sh never deletes it, so the whole lifecycle is manual.
Check whether the filter is currently active. Resource existence is not proof – a silent NACK leaves the EnvoyFilter in place but ineffective. The preflight is answered before auth, so an unauthenticated
OPTIONSis the cleanest probe: 204 means the filter is live, 404 means stock gateway behavior (OPTIONS does not match any HTTPRoute, so the gateway returns 404 before auth runs):Delete it:
Verify the rollback. Re-run the probe: expect 404 – without the Lua filter,
OPTIONSdoes not match any HTTPRoute and the gateway returns 404 before auth runs. Re-run the three checks in the Verify section: expect noaccess-control-allow-originon any response. The xDS config push is immediate; no pod restarts needed.
- Access ends immediately. Browsers cache preflight decisions for up to 24h (
access-control-max-age), but a cached preflight grants nothing after the delete: real responses stop carrying CORS headers, so the browser blocks them regardless. Cross-origin access ends as soon as the gateway stops emitting the headers. - Outlives teardown. A full
cleanup-maas.shrun leavesmaas-cors-headers(with*CORS) sitting inopenshift-ingresson an otherwise torn-down gateway – delete it manually if you want the cluster clean. Platform upgrades do not re-create it: the MaaS controller re-applies only its own filters (such asauthorino-tls-bootstrap), never this one.
Caveats
- Silent NACK: if the listener update is rejected, Envoy keeps its last-known-good config – the EnvoyFilter resource still exists but CORS never appears. Check
oc logs -n openshift-ingress deploy/maas-default-gateway-openshift-default -c istio-proxyfor config rejections before concluding the filter applied. - Controller reconcile: the MaaS controller manages EnvoyFilters on this gateway (it creates the
authorino-tls-bootstrapone itself) and may re-apply its own set on upgrade – re-check after platform upgrades. - If chat requests break: remove the filter first (
oc delete envoyfilter maas-cors-headers -n openshift-ingress) – the MaaS disconnected setup shows the gateway falls back to deny-all when its WASM filter fails, so filter-chain interference is the prime suspect.