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
- Client Credentials
- Service Account User
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:Human-readable name for the service (e.g., “Batch ETL Job”)
Purpose/description of the service
Authentication mode:
client_credentials or service_account_userUser ID to act as for permission inheritance (e.g.,
user:alice). Required if authentication_mode is service_account_user.Whether to inherit permissions from associated user
Service principal created successfully
Invalid authentication mode or missing required fields
Not authenticated
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:Service principals retrieved successfully
Not authenticated
GET /
Get details of a specific service principal. Returns service principal details if the current user is the owner. Path Parameters:Unique identifier of the service principal
Service principal details retrieved
Not authenticated
Not the owner of this service principal
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:Unique identifier of the service principal
Secret rotated successfully
Not authenticated
Not the owner of this service principal
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:Unique identifier of the service principal
Service principal deleted successfully
Not authenticated
Not the owner of this service principal
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. Wheninherit_permissions is true, the service principal can act on behalf of the user and inherit all their permissions.
Path Parameters:
Unique identifier of the service principal
User ID to associate (e.g.,
user:alice)Whether to inherit permissions from the user
User association updated successfully
Not authenticated
Not the owner of this service principal
Service principal not found
Using Service Principals
1. Create Service Principal
2. Authenticate as Service Principal
3. Make API Requests
Security Best Practices
Secret Storage
Secret Storage
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
Principle of Least Privilege
Principle of Least Privilege
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
Secret Rotation
Secret Rotation
Implement zero-downtime secret rotation
- Generate new secret using rotate-secret endpoint
- Update service configuration with new secret
- Restart service to use new credentials
- Old secret is invalidated immediately
Monitoring & Auditing
Monitoring & Auditing
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
Related Documentation
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!