Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f7b279

Browse files
authored
feat: add an organization member permission level (#19953)
1 parentc3cbd97 commit4f7b279

File tree

23 files changed

+611
-304
lines changed

23 files changed

+611
-304
lines changed

‎coderd/apidoc/docs.go‎

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

‎coderd/apidoc/swagger.json‎

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

‎coderd/authorize_test.go‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,25 @@ func TestCheckPermissions(t *testing.T) {
5050
},
5151
Action:"read",
5252
},
53-
readMyself: {
53+
readOrgWorkspaces: {
5454
Object: codersdk.AuthorizationObject{
55-
ResourceType:codersdk.ResourceUser,
56-
OwnerID:"me",
55+
ResourceType:codersdk.ResourceWorkspace,
56+
OrganizationID:adminUser.OrganizationID.String(),
5757
},
5858
Action:"read",
5959
},
60-
readOwnWorkspaces: {
60+
readMyself: {
6161
Object: codersdk.AuthorizationObject{
62-
ResourceType:codersdk.ResourceWorkspace,
62+
ResourceType:codersdk.ResourceUser,
6363
OwnerID:"me",
6464
},
6565
Action:"read",
6666
},
67-
readOrgWorkspaces: {
67+
readOwnWorkspaces: {
6868
Object: codersdk.AuthorizationObject{
6969
ResourceType:codersdk.ResourceWorkspace,
7070
OrganizationID:adminUser.OrganizationID.String(),
71+
OwnerID:"me",
7172
},
7273
Action:"read",
7374
},
@@ -92,9 +93,9 @@ func TestCheckPermissions(t *testing.T) {
9293
UserID:adminUser.UserID,
9394
Check:map[string]bool{
9495
readAllUsers:true,
96+
readOrgWorkspaces:true,
9597
readMyself:true,
9698
readOwnWorkspaces:true,
97-
readOrgWorkspaces:true,
9899
updateSpecificTemplate:true,
99100
},
100101
},
@@ -104,9 +105,9 @@ func TestCheckPermissions(t *testing.T) {
104105
UserID:orgAdminUser.ID,
105106
Check:map[string]bool{
106107
readAllUsers:true,
108+
readOrgWorkspaces:true,
107109
readMyself:true,
108110
readOwnWorkspaces:true,
109-
readOrgWorkspaces:true,
110111
updateSpecificTemplate:true,
111112
},
112113
},
@@ -116,9 +117,9 @@ func TestCheckPermissions(t *testing.T) {
116117
UserID:memberUser.ID,
117118
Check:map[string]bool{
118119
readAllUsers:false,
120+
readOrgWorkspaces:false,
119121
readMyself:true,
120122
readOwnWorkspaces:true,
121-
readOrgWorkspaces:false,
122123
updateSpecificTemplate:false,
123124
},
124125
},

‎coderd/database/db2sdk/db2sdk.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,12 +714,13 @@ func RBACRole(role rbac.Role) codersdk.Role {
714714

715715
orgPerms:=role.ByOrgID[slim.OrganizationID]
716716
return codersdk.Role{
717-
Name:slim.Name,
718-
OrganizationID:slim.OrganizationID,
719-
DisplayName:slim.DisplayName,
720-
SitePermissions:List(role.Site,RBACPermission),
721-
OrganizationPermissions:List(orgPerms.Org,RBACPermission),
722-
UserPermissions:List(role.User,RBACPermission),
717+
Name:slim.Name,
718+
OrganizationID:slim.OrganizationID,
719+
DisplayName:slim.DisplayName,
720+
SitePermissions:List(role.Site,RBACPermission),
721+
UserPermissions:List(role.User,RBACPermission),
722+
OrganizationPermissions:List(orgPerms.Org,RBACPermission),
723+
OrganizationMemberPermissions:List(orgPerms.Member,RBACPermission),
723724
}
724725
}
725726

@@ -734,8 +735,8 @@ func Role(role database.CustomRole) codersdk.Role {
734735
OrganizationID:orgID,
735736
DisplayName:role.DisplayName,
736737
SitePermissions:List(role.SitePermissions,Permission),
737-
OrganizationPermissions:List(role.OrgPermissions,Permission),
738738
UserPermissions:List(role.UserPermissions,Permission),
739+
OrganizationPermissions:List(role.OrgPermissions,Permission),
739740
}
740741
}
741742

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,13 @@ var (
395395
Identifier: rbac.RoleIdentifier{Name:"subagentapi"},
396396
DisplayName:"Sub Agent API",
397397
Site: []rbac.Permission{},
398-
User:rbac.Permissions(map[string][]policy.Action{
399-
rbac.ResourceWorkspace.Type: {policy.ActionRead,policy.ActionUpdate,policy.ActionCreateAgent,policy.ActionDeleteAgent},
400-
}),
398+
User: []rbac.Permission{},
401399
ByOrgID:map[string]rbac.OrgPermissions{
402-
orgID.String(): {},
400+
orgID.String(): {
401+
Member:rbac.Permissions(map[string][]policy.Action{
402+
rbac.ResourceWorkspace.Type: {policy.ActionRead,policy.ActionUpdate,policy.ActionCreateAgent,policy.ActionDeleteAgent},
403+
}),
404+
},
403405
},
404406
},
405407
}),
@@ -1290,14 +1292,17 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
12901292
returnxerrors.Errorf("invalid role: %w",err)
12911293
}
12921294

