Service Accounts
Service accounts allow non-interactive processes, background workers, schedulers, cleanup jobs, and automated pipelines, to authenticate with CRAFT using machine identity. Service accounts authenticate against the master realm in Keycloak (not the organization realm), which gives them platform-level access scoped by explicit organization and project headers.Detection
The platform identifies a request as coming from a service account when:- The client ID in the JWT begins with the
svc-prefix (e.g.,svc-data-pipeline) - The JWT contains the
serviceAccountrealm role - The authentication was performed against the Keycloak master realm
Authentication Flow
1
Obtain a Client Credentials Token
Service accounts use the OAuth 2.0 Client Credentials grant, no user interaction required.Response:
2
Pass Service Account Context Headers
Service account JWTs do not carry tenant context. Pass these required headers:
X-Org-Id, the organization context (required; replaces the realm-derived org in user tokens)X-Project-ID, the project scope for project-scoped endpoints (required when applicable)
X-On-Behalf-Of: <user-id> (optional).3
Acting on Behalf of a User (optional)
The
X-On-Behalf-Of header is recorded in audit logs but does not grant additional permissions. Include it whenever the service account is operating on a user’s behalf. The get_headers() helper accepts it as an optional parameter.Creating a Service Account
1
Create a Confidential Client in Keycloak
In the Keycloak master realm admin console:
- Navigate to Clients → Create client
- Set Client ID with the
svc-prefix (e.g.,svc-nightly-cleanup) - Set Client Protocol:
openid-connect - Set Access Type:
confidential - Enable Service Accounts Enabled
- Save and note the generated client secret
2
Assign the serviceAccount Role
In the client’s Service Account Roles tab:
- Select Realm Roles
- Assign the
serviceAccountrole
3
Grant Platform Permissions
Service accounts access the platform APIs with the same permission model as users. Grant the service account access to specific organizations and projects via the platform admin API or the Runtime UI.
Use Cases
Token Expiry and Rotation
Service account tokens are short-lived (configurable, default 1 hour). Background workers should implement automatic token refresh:Related
Authentication
Overview of all authentication methods including user tokens and OIDC.
Authorization
How permissions are checked for service account requests.
Projects
Project-level isolation and the X-Project-ID header.

