@@ -232,8 +232,8 @@ var (
232232 // Provisionerd creates usage events
233233 rbac .ResourceUsageEvent .Type : {policy .ActionCreate },
234234 }),
235- Org : map [ string ] []rbac.Permission {},
236- User : [ ]rbac.Permission {},
235+ User : []rbac.Permission {},
236+ ByOrgID : map [ string ]rbac.OrgPermissions {},
237237 },
238238 }),
239239 Scope : rbac .ScopeAll ,
@@ -257,8 +257,8 @@ var (
257257 rbac .ResourceWorkspace .Type : {policy .ActionDelete , policy .ActionRead , policy .ActionUpdate , policy .ActionWorkspaceStart , policy .ActionWorkspaceStop },
258258 rbac .ResourceWorkspaceDormant .Type : {policy .ActionDelete , policy .ActionRead , policy .ActionUpdate , policy .ActionWorkspaceStop },
259259 }),
260- Org : map [ string ] []rbac.Permission {},
261- User : [ ]rbac.Permission {},
260+ User : []rbac.Permission {},
261+ ByOrgID : map [ string ]rbac.OrgPermissions {},
262262 },
263263 }),
264264 Scope : rbac .ScopeAll ,
@@ -280,8 +280,8 @@ var (
280280 rbac .ResourceWorkspaceDormant .Type : {policy .ActionRead , policy .ActionUpdate },
281281 rbac .ResourceProvisionerJobs .Type : {policy .ActionRead , policy .ActionUpdate },
282282 }),
283- Org : map [ string ] []rbac.Permission {},
284- User : [ ]rbac.Permission {},
283+ User : []rbac.Permission {},
284+ ByOrgID : map [ string ]rbac.OrgPermissions {},
285285 },
286286 }),
287287 Scope : rbac .ScopeAll ,
@@ -299,8 +299,8 @@ var (
299299 Site : rbac .Permissions (map [string ][]policy.Action {
300300 rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
301301 }),
302- Org : map [ string ] []rbac.Permission {},
303- User : [ ]rbac.Permission {},
302+ User : []rbac.Permission {},
303+ ByOrgID : map [ string ]rbac.OrgPermissions {},
304304 },
305305 }),
306306 Scope : rbac .ScopeAll ,
@@ -318,8 +318,8 @@ var (
318318 Site : rbac .Permissions (map [string ][]policy.Action {
319319 rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
320320 }),
321- Org : map [ string ] []rbac.Permission {},
322- User : [ ]rbac.Permission {},
321+ User : []rbac.Permission {},
322+ ByOrgID : map [ string ]rbac.OrgPermissions {},
323323 },
324324 }),
325325 Scope : rbac .ScopeAll ,
@@ -336,8 +336,8 @@ var (
336336 Site : rbac .Permissions (map [string ][]policy.Action {
337337 rbac .ResourceConnectionLog .Type : {policy .ActionUpdate , policy .ActionRead },
338338 }),
339- Org : map [ string ] []rbac.Permission {},
340- User : [ ]rbac.Permission {},
339+ User : []rbac.Permission {},
340+ ByOrgID : map [ string ]rbac.OrgPermissions {},
341341 },
342342 }),
343343 Scope : rbac .ScopeAll ,
@@ -357,8 +357,8 @@ var (
357357 rbac .ResourceWebpushSubscription .Type : {policy .ActionCreate , policy .ActionRead , policy .ActionUpdate , policy .ActionDelete },
358358 rbac .ResourceDeploymentConfig .Type : {policy .ActionRead , policy .ActionUpdate }, // To read and upsert VAPID keys
359359 }),
360- Org : map [ string ] []rbac.Permission {},
361- User : [ ]rbac.Permission {},
360+ User : []rbac.Permission {},
361+ ByOrgID : map [ string ]rbac.OrgPermissions {},
362362 },
363363 }),
364364 Scope : rbac .ScopeAll ,
@@ -376,8 +376,8 @@ var (
376376 // The workspace monitor needs to be able to update monitors
377377 rbac .ResourceWorkspaceAgentResourceMonitor .Type : {policy .ActionUpdate },
378378 }),
379- Org : map [ string ] []rbac.Permission {},
380- User : [ ]rbac.Permission {},
379+ User : []rbac.Permission {},
380+ ByOrgID : map [ string ]rbac.OrgPermissions {},
381381 },
382382 }),
383383 Scope : rbac .ScopeAll ,
@@ -393,12 +393,12 @@ var (
393393 Identifier : rbac.RoleIdentifier {Name : "subagentapi" },
394394 DisplayName : "Sub Agent API" ,
395395 Site : []rbac.Permission {},
396- Org : map [string ][]rbac.Permission {
397- orgID .String (): {},
398- },
399396 User : rbac .Permissions (map [string ][]policy.Action {
400397 rbac .ResourceWorkspace .Type : {policy .ActionRead , policy .ActionUpdate , policy .ActionCreateAgent , policy .ActionDeleteAgent },
401398 }),
399+ ByOrgID : map [string ]rbac.OrgPermissions {
400+ orgID .String (): {},
401+ },
402402 },
403403 }),
404404 Scope : rbac .ScopeAll ,
@@ -437,8 +437,8 @@ var (
437437 rbac .ResourceOauth2App .Type : {policy .ActionCreate , policy .ActionRead , policy .ActionUpdate , policy .ActionDelete },
438438 rbac .ResourceOauth2AppSecret .Type : {policy .ActionCreate , policy .ActionRead , policy .ActionUpdate , policy .ActionDelete },
439439 }),
440- Org : map [ string ] []rbac.Permission {},
441- User : [ ]rbac.Permission {},
440+ User : []rbac.Permission {},
441+ ByOrgID : map [ string ]rbac.OrgPermissions {},
442442 },
443443 }),
444444 Scope : rbac .ScopeAll ,
@@ -455,8 +455,8 @@ var (
455455 Site : rbac .Permissions (map [string ][]policy.Action {
456456 rbac .ResourceProvisionerDaemon .Type : {policy .ActionRead },
457457 }),
458- Org : map [ string ] []rbac.Permission {},
459- User : [ ]rbac.Permission {},
458+ User : []rbac.Permission {},
459+ ByOrgID : map [ string ]rbac.OrgPermissions {},
460460 },
461461 }),
462462 Scope : rbac .ScopeAll ,
@@ -532,8 +532,8 @@ var (
532532 Site : rbac .Permissions (map [string ][]policy.Action {
533533 rbac .ResourceFile .Type : {policy .ActionRead },
534534 }),
535- Org : map [ string ] []rbac.Permission {},
536- User : [ ]rbac.Permission {},
535+ User : []rbac.Permission {},
536+ ByOrgID : map [ string ]rbac.OrgPermissions {},
537537 },
538538 }),
539539 Scope : rbac .ScopeAll ,
@@ -553,8 +553,8 @@ var (
553553 // reads/processes them.
554554 rbac .ResourceUsageEvent .Type : {policy .ActionRead , policy .ActionUpdate },
555555 }),
556- Org : map [ string ] []rbac.Permission {},
557- User : [ ]rbac.Permission {},
556+ User : []rbac.Permission {},
557+ ByOrgID : map [ string ]rbac.OrgPermissions {},
558558 },
559559 }),
560560 Scope : rbac .ScopeAll ,
@@ -577,8 +577,8 @@ var (
577577 rbac .ResourceApiKey .Type : {policy .ActionRead }, // Validate API keys.
578578 rbac .ResourceAibridgeInterception .Type : {policy .ActionCreate , policy .ActionRead , policy .ActionUpdate },
579579 }),
580- Org : map [ string ] []rbac.Permission {},
581- User : [ ]rbac.Permission {},
580+ User : []rbac.Permission {},
581+ ByOrgID : map [ string ]rbac.OrgPermissions {},
582582 },
583583 }),
584584 Scope : rbac .ScopeAll ,
@@ -1254,13 +1254,13 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
12541254 return xerrors .Errorf ("invalid role: %w" , err )
12551255 }
12561256
1257- if len (rbacRole .Org ) > 0 && len (rbacRole .Site ) > 0 {
1257+ if len (rbacRole .ByOrgID ) > 0 && len (rbacRole .Site ) > 0 {
12581258 // This is a choice to keep roles simple. If we allow mixing site and org scoped perms, then knowing who can
12591259 // do what gets more complicated.
12601260 return xerrors .Errorf ("invalid custom role, cannot assign both org and site permissions at the same time" )
12611261 }
12621262
1263- if len (rbacRole .Org ) > 1 {
1263+ if len (rbacRole .ByOrgID ) > 1 {
12641264 // Again to avoid more complexity in our roles
12651265 return xerrors .Errorf ("invalid custom role, cannot assign permissions to more than 1 org at a time" )
12661266 }
@@ -1273,8 +1273,8 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
12731273 }
12741274 }
12751275
1276- for orgID , perms := range rbacRole .Org {
1277- for _ , orgPerm := range perms {
1276+ for orgID , perms := range rbacRole .ByOrgID {
1277+ for _ , orgPerm := range perms . Org {
12781278 err := q .customRoleEscalationCheck (ctx , act , orgPerm , rbac.Object {OrgID : orgID , Type : orgPerm .ResourceType })
12791279 if err != nil {
12801280 return xerrors .Errorf ("org=%q: %w" , orgID , err )
0 commit comments