You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(membership): member removal covers disabled projects and groups - #2049
Removing a member from an organization now also removes their access on disabled projects and groups. Stacked on #2048.
Changes
cascadeRemovePrincipal lists the organization's projects and groups with IncludeDisabled: true. The member's policies on disabled projects and groups, their policies on custom resources in disabled projects, and their member relation on disabled groups are removed with the rest.
The membership tests expect the new list filters.
Technical Details
Enabling a project or group again does not give a removed member their access back.
The deleter already lists projects and groups with IncludeDisabled: true.
User delete does not change. It already ends by removing all of the user's policies and every relation they are in, and TestUserDeleteLeavesNoAccessAndNoLivePolicy already covers a disabled project and group.
Service users do not reach this removal. The endpoint refuses them, and service user delete removes their policies and relations itself.
Test Plan
go test ./core/membership/ passes. The removal and user delete tests expect IncludeDisabled: true on both lists. Without the flag, 18 cases fail.
e2e TestOrgMemberRemovalLeavesNoAccessOnDisabledProjectsAndGroups: a member holds a role on a project, a group, and an order in that project, and the group holds viewer on a second project. The project and group are disabled, the member is removed, and both are enabled again. No live policy is left, the member has no get on any of them, and the group no longer gives access to the second project. Without the fix, all three checks fail.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Removing an organization member now also removes their access to projects and groups that were disabled at the time of removal. This prevents access from reappearing if those resources are later enabled.
Access granted through a group is also cleaned up when the member is removed, including access to disabled projects.
Organization member removal now includes disabled projects and groups when it identifies policies and relations for cleanup. Unit tests cover the updated query filters, and an end-to-end regression test checks access after disabled resources are re-enabled.
Changes: Member removal cleanup
Layer / File(s)
Summary
Removal cascade and unit coverage core/membership/org.go, core/membership/org_test.go
cascadeRemovePrincipal now includes disabled projects and groups in its listings. Unit tests expect these filters across removal and cleanup cases.
This PR makes organization member removal also clean up access on disabled projects and groups, so re-enabling them no longer restores a removed member's access. The change is small and well covered by tests. One earlier open concern remains: if cleanup fails partway during removal, the member's personal access tokens may not be revoked. Resolve or explicitly accept that before merging.
Pre-merge checks: 2
Check name
Status
Explanation
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between cad5c3c and fe9dfac.
Files selected for processing: 2
core/membership/org.go
core/membership/org_test.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
The fix looks right. Both list calls now include disabled projects and groups, and the postgres repos honor the flag. The project list also feeds the custom resource cleanup, so orders in a disabled project get cleaned up too.
I ran the new e2e test locally. It passes with the fix. With the old org.go all three sub tests fail. Unit tests and lint pass.
Two things for later, not for this PR:
Removing someone straight from a disabled project or group still fails with "not found". RemoveProjectMember, SetGroupMemberRole and RemoveGroupMember call Get, and GetByID skips disabled rows. Worth a follow up issue.
Members removed before this fix may still have live policies and group relations on disabled projects and groups. Do we want a one time cleanup, or is it fine to leave them?
Removing someone straight from a disabled project or group: agreed. SetProjectMemberRole, RemoveProjectMember, SetGroupMemberRole and RemoveGroupMember all load the project or group first, and GetByID skips disabled rows. Follow-up issue: Removing a member from a disabled project or group fails with not found #2051.
Members removed before this fix: removing them again won't clean these up, because the member check stops before the cleanup runs. Whether a one-time cleanup is needed depends on live data, which has to be checked first. We will decide after that, not now.
Reviewing files that changed from the base of the PR and between 2d93a34 and cad5c3c.
Files selected for processing: 8
core/membership/mocks/user_pat_service.go
core/membership/org.go
core/membership/org_test.go
core/membership/service.go
core/userpat/service.go
core/userpat/service_test.go
test/e2e/regression/api_test.go
test/e2e/regression/pat_test.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
cascadeRemovePrincipal now lists the org's projects and groups with IncludeDisabled, so a removed member's policies there, their custom-resource policies in disabled projects, and their group member relations are removed too.
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
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
Removing a member from an organization now also removes their access on disabled projects and groups. Stacked on #2048.
Changes
cascadeRemovePrincipallists the organization's projects and groups withIncludeDisabled: true. The member's policies on disabled projects and groups, their policies on custom resources in disabled projects, and theirmemberrelation on disabled groups are removed with the rest.Technical Details
IncludeDisabled: true.TestUserDeleteLeavesNoAccessAndNoLivePolicyalready covers a disabled project and group.Test Plan
go test ./core/membership/passes. The removal and user delete tests expectIncludeDisabled: trueon both lists. Without the flag, 18 cases fail.TestOrgMemberRemovalLeavesNoAccessOnDisabledProjectsAndGroups: a member holds a role on a project, a group, and an order in that project, and the group holds viewer on a second project. The project and group are disabled, the member is removed, and both are enabled again. No live policy is left, the member has nogeton any of them, and the group no longer gives access to the second project. Without the fix, all three checks fail.go test ./test/e2e/...passes.make testpasses.golangci-lint runreports no issues.