diff --git a/apps/coordinator/docs/openapi.yaml b/apps/coordinator/docs/openapi.yaml index 6383da27..0e1c17c2 100644 --- a/apps/coordinator/docs/openapi.yaml +++ b/apps/coordinator/docs/openapi.yaml @@ -21,6 +21,15 @@ tags: description: Query audit log events for organizations and projects. - name: Projects description: Create and manage projects within an organization. + - name: RBAC + description: | + Role-based access control. Browse the roles catalog, read the caller's + effective permissions, list org/project members, and assign, change, or + revoke org-level and project-level roles. + + These routes are gated by the per-organization `operator-authz` feature + flag. While the flag is OFF for an organization, every route below except + `GET /capabilities` is absent and returns `404`. paths: /api/v1/orgs/{organization_id}/audit_logs: @@ -390,6 +399,167 @@ paths: schema: $ref: '#/components/schemas/ErrorEnvelope' + post: + security: + - Bearer: [] + tags: + - RBAC + summary: Assign an org member to this project at a role + operationId: rbac-project-members-assign + description: | + Directly assign an existing organization member to this project at a + project-level role. Requires the `members_update` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/MemberAssignRequest' + responses: + '201': + description: Created -- the member was assigned to the project. + content: + application/json: + schema: + $ref: '#/components/schemas/MemberRowEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_update` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the org/project is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: Unprocessable Entity -- the role is not a project-level role, or `account_id` is malformed + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '503': + description: Service Unavailable -- the policy store could not be reached + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + /api/v1/orgs/{organization_id}/projects/{project_id}/members/{account_id}: + put: + security: + - Bearer: [] + tags: + - RBAC + summary: Change a project member's role + operationId: rbac-project-members-change-role + description: | + Change the project-level role of an existing project member. Requires + the `members_update` project permission. Re-assigning the role the member + already holds is an idempotent success. + + Note: organization admins inherit administration over every child project + and hold no per-project role binding, so their project role cannot be + changed through this endpoint. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + - $ref: '#/components/parameters/AccountId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/MemberRoleUpdateRequest' + responses: + '200': + description: OK -- the member's role was changed (or already matched). + content: + application/json: + schema: + $ref: '#/components/schemas/MemberRowEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_update` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the org/project/member is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: Unprocessable Entity -- the role is not a project-level role + 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}/assignable-members: + get: + security: + - Bearer: [] + tags: + - RBAC + summary: List org members assignable to this project + operationId: rbac-project-assignable-members-list + description: | + List organization members who are eligible to be assigned to this + project. Requires the `members_update` project permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/ProjectId' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AssignableAccountsResponseEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_update` on the project + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the org/project is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + /api/v1/orgs/{organization_id}/projects/{project_id}/members/{member_account_id}: delete: security: @@ -420,14 +590,297 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' - '401': - description: Unauthorized + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller cannot remove this member + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + # ── RBAC: capabilities, roles catalog, org membership & roles ───────────────── + /api/v1/orgs/{organization_id}/capabilities: + get: + security: + - Bearer: [] + tags: + - RBAC + summary: Get the caller's org-level capabilities + operationId: rbac-org-capabilities + description: | + Report the caller's effective org-level permissions plus the billing + capability block. Mounted regardless of the `operator-authz` flag: when + the flag is OFF the response carries `authz.enabled = false` with no + permissions, so a client can detect the flag state without inferring it + from a missing route. + parameters: + - $ref: '#/components/parameters/OrganizationId' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/OrgCapabilities' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller is not a member of the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- caller is not a member of the organization (flag-OFF) + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + /api/v1/orgs/{organization_id}/authz/roles: + get: + security: + - Bearer: [] + tags: + - RBAC + summary: List roles available in the organization + operationId: rbac-roles-list + description: | + Return the roles catalog for the organization -- every role key with its + display name, level, and the permission bundle it grants. Use a role key + from this catalog as the `role` field when assigning or changing a role. + parameters: + - $ref: '#/components/parameters/OrganizationId' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/RolesResponseEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller is not a member of the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF for this organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + /api/v1/orgs/{organization_id}/members: + get: + security: + - Bearer: [] + tags: + - RBAC + summary: List organization members with their org-level role + operationId: rbac-org-members-list + description: | + The organization member directory: every account in the org with its + org-level role (or none). Requires the `members_read` org permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/OrgMembersResponseEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_read` on the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the caller is not a member of the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + + post: + security: + - Bearer: [] + tags: + - RBAC + summary: Assign an org-level role + operationId: rbac-org-members-assign + description: | + Assign an org-level role (e.g. `org_admin`) to an organization member. + Requires the `members_update` org permission. + parameters: + - $ref: '#/components/parameters/OrganizationId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/MemberAssignRequest' + responses: + '201': + description: Created -- the org-level role was assigned. + content: + application/json: + schema: + $ref: '#/components/schemas/OrgMemberRowEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_update` on the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the caller is not a member of the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: Unprocessable Entity -- the role is not an org-level role, or `account_id` is malformed + 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}/members/{account_id}: + put: + security: + - Bearer: [] + tags: + - RBAC + summary: Change an org-level role + operationId: rbac-org-members-change-role + description: | + Change the org-level role of an organization member. Requires the + `members_update` org permission. Re-assigning the role the member already + holds is an idempotent success. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/AccountId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/MemberRoleUpdateRequest' + responses: + '200': + description: OK -- the member's org-level role was changed (or already matched). + content: + application/json: + schema: + $ref: '#/components/schemas/OrgMemberRowEnvelope' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_update` on the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the org/member is not visible to the caller + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '422': + description: Unprocessable Entity -- the role is not an org-level role + 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: + - RBAC + summary: Revoke an org-level role binding + operationId: rbac-org-members-remove + description: | + Revoke the caller-specified account's org-level role binding. Requires + the `members_delete` org permission. This removes the org-level role only + and does not affect legacy organization membership. + + Removal is fail-closed: if the policy store cannot be reached the binding + is left intact and the request fails with `503` rather than reporting a + removal that did not happen. + parameters: + - $ref: '#/components/parameters/OrganizationId' + - $ref: '#/components/parameters/AccountId' + responses: + '204': + description: No Content -- the org-level role binding was revoked. + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '403': + description: Forbidden -- caller lacks `members_delete` on the organization + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + '404': + description: Not Found -- the `operator-authz` flag is OFF, or the org/member is not visible to the caller content: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' - '403': - description: Forbidden -- caller cannot remove this member + '503': + description: Service Unavailable -- the policy store (OpenFGA) could not be reached content: application/json: schema: @@ -460,6 +913,15 @@ components: type: string format: uuid + AccountId: + name: account_id + in: path + required: true + description: Account ID (UUID) of the member whose role is being changed or revoked. + schema: + type: string + format: uuid + ActionFilter: name: action in: query @@ -879,3 +1341,376 @@ components: description: Total number of items. viewer: $ref: '#/components/schemas/ProjectMembersViewerResponse' + + # ── RBAC schemas ───────────────────────────────────────────────────────── + RoleLevel: + type: string + enum: + - org + - project + description: The object level a role applies to. + + ContainerRef: + type: object + required: + - type + - id + properties: + type: + $ref: '#/components/schemas/RoleLevel' + id: + type: string + description: ID of the org or project the role is held in. + name: + type: string + nullable: true + description: Display name of the container, if available. + + RoleRef: + type: object + required: + - key + - display_name + - level + - builtin + - container + properties: + key: + type: string + description: 'Opaque role key (e.g. `org_admin`, `project_admin`, `project_member`).' + display_name: + type: string + description: Human-readable role name. + level: + $ref: '#/components/schemas/RoleLevel' + builtin: + type: boolean + description: Whether this is a built-in role (not a custom org role). + container: + $ref: '#/components/schemas/ContainerRef' + + ScopedPermission: + type: object + required: + - token + - level + properties: + token: + type: string + description: | + Permission token held by the role, e.g. `members_update`, + `audit_logs_read`, `tools_execute`. The same token can exist at both + levels, so `level` disambiguates. + level: + $ref: '#/components/schemas/RoleLevel' + + RoleCatalogEntry: + type: object + required: + - key + - display_name + - level + - builtin + - editable + - invitable + - permissions + properties: + key: + type: string + description: Opaque role key. + display_name: + type: string + description: Human-readable role name. + level: + $ref: '#/components/schemas/RoleLevel' + builtin: + type: boolean + description: Whether this is a built-in role. + editable: + type: boolean + description: Whether the role's permission bundle can be edited. + invitable: + type: boolean + description: Whether members can be invited directly at this role. + permissions: + type: array + items: + $ref: '#/components/schemas/ScopedPermission' + + RolesResponse: + type: object + required: + - roles + properties: + roles: + type: array + items: + $ref: '#/components/schemas/RoleCatalogEntry' + + RolesResponseEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/RolesResponse' + + MemberActions: + type: object + required: + - can_remove + - can_change_role + properties: + can_remove: + type: boolean + description: Whether the caller can remove this member. + cannot_remove_reason: + type: string + nullable: true + description: Reason why the member cannot be removed, if any. + can_change_role: + type: boolean + description: Whether the caller can change this member's role. + + MemberRow: + type: object + required: + - account_id + - email + - role + - actions + properties: + account_id: + type: string + format: uuid + description: Account ID of the member. + email: + type: string + format: email + description: Email address of the member. + full_name: + type: string + nullable: true + description: Full name of the member. + preferred_name: + type: string + nullable: true + description: Preferred name of the member. + role: + $ref: '#/components/schemas/RoleRef' + actions: + $ref: '#/components/schemas/MemberActions' + + MemberRowEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/MemberRow' + + OrgMemberRow: + type: object + required: + - account_id + - email + properties: + account_id: + type: string + format: uuid + description: Account ID of the member. + email: + type: string + format: email + description: Email address of the member. + name: + type: string + nullable: true + description: Full name of the member. + org_role: + allOf: + - $ref: '#/components/schemas/RoleRef' + nullable: true + description: The member's org-level role, or null if they hold none. + + OrgMemberRowEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/OrgMemberRow' + + OrgMembersResponse: + type: object + required: + - items + - count + - total_count + properties: + items: + type: array + items: + $ref: '#/components/schemas/OrgMemberRow' + count: + type: integer + description: Number of members in this response. + total_count: + type: integer + description: Total number of members in the organization. + + OrgMembersResponseEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/OrgMembersResponse' + + AssignableAccount: + type: object + required: + - account_id + - email + properties: + account_id: + type: string + format: uuid + description: Account ID of the assignable member. + email: + type: string + format: email + description: Email address of the member. + name: + type: string + nullable: true + description: Full name of the member. + + AssignableAccountsResponse: + type: object + required: + - items + - count + - total_count + properties: + items: + type: array + items: + $ref: '#/components/schemas/AssignableAccount' + count: + type: integer + description: Number of members in this response. + total_count: + type: integer + description: Total number of assignable members. + + AssignableAccountsResponseEnvelope: + type: object + required: + - code + - msg + - data + properties: + code: + type: integer + example: 200 + msg: + type: string + example: Request successful + data: + $ref: '#/components/schemas/AssignableAccountsResponse' + + MemberAssignRequest: + type: object + required: + - account_id + - role + properties: + account_id: + type: string + format: uuid + description: Account ID of the org member to assign. + role: + type: string + description: | + Role key to assign. Must be a role whose catalog level matches the + endpoint (org-level key for org endpoints, project-level key for + project endpoints), else the request is rejected with 422. + + MemberRoleUpdateRequest: + type: object + required: + - role + properties: + role: + type: string + description: | + New role key. Must match the endpoint's level (org or project), else + the request is rejected with 422. + + OrgAuthzCapabilities: + type: object + required: + - enabled + - permissions + properties: + enabled: + type: boolean + description: Whether operator RBAC is enabled for this organization. + permissions: + type: array + description: Org-level permission tokens the caller holds. + items: + type: string + + BillingCapabilities: + type: object + required: + - enabled + properties: + enabled: + type: boolean + description: Whether billing capabilities are enabled for the caller. + + OrgCapabilities: + type: object + required: + - authz + - billing + properties: + authz: + $ref: '#/components/schemas/OrgAuthzCapabilities' + billing: + $ref: '#/components/schemas/BillingCapabilities'