diff --git a/apps/coordinator/docs/openapi.yaml b/apps/coordinator/docs/openapi.yaml index 96855e85..8d48a549 100644 --- a/apps/coordinator/docs/openapi.yaml +++ b/apps/coordinator/docs/openapi.yaml @@ -21,6 +21,8 @@ tags: description: Query audit log events for organizations and projects. - name: Projects description: Create and manage projects within an organization. + - name: User Sources + description: Create and manage project-bound OIDC user sources. - name: RBAC description: | Role-based access control. Browse the roles catalog, read the caller's @@ -41,17 +43,19 @@ paths: summary: List organization audit logs operationId: audit-logs-list-org description: | - Query audit logs for an organization with cursor-based pagination. + Query audit logs for an organization, newest first, paginated by offset. - Optionally filter by action, source, resource type, and time range. + Optionally filter by action, source, resource type, resource ID, and time + range. The reported total counts the entries the filters select, not the page. parameters: - $ref: '#/components/parameters/OrganizationId' - $ref: '#/components/parameters/ActionFilter' - $ref: '#/components/parameters/SourceFilter' - $ref: '#/components/parameters/ResourceTypeFilter' + - $ref: '#/components/parameters/ResourceIdFilter' - $ref: '#/components/parameters/StartTime' - $ref: '#/components/parameters/EndTime' - - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Offset' - $ref: '#/components/parameters/Limit' responses: '200': @@ -94,18 +98,20 @@ paths: summary: List project audit logs operationId: audit-logs-list-project description: | - Query audit logs for a specific project with cursor-based pagination. + Query audit logs for a specific project, newest first, paginated by offset. - Optionally filter by action, source, resource type, and time range. + Optionally filter by action, source, resource type, resource ID, and time + range. The reported total counts the entries the filters select, not the page. parameters: - $ref: '#/components/parameters/OrganizationId' - $ref: '#/components/parameters/ProjectId' - $ref: '#/components/parameters/ActionFilter' - $ref: '#/components/parameters/SourceFilter' - $ref: '#/components/parameters/ResourceTypeFilter' + - $ref: '#/components/parameters/ResourceIdFilter' - $ref: '#/components/parameters/StartTime' - $ref: '#/components/parameters/EndTime' - - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Offset' - $ref: '#/components/parameters/Limit' responses: '200': @@ -603,6 +609,425 @@ paths: schema: $ref: '#/components/schemas/ErrorEnvelope' + # ── User Sources ──────────────────────────────────────────────────────────── + /api/v1/orgs/{organization_id}/projects/{project_id}/user_sources: + get: + security: + - Bearer: [] + tags: + - User Sources + summary: List user sources + operationId: user-sources-list + description: | + List user sources visible in this project, newest first, paginated by + offset. `total_count` is the full matching set before pagination. + + `client_secret` is never returned. + + Requires the `user_sources_read` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - name: limit + in: query + required: false + description: Results per page. + schema: + type: integer + default: 100 + minimum: 1 + maximum: 500 + - name: offset + in: query + required: false + description: Rows to skip before the page. + schema: + type: integer + default: 0 + minimum: 0 + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceListEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_read` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- organization or project is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: Unprocessable Entity -- `limit` or `offset` is out of range + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + post: + security: + - Bearer: [] + tags: + - User Sources + summary: Create a user source + operationId: user-sources-create + description: | + Create a project-bound user source. The new record always has + `binding_type: project`. Its `id` is a `us_`-prefixed KSUID; pass that + id to Engine gateway create/update as `user_source_id` when + `auth_type=user_source`. + + The Coordinator probes the issuer's OIDC discovery document and JWKS + before persisting. A malformed, unreachable, or self-inconsistent + issuer is rejected with `422`. The stored issuer string is the + caller's exact input (no trailing-slash normalization) so it can be + exact-matched against the `iss` claim on upstream ID tokens. + + `scopes` must include `openid`. Duplicates are collapsed on write + while preserving first occurrence. `client_secret` is stored + encrypted and is never returned. + + Requires the `user_sources_create` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceCreateRequest' + responses: + '201': + description: Created + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceEnvelope' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_create` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- organization or project is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: | + Unprocessable Entity -- the body failed validation, `scopes` omitted + `openid`, or the issuer failed OIDC discovery / JWKS checks. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + /api/v1/orgs/{organization_id}/projects/{project_id}/user_sources/{user_source_id}: + get: + security: + - Bearer: [] + tags: + - User Sources + summary: Get a user source + operationId: user-sources-get + description: | + Return one project-bound user source. `client_secret` is never returned. + + Organization-bound records (`binding_type: organization`) return `422`, + not `404`, with guidance to use the organization scope. Platform-internal + (`static`) records return `404`. Unknown ids return `404`. A malformed + id (missing or wrong `us_` prefix, or not a KSUID) returns `422`. + + Requires the `user_sources_read` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - $ref: '#/components/parameters/UserSourceId' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_read` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- user source is unknown, static-bound, or not visible + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: | + Unprocessable Entity -- `user_source_id` is malformed, or the record + is organization-bound (use the organization scope). + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + put: + security: + - Bearer: [] + tags: + - User Sources + summary: Replace a user source + operationId: user-sources-replace + description: | + Full replace of a project-bound user source. `client_secret` is + required. The Coordinator re-validates the issuer's OIDC discovery + document and JWKS. `client_secret` is never returned. + + Organization-bound records return `422`. Static records return `404`. + + Requires the `user_sources_update` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - $ref: '#/components/parameters/UserSourceId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceReplaceRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceEnvelope' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_update` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- user source is unknown, static-bound, or not visible + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: | + Unprocessable Entity -- the body failed validation, `client_secret` + is missing, the issuer failed OIDC checks, `user_source_id` is + malformed, or the record is organization-bound. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + patch: + security: + - Bearer: [] + tags: + - User Sources + summary: Patch a user source + operationId: user-sources-patch + description: | + Partial update of a project-bound user source. Omitted fields keep + their stored values. + + `client_secret`: omit to keep the stored secret; send a new value to + rotate; send explicit `null` to clear. `issuer` must not be `null`. + `description` sent as `null` is stored as an empty string. + + The Coordinator re-validates OIDC discovery and JWKS only when + `issuer` or `scopes` actually change, so a transient IdP outage does + not block a status flip. `client_secret` is never returned. + + Organization-bound records return `422`. Static records return `404`. + + Requires the `user_sources_update` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - $ref: '#/components/parameters/UserSourceId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourcePatchRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserSourceEnvelope' + '400': + description: Bad Request -- `issuer` was sent as `null` + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_update` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- user source is unknown, static-bound, or not visible + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: | + Unprocessable Entity -- the body failed validation, the issuer + failed OIDC checks, `user_source_id` is malformed, or the record + is organization-bound. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + delete: + security: + - Bearer: [] + tags: + - User Sources + summary: Delete a user source + operationId: user-sources-delete + description: | + Permanently delete a project-bound user source. Returns `204` with no + body on success. + + Organization-bound records return `422`. Static records return `404`. + + Requires the `user_sources_delete` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - $ref: '#/components/parameters/UserSourceId' + responses: + '204': + description: No Content -- the user source was deleted. + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `user_sources_delete` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- user source is unknown, static-bound, or not visible + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: | + Unprocessable Entity -- `user_source_id` is malformed, or the + record is organization-bound. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + # ── RBAC: capabilities, roles catalog, org membership & roles ───────────────── /api/v1/orgs/{organization_id}/capabilities: get: @@ -947,6 +1372,19 @@ components: type: string format: uuid + UserSourceId: + name: user_source_id + in: path + required: true + description: | + User source id. A `us_`-prefixed KSUID (for example + `us_0000GfkSkVjL1s3EM2wUfhjxv7B`). The Engine validates the same + prefix when the id is passed as `user_source_id` on a gateway. + schema: + type: string + pattern: '^us_[0-9A-Za-z]{27}$' + example: us_0000GfkSkVjL1s3EM2wUfhjxv7B + ActionFilter: name: action in: query @@ -979,6 +1417,14 @@ components: schema: type: string + ResourceIdFilter: + name: resource_id + in: query + required: false + description: Filter by the resource's unique identifier. + schema: + type: string + StartTime: name: start_time in: query @@ -997,13 +1443,15 @@ components: type: string format: date-time - Cursor: - name: cursor + Offset: + name: offset in: query required: false - description: Opaque pagination cursor returned by a previous response. + description: How many matching entries to skip before this page. schema: - type: string + type: integer + minimum: 0 + default: 0 Limit: name: limit @@ -1054,19 +1502,25 @@ components: type: object required: - items - - has_more + - total_count + - limit + - offset properties: items: type: array items: $ref: '#/components/schemas/AuditLogResponse' - next_cursor: - type: string - nullable: true - description: Cursor to pass as the `cursor` query parameter for the next page. - has_more: - type: boolean - description: Whether additional pages exist beyond this one. + total_count: + type: integer + description: >- + Total entries matching the filters, across every page. Add the page's + limit to its offset until that reaches this value to walk the set. + limit: + type: integer + description: Page size the request asked for. + offset: + type: integer + description: Offset the request asked for. AuditLogResponse: type: object @@ -1767,3 +2221,349 @@ components: $ref: '#/components/schemas/OrgAuthzCapabilities' billing: $ref: '#/components/schemas/BillingCapabilities' + + # ── User Source schemas ───────────────────────────────────────────────── + UserSourceBindingType: + type: string + enum: + - project + - organization + description: | + Whether the record is project-scoped (mutable on this route) or + organization-scoped (inherited; GET/PUT/PATCH/DELETE through the + project path return `422`). Platform-internal `static` bindings + never appear on the wire. + + UserSourceStatus: + type: string + enum: + - active + - inactive + description: Whether the user source is active. + + UserSourceProtocol: + type: string + enum: + - oidc + description: Authentication protocol. Only OIDC is supported. + + UserSource: + type: object + required: + - id + - organization_id + - binding_type + - name + - description + - protocol + - issuer + - client_id + - subject_claim + - scopes + - status + - created_at + - updated_at + properties: + id: + type: string + description: User source id (`us_`-prefixed KSUID). + pattern: '^us_[0-9A-Za-z]{27}$' + example: us_0000GfkSkVjL1s3EM2wUfhjxv7B + organization_id: + type: string + format: uuid + description: Owning organization. + project_id: + type: string + format: uuid + nullable: true + description: Owning project. `null` for organization-bound records. + binding_type: + $ref: '#/components/schemas/UserSourceBindingType' + name: + type: string + description: Human-readable name. + description: + type: string + description: Freeform description. Never shown to end users. + protocol: + $ref: '#/components/schemas/UserSourceProtocol' + issuer: + type: string + description: | + OIDC issuer URL, stored exactly as submitted (no trailing-slash + normalization) so it can be exact-matched against the `iss` claim. + client_id: + type: string + description: OIDC client ID. + subject_claim: + type: string + description: OIDC claim used as the stable subject identifier. + example: sub + scopes: + type: array + items: + type: string + description: OIDC scopes requested from the upstream IdP. + example: + - openid + - profile + - email + status: + $ref: '#/components/schemas/UserSourceStatus' + created_at: + type: string + format: date-time + description: Creation timestamp. + updated_at: + type: string + format: date-time + description: Last-updated timestamp. + + UserSourceList: + type: object + required: + - items + - total_count + - limit + - offset + properties: + items: + type: array + items: + $ref: '#/components/schemas/UserSource' + total_count: + type: integer + description: Total matching items across every page. + limit: + type: integer + description: Page size the request asked for. + offset: + type: integer + description: Offset the request asked for. + + UserSourceEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/UserSource' + + UserSourceListEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/UserSourceList' + + UserSourceCreateRequest: + type: object + required: + - name + - issuer + - client_id + - client_secret + properties: + name: + type: string + minLength: 1 + maxLength: 255 + description: Human-readable name. + description: + type: string + maxLength: 4000 + default: '' + description: Freeform description. Visible to project members, never to end users. + protocol: + allOf: + - $ref: '#/components/schemas/UserSourceProtocol' + default: oidc + issuer: + type: string + minLength: 1 + maxLength: 2048 + format: uri + description: | + OIDC issuer URL. Stored verbatim. Must be reachable and serve a + self-consistent discovery document and JWKS at create time. + client_id: + type: string + minLength: 1 + maxLength: 2048 + description: OIDC client ID. + client_secret: + type: string + minLength: 1 + maxLength: 4096 + description: | + OIDC client secret (plaintext; stored encrypted). Never returned + in responses. + subject_claim: + type: string + minLength: 1 + maxLength: 2048 + default: sub + description: OIDC claim used as the stable subject identifier. + scopes: + type: array + minItems: 1 + maxItems: 64 + default: + - openid + - profile + - email + items: + type: string + minLength: 1 + maxLength: 1024 + description: | + OIDC scopes requested from the upstream IdP. Must include + `openid`. Tokens must not contain whitespace. Duplicates are + collapsed on write while preserving first occurrence. + status: + allOf: + - $ref: '#/components/schemas/UserSourceStatus' + default: active + + UserSourceReplaceRequest: + type: object + required: + - name + - issuer + - client_id + - client_secret + properties: + name: + type: string + minLength: 1 + maxLength: 255 + description: Human-readable name. + description: + type: string + maxLength: 4000 + default: '' + description: Freeform description. + protocol: + allOf: + - $ref: '#/components/schemas/UserSourceProtocol' + default: oidc + issuer: + type: string + minLength: 1 + maxLength: 2048 + format: uri + description: OIDC issuer URL. Stored verbatim. Re-validated on replace. + client_id: + type: string + minLength: 1 + maxLength: 2048 + description: OIDC client ID. + client_secret: + type: string + minLength: 1 + maxLength: 4096 + description: | + OIDC client secret (plaintext; stored encrypted). Required on + replace. Never returned in responses. + subject_claim: + type: string + minLength: 1 + maxLength: 2048 + default: sub + description: OIDC claim used as the stable subject identifier. + scopes: + type: array + minItems: 1 + maxItems: 64 + default: + - openid + - profile + - email + items: + type: string + minLength: 1 + maxLength: 1024 + description: | + OIDC scopes requested from the upstream IdP. Must include + `openid`. + status: + allOf: + - $ref: '#/components/schemas/UserSourceStatus' + default: active + + UserSourcePatchRequest: + type: object + properties: + name: + type: string + minLength: 1 + maxLength: 255 + description: Human-readable name. Omit to keep the stored value. + description: + type: string + maxLength: 4000 + description: | + Freeform description. Omit to keep the stored value. Explicit + `null` is stored as an empty string. + protocol: + $ref: '#/components/schemas/UserSourceProtocol' + issuer: + type: string + minLength: 1 + maxLength: 2048 + format: uri + nullable: true + description: | + OIDC issuer URL. Omit to keep the stored value. Must not be + `null`. Re-validated only when the string actually changes. + client_id: + type: string + minLength: 1 + maxLength: 2048 + description: OIDC client ID. Omit to keep the stored value. + client_secret: + type: string + minLength: 1 + maxLength: 4096 + nullable: true + description: | + OIDC client secret. Omit to keep the stored secret. Send a new + value to rotate. Explicit `null` clears the secret. Never + returned in responses. + subject_claim: + type: string + minLength: 1 + maxLength: 2048 + description: OIDC claim used as the stable subject identifier. + scopes: + type: array + minItems: 1 + maxItems: 64 + items: + type: string + minLength: 1 + maxLength: 1024 + description: | + OIDC scopes requested from the upstream IdP. Must include + `openid` when sent. Re-validated only when the set actually + changes. + status: + $ref: '#/components/schemas/UserSourceStatus'