Repository navigation
fix(membership): revoke a removed member's PATs in the org #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,12 +205,19 @@ func (s *Service) SetPATAllProjectsRole(ctx context.Context, orgID, patID, roleI | |
| // relations. Returns ErrNotMember if the principal has no policies on this org, | ||
| // and ErrLastOwnerRole when removing the org's last owner. | ||
| func (s *Service) RemoveOrganizationMember(ctx context.Context, orgID, principalID, principalType string) error { | ||
| return s.removeOrganizationMember(ctx, orgID, principalID, principalType, false) | ||
| removeErr := s.removeOrganizationMember(ctx, orgID, principalID, principalType, false) | ||
| if removeErr != nil && !errors.Is(removeErr, ErrNotMember) { | ||
| return removeErr | ||
| } | ||
| if patErr := s.revokeMemberPATs(ctx, orgID, principalID, principalType); patErr != nil { | ||
| return patErr | ||
| } | ||
| return removeErr | ||
| } | ||
|
|
||
| // RemoveOrganizationMemberOnDelete is RemoveOrganizationMember for deleting a | ||
| // user. It also works on a disabled org, because the user has to leave every | ||
| // org before the account can go. | ||
| // org before the account can go. It leaves PATs to the user delete. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small one: this adds a new sentence to a code comment. We are trying not to add new code comments. Could the "leaves PATs to the user delete" note move to the PR description instead?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping this line. The code here can't show it: user delete revokes all of the user's PATs itself, in |
||
| func (s *Service) RemoveOrganizationMemberOnDelete(ctx context.Context, orgID, principalID, principalType string) error { | ||
| return s.removeOrganizationMember(ctx, orgID, principalID, principalType, true) | ||
| } | ||
|
|
@@ -392,6 +399,23 @@ func (s *Service) removeCustomResourceAccess(ctx context.Context, principalID, p | |
| return nil | ||
| } | ||
|
|
||
| func (s *Service) revokeMemberPATs(ctx context.Context, orgID, principalID, principalType string) error { | ||
| if principalType != schema.UserPrincipal { | ||
| return nil | ||
| } | ||
| if s.userPATService == nil { | ||
| s.log.ErrorContext(ctx, "user PAT service not set: PATs left behind", | ||
| "org_id", orgID, | ||
| "principal_id", principalID, | ||
| ) | ||
| return nil | ||
| } | ||
| if err := s.userPATService.OnOrgMemberRemoved(ctx, orgID, principalID); err != nil { | ||
| return fmt.Errorf("revoke member PATs: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // validateMinOwnerConstraint ensures the org always has at least one owner after a role change. | ||
| // Returns the resolved owner role ID for reuse by callers. | ||
| func (s *Service) validateMinOwnerConstraint(ctx context.Context, orgID, newRoleID string, existing []policy.Policy) (string, error) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: raystack/frontier
Length of output: 19075
Script executed:
Repository: raystack/frontier
Length of output: 32815
Script executed:
Repository: raystack/frontier
Length of output: 26172
Script executed:
Repository: raystack/frontier
Length of output: 795
Allow retries to finish PAT policy cleanup.
If policy cleanup fails after
revokePATsoft-deletes a PAT, the next member-removal attempt skips that PAT becauseUserPATRepository.Listexcludes deleted rows. Its policies can remain until a separate cleanup occurs.Make pending cleanup reachable on retry without changing normal PAT listings.