Skip to main content

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​

  1. In the Admin UI open Roles in the left nav (/ui/roles) and click + Create Role.

  2. Enter support-engineer as Role Name, pick internal_user_viewer as Base Role, set keys.read, keys.write, users.read and logs.read to 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.

  3. 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-..."}'
  4. 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.

  1. If any denied permission covers the route, the request is refused.
  2. If the role grants *, every management route in the catalogue is allowed.
  3. If any granted permission covers the route, the request is allowed.
  4. 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_viewer that mentions no key permission stops an internal_user from 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.

DomainCoversPermissions
keysVirtual keyskeys.read, keys.write
teamsTeams and their membersteams.read, teams.write
usersInternal users and customersusers.read, users.write
organizationsOrganizations and their membersorganizations.read, organizations.write
modelsModel deployments and pricingmodels.read, models.write
spendSpend reports and usage analyticsspend.read, spend.write (global spend reset)
logsRequest 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 reasonlogs.read, logs.prompts, logs.responses, logs.tool_arguments, logs.reveal
budgetsBudgetsbudgets.read, budgets.write
guardrailsGuardrails and policiesguardrails.read, guardrails.write
tagsTagstags.read, tags.write
projectsProjectsprojects.read, projects.write
mcpMCP servers, toolsets and sessions. Toolset changes and publishing servers stay with proxy adminsmcp.read, mcp.write
agentsAgents, their identity status and agent spend. Fetching an upstream card with /v1/a2a/discover stays with proxy adminsagents.read, agents.write
custom_agentsCustom 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 definitioncustom_agents.read, custom_agents.write
workflowsWorkflow 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 adminsworkflows.read, workflows.write
triggersWorkflow triggers. Write also covers sending chat messages and form submissionstriggers.read, triggers.write
approvalsHuman approval requests and policies. Write opens the decision routes, but only the policy makes someone an approver. Changing policies stays with adminsapprovals.read, approvals.write
environmentsEnvironment 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 adminsenvironments.read, environments.write
code_graphCode 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 Appcode_graph.read, code_graph.reindex, code_graph.manage
credentialsProvider credentialscredentials.read, credentials.write
settingsProxy configuration, callbacks and alertingsettings.read, settings.write
routingAuto-routersrouting.read, routing.write
auditAudit 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 themaudit.read
statusStatus page and incidentsstatus.read, status.write
alertsAlerts inbox, usage baselines and live deployment speedalerts.read, alerts.write
complianceCompliance 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 reportscompliance.read, compliance.write
billingBilling accounts and invoicesbilling.read, billing.write
cloudSpanway Cloud tenants, their credits, provider keys and the super admin tenant routescloud.read, cloud.write
evalsEval datasets, scorers and runsevals.read, evals.write
sanctionsThe sanctions screening review queue, OFAC report tasks and the geofence statussanctions.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​

MethodPathSummary
GET/role/permissionsThe permission catalogue for custom roles
GET/role/listList custom roles
GET/role/infoGet a custom role with its user count
POST/role/newCreate a custom role
POST/role/updateUpdate a custom role
DELETE/role/deleteDelete a custom role
POST/role/assignGive a user a custom role
POST/role/unassignTake 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>"}}.

StatusMessageMeaning and fix
403The '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.
403Your 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.
403Only proxy admins can change this resourceA non admin called a write route such as /role/new or /role/assign. Use a proxy admin key.
403Only proxy admins can read this resourceA caller who is neither a proxy admin nor an admin viewer called /role/list, /role/info or /role/permissions.
403user not allowed to access this route. Route=<route> is denied by the user's custom roleThe user's custom role denies a permission that covers the route, and denials win. Remove the denial or use another role.
400user_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.
422Value error, unknown permissions: <names>. See GET /role/permissionsA permission name is not in the catalogue. Check GET /role/permissions.
422Value 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.
400role_name=<name> already existsRole names are unique. Choose another.
400nothing to updateThe update sent no field.
404role_id=<id> not found or user_id=<id> not foundThe id is wrong. List roles with GET /role/list.
500DB 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_keysThe 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.

LineMeaning
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 unavailableThe 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.