Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5a47132
feat: Add ACL list support to rego objects
Emyrk Sep 13, 2022
03f69bf
Add unit tests
Emyrk Sep 13, 2022
91a358d
Rename ACL list
Emyrk Sep 13, 2022
8f837b7
Flip rego json to key by user id
Emyrk Sep 15, 2022
8378c9b
feat: add template ACL
sreya Sep 17, 2022
54a0d13
add down migration
sreya Sep 19, 2022
72ea751
remove unused file
sreya Sep 19, 2022
d533a16
undo insert templates query change
sreya Sep 19, 2022
f56fcf9
add patch endpoint tests
sreya Sep 19, 2022
f162694
Unit test use shadowed copied value
Emyrk Sep 19, 2022
ea25c08
Allow wildcards for ACL list
Emyrk Sep 19, 2022
5a081eb
fix authorize bug
sreya Sep 19, 2022
072b3e4
feat: Allow filter to accept objects of multiple types
Emyrk Sep 19, 2022
205c36c
add support for private templates
sreya Sep 19, 2022
ba32928
go.mod
sreya Sep 19, 2022
5c6344f
Merge branch 'main' into resource_acl_list
sreya Sep 19, 2022
ef15908
fix rbac merge woes
sreya Sep 19, 2022
8ab5200
update migration
sreya Sep 19, 2022
c040e8e
fix workspaces_test
sreya Sep 19, 2022
1f4ceee
remove sqlx
sreya Sep 19, 2022
7cc71e1
fix audit
sreya Sep 19, 2022
131d5ed
fix lint
sreya Sep 19, 2022
8c3ee6a
Revert "remove sqlx"
sreya Sep 19, 2022
fe2af91
add test for list templates
sreya Sep 20, 2022
0218c4e
fix error msg
sreya Sep 20, 2022
6883106
fix sqlx woes
sreya Sep 20, 2022
4fbd9be
fix lint
sreya Sep 20, 2022
c96a6ca
fix audit
sreya Sep 20, 2022
57ba8b3
make gen
sreya Sep 20, 2022
c66d247
Merge branch 'main' into resource_acl_list
sreya Sep 20, 2022
0af367a
fix merge woes
sreya Sep 20, 2022
f6c3f51
fix test template
sreya Sep 20, 2022
6e72286
fmt
sreya Sep 20, 2022
44bcbde
Add base layout
BrunoQuaresma Sep 21, 2022
0f80beb
Add table
BrunoQuaresma Sep 21, 2022
d274d62
Add search user
BrunoQuaresma Sep 21, 2022
943c76b
Add user role
BrunoQuaresma Sep 21, 2022
7f7f1d3
Add update and delete
BrunoQuaresma Sep 21, 2022
967a1a9
Fix summary view
BrunoQuaresma Sep 21, 2022
1324991
Merge branch 'resource_acl_list' of github.com:coder/coder into resou…
BrunoQuaresma Sep 21, 2022
bd34d20
Merge branch 'resource_acl_list' of github.com:coder/coder into resou…
sreya Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Add ACL list support to rego objects
  • Loading branch information
Emyrk committed Sep 13, 2022
commit 5a47132313b5280381106bfcac249ea3f8d0e0b0
13 changes: 13 additions & 0 deletions coderd/rbac/authz_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ func TestAuthorizeDomain(t *testing.T) {
},
}

testAuthorize(t, "ACLList", user, []authTestCase{
{
resource: ResourceWorkspace.WithOwner(unuseID.String()).InOrg(unuseID).WithACL(map[Action][]string{
ActionRead: {user.UserID},
ActionDelete: {user.UserID},
ActionCreate: {user.UserID},
ActionUpdate: {user.UserID},
}),
actions: allActions(),
allow: true,
},
})

