-
Notifications
You must be signed in to change notification settings - Fork 38
feat(groups): Allow group membership management #2142
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
Conversation
maybe more like feature? :) |
Great description of the PR @javirln! |
@javirln let me know once you have fixed the conflicts |
c7a9e37
to
b093750
Compare
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
a21a6a2
to
5c8a978
Compare
} | ||
|
||
// Update the user membership with the role of maintainer | ||
_, err = tx.Membership.Create(). |
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.
If I'm not wrong, we agreed on not adding the OrgAdmin as maintainer. They can declare other maintainers, but they don't need to be maintainers as they are already admins (and maintainers are not mandatory)
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.
in GitHub, the creator of the group becomes a maintainer automatically, then they can leave though
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.
Yes, not a big deal at all. Let's keep it.
|
||
func newGroupDeleteCmd() *cobra.Command { | ||
var groupName string | ||
var force bool |
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.
is force used?
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.
I think it is from a previous implementation, removing it.
return cmd | ||
} | ||
|
||
func GroupListTableOutput(groupListResult *action.GroupListResult) 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.
it might not need to be exposed
} | ||
|
||
// Helper function to format time string | ||
func formatTime(timeStr string) string { |
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.
this doesn't exist already?
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.
I haven't seen it, we parse the time individually, see the example of workflow list
chainloop/app/cli/cmd/workflow_list.go
Line 128 in e461bc7
p.CreatedAt.Format(time.RFC822), |
} | ||
|
||
// Update the user membership with the role of maintainer | ||
_, err = tx.Membership.Create(). |
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.
in GitHub, the creator of the group becomes a maintainer automatically, then they can leave though
app/cli/cmd/group.go
Outdated
Hidden: true, | ||
} | ||
|
||
cmd.AddCommand(newGroupCreateCmd(), newGroupDescribeCmd(), newGroupListCmd(), newGroupDeleteCmd(), newGroupMembersCmd()) |
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.
The GroupUpdate operation is implemented in backend but not exposed in the CLI. We can do it later.
app/controlplane/pkg/biz/group.go
Outdated
return false, NewErrValidationStr("organization ID, group ID, and user ID cannot be empty") | ||
} | ||
|
||
membership, err := uc.groupRepo.FindGroupMembershipByGroupAndID(ctx, groupID, userID) |
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.
I think here we should now use the enforcer.
|
||
// If a specific policy was provided, check if the user's role allows that policy | ||
if policy != nil && s.enforcer != nil { | ||
pass, err := s.enforcer.Enforce(userRole, policy) |
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.
Here, userRole
would be the Organization role, not the "maintainer" role. The idea would be to remove the above if isMaintainer
check (or leave it as a double check), and look for the membership role of the user in the group. If found (it would be role:group:maintainer
, we use it to enforce the permission. You can just use the current helpers:
// Allow if user has admin or owner role
if userRole == string(authz.RoleAdmin) || userRole == string(authz.RoleOwner) {
return nil
}
...
return authorizeResource(ctx, policy, authz.ResourceTypeGroup, resolvedGroupID)
This way we rely entirely on roles to authorize the operation. It might look more complex, but it's way more flexible, since we can add later other roles, or remove some permissions from the current one, etc.
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.
Update: authorizeResource
cannot be used since it only works if RBAC is enabled (Member role). You'll need to iterate through user resource memberships from the context.
@javirln we are almost there. I found that the Role is not used at all, since it's still using the maintainer flag for everything. |
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.
Thanks @javirln
Thanks @javirln it works great! |
This patch introduces support for managing users within a group. Key changes include:
IdentityReference
for group-related requestsPermissions matrix:
Pending:
CLI Examples:
Creating a group
Adding members to a group
Listing members of a group
Removing members from a group
Removing groups