Skip to main content

IP and route allow-lists

Allow-lists narrow who can reach the gateway and what they can reach once there. The IP allow-list rejects requests from network addresses you have not approved, gateway-wide or per key, team and organization. Route allow-lists limit a caller to the endpoints their integration actually needs, so a key meant for chat completions cannot call key management, and a SCIM token cannot call anything but SCIM. Together they mean a leaked key is useless from the wrong network and a mis-scoped key cannot reach the wrong routes.

The gateway-wide IP allow-list and writing per-scope IP lists need an enterprise license with the ip_allowlist feature. A stored per-scope list is enforced either way. Route allow-lists are part of the free gateway.

A real-world scenario​

A finance team's reporting job runs on servers in 198.51.100.0/24 and only ever calls /v1/chat/completions. If its key leaked, the admin wants it to be worthless anywhere else. She creates the key with allowed_routes limited to the inference routes and allowed_ips limited to that range. Separately, the whole gateway sits behind a corporate network, so she turns on the gateway-wide list for the office and VPN ranges and keeps it editable from the Admin UI.

Steps​

  1. Tell the gateway how to find the client's address. Behind a load balancer, list the load balancer's ranges in trusted_proxy_ranges so X-Forwarded-For is read, otherwise every request would be checked against the load balancer's own address.

    general_settings:
    trusted_proxy_ranges: ["10.10.0.0/16"]
    allowed_ips: ["10.0.0.5", "10.0.0.0/8", "2001:db8::/32"]
  2. To manage the gateway-wide list at runtime instead, leave allowed_ips out of the file, turn on store_model_in_db, and open Settings, Admin Settings, the Security Settings tab, and choose Allowed IPs. Add the office range there. The same through the API:

    curl -s -X POST http://localhost:4000/add/allowed_ip \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"ip": "203.0.113.0/24"}'
  3. Create the reporting key with both allow-lists. In the Admin UI open Virtual Keys and create the key, then open it, click Edit, fill in Allowed IPs with 198.51.100.0/24 and save. The create form has no Allowed IPs field, the key edit form does. The same through the API, with the route list too, in one call:

    curl -s -X POST http://localhost:4000/key/generate \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"key_alias": "finance-reporting", "allowed_routes": ["llm_api_routes"], "allowed_ips": ["198.51.100.0/24"]}'
  4. Test from a server in the range, then from your laptop.

    curl -s http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-finance" \
    -H "Content-Type: application/json" -d '{"model": "claude-sonnet", "messages": [{"role": "user", "content": "Hi"}]}'
    curl -s http://localhost:4000/key/list -H "Authorization: Bearer sk-finance"

Expected result​

Step 2 answers {"message": "IP 203.0.113.0/24 added successfully", "status": "success"} and the change appears in the audit log. From a server in 198.51.100.0/24 the chat completion in step 4 succeeds. From your laptop it is refused with 403 and a message naming the key as the scope that refused it. The /key/list call is refused with 403 from anywhere, with a message naming the route, because the key may only call inference routes. A request from outside the gateway-wide list is refused before authentication, whichever key it carries.

The gateway-wide IP allow-list​

general_settings.allowed_ips lists the client addresses allowed to call the gateway. Each entry is an IPv4 or IPv6 address or a CIDR range, such as 10.0.0.0/8 or 2001:db8::/32, and an entry that is neither stops the config from loading. Every request from another address is refused before authentication.

The list can be managed at runtime when store_model_in_db is on. GET /get/allowed_ips returns it (the Admin UI reads the list with this route, so it is not part of the published API reference), POST /add/allowed_ip and POST /delete/allowed_ip change it with a body of {"ip": "10.0.0.7"}, the change is saved to the database config and written to the audit log, and a duplicate address is rejected with 400. Adding an address needs the ip_allowlist license feature, and both routes refuse with 500 and leave the live list untouched while store_model_in_db is off. Only a proxy admin may change the list. Any other key, such as an internal user, team admin or admin viewer key, gets 403 Only proxy admins can manage the IP allowlist. or, for an admin viewer, user not allowed to access this route. Removing the last address is refused with 400, because an empty list blocks every request, the Admin UI included. Add the address that should stay allowed first, or turn the list off.

POST /disable/allowed_ips with the body {"confirm": true} turns the allowlist off so every IP address is allowed again, removes the saved list from the database config and writes the change to the audit log. Only a proxy admin can call it, it needs the ip_allowlist license feature and store_model_in_db, and it is refused with 400 when allowed_ips is set in the config file, which you then edit instead. The Allowed IPs dialog on the Security Settings tab of the Admin Settings page edits the same list, offers no Delete on the last address, and has a Turn off IP allowlist button that asks you to confirm that every IP address will be allowed.

MethodPathSummary
POST/add/allowed_ipAdd an address or range to the gateway IP allowlist
POST/delete/allowed_ipRemove an address or range from the gateway IP allowlist
POST/disable/allowed_ipsTurn the gateway IP allowlist off

Which address is checked​

Every allow-list on this page checks the same client address. When the direct peer of the connection is inside general_settings.trusted_proxy_ranges, the gateway reads X-Forwarded-For from right to left and takes the first address that is not one of your proxies, so an entry a client forged on the left of the header is never used. When the peer is not a trusted proxy, or trusted_proxy_ranges is unset, the peer address of the connection is the client and X-Forwarded-For is ignored. A request sent straight to the gateway therefore cannot choose the address it is checked against. The per-address limit on starting a CLI sign-in (/sso/cli/start) counts attempts by this same address.

use_x_forwarded_for: true on its own no longer trusts the header. Earlier releases read the raw header whenever it was set, which let any client pick its address. If you run behind a load balancer and relied on that, set trusted_proxy_ranges to the load balancer's ranges, otherwise every request is checked against the load balancer's own address and the gateway logs a warning about it.

If uvicorn runs with proxy headers enabled and its FORWARDED_ALLOW_IPS includes your proxy, uvicorn has already replaced the peer address with the forwarded one before the gateway sees it. In that setup leave your proxy out of trusted_proxy_ranges, or turn off uvicorn's proxy header handling, so the header is not trusted twice.

Per key, team and organization​

Keys, teams and organizations can each carry their own allowed_ips list, using the same address and CIDR format, with at most 256 entries. Keys and teams take it as a top level field on /key/generate, /key/update, /key/regenerate, /team/new and /team/update. Organizations take it under metadata.allowed_ips on /organization/new, /organization/update and PATCH /v2/organization/{organization_id}. In the Admin UI the field is Allowed IPs on the key and team edit forms.

curl -s -X POST http://localhost:4000/key/update -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"key": "sk-...", "allowed_ips": ["198.51.100.0/24", "2001:db8::/48"]}'

The lists combine. A request must come from an address that is in every list that is set on its organization, its team and its key, and the gateway wide list still applies on top. A scope without a list adds no restriction. A refused request gets 403 with a message that names the scope that refused it. A stored list that does not parse, for example after a hand edit in the database, refuses every request for that scope until it is fixed.

Only proxy admins can set, change or remove these lists, whether through the top level field or by editing metadata. A team admin, an org admin or the owner of a key gets 403 if a request would widen or drop a list, including by replacing metadata with a copy that leaves it out. Sending "allowed_ips": null clears the list, and for an organization that means "metadata": {"allowed_ips": null} on /organization/update or PATCH /v2/organization/{organization_id}. Leaving the field out of /organization/update keeps the stored list, since that route merges metadata. An empty list is refused with 400 because it would lock every client out, and the gateway also refuses to save a list while use_x_forwarded_for is on without trusted_proxy_ranges, since every request would then be checked against your proxy's address.

The lists are checked for virtual keys, JWT and OAuth2 callers in the shared authorization step. They do not apply to Admin UI session keys, to requests a custom auth handler admits without custom_auth_run_common_checks, or to the restricted fallback identity used when allow_requests_on_db_unavailable lets a request through during a database outage. Requests made with the master key are only subject to the gateway wide list. For the Admin UI sign-in page, which must stay reachable, see the failed login lockout and trusted_proxy_ranges in security settings.

Route allow-lists on keys​

A virtual key accepts allowed_routes, a list of exact paths or route group names.

curl -s -X POST http://localhost:4000/key/generate -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "embeddings-only", "allowed_routes": ["/v1/embeddings", "info_routes"]}'

