Skip to main content

Overview

The Service Principals API provides endpoints for creating and managing service principals - non-human identities for machine-to-machine authentication. Service principals enable automated processes, batch jobs, and integrations to authenticate securely without requiring user credentials.
v2.8.0 adds comprehensive service principal management with permission inheritance and OpenFGA integration.

Use Cases

  • Batch Jobs: ETL processes, data synchronization, scheduled tasks
  • CI/CD Pipelines: Automated deployments, testing, infrastructure provisioning
  • Microservices: Service-to-service authentication
  • Integrations: Third-party system integrations, webhooks

Authentication Modes

Standard OAuth2 client credentials flow
  • Service authenticates with service_id + client_secret
  • Receives JWT token for API access
  • No user association required

Base URL

Authentication

All endpoints require user authentication:
  • Authorization: Bearer {token}
  • Users can only manage service principals they own

Endpoints

POST /

Create a new service principal. Creates a service principal with the specified authentication mode. The calling user becomes the owner of the service principal. Request Body:
string
required
Human-readable name for the service (e.g., “Batch ETL Job”)
string
required
Purpose/description of the service
string
default:"client_credentials"
Authentication mode: client_credentials or service_account_user
string
User ID to act as for permission inheritance (e.g., user:alice). Required if authentication_mode is service_account_user.
boolean
default:false
Whether to inherit permissions from associated user
Request Example:
Response:
Save the client_secret securely - it will not be shown again! Store it in a secret manager (e.g., HashiCorp Vault, AWS Secrets Manager, Azure Key Vault).
Status Codes:
Created
Service principal created successfully
Bad Request
Invalid authentication mode or missing required fields
Unauthorized
Not authenticated
Conflict
Service principal with this ID already exists

GET /

List service principals owned by the current user. Returns all service principals where the current user is the owner. Does not include client secrets. Request Example:
Response:
Status Codes:
Success
Service principals retrieved successfully
Unauthorized
Not authenticated

GET /

Get details of a specific service principal. Returns service principal details if the current user is the owner. Path Parameters:
string
required
Unique identifier of the service principal
Request Example:
Response:
Status Codes:
Success
Service principal details retrieved
Unauthorized
Not authenticated
Forbidden
Not the owner of this service principal
Not Found
Service principal not found

POST //rotate-secret

Rotate service principal secret. Generates a new client secret for the service principal. The old secret is invalidated immediately. Path Parameters:
string
required
Unique identifier of the service principal
Request Example:
Response:
Update your service configuration immediately! The old secret is invalidated and will no longer work. Save the new client_secret securely.
Status Codes:
Success
Secret rotated successfully
Unauthorized
Not authenticated
Forbidden
Not the owner of this service principal
Not Found
Service principal not found

DELETE /

Delete a service principal. Permanently deletes the service principal from Keycloak and OpenFGA. This action cannot be undone. Path Parameters:
string
required
Unique identifier of the service principal
Request Example:
Response: No content (HTTP 204) Status Codes:
No Content
Service principal deleted successfully
Unauthorized
Not authenticated
Forbidden
Not the owner of this service principal
Not Found
Service principal not found

POST //associate-user

Associate service principal with a user for permission inheritance. Links a service principal to a user, optionally enabling permission inheritance. When inherit_permissions is true, the service principal can act on behalf of the user and inherit all their permissions. Path Parameters:
string
required
Unique identifier of the service principal
Query Parameters:
string
required
User ID to associate (e.g., user:alice)
boolean
default:true
Whether to inherit permissions from the user
Request Example:
Response:
Status Codes:
Success
User association updated successfully
Unauthorized
Not authenticated
Forbidden
Not the owner of this service principal
Not Found
Service principal not found

Using Service Principals

1. Create Service Principal

2. Authenticate as Service Principal

3. Make API Requests


Security Best Practices

Never hardcode secrets in code or configuration files
  • Use secret managers: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault
  • Inject secrets at runtime via environment variables
  • Rotate secrets regularly (quarterly or after security incidents)
  • Use separate service principals for different environments
Grant minimum required permissions
  • Create service principals with specific, limited scopes
  • Use permission inheritance only when necessary
  • Associate with users who have minimal required permissions
  • Regularly audit service principal permissions
Implement zero-downtime secret rotation
  1. Generate new secret using rotate-secret endpoint
  2. Update service configuration with new secret
  3. Restart service to use new credentials
  4. Old secret is invalidated immediately
Automate rotation with tools like cert-manager or custom automation.
Track service principal activity
  • Enable audit logging for all service principal operations
  • Monitor authentication attempts and failures
  • Alert on unusual activity patterns
  • Review service principal usage quarterly
  • Disable unused service principals

Service Principals Guide

Complete service principal setup guide

Permission Inheritance

OpenFGA permission inheritance design

Authentication API

User authentication endpoints

Authorization Guide

OpenFGA authorization model

Production Ready: Service principals support enterprise authentication patterns with Keycloak and OpenFGA!