Skip to content

Commit 8f837b7

Browse files
committed
Flip rego json to key by user id
1 parent 91a358d commit 8f837b7

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

coderd/rbac/authz_internal_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,23 @@ func TestAuthorizeDomain(t *testing.T) {
193193

194194
testAuthorize(t, "ACLList", user, []authTestCase{
195195
{
196-
resource: ResourceWorkspace.WithOwner(unuseID.String()).InOrg(unuseID).WithACLUserList(map[Action][]string{
197-
ActionRead: {user.UserID},
198-
ActionDelete: {user.UserID},
199-
ActionCreate: {user.UserID},
200-
ActionUpdate: {user.UserID},
196+
resource: ResourceWorkspace.WithOwner(unuseID.String()).InOrg(unuseID).WithACLUserList(map[string][]Action{
197+
user.UserID: allActions(),
201198
}),
202199
actions: allActions(),
203200
allow: true,
204201
},
205202
{
206-
resource: ResourceWorkspace.WithOwner(unuseID.String()).InOrg(unuseID).WithACLUserList(map[Action][]string{
207-
ActionRead: {user.UserID},
208-
ActionUpdate: {user.UserID},
203+
resource: ResourceWorkspace.WithOwner(unuseID.String()).InOrg(unuseID).WithACLUserList(map[string][]Action{
204+
user.UserID: {ActionRead, ActionUpdate},
209205
}),
210206
actions: []Action{ActionCreate, ActionDelete},
211207
allow: false,
212208
},
213209
{
214210
// By default users cannot update templates
215-
resource: ResourceTemplate.InOrg(defOrg).WithACLUserList(map[Action][]string{
216-
ActionUpdate: {user.UserID},
211+
resource: ResourceTemplate.InOrg(defOrg).WithACLUserList(map[string][]Action{
212+
user.UserID: {ActionUpdate},
217213
}),
218214
actions: []Action{ActionRead, ActionUpdate},
219215
allow: true,

coderd/rbac/object.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ type Object struct {
139139
// Type is "workspace", "project", "app", etc
140140
Type string `json:"type"`
141141

142-
// map[action][]user_id
143-
ACLUserList map[Action][]string ` json:"acl_user_list"`
142+
// map[string][]Action
143+
ACLUserList map[string][]Action ` json:"acl_user_list"`
144144
}
145145

146146
func (z Object) RBACObject() Object {
@@ -175,7 +175,7 @@ func (z Object) WithOwner(ownerID string) Object {
175175
}
176176

177177
// WithACLUserList adds an ACL list to a given object
178-
func (z Object) WithACLUserList(acl map[Action][]string) Object {
178+
func (z Object) WithACLUserList(acl map[string][]Action) Object {
179179
return Object{
180180
Owner: z.Owner,
181181
OrgID: z.OrgID,

coderd/rbac/policy.rego

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ allow {
160160
# ACL Allow
161161
allow {
162162
# Should you have to be a member of the org too?
163-
input.subject.id in input.object.acl_user_list[input.action]
163+
perms := input.object.acl_user_list[input.subject.id]
164+
input.action in perms
164165
}
165-
166-

0 commit comments

Comments
 (0)