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
Sep 21, 2022
0f80beb
Add table
Sep 21, 2022
d274d62
Add search user
Sep 21, 2022
943c76b
Add user role
Sep 21, 2022
7f7f1d3
Add update and delete
Sep 21, 2022
967a1a9
Fix summary view
Sep 21, 2022
1324991
Merge branch 'resource_acl_list' of github.com:coder/coder into resou…
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
Prev Previous commit
Next Next commit
add support for private templates
  • Loading branch information
sreya committed Sep 19, 2022
commit 205c36c7718eba89ab1f45be997298b7640b2059
2 changes: 2 additions & 0 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
tpl.Icon = arg.Icon
tpl.MaxTtl = arg.MaxTtl
tpl.MinAutostartInterval = arg.MinAutostartInterval
tpl.IsPrivate = arg.IsPrivate
q.templates[idx] = tpl
return tpl, nil
}
Expand Down Expand Up @@ -1670,6 +1671,7 @@ func (q *fakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
MaxTtl: arg.MaxTtl,
MinAutostartInterval: arg.MinAutostartInterval,
CreatedBy: arg.CreatedBy,
IsPrivate: arg.IsPrivate,
}
template = template.SetUserACL(database.UserACL{})
q.templates = append(q.templates, template)
Expand Down
3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/migrations/000050_template_acl.down.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BEGIN;

ALTER TABLE templates DROP COLUMN user_acl;
ALTER TABLE templates DROP COLUMN is_private;
DROP TYPE template_role;

COMMIT;
1 change: 1 addition & 0 deletions coderd/database/migrations/000050_template_acl.up.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BEGIN;

ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}';
ALTER TABLE templates ADD COLUMN is_private boolean NOT NULL default 'false';

CREATE TYPE template_role AS ENUM (
'read',
Expand Down
10 changes: 7 additions & 3 deletions coderd/database/modelmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ func templateRoleToActions(t TemplateRole) []rbac.Action {
}

func (t Template) RBACObject() rbac.Object {
return rbac.ResourceTemplate.InOrg(t.OrganizationID).WithACLUserList(t.UserACL().Actions())
obj := rbac.ResourceTemplate
if t.IsPrivate {
obj = rbac.ResourceTemplatePrivate
}
return obj.InOrg(t.OrganizationID).WithACLUserList(t.UserACL().Actions())
}

func (t TemplateVersion) RBACObject(template Template) rbac.Object {
func (TemplateVersion) RBACObject(template Template) rbac.Object {
// Just use the parent template resource for controlling versions
return rbac.ResourceTemplate.InOrg(t.OrganizationID).WithACLUserList(template.UserACL().Actions())
return template.RBACObject()
}

func (w Workspace) RBACObject() rbac.Object {
Expand Down
1 change: 1 addition & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ INSERT INTO
max_ttl,
min_autostart_interval,
created_by,
icon
icon,
is_private
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING *;

-- name: UpdateTemplateActiveVersionByID :exec
UPDATE
Expand Down Expand Up @@ -100,7 +101,8 @@ SET
max_ttl = $4,
min_autostart_interval = $5,
name = $6,
icon = $7
icon = $7,
is_private = $8
WHERE
id = $1
RETURNING
Expand Down
13 changes: 12 additions & 1 deletion coderd/rbac/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ var (
Name: templateAdmin,
DisplayName: "Template Admin",
Site: permissions(map[string][]Action{
ResourceTemplate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceTemplate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceTemplatePrivate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
// CRUD all files, even those they did not upload.
ResourceFile.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceWorkspace.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
Expand Down Expand Up @@ -167,11 +168,21 @@ var (
ResourceType: ResourceOrganization.Type,
Action: ActionRead,
},
{
// All org members can read templates in the org
ResourceType: ResourceTemplate.Type,
Action: ActionRead,
},
{
// Can read available roles.
ResourceType: ResourceOrgRoleAssignment.Type,
Action: ActionRead,
},
{
// Can read public templates.
ResourceType: ResourceTemplate.Type,
Action: ActionRead,
},
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions coderd/rbac/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ var (
Type: "template",
}

ResourceTemplatePrivate = Object{
Type: "template_private",
}

ResourceFile = Object{
Type: "file",
}
Expand Down
16 changes: 11 additions & 5 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
MaxTtl: int64(maxTTL),
MinAutostartInterval: int64(minAutostartInterval),
CreatedBy: apiKey.UserID,
IsPrivate: createTemplate.IsPrivate,
})
if err != nil {
return xerrors.Errorf("insert template: %s", err)
Expand Down Expand Up @@ -457,10 +458,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {

// Only users who are able to create templates (aka template admins)
// are able to control user permissions.
// TODO: It might be cleaner to control template perms access
// via a separate RBAC resource, and restrict all actions to the template
// admin role.
if len(req.UserPerms) > 0 && !api.Authorize(r, rbac.ActionCreate, template) {
if (len(req.UserPerms) > 0 || req.IsPrivate != nil) &&
!api.Authorize(r, rbac.ActionCreate, template) {
httpapi.ResourceNotFound(rw)
return
}
Expand Down Expand Up @@ -525,7 +524,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
req.Icon == template.Icon &&
req.MaxTTLMillis == time.Duration(template.MaxTtl).Milliseconds() &&
req.MinAutostartIntervalMillis == time.Duration(template.MinAutostartInterval).Milliseconds() &&
len(req.UserPerms) == 0 {
len(req.UserPerms) == 0 &&
(req.IsPrivate == nil || req.IsPrivate != nil && *req.IsPrivate == template.IsPrivate) {
return nil
}

Expand All @@ -535,6 +535,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
icon := req.Icon
maxTTL := time.Duration(req.MaxTTLMillis) * time.Millisecond
minAutostartInterval := time.Duration(req.MinAutostartIntervalMillis) * time.Millisecond
isPrivate := template.IsPrivate

if name == "" {
name = template.Name
Expand All @@ -545,6 +546,9 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
if minAutostartInterval == 0 {
minAutostartInterval = time.Duration(template.MinAutostartInterval)
}
if req.IsPrivate != nil {
isPrivate = *req.IsPrivate
}

if len(req.UserPerms) > 0 {
userACL := template.UserACL()
Expand Down Expand Up @@ -572,6 +576,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
Icon: icon,
MaxTtl: int64(maxTTL),
MinAutostartInterval: int64(minAutostartInterval),
IsPrivate: isPrivate,
})
if err != nil {
return err
Expand Down Expand Up @@ -819,6 +824,7 @@ func (api *API) convertTemplate(
CreatedByID: template.CreatedBy,
CreatedByName: createdByName,
UserRoles: convertTemplateACL(template.UserACL()),
IsPrivate: template.IsPrivate,
}
}

Expand Down
Loading