Introducing a new way to review your PRs.

Read the announcement

semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform/OpenTofu/Terragrunt, PowerShell and other DevOps tools.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / http-api-and-access-control

HTTP API and access control

The HTTP API is the main boundary between clients and Semaphore. It routes public sign-in requests, authenticated global resources, project resources, task execution, runner traffic, and audit data through shared checks for identity, scope, permission, and safe state change.

API surface

Route groups

The API server in home/…/router.go groups routes by trust boundary and resource scope. Public routes support login and session verification. Separate internal and webhook routes serve runners and external integrations. Authenticated routes serve the web console and API clients.

The main route groups are:

Route groupPurposeAccess boundary
/api/authStart, verify, recover, and end user sessionsPublic entry points, with session checks where needed
/api/internal/runnersRegister and communicate with runnersRunner token
/api/integrations and /api/terraformReceive external events and state callsIntegration or inventory-specific checks
/api/* authenticated routesServe users, system settings, projects, tasks, roles, and audit dataSession or API token plus route permission
/.well-known/jwks.json, /api/ping, and /api/metricsPublish key data, health status, and metricsPublic, or separate metrics credentials

The same server also returns the web application for non-API paths. An unknown path under /api stays an API 404 instead of becoming a web-app route. This keeps client errors distinct from browser navigation.

References: api/router.go• L134-205 api/router.go• L696-710

Global and project scopes

Global routes address the Semaphore instance. They cover users, global roles, system options, cluster status, global runners, applications, and the instance audit log. Project routes begin with /api/project/{project_id} and apply project membership and project permissions before they reach a resource action.

Project routes separate member-readable data from management actions. A member can read only the project data allowed by the effective project view. Resource changes, user management, role changes, task control, workflow edits, and approvals use narrower permission checks.

The project API is described in Project resource API. Task and runner endpoints are described in Task and runner API.

References: api/router.go• L207-336 api/router.go• L342-451 api/router.go• L533-631

Project resource query behavior

Project resource endpoints expose both broad views and focused resource data. View lists can filter by view type and can request template status counts. Managed inventories also expose paged host lists, while host changes remain tied to the selected inventory.

These query options keep the API useful for project screens without changing the access boundary. Counts use only templates the caller may see, and a host from another inventory is treated as absent.

References: api/…/views.go• L49-127 api/…/inventory_hosts.go• L88-134 api/router.go• L362-369 api/router.go• L496-511

Request lifecycle

Request context

The request context carries the facts that later route checks and handlers need. Authentication adds the user and audit actor. Project middleware adds the project, membership, and effective project permissions. Resource middleware adds the selected template, workflow, task, runner, inventory, view, or other object.

This staged context lets a route check the relationship between the caller and the requested object before the action runs. It also keeps handlers focused on the requested operation rather than repeating lookup and scope checks.

References: api/…/context.go• L10-35 api/…/project.go• L19-85 api/…/templates.go• L16-42 api/…/workflows.go• L22-67

Handler response contract

Authenticated API routes use JSON by default. Handlers return the resource for successful reads, no content for successful changes that have no response body, and a structured error for client-visible failures. Missing objects use not-found behavior. Invalid input uses a bad-request response. Permission failures use forbidden behavior.

Route parameters are validated before a handler acts. A malformed identifier is a client error for API requests. This prevents a bad path value from becoming a store lookup with an unclear result.

References: api/router.go• L47-61 api/…/write_response.go• L14-62 api/…/route_params.go• L11-76

State-changing request protection

Browser requests that change state pass a cross-site request check when they use the session cookie. The check accepts the server’s own origin and blocks a different Origin or Referer. API-token requests do not rely on browser cookie behavior, so they are not subject to this browser check.

This protection sits before the authenticated API route tree. It reduces the chance that a page on another site can use a user’s active browser session to change Semaphore state.

References: api/router.go• L200-205 api/auth.go• L392-483 api/audit_log_test.go• L49-70

Access control

Authentication methods

The API recognizes two user authentication methods. A verified session comes from the signed semaphore cookie and is checked against the stored session. An API client can send a bearer token, which is checked for existence and expiry. Both methods resolve to a user before an authenticated handler runs.

Sessions can require an extra verification step. The API exposes email or TOTP verification and recovery before it treats the session as fully authenticated. The details of login, identity providers, MFA, sessions, tokens, and keys are covered in Identity, sessions, and security.

Authentication failures return unauthorized responses. Failed token use records only a token fingerprint in audit data. The raw token is not used as the audit identity.

References: api/auth.go• L23-67 api/auth.go• L187-256 api/auth.go• L259-370

Global permissions

Global permissions control actions that affect the whole instance. An administrator has all global permissions. Other users receive effective permissions from their global roles. Routes use these permissions for system management, global role administration, user management, and audit-log access.

Global permission checks run after authentication and before the protected handler. A denied check stops the request and records the denied route and permission in the audit stream. The route permission table is checked against the live router so new instance-wide protected routes do not silently fall outside this contract.

References: api/global_permissions.go• L21-73 api/router.go• L241-336 api/global_routes_test.go• L21-112 api/global_routes_test.go• L271-322

Project permissions

Project access starts by loading the project and the caller’s membership. The server combines permissions from assigned roles, mapped roles, and grants on a template or workflow when those objects are in the route. An administrator may enter a project without a membership record.

Read routes require the project read permission even when the route also has a stronger write permission. Object middleware hides templates, workflows, tasks, and related resources that the caller may not read by returning not-found behavior. This avoids exposing the existence of protected objects.

Write routes then apply the permission for the requested action. Examples include managing project resources, editing workflows, running tasks, approving workflow steps, and managing project users. Inventory hosts inherit the selected project and managed inventory boundary rather than accepting those owners from the request body.

References: api/…/project.go• L19-115 api/…/tasks.go• L227-305 api/…/templates.go• L16-42 api/…/workflows.go• L22-46 api/…/inventory.go• L17-35 api/…/inventory_hosts.go• L88-181

Runner request boundary

Runner traffic uses a separate trust boundary from user traffic. Registration accepts a valid registration token, while later polling and progress requests use the runner token and become actions of that runner in the audit context.

The server treats runner reports as state updates for the assigned task. It accepts reports only for live tasks assigned to that runner, tells a stale runner to stop an orphaned or reassigned job, and rejects invalid task status or output data before it can corrupt task state.

References: api/…/runners.go• L23-64 api/…/runners.go• L95-181 api/…/runners.go• L381-539 api/…/runners.go• L542-671 api/…/runners_test.go• L68-249

Audit-sensitive endpoints

Audit record flow

Audit records describe security events and important resource changes. The authenticated request establishes the actor. Authentication failures, cross-site request blocks, permission denials, MFA actions, and resource changes add the event kind, target, outcome, and relevant scope. Inventory and inventory-host changes record the project resource and describe changed fields without placing variable values or bearer secrets in the audit target.

The audit log is different from the project event log. The audit log is a protected security record for authorized readers. The project event log supports project activity and integration notifications. Both can be produced by API actions, but they serve different readers and purposes.

References: api/…/audit.go• L10-39 api/…/event_log.go• L11-65 api/auth.go• L269-347 api/…/project.go• L141-194 api/…/inventory.go• L126-148 api/…/inventory_hosts.go• L46-85

Audit log access

The global audit endpoints expose the security record as a paged list or an export. Only administrators and users with the global audit-read permission can use them. A browser request marked as cross-site is rejected before the audit handler runs.

Audit reads use a cursor in either the older or newer direction. The endpoint rejects invalid cursors and does not accept both directions at once. This keeps paging stable while new events arrive.

References: api/router.go• L236-240 api/audit_log.go• L17-47 api/audit_log.go• L55-118 api/audit_log_test.go• L90-163

Sensitive resource actions

The API treats identity changes, permission changes, project membership changes, task control, runner management, workflow approvals, project backup and restore, inventory host changes, and project deletion as sensitive actions. Their route permissions and audit records protect both the action and the record of who performed it.

Project backup export records the project snapshot that was returned. Restore checks the backup before it creates data, refuses feature-gated workflow content when the plan does not allow it, and records the object counts only after a successful restore. Inventory host changes record field names and variable-key changes rather than secret values.

The safest way to change one of these endpoints is to follow the full route chain: authentication, scope loading, object loading, permission check, action, and audit record. A change that keeps the action working but skips one of these links can expose data or leave an incomplete security trail.

References: api/router.go• L317-335 api/router.go• L408-422 api/router.go• L449-459 api/router.go• L496-511 api/router.go• L535-596 api/…/backup_restore.go• L94-214 api/…/inventory_hosts.go• L186-317 api/…/resources_audit_test.go• L168-235

Use these pages for the detailed API areas that this overview intentionally keeps short:

  • Identity, sessions, and security covers login methods, MFA, sessions, tokens, JWKS, global permissions, and identity audit behavior.
  • Project resource API covers project resources, members, grants, repositories, inventories, environments, keys, templates, workflows, integrations, schedules, and backups.
  • Task and runner API covers task launch and control, task output, workflow runs, runner registration, runner health, and runner management.

Change checklist

When these files or sections are changed, remember to consider these:

  • A new authenticated route must join the correct middleware chain for session or token authentication, CSRF protection, global role loading, and JSON responses.
  • A project route must load its project before its permission check and must choose whether hidden objects return not-found rather than forbidden.
  • A new state-changing action must define its required global or project permission and its audit event or denial record.
  • A new audit endpoint must preserve both the global audit-read check and the cross-site request restriction.
  • A change to route order must keep fixed catalog paths ahead of routes that treat the same word as an identifier.
  • Runner routes must keep user authentication separate from runner-token authentication and must preserve the runner audit actor.
  • Inventory-host routes must keep the managed-inventory check and must scope every host lookup to both the project and inventory.
  • View query options must keep unknown filters as client errors and must not add template counts for views that do not expose them.
  • Backup and restore changes must keep feature checks before creation and must record only a completed restore.

Important failure modes

TriggerConsequenceGuard
A state-changing browser request has a foreign originThe request is rejected with forbidden status and a CSRF audit eventSame-origin checking before authenticated API handlers
A session is missing, expired, or not fully verifiedThe request cannot reach protected resourcesStored-session validation plus email or TOTP verification
A bearer token is unknown or expiredThe client receives unauthorized status and the rejection is audited by fingerprintToken lookup and expiry checks
A project member lacks the action permissionThe request receives forbidden status and the denial records the route and permissionProject permission middleware
A member requests an object outside the member’s read scopeThe object appears absentObject middleware returns not-found behavior
An audit reader lacks global audit permission or sends a cross-site browser requestAudit data is not returnedAudit middleware checks both conditions
A host endpoint targets a non-managed inventory or a host in another inventoryThe request fails without changing the other inventoryManaged-inventory check plus project-and-inventory-scoped lookup
A view request uses an unknown type or include valueThe API returns bad request instead of silently changing the resultExplicit query-value validation
A runner reports a finished or reassigned taskThe server returns the task in terminated_jobs and keeps terminal or new-runner stateRunner and task ownership checks before progress updates

Key files

FileWhy to read it
api/router.goDefines the route groups, middleware boundaries, global resources, project resources, task routes, runner routes, and audit endpoints.
api/auth.goDefines session and bearer-token authentication, MFA gates, metrics credentials, and CSRF protection.
api/global_permissions.goDefines how administrators and global roles receive instance-wide access.
api/…/project.goDefines project loading, membership-derived permissions, project checks, and project-level audit behavior.
api/…/inventory.go and api/…/inventory_hosts.goDefine inventory scope and the managed-inventory host API, including audit records for host changes.
api/…/views.goDefines project view filters and optional template statistics.
api/…/backup_restore.goDefines project backup export and restore checks, audit records, and failure boundaries.
api/audit_log.goDefines audit-log access rules, cursor paging, and export access.
api/…/audit.goDefines request audit access and the common denied-action record.
api/…/tasks.goShows how task objects and task-specific grants are loaded before task actions.
api/…/runners.goDefines runner-token authentication, runner polling and progress boundaries, and the runner request identity.