testAuthorize(t, "Member", user, []authTestCase{
// Org + me
{resource: ResourceWorkspace.InOrg(defOrg).WithOwner(user.UserID), actions: allActions(), allow: true},
Expand Down
46 changes: 23 additions & 23 deletions coderd/rbac/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ var (
return Role{
Name: owner,
DisplayName: "Owner",
Site: permissions(map[Object][]Action{
ResourceWildcard: {WildcardSymbol},
Site: permissions(map[string][]Action{
ResourceWildcard.Type: {WildcardSymbol},
}),
}
},
Expand All @@ -74,15 +74,15 @@ var (
return Role{
Name: member,
DisplayName: "",
Site: permissions(map[Object][]Action{
Site: permissions(map[string][]Action{
// All users can read all other users and know they exist.
ResourceUser: {ActionRead},
ResourceRoleAssignment: {ActionRead},
ResourceUser.Type: {ActionRead},
ResourceRoleAssignment.Type: {ActionRead},
// All users can see the provisioner daemons.
ResourceProvisionerDaemon: {ActionRead},
ResourceProvisionerDaemon.Type: {ActionRead},
}),
User: permissions(map[Object][]Action{
ResourceWildcard: {WildcardSymbol},
User: permissions(map[string][]Action{
ResourceWildcard.Type: {WildcardSymbol},
}),
}
},
Expand All @@ -94,11 +94,11 @@ var (
return Role{
Name: auditor,
DisplayName: "Auditor",
Site: permissions(map[Object][]Action{
Site: permissions(map[string][]Action{
// Should be able to read all template details, even in orgs they
// are not in.
ResourceTemplate: {ActionRead},
ResourceAuditLog: {ActionRead},
ResourceTemplate.Type: {ActionRead},
ResourceAuditLog.Type: {ActionRead},
}),
}
},
Expand All @@ -107,13 +107,13 @@ var (
return Role{
Name: templateAdmin,
DisplayName: "Template Admin",
Site: permissions(map[Object][]Action{
ResourceTemplate: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
Site: permissions(map[string][]Action{
ResourceTemplate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
// CRUD all files, even those they did not upload.
ResourceFile: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceWorkspace: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceFile.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceWorkspace.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
// CRUD to provisioner daemons for now.
ResourceProvisionerDaemon: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceProvisionerDaemon.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
}),
}
},
Expand All @@ -122,11 +122,11 @@ var (
return Role{
Name: userAdmin,
DisplayName: "User Admin",
Site: permissions(map[Object][]Action{
ResourceRoleAssignment: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceUser: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
Site: permissions(map[string][]Action{
ResourceRoleAssignment.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceUser.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
// Full perms to manage org members
ResourceOrganizationMember: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceOrganizationMember.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
}),
}
},
Expand Down Expand Up @@ -390,14 +390,14 @@ func roleSplit(role string) (name string, orgID string, err error) {

// permissions is just a helper function to make building roles that list out resources
// and actions a bit easier.
func permissions(perms map[Object][]Action) []Permission {
func permissions(perms map[string][]Action) []Permission {
list := make([]Permission, 0, len(perms))
for k, actions := range perms {
for objectType, actions := range perms {
for _, act := range actions {
act := act
list = append(list, Permission{
Negate: false,
ResourceType: k.Type,
ResourceType: objectType,
Action: act,
})
}
Expand Down
14 changes: 13 additions & 1 deletion coderd/rbac/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ type Object struct {

// Type is "workspace", "project", "app", etc
Type string `json:"type"`
// TODO: SharedUsers?

// map[action][]user_id
ACLList map[Action][]string ` json:"acl_list"`
}

func (z Object) RBACObject() Object {
Expand Down Expand Up @@ -171,3 +173,13 @@ func (z Object) WithOwner(ownerID string) Object {
Type: z.Type,
}
}

// WithACL adds an ACL list to a given object
func (z Object) WithACL(acl map[Action][]string) Object {
return Object{
Owner: z.Owner,
OrgID: z.OrgID,
Type: z.Type,
ACLList: acl,
}
}
1 change: 1 addition & 0 deletions coderd/rbac/partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func newPartialAuthorizer(ctx context.Context, subjectID string, roles []Role, a
rego.Unknowns([]string{
"input.object.owner",
"input.object.org_owner",
"input.object.acl_list",
}),
rego.Input(input),
).Partial(ctx)
Expand Down
9 changes: 8 additions & 1 deletion coderd/rbac/policy.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import future.keywords
# A great playground: https://play.openpolicyagent.org/
# Helpful cli commands to debug.
# opa eval --format=pretty 'data.authz.allow = true' -d policy.rego -i input.json
# opa eval --partial --format=pretty 'data.authz.allow = true' -d policy.rego --unknowns input.object.owner --unknowns input.object.org_owner -i input.json
# opa eval --partial --format=pretty 'data.authz.allow = true' -d policy.rego --unknowns input.object.owner --unknowns input.object.org_owner --unknowns input.object.acl_list -i input.json

#
# This policy is specifically constructed to compress to a set of queries if the
Expand Down Expand Up @@ -156,3 +156,10 @@ allow {
org_mem
user = 1
}

# ACL Allow
allow {
# Should you have to be a member of the org too?
input.subject.id in input.object.acl_list[input.action]
}