Authentication & RBAC
OSAPI uses JWT bearer tokens for authentication and fine-grained resource:verb
permissions for authorization. Every API endpoint (except health probes)
requires a valid token.
How It Works
JWT Signing
OSAPI uses HMAC-SHA256 (HS256) symmetric signing. The same signing_key is
used to both create and verify tokens:
osapi token generate ──[signs with signing_key]──> JWT
Client ──[sends JWT]──> API Server ──[verifies with signing_key]──> Allow/Deny
Only someone who knows the signing key can create valid tokens. If the signing key is compromised, rotate it immediately -- all previously issued tokens become invalid.
Token Structure
A token carries three pieces of authorization data:
- Roles (
rolesclaim, required) -- one or more ofadmin,write,read - Permissions (
permissionsclaim, optional) -- directresource:verbgrants that override role expansion - Subject (
subclaim) -- user identity for audit logging
Generate tokens with the CLI. See CLI Reference for usage and examples, or the API Reference for the REST endpoints.
Permission Resolution
When a request arrives, the middleware resolves the caller's effective permissions:
Roles and Permissions
Built-in roles expand to these default permissions:
| Role | Permissions |
|---|---|
admin | node:read, network:read, network:write, job:read, job:write, health:read, audit:read |
write | node:read, network:read, network:write, job:read, job:write, health:read |
read | node:read, network:read, job:read, health:read |
Custom Roles
Define custom roles in the configuration to create new role names or override default permission mappings:
api:
server:
security:
roles:
ops:
permissions:
- node:read
- health:read
netadmin:
permissions:
- network:read
- network:write
- health:read
Configuration
api:
server:
security:
# HS256 signing key (REQUIRED)
# Generate with: openssl rand -hex 32
signing_key: '<64-char hex string>'
client:
security:
# JWT for client requests (REQUIRED)
# Generate with: osapi token generate
bearer_token: '<jwt>'
See Configuration for the full reference including custom roles and CORS settings.
Related
- CLI Reference -- token generation and validation commands
- API Reference -- REST API documentation
- Configuration -- full configuration reference
- Architecture -- system design overview