1293-
iflen(rbacRole.ByOrgID)>0&&len(rbacRole.Site)>0 {
1294-
// This is a choice to keep roles simple. If we allow mixing site and org scoped perms, then knowing who can
1295-
// do what gets more complicated.
1296-
returnxerrors.Errorf("invalid custom role, cannot assign both org and site permissions at the same time")
1295+
iflen(rbacRole.ByOrgID)>0&& (len(rbacRole.Site)>0||len(rbacRole.User)>0) {
1296+
// This is a choice to keep roles simple. If we allow mixing site and org
1297+
// scoped perms, then knowing who can do what gets more complicated. Roles
1298+
// should either be entirely org-scoped or entirely unrelated to
1299+
// organizations.
1300+
returnxerrors.Errorf("invalid custom role, cannot assign both org-scoped and site/user permissions at the same time")
12971301
}
12981302

12991303
iflen(rbacRole.ByOrgID)>1 {
1300-
// Again to avoid more complexity in our roles
1304+
// Again to avoid more complexity in our roles. Roles are limited to one
1305+
// organization.
13011306
returnxerrors.Errorf("invalid custom role, cannot assign permissions to more than 1 org at a time")
13021307
}
13031308

@@ -1313,7 +1318,18 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
13131318
for_,orgPerm:=rangeperms.Org {
13141319
err:=q.customRoleEscalationCheck(ctx,act,orgPerm, rbac.Object{OrgID:orgID,Type:orgPerm.ResourceType})
13151320
iferr!=nil {
1316-
returnxerrors.Errorf("org=%q: %w",orgID,err)
1321+
returnxerrors.Errorf("org=%q: org: %w",orgID,err)
1322+
}
1323+
}
1324+
for_,memberPerm:=rangeperms.Member {
1325+
// The person giving the permission should still be required to have
1326+
// the permissions throughout the org in order to give individuals the
1327+
// same permission among their own resources, since the role can be given
1328+
// to anyone. The `Owner` is intentionally omitted from the `Object` to
1329+
// enforce this.
1330+
err:=q.customRoleEscalationCheck(ctx,act,memberPerm, rbac.Object{OrgID:orgID,Type:memberPerm.ResourceType})
1331+
iferr!=nil {
1332+
returnxerrors.Errorf("org=%q: member: %w",orgID,err)
13171333
}
13181334
}
13191335
}
@@ -1331,8 +1347,8 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
13311347
func (q*querier)authorizeProvisionerJob(ctx context.Context,job database.ProvisionerJob)error {
13321348
switchjob.Type {
13331349
casedatabase.ProvisionerJobTypeWorkspaceBuild:
1334-
// Authorized call to get workspace build. If we can read the build, we
1335-
//canread the job.
1350+
// Authorized call to get workspace build. If we can read the build, we can
1351+
// read the job.
13361352
_,err:=q.GetWorkspaceBuildByJobID(ctx,job.ID)
13371353
iferr!=nil {
13381354
returnxerrors.Errorf("fetch related workspace build: %w",err)
@@ -1375,8 +1391,8 @@ func (q *querier) ActivityBumpWorkspace(ctx context.Context, arg database.Activi
13751391
}
13761392

13771393
func (q*querier)AllUserIDs(ctx context.Context,includeSystembool) ([]uuid.UUID,error) {
1378-
// Although this technically only reads users, only system-related functions should be
1379-
// allowed to call this.
1394+
// Although this technically only reads users, only system-related functions
1395+
//should beallowed to call this.
13801396
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceSystem);err!=nil {
13811397
returnnil,err
13821398
}
@@ -1395,8 +1411,8 @@ func (q *querier) ArchiveUnusedTemplateVersions(ctx context.Context, arg databas
13951411
}
13961412

13971413
func (q*querier)BatchUpdateWorkspaceLastUsedAt(ctx context.Context,arg database.BatchUpdateWorkspaceLastUsedAtParams)error {
1398-
// Could be any workspace and checking auth to each workspace is overkill for the purpose
1399-
// of this function.
1414+
// Could be any workspace and checking auth to each workspace is overkill for
1415+
//the purposeof this function.
14001416
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceWorkspace.All());err!=nil {
14011417
returnerr
14021418
}

‎coderd/database/modelmethods.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (s APIKeyScopes) expandRBACScope() (rbac.Scope, error) {
208208
fororgID,perms:=rangeexpanded.ByOrgID {
209209
orgPerms:=merged.ByOrgID[orgID]
210210
orgPerms.Org=append(orgPerms.Org,perms.Org...)
211+
orgPerms.Member=append(orgPerms.Member,perms.Member...)
211212
merged.ByOrgID[orgID]=orgPerms
212213
}
213214
merged.User=append(merged.User,expanded.User...)
@@ -220,6 +221,7 @@ func (s APIKeyScopes) expandRBACScope() (rbac.Scope, error) {
220221
merged.User=rbac.DeduplicatePermissions(merged.User)
221222
fororgID,perms:=rangemerged.ByOrgID {
222223
perms.Org=rbac.DeduplicatePermissions(perms.Org)
224+
perms.Member=rbac.DeduplicatePermissions(perms.Member)
223225
merged.ByOrgID[orgID]=perms
224226
}
225227

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp