Global control plane
Teams that run several gateways, one per region or per business unit, usually want one place to administer them. The global control plane is a gateway instance whose only job is to serve the Admin UI for a registry of worker instances. Each worker keeps its own database, keys and configuration, nothing is shared or replicated, and the control plane simply tells the UI where the workers are and lets an admin sign in to one of them. This is an enterprise feature.
A real-world scenario
A company runs one gateway in Frankfurt for its European teams and one in Virginia for the American ones, each with its own database so that no customer data crosses the Atlantic. The platform team wants its admins to sign in once a day in one place. They run a third, small gateway as the control plane with both workers in its worker_registry, set control_plane_url on each worker, and give admins the control plane's URL. On the sign-in page an admin picks Europe, signs in with the company's identity provider against the Frankfurt worker, and sees its keys, teams and spend. Switching to United States from the header signs them in to Virginia instead.
The control plane
List the workers in worker_registry at the top level of the control plane's config.yaml. Setting it makes the instance a control plane, which serves the UI. Nothing stops model traffic on it, so do not point clients or load balancers at it for model calls.
worker_registry:
- worker_id: eu
name: Europe
url: https://gateway-eu.example.com
- worker_id: us
name: United States
url: https://gateway-us.example.com
Each entry needs a worker_id, a display name and an http:// or https:// url. The UI reads the registry from GET /.well-known/spanway-ui-config, which reports is_control_plane: true and the workers list, and shows a worker picker on the sign-in page. Without a licence the gateway refuses to start with worker_registry set.
The workers
Each worker names the control plane that manages it so that the UI served from the control plane's origin can sign in against the worker cross origin.
general_settings:
control_plane_url: https://control.example.com
Setting control_plane_url enables two routes on the worker. POST /v3/login takes a username and password, authenticates them exactly like the normal sign-in, and instead of setting a cookie returns a single use code that lives for 60 seconds. POST /v3/login/exchange redeems the code for the session token and sets the session cookie for the worker's origin. The two step shape keeps the token out of cross origin responses and browser history. Both routes return 404 on a worker without control_plane_url.
SSO works the same way. The UI sends the browser to the worker's SSO endpoint with a return_to of the control plane, the worker only honours a return_to whose origin matches control_plane_url, and after the identity provider round trip it redirects back to the control plane with a single use code that the UI exchanges at /v3/login/exchange.
Because the browser calls each worker from the control plane's address, every worker must allow that address for cross origin calls with cookies. Set SPANWAY_CORS_ORIGINS on each worker to the control plane's origin, for example https://control.example.com. With a named origin the worker also allows credentials, which the sign-in needs. Without it the worker allows every origin without credentials, the browser refuses the sign-in answer, and the sign-in page shows a network error even though the curl in step 2 works.
The login codes are stored in the coordination Redis when one is configured. Any worker with control_plane_url and no Redis logs a WARNING at startup, because when the worker runs several instances, or several worker processes in one instance, the exchange may reach a different one than the login and fail with 401. Configure Redis, or keep sessions sticky and run one worker process.
Switching workers in the UI
The sign-in page of the control plane lists the workers. Picking one points every management call of the session at that worker's URL, and the choice is remembered in the browser. Once signed in, a worker dropdown in the dashboard header switches to another worker, which clears the current session and returns to the sign-in page for the new one. The UI stores the selected worker id and URL in browser storage and only accepts http or https worker URLs. Everything the admin then sees, keys, teams, spend and settings, belongs to the selected worker alone.
Step by step
-
Write the control plane's
config.yamlwithworker_registryas above and start it with a license. Use it for the Admin UI only. -
Add
general_settings.control_plane_urlto every worker's config, setSPANWAY_CORS_ORIGINS=https://control.example.comin every worker's environment, and roll the workers. Confirm a worker exposes the cross origin sign-in routes:curl -X POST https://gateway-eu.example.com/v3/login \-H "Content-Type: application/json" \-d '{"username": "admin", "password": "the-password"}'Expected result:
{"code": "...", "expires_in": 60}with a single use code, or{"mfa_required": true, ...}when two-factor sign-in applies. A worker withoutcontrol_plane_urlanswers 404. The sign-in routes are used by the Admin UI and are not part of the published API reference. -
Read the registry the UI loads from the control plane:
curl https://control.example.com/.well-known/spanway-ui-configExpected result:
"is_control_plane": trueand theworkerslist with eachworker_id,nameandurl. -
Open
https://control.example.com/ui. The sign-in page shows the worker picker. Pick a worker, sign in, and the dashboard header shows a worker dropdown. Everything you see belongs to the selected worker.
Errors
| Status or symptom | Meaning | Fix |
|---|---|---|
Startup error Trying to use `worker_registry`. You must be a Spanway Enterprise user to use this feature. ... | No valid license, the control plane is an enterprise feature. | Set SPANWAY_LICENSE, see enterprise. |
404 /v3/login is only available on workers with control_plane_url configured | The worker has no control_plane_url. | Set it in the worker's general_settings and restart. |
400 Missing 'code' parameter on POST /v3/login/exchange | The exchange got no code, usually after a broken redirect. | Sign in again from the control plane. |
401 Invalid or expired login code on POST /v3/login/exchange | The code expired after 60 seconds, was already used, or reached another instance or worker process that does not share Redis. The sign-in page shows the same message. | Sign in again. Configure the coordination Redis, or sticky sessions with one worker process. |
400 return_to does not match the configured control_plane_url | SSO was asked to return to an address other than the control plane. | Make control_plane_url exactly the origin users type into the browser. |
The sign-in page shows a network error while curl works | The browser refused the worker's answer because SPANWAY_CORS_ORIGINS does not name the control plane. | Set SPANWAY_CORS_ORIGINS on every worker to the control plane's origin. |
The gateway does not start and logs Worker URL must start with http:// or https:// | Config validation refuses a worker_registry entry whose url has no http:// or https:// scheme. | Fix the url in worker_registry and restart. |
| A WARNING at worker startup about login codes and Redis | The worker has control_plane_url but no coordination Redis. | Configure the coordination Redis, or keep sessions sticky with one worker process. |
The error reference lists these messages too.
Logs
| Level | Line | Meaning |
|---|---|---|
| WARNING | control_plane_url is configured but Redis is not configured for Spanway caching. Login codes (SSO and /v3/login) will not be shared across instances ... | Sign-in codes stay in one process, so an exchange that reaches another one fails with 401. Configure Redis on the worker. |
| INFO | Ignoring stale spanway_cp_return_to cookie; landing on dashboard | An old return address from an earlier control plane sign-in was ignored. Normal. |
Related
- Admin UI SSO for the identity provider setup the workers use.
- Sign-in security settings for two-factor sign-in and lockout, which apply to
/v3/logintoo. - Redis requirements for the coordination Redis.
- Enterprise features for the license.