Repository navigation
feat(work-management): implement workspace administration and RBAC (#9) - #65
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements workspace and project administration, membership management, secure invitations, and action-level Role-Based Access Control (RBAC) for EventFlow's Work Management bounded context.
This PR establishes the workspace as the primary tenant isolation and authorization boundary, integrating with the trusted
AuthenticatedPrincipalinfrastructure delivered by Issue #10.The implementation includes authenticated HTTP endpoints, tenant-aware application services, PostgreSQL persistence, transactional membership operations, concurrency protections, audit records, and comprehensive IDOR/BOLA security tests.
Changes
owner,admin,triager,approver,contributor, andviewer.Motivation
EventFlow requires secure workspace-level isolation to support multiple independent teams, projects, integrations, and members.
Although the existing authentication infrastructure verifies user identity, authentication alone does not establish which workspace resources a user may access or modify.
This PR introduces explicit workspace membership and action-level authorization, ensuring that users can access only the resources and operations permitted by their active membership.
It also establishes the authorization foundation required by future Work Management workflows and integrations.
Type of Change
Related Issues
Closes #9
Depends on:
Related:
Implementation Details
Architecture
The implementation preserves EventFlow's bounded-context architecture.
Work Management owns workspace administration, projects, membership, invitations, and authorization.
Order Processing remains independent and unchanged.
The authorization flow is:
Authorization is enforced in application services, not exclusively in HTTP route handlers.
This prevents bypasses when business operations are invoked outside the HTTP layer.
Persistence
Introduces:
workspace_membershipsworkspace_invitationsAdds Alembic migration:
0003_workspace_membership_rbacThe migration depends on:
0002_auth_sessionsPersistence includes:
Existing migrations remain unchanged.
Workspace and Project Management
Implements authenticated administration for workspaces and their projects.
Workspace creation atomically establishes the initial owner membership.
Project operations validate both workspace membership and resource ownership.
Cross-workspace identifier substitution does not grant access.
Membership and RBAC
Implements the following workspace roles:
owneradmintriagerapprovercontributorviewerPermissions are evaluated per action rather than relying solely on HTTP methods or route-level role checks.
The current workspace administration policy includes:
workspace:readworkspace:updateproject:createproject:readproject:updatemembership:readmembership:update_rolemembership:revokemembership:transfer_ownershipmembership:inviteWorkspace creation, accessible-workspace listing, and identity-bound invitation acceptance use authenticated-principal scope with additional operation-specific checks.
An administrator cannot grant, assign, or demote the owner role outside the explicit ownership policy.
Secure Invitations
Implements invitation creation, acceptance, revocation, and expiration.
Security properties include:
Invitation response semantics:
404.404.409.Transactional Consistency
Workspace and membership operations use explicit transactional units of work.
The implementation protects:
The last active owner cannot be removed or demoted through ordinary membership operations.
Concurrency Protection
PostgreSQL row-level locking and database constraints protect concurrent membership and invitation operations.
The final audit identified a race condition in invitation revocation.
Previously, revocation checked invitation state without acquiring the same row lock used by acceptance.
A concurrent acceptance could commit membership creation before revocation updated the invitation state, producing contradictory results.
The correction introduces:
InvitationRepository.get_for_update(...)Invitation revocation now follows the same locking protocol as acceptance.
The defect was reproduced with a regression test before the fix was restored and validated.
HTTP API and Contracts
Implements 16 authenticated workspace administration routes.
Extends:
contracts/openapi/work-management.yamlcontracts/schemas/work_management.yamlPreserves:
/v1/API prefix.Three operations use
x-authorization-scope: authenticatedwith additional identity or membership restrictions appropriate to their responsibilities.Security Considerations
Tenant Isolation
Workspace membership is evaluated using the trusted internal user identity.
Resource identifiers alone never establish access rights.
Workspace-scoped resources are protected against cross-tenant access.
IDOR/BOLA Protection
Security tests cover identifier substitution involving:
Unauthorized cross-workspace access is concealed with
404responses under the implemented policy.Privilege Escalation
The implementation rejects:
Membership Revocation
Revoked members immediately lose workspace authorization, even if their authentication credentials remain valid.
Owner Preservation
Transactional safeguards prevent operations from leaving a workspace without an active owner.
Auditability
Membership, invitation, and workspace administration operations integrate with the existing audit infrastructure.
Invitation secrets are not persisted in plaintext.
Testing
The final local validation used PostgreSQL 17.10 and the existing
jsr-testrunnerinfrastructure.Results
The single skipped test requires a live Keycloak environment and belongs to the Issue #10 authentication integration suite.
The previously skipped 59 PostgreSQL-dependent tests were executed successfully.
Verified Scenarios
Validation Commands
Concurrency Test Evidence
Concurrency tests used real PostgreSQL transactions and deterministic thread barriers.
Known Limitations
Keycloak Integration Test
One existing Issue #10 integration test was skipped locally because the live Keycloak authentication stack was not started.
The CI authentication job is configured to run the corresponding integration tests.
Remote CI execution remains pending.
Concurrent ETag Updates
The current API enforces stale ETag preconditions and returns
412when appropriate.However, simultaneous updates presenting the same initially valid ETag are not guaranteed to prevent every lost-update race.
This limitation is documented in the existing API architecture and is outside the currently guaranteed optimistic-concurrency contract.
It should be addressed separately if stronger atomic compare-and-update semantics become a requirement.
Backward Compatibility
Review Checklist
Commits
ec67564— feat(work-management): implement workspace administration and RBAC ([FEAT] Implementar workspaces, projetos, membros e permissões #9)350adb1— fix(work-management): harden workspace RBAC and integration guarantees ([FEAT] Implementar workspaces, projetos, membros e permissões #9)Outcome
Issue #9 establishes the workspace administration, membership, invitation, and authorization foundation required by EventFlow's Work Management domain.
All required Issue #9 PostgreSQL integration, authorization, IDOR/BOLA, and concurrency tests passed locally.
The implementation is ready for Pull Request review, subject to remote CI verification and final maintainer approval.