@@ -281,8 +281,9 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
281
281
// Note: even without PrebuiltWorkspace permissions, access is still granted via Workspace permissions.
282
282
ResourcePrebuiltWorkspace .Type : {policy .ActionUpdate ,policy .ActionDelete },
283
283
})... ),
284
- Org :map [string ][]Permission {},
285
- User : []Permission {},
284
+ Org :map [string ][]Permission {},
285
+ User : []Permission {},
286
+ OrgMember :map [string ][]Permission {},
286
287
}.withCachedRegoValue ()
287
288
288
289
memberRole := Role {
@@ -308,6 +309,7 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
308
309
ResourceProvisionerDaemon .Type : {policy .ActionRead ,policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate },
309
310
})... ,
310
311
),
312
+ OrgMember :map [string ][]Permission {},
311
313
}.withCachedRegoValue ()
312
314
313
315
auditorRole := Role {
@@ -328,8 +330,9 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
328
330
ResourceDeploymentStats .Type : {policy .ActionRead },
329
331
ResourceDeploymentConfig .Type : {policy .ActionRead },
330
332
}),
331
- Org :map [string ][]Permission {},
332
- User : []Permission {},
333
+ Org :map [string ][]Permission {},
334
+ User : []Permission {},
335
+ OrgMember :map [string ][]Permission {},
333
336
}.withCachedRegoValue ()
334
337
335
338
templateAdminRole := Role {
@@ -351,8 +354,9 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
351
354
ResourceOrganization .Type : {policy .ActionRead },
352
355
ResourceOrganizationMember .Type : {policy .ActionRead },
353
356
}),
354
- Org :map [string ][]Permission {},
355
- User : []Permission {},
357
+ Org :map [string ][]Permission {},
358
+ User : []Permission {},
359
+ OrgMember :map [string ][]Permission {},
356
360
}.withCachedRegoValue ()
357
361
358
362
userAdminRole := Role {
@@ -375,8 +379,9 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
375
379
// Manage org membership based on OIDC claims
376
380
ResourceIdpsyncSettings .Type : {policy .ActionRead ,policy .ActionUpdate },
377
381
}),
378
- Org :map [string ][]Permission {},
379
- User : []Permission {},
382
+ Org :map [string ][]Permission {},
383
+ User : []Permission {},
384
+ OrgMember :map [string ][]Permission {},
380
385
}.withCachedRegoValue ()
381
386
382
387
builtInRoles = map [string ]func (orgID uuid.UUID )Role {
@@ -427,7 +432,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
427
432
ResourcePrebuiltWorkspace .Type : {policy .ActionUpdate ,policy .ActionDelete },
428
433
})... ),
429
434
},
430
- User : []Permission {},
435
+ User : []Permission {},
436
+ OrgMember :map [string ][]Permission {},
431
437
}
432
438
},
433
439
@@ -448,7 +454,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
448
454
ResourceAssignOrgRole .Type : {policy .ActionRead },
449
455
}),
450
456
},
451
- User : []Permission {},
457
+ User : []Permission {},
458
+ OrgMember :map [string ][]Permission {},
452
459
}
453
460
},
454
461
orgAuditor :func (organizationID uuid.UUID )Role {
@@ -468,7 +475,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
468
475
ResourceOrganizationMember .Type : {policy .ActionRead },
469
476
}),
470
477
},
471
- User : []Permission {},
478
+ User : []Permission {},
479
+ OrgMember :map [string ][]Permission {},
472
480
}
473
481
},
474
482
orgUserAdmin :func (organizationID uuid.UUID )Role {
@@ -492,7 +500,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
492
500
ResourceIdpsyncSettings .Type : {policy .ActionRead ,policy .ActionUpdate },
493
501
}),
494
502
},
495
- User : []Permission {},
503
+ User : []Permission {},
504
+ OrgMember :map [string ][]Permission {},
496
505
}
497
506
},
498
507
orgTemplateAdmin :func (organizationID uuid.UUID )Role {
@@ -519,7 +528,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
519
528
ResourceProvisionerJobs .Type : {policy .ActionRead ,policy .ActionUpdate ,policy .ActionCreate },
520
529
}),
521
530
},
522
- User : []Permission {},
531
+ User : []Permission {},
532
+ OrgMember :map [string ][]Permission {},
523
533
}
524
534
},
525
535
// orgWorkspaceCreationBan prevents creating & deleting workspaces. This
@@ -554,7 +564,8 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
554
564
},
555
565
},
556
566
},
557
- User : []Permission {},
567
+ User : []Permission {},
568
+ OrgMember :map [string ][]Permission {},
558
569
}
559
570
},
560
571
}
@@ -665,9 +676,10 @@ func (perm Permission) Valid() error {
665
676
}
666
677
667
678
// Role is a set of permissions at multiple levels:
668
- // - Site level permissions apply EVERYWHERE
669
- // - Org level permissions apply to EVERYTHING in a given ORG
670
- // - User level permissions are the lowest
679
+ // - Site permissions apply EVERYWHERE
680
+ // - Org permissions apply to EVERYTHING in a given ORG
681
+ // - User permissions apply to all resources the user owns
682
+ // - OrgMember permissions apply to resources in the given org that the user owns
671
683
// This is the type passed into the rego as a json payload.
672
684
// Users of this package should instead **only** use the role names, and
673
685
// this package will expand the role names into their json payloads.
@@ -677,11 +689,13 @@ type Role struct {
677
689
// that means the UI should never display it.
678
690
DisplayName string `json:"display_name"`
679
691
Site []Permission `json:"site"`
680
- // Org is a map of orgid to permissions. We represent orgid as a string.
681
- // We scope the organizations in the role so we can easily combine all the
682
- // roles.
692
+ // Org is a map of organization IDs to permissions. Grouping by organization
693
+ // makes roles easy to combine.
683
694
Org map [string ][]Permission `json:"org"`
684
695
User []Permission `json:"user"`
696
+ // OrgMember is a map of organization IDs to permissions. Grouping by
697
+ // organization makes roles easy to combine.
698
+ OrgMember map [string ][]Permission `json:"org_member"`
685
699
686
700
// cachedRegoValue can be used to cache the rego value for this role.
687
701
// This is helpful for static roles that never change.