Skip to content

Commit 7bcc08b

Browse files
authored
feat(rbac): allow role inheritance and additional roles (#2281)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 8eb3774 commit 7bcc08b

File tree

19 files changed

+1068
-27
lines changed

19 files changed

+1068
-27
lines changed

app/controlplane/pkg/authz/authz.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ const (
9090

9191
// RoleGroupMaintainer is a role that can manage groups in an organization.
9292
RoleGroupMaintainer Role = "role:group:maintainer"
93+
94+
// Product roles
95+
96+
RoleProductViewer Role = "role:product:viewer"
97+
RoleProductAdmin Role = "role:product:admin"
9398
)
9499

95100
// ManagedResources are the resources that are managed by Chainloop, considered during permissions sync
@@ -443,6 +448,8 @@ func (Role) Values() (roles []string) {
443448
RoleProjectAdmin,
444449
RoleProjectViewer,
445450
RoleGroupMaintainer,
451+
RoleProductAdmin,
452+
RoleProductViewer,
446453
} {
447454
roles = append(roles, string(s))
448455
}

app/controlplane/pkg/authz/membership.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727

2828
ResourceTypeOrganization ResourceType = "organization"
2929
ResourceTypeProject ResourceType = "project"
30+
ResourceTypeProduct ResourceType = "product"
3031
ResourceTypeGroup ResourceType = "group"
3132
)
3233

@@ -46,6 +47,7 @@ func (ResourceType) Values() (values []string) {
4647
string(ResourceTypeOrganization),
4748
string(ResourceTypeProject),
4849
string(ResourceTypeGroup),
50+
string(ResourceTypeProduct),
4951
)
5052

5153
return

app/controlplane/pkg/biz/membership.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Membership struct {
4040
MemberID uuid.UUID
4141
ResourceType authz.ResourceType
4242
ResourceID uuid.UUID
43+
ParentID *uuid.UUID
4344
}
4445

4546
// ListByOrgOpts are the options to filter memberships of an organization
@@ -74,7 +75,7 @@ type MembershipRepo interface {
7475
// ListGroupMembershipsByUser returns all memberships of the users inherited from groups
7576
ListGroupMembershipsByUser(ctx context.Context, userID uuid.UUID) ([]*Membership, error)
7677
ListAllByResource(ctx context.Context, rt authz.ResourceType, id uuid.UUID) ([]*Membership, error)
77-
AddResourceRole(ctx context.Context, orgID uuid.UUID, resourceType authz.ResourceType, resID uuid.UUID, mType authz.MembershipType, memberID uuid.UUID, role authz.Role) error
78+
AddResourceRole(ctx context.Context, orgID uuid.UUID, resourceType authz.ResourceType, resID uuid.UUID, mType authz.MembershipType, memberID uuid.UUID, role authz.Role, parentID *uuid.UUID) error
7879
}
7980

8081
type MembershipsRBAC interface {
@@ -409,7 +410,7 @@ func (uc *MembershipUseCase) SetProjectOwner(ctx context.Context, orgID, project
409410
}
410411
}
411412

412-
if err = uc.repo.AddResourceRole(ctx, orgID, authz.ResourceTypeProject, projectID, authz.MembershipTypeUser, userID, authz.RoleProjectAdmin); err != nil {
413+
if err = uc.repo.AddResourceRole(ctx, orgID, authz.ResourceTypeProject, projectID, authz.MembershipTypeUser, userID, authz.RoleProjectAdmin, nil); err != nil {
413414
return fmt.Errorf("failed to set project owner: %w", err)
414415
}
415416

app/controlplane/pkg/data/ent/client.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/pkg/data/ent/membership.go

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/pkg/data/ent/membership/membership.go

Lines changed: 57 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)