This document explains how the Red Hat Insights Identity Middleware has been integrated into the Job Scheduler service.
The service now uses the github.com/redhatinsights/platform-go-middlewares/identity package to enforce authentication and authorization for all API endpoints.
- All
/api/v1/*routes now require valid Red Hat Identity headers - The
identity.EnforceIdentitymiddleware is applied to all API routes - User identity information is extracted from the
X-Rh-Identityheader
- Organization ID: Automatically extracted from identity context (
ident.Identity.OrgID) - Username: Extracted from identity context (
ident.Identity.User.Username) with fallback to email - Users can only access jobs within their own organization
Request Changes:
- Removed
org_idandusernamefields from request bodies - These are now automatically populated from the authenticated user's identity
Before:
{
"name": "My Job",
"org_id": "12345",
"username": "john.doe",
"schedule": "*/10 * * * *",
"payload": {
"type": "message",
"details": {"message": "Hello"}
}
}After:
{
"name": "My Job",
"schedule": "*/10 * * * *",
"payload": {
"type": "message",
"details": {"message": "Hello"}
}
}- Organization Isolation: Users can only see/manage jobs from their organization
- Authorization Checks: All operations verify job ownership before execution
- No Cross-Org Access: Jobs from other organizations return "not found" errors
All API requests must include a valid X-Rh-Identity header containing base64-encoded identity information:
curl -H "X-Rh-Identity: <base64-encoded-identity>" \
-H "Content-Type: application/json" \
-d '{"name": "Test Job", "schedule": "*/10 * * * *", "payload": {"type": "message", "details": {"message": "Hello"}}}' \
http://localhost:5000/api/v1/jobsThe X-Rh-Identity header should contain base64-encoded JSON:
{
"identity": {
"account_number": "000001",
"org_id": "000001",
"user": {
"username": "john.doe",
"email": "john.doe@example.com",
"user_id": "john.doe-id"
},
"type": "User"
}
}For testing purposes, the cmd/test/main.go includes a mock identity header:
// Base64 encoded test identity
req.Header.Set("X-Rh-Identity", "eyJpZGVudGl0eSI6eyJhY2NvdW50X251bWJlciI6IjAwMDAwMSIsIm9yZ19pZCI6IjAwMDAwMSIsInVzZXIiOnsidXNlcm5hbWUiOiJ0ZXN0dXNlciIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsInVzZXJfaWQiOiJ0ZXN0dXNlci1pZCJ9LCJ0eXBlIjoiVXNlciJ9fQ==")The username field is still stored in the database and populated from the identity context. Existing data will have default values ("unknown") for username until updated.
All endpoints under /api/v1/ now require authentication:
POST /api/v1/jobs- Create jobGET /api/v1/jobs- List jobs (filtered by user's org)GET /api/v1/jobs/{id}- Get job (org ownership check)PUT /api/v1/jobs/{id}- Update job (org ownership check)PATCH /api/v1/jobs/{id}- Patch job (org ownership check)DELETE /api/v1/jobs/{id}- Delete job (org ownership check)POST /api/v1/jobs/{id}/run- Run job (org ownership check)POST /api/v1/jobs/{id}/pause- Pause job (org ownership check)POST /api/v1/jobs/{id}/resume- Resume job (org ownership check)
HTTP 400 Bad Request
{
"error": "Missing organization ID in identity"
}HTTP 404 Not Found
{
"error": "Job not found"
}This ensures users cannot determine if jobs exist in other organizations.