Route groups are the named sets the gateway uses internally. The ones most useful on keys are llm_api_routes for every inference route, openai_routes for the OpenAI compatible ones, anthropic_routes, mcp_routes and its halves mcp_inference_routes and mcp_management_routes, agent_routes with agent_inference_routes and agent_management_routes, info_routes, management_routes, spend_tracking_routes, key_management_routes, trace_read_routes (reading traces and the trace SQL query), trace_ingest_routes (the POST /v1/traces and POST /v1/logs uploads), trace_telemetry_routes (both of those) and passthrough_routes_wildcard. For environment promotion there are four: environment_read_routes opens the environment info, plan list, plan details and managed objects reads, environment_write_routes opens export, plan, reject and apply, environment_approve_routes opens only plan approval, and environment_deploy_routes opens the reads plus plan and apply, never approve, which is the set for a CI deploy key. A wildcard such as /scim/* matches a path prefix. A key with an empty or missing list keeps the routes its role allows. The same field exists on team service account keys.

Only a proxy admin may set allowed_routes on a key. Other callers pick a preset instead with key_type: llm_api gives llm_api_routes and read_only gives info_routes, and an info_routes key made by a non admin stays read only. Setting any other list as a non admin is refused with 403.

Route allow-lists for JWT roles​

For callers authenticated with JWTs, spanway_jwtauth.admin_allowed_routes, team_allowed_routes and public_allowed_routes play the same role per kind of token.

general_settings.allowed_routes is a gateway wide list checked before the key is looked up. It takes exact paths, * wildcards and route group names, the same as a key's list, and refuses every other route for every caller, proxy admins and the master key included. List the admin routes your team uses, such as /ui/* and management_routes, or you lock yourself out of the Admin UI. The list needs no license.

general_settings:
allowed_routes: ["llm_api_routes", "info_routes"]

A request to a route outside the applicable list is refused with 403 and a message that names the route.

Errors​

What you seeWhyFix
403 Access forbidden: IP address <ip> not allowed. on every request after turning on allowed_ips, including from allowed addresses.The gateway sees the load balancer's address, not the client's.Set trusted_proxy_ranges to the load balancer's ranges. The startup log warns when use_x_forwarded_for is on without it.
The gateway refuses to start naming allowed_ips.An entry is not an address or CIDR range.Fix the entry.
The gateway refuses to start with general_settings.allowed_ips is set. The 'ip_allowlist' feature needs a Spanway enterprise license that includes it.The config file sets the list on a gateway whose license lacks the feature.Add the license, or remove allowed_ips from the file.
400 IP address already exists from /add/allowed_ip.The address is already in the list.Nothing to do.
404 IP address not found from /delete/allowed_ip.The address is not in the list.Check the list in the Allowed IPs dialog.
400 saying the last address cannot be removed.Removing it would block every request.Add the address that should stay first, or use /disable/allowed_ips.
400 from /add/allowed_ip, /delete/allowed_ip or /disable/allowed_ips with keys and section naming allowed_ips.The list is set in the config file, which wins over the database.Edit config.yaml and reload.
500 Set store_model_in_db: true in general_settings to manage allowed_ips at runtime.Runtime changes need the database config.Set general_settings.store_model_in_db: true, or edit the file.
500 DB not connected. ...The gateway has no database.Set DATABASE_URL.
403 Only proxy admins can manage the IP allowlist.A key of any other role, such as an internal user or a team key, called add, delete or turn off. An admin viewer is refused with user not allowed to access this route instead.Use a proxy admin key.
403 naming the ip_allowlist feature, from add or turn off.The license does not include it. Removing an address works without it.Ask for a license with ip_allowlist, see enterprise.
403 Access forbidden: IP address <ip> is not in this key's allowed_ips. (or team's, organization's)The request comes from an address outside that scope's list.Call from an allowed address, or have a proxy admin widen the list.
403 Access forbidden: <scope>'s allowed_ips setting is invalid. Ask an admin to fix it.The stored list does not parse.Have a proxy admin save a valid list.
403 when a team admin or key owner edits a key or team.The edit would widen or drop an allowed_ips list.Only a proxy admin may change the list. Send the stored list unchanged, or leave allowed_ips out.
400 saying an empty list is not allowed.allowed_ips: [] would lock every client out.Send null to clear the list.
400 allowed_ips can hold at most 256 entries.The list is too long.Merge addresses into CIDR ranges.
403 Only proxy admins can set allowed_routes on a key. Use key_type to pick a preset route bucket instead.A non admin sent allowed_routes.Send key_type, or ask a proxy admin.
403 Access forbidden: Route <route> not allowedgeneral_settings.allowed_routes leaves the route out.Add the path, a wildcard or a route group to the list.
403 Virtual key is not allowed to call this route. ...The key's allowed_routes or the JWT role's routes leave it out.Add the route or its group to the right list.

Logs​

LevelLineMeaningAction
WARNINGuse_x_forwarded_for is true but trusted_proxy_ranges is not set, so X-Forwarded-For is ignored ...The gateway checks the direct peer address, usually your load balancer.Set trusted_proxy_ranges.
ERRORStored <scope> allowed_ips is invalid, denying the request: <reason>A key, team or organization list cannot be read and its requests are refused.Save a valid list on that scope.
ERRORRoute <route> not in allowed_routes=<list>A request was refused by general_settings.allowed_routes.Normal for a blocked route. Add the route if it should work.