Custom roles
Custom roles let you give people exactly the management access they need. A custom role starts from a built-in base role and adds or removes permissions. Granted permissions open management routes the base role could not reach, denied permissions close routes the base role would otherwise allow, and everything the role does not mention is decided by the base role, not by the user's own Global Proxy Role. Custom roles are an enterprise feature that needs the custom_roles license feature. Without it every /role route returns 403, and roles already assigned to users stop having any effect, so those users fall back to their Global Proxy Role until the feature is back. Custom roles never restrict a proxy_admin, so the gateway refuses to assign one to a proxy admin.
A real-world scenario
A support desk needs to look up keys and logs when a customer calls, and to block a leaked key straight away, but must never see or change provider credentials. None of the built-in roles fits: a viewer cannot block keys and an admin can do far too much. The admin creates a support-engineer role on top of the read only viewer role, grants it key, user and log permissions, denies credentials, and assigns it to the support engineers. They can now do exactly their job, and every change to the role is in the audit log.
Step by step
-
In the Admin UI open Roles in the left nav (
/ui/roles) and click + Create Role. -
Enter
support-engineeras Role Name, pickinternal_user_vieweras Base Role, setkeys.read,keys.write,users.readandlogs.readto Grant and both credentials permissions to Deny, then click Create Role. The same role can be created with curl, as shown in Create a role. -
Assign it. Open Internal Users, open the engineer, click Edit Settings, pick the role under Custom Role and click Save Changes, or call:
curl -X POST http://localhost:4000/role/assign \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"user_id": "user-123", "role_id": "8f6c2b1e-..."}' -
Have the engineer sign in again or send their next request, which picks up the new role.
Expected result
The engineer can list keys, open logs and block or unblock a key, and any credentials route answers 403 for them. GET /role/info?role_id=... shows the role with assigned_user_count: 1, /v2/user/info shows the engineer's custom_role_id, and the audit log holds one row for the role creation and one for the assignment.
How a request is decided
For each management request from a user who holds a custom role, the gateway checks the role's permissions against the route and HTTP method.
- If any denied permission covers the route, the request is refused.
- If the role grants
*, every management route in the catalogue is allowed. - If any granted permission covers the route, the request is allowed.
- Otherwise the role's base role decides, with the same rules as a user who holds that built-in role. The user's own Global Proxy Role is not used while the custom role is assigned. For example, a role on
internal_user_viewerthat mentions no key permission stops aninternal_userfrom creating keys.
Denials always win over grants. Changes to a role, and assignments, take effect on the user's next request, because the gateway evicts the affected users from its auth cache.
Base roles
A custom role must extend one of internal_user, internal_user_viewer or proxy_admin_viewer. Admin roles cannot be used as a base, so a custom role can never be more powerful than a proxy admin by accident.
Permission catalogue
Each permission is named <domain>.read or <domain>.write. A read permission covers the domain's read routes. Where a route serves both reads and writes (for example /alerting/settings), the read permission only matches GET, HEAD and OPTIONS on it. GET /role/permissions returns the full catalogue with the exact routes each permission covers.
| Domain | Covers | Permissions |
|---|---|---|
keys | Virtual keys | keys.read, keys.write |
teams | Teams and their members | teams.read, teams.write |
users | Internal users and customers | users.read, users.write |
organizations | Organizations and their members | organizations.read, organizations.write |
models | Model deployments and pricing | models.read, models.write |
spend | Spend reports and usage analytics | spend.read, spend.write (global spend reset) |
logs | Request logs and traces. logs.prompts, logs.responses and logs.tool_arguments open no route: deny them to hide that content from the role, and grant logs.reveal to let the role reveal it one request at a time with an audited reason | logs.read, logs.prompts, logs.responses, logs.tool_arguments, logs.reveal |
budgets | Budgets | budgets.read, budgets.write |
guardrails | Guardrails and policies | guardrails.read, guardrails.write |
tags | Tags | tags.read, tags.write |
projects | Projects | projects.read, projects.write |
mcp | MCP servers, toolsets and sessions. Toolset changes and publishing servers stay with proxy admins | mcp.read, mcp.write |
agents | Agents, their identity status and agent spend. Fetching an upstream card with /v1/a2a/discover stays with proxy admins | agents.read, agents.write |
custom_agents | Custom agents, their runs and workflow template installs. Installing, upgrading and uninstalling a template need custom_agents.write and workflows.write together, because they create and change custom agents and a workflow definition | custom_agents.read, custom_agents.write |
workflows | Workflow runner runs, their dead letters, replays and pinned test data, and workflow definitions. Read also lists workflow template installs, and template writes need this domain's write as well as custom_agents.write. Releasing a halted agent and halting or deleting a definition stay with proxy admins | workflows.read, workflows.write |
triggers | Workflow triggers. Write also covers sending chat messages and form submissions | triggers.read, triggers.write |
approvals | Human approval requests and policies. Write opens the decision routes, but only the policy makes someone an approver. Changing policies stays with admins | approvals.read, approvals.write |
environments | Environment exports, plans and applies. The grant opens the routes but the caller still needs proxy admin or organization admin authority for the scope, and approving a plan stays with admins | environments.read, environments.write |
code_graph | Code graph repositories in the role holder's own organization. code_graph.read lists them, code_graph.reindex also queues index runs, code_graph.manage also connects, configures and disconnects repositories, binds credentials and installs the GitHub App | code_graph.read, code_graph.reindex, code_graph.manage |
credentials | Provider credentials | credentials.read, credentials.write |
settings | Proxy configuration, callbacks and alerting | settings.read, settings.write |
routing | Auto-routers | routing.read, routing.write |
audit | Audit logs. audit.read lets the holder read the audit log, verify its hash chain and list the export ledger (GET /audit, GET /audit/{id}, GET /audit/verify, GET /audit/exports), which suits an outside auditor or a compliance officer who should see who changed what without being an admin. Billing fields of Cloud tenant rows stay hidden from them, as they are from admin viewers. The Audit Logs and Export Ledger tabs on Logs still show only for the Admin and Admin Viewer roles, so a holder reads these routes with curl or a client. Without the grant, only the Admin and Admin Viewer roles read them | audit.read |
status | Status page and incidents | status.read, status.write |
alerts | Alerts inbox, usage baselines and live deployment speed | alerts.read, alerts.write |
compliance | Compliance reports, controls, evidence bundles, retention, data residency and data subject requests. compliance.read opens every read route. compliance.write opens the changes, runs, snapshots, bundle generation and data subject exports and erasures, plus reading retention and residency, so grant both to someone who also reads reports | compliance.read, compliance.write |
billing | Billing accounts and invoices | billing.read, billing.write |
cloud | Spanway Cloud tenants, their credits, provider keys and the super admin tenant routes | cloud.read, cloud.write |
evals | Eval datasets, scorers and runs | evals.read, evals.write |
sanctions | The sanctions screening review queue, OFAC report tasks and the geofence status | sanctions.read, sanctions.write |
Three areas have no permission because their handlers only trust built-in roles, so a grant could never take effect. Custom roles themselves are managed by proxy admins, access requests are reviewed by a proxy admin or the admin of the team the request is for, and organization single sign-on and organization SCIM tokens are managed by a proxy admin or that organization's admins. /model/block and /model/unblock also stay with proxy admins. A role saved before these permissions were removed keeps the names, and they grant nothing. The Admin UI drops those names when it opens the role for editing, so saving works. An API update that sends them back is refused with 422 unknown permissions, so leave them out of the request.
Endpoints
| Method | Path | Summary |
|---|---|---|
| GET | /role/permissions | The permission catalogue for custom roles |
| GET | /role/list | List custom roles |
| GET | /role/info | Get a custom role with its user count |
| POST | /role/new | Create a custom role |
| POST | /role/update | Update a custom role |
| DELETE | /role/delete | Delete a custom role |
| POST | /role/assign | Give a user a custom role |
| POST | /role/unassign | Take a custom role away from a user |
Creating, changing, deleting and assigning roles needs a proxy_admin. A proxy_admin_viewer can read the catalogue.
Create a role
This role lets a support engineer read keys, users and logs and block or unblock keys, but never touch credentials.
curl -X POST http://localhost:4000/role/new \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"role_name": "support-engineer",
"description": "Read keys, users and logs, and block keys",
"base_role": "internal_user_viewer",
"permissions": ["keys.read", "keys.write", "users.read", "logs.read"],
"denied_permissions": ["credentials.read", "credentials.write"]
}'
{
"role_id": "8f6c2b1e-...",
"role_name": "support-engineer",
"description": "Read keys, users and logs, and block keys",
"base_role": "internal_user_viewer",
"permissions": ["keys.read", "keys.write", "users.read", "logs.read"],
"denied_permissions": ["credentials.read", "credentials.write"],
"created_by": "admin-user-id",
"created_at": "2026-10-14T09:12:00Z",
"updated_at": "2026-10-14T09:12:00Z"
}
Unknown permission names and admin base roles are rejected with 422, and the message reads Value error, unknown permissions: keys.admin. See GET /role/permissions or Value error, base_role must be one of [...]. A duplicate role_name returns 400.
Assign and remove a role
curl -X POST http://localhost:4000/role/assign \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"user_id": "user-123", "role_id": "8f6c2b1e-..."}'
{"user_id": "user-123", "custom_role_id": "8f6c2b1e-..."}
POST /role/unassign with a user_id clears the custom role so only the user's Global Proxy Role applies. GET /role/info?role_id=... returns the role with assigned_user_count. Deleting a role returns how many users lost it, for example {"role_id": "8f6c2b1e-...", "unassigned_users": 1}, and those users fall back to their Global Proxy Role. Every create, update, delete, assign and unassign is written to the audit log with before and after values. A delete writes one deleted row on Spanway_RoleTable plus one updated row on Spanway_UserTable for every user who lost the role, with custom_role_id before and after. /v2/user/info returns the user's custom_role_id.
In the Admin UI
The Roles page lists roles and shows the catalogue grouped by domain, with an Inherit, Grant or Deny choice for each permission. Inherit, the default, lets the base role decide, Grant allows the routes even when the base role would refuse them, and Deny refuses them even when the base role or a grant would allow them. You assign a role from the user's Edit Settings form on Internal Users. When the license does not include custom_roles, the page shows a notice naming that feature instead of lists that would fail with 403, even if the license is otherwise valid. Only proxy admins see the create, edit and delete buttons.
Errors
Role routes answer errors as {"detail": {"error": "<message>"}}.
| Status | Message | Meaning and fix |
|---|---|---|
| 403 | The 'custom_roles' feature needs a Spanway enterprise license. You must be a Spanway Enterprise user to use this feature... | The gateway has no Enterprise license. Set SPANWAY_LICENSE. |
| 403 | Your Spanway license does not include the 'custom_roles' feature. Contact sales@spanway.ai to add it. | The license is valid but lacks the feature. Ask for it to be added. |
| 403 | Only proxy admins can change this resource | A non admin called a write route such as /role/new or /role/assign. Use a proxy admin key. |
| 403 | Only proxy admins can read this resource | A caller who is neither a proxy admin nor an admin viewer called /role/list, /role/info or /role/permissions. |
| 403 | user not allowed to access this route. Route=<route> is denied by the user's custom role | The user's custom role denies a permission that covers the route, and denials win. Remove the denial or use another role. |
| 400 | user_id=<id> is a proxy_admin, and custom roles never restrict proxy admins | /role/assign was called for a proxy admin. Change the user's Global Proxy Role first if the role should apply. |
| 422 | Value error, unknown permissions: <names>. See GET /role/permissions | A permission name is not in the catalogue. Check GET /role/permissions. |
| 422 | Value error, base_role must be one of [...] | The base role is an admin role or unknown. Use internal_user, internal_user_viewer or proxy_admin_viewer. |
| 400 | role_name=<name> already exists | Role names are unique. Choose another. |
| 400 | nothing to update | The update sent no field. |
| 404 | role_id=<id> not found or user_id=<id> not found | The id is wrong. List roles with GET /role/list. |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | The gateway has no database. Set DATABASE_URL and restart. |
Logs
Both lines are written at DEBUG level, so you see them only when the gateway runs with --detailed_debug or SPANWAY_LOG=DEBUG. Neither needs action.
| Line | Meaning |
|---|---|
custom role <name> decided <allow, deny or inherit> for route <route> | Shows how a user's custom role decided one request. Use it to find out why a route was refused or allowed. |
custom role <name> ignored: enterprise package unavailable | The gateway image has no enterprise package, so the role is not applied and the user's Global Proxy Role decides. |
To create and assign a role in the Admin UI, open Roles under Access Control and click + Create Role, then assign it from the user's detail page on Internal Users. See the Roles page.
Related
- Roles page for the Admin UI.
- Access control for the built-in roles.
- Enterprise for the license feature.