@@ -232,8 +232,8 @@ var (
232
232
// Provisionerd creates usage events
233
233
rbac .ResourceUsageEvent .Type : {policy .ActionCreate },
234
234
}),
235
- Org :map [ string ] []rbac.Permission {},
236
- User : [ ]rbac.Permission {},
235
+ User : []rbac.Permission {},
236
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
237
237
},
238
238
}),
239
239
Scope :rbac .ScopeAll ,
@@ -257,8 +257,8 @@ var (
257
257
rbac .ResourceWorkspace .Type : {policy .ActionDelete ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionWorkspaceStart ,policy .ActionWorkspaceStop },
258
258
rbac .ResourceWorkspaceDormant .Type : {policy .ActionDelete ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionWorkspaceStop },
259
259
}),
260
- Org :map [ string ] []rbac.Permission {},
261
- User : [ ]rbac.Permission {},
260
+ User : []rbac.Permission {},
261
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
262
262
},
263
263
}),
264
264
Scope :rbac .ScopeAll ,
@@ -279,8 +279,8 @@ var (
279
279
rbac .ResourceWorkspace .Type : {policy .ActionRead ,policy .ActionUpdate },
280
280
rbac .ResourceProvisionerJobs .Type : {policy .ActionRead ,policy .ActionUpdate },
281
281
}),
282
- Org :map [ string ] []rbac.Permission {},
283
- User : [ ]rbac.Permission {},
282
+ User : []rbac.Permission {},
283
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
284
284
},
285
285
}),
286
286
Scope :rbac .ScopeAll ,
@@ -298,8 +298,8 @@ var (
298
298
Site :rbac .Permissions (map [string ][]policy.Action {
299
299
rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
300
300
}),
301
- Org :map [ string ] []rbac.Permission {},
302
- User : [ ]rbac.Permission {},
301
+ User : []rbac.Permission {},
302
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
303
303
},
304
304
}),
305
305
Scope :rbac .ScopeAll ,
@@ -317,8 +317,8 @@ var (
317
317
Site :rbac .Permissions (map [string ][]policy.Action {
318
318
rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
319
319
}),
320
- Org :map [ string ] []rbac.Permission {},
321
- User : [ ]rbac.Permission {},
320
+ User : []rbac.Permission {},
321
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
322
322
},
323
323
}),
324
324
Scope :rbac .ScopeAll ,
@@ -335,8 +335,8 @@ var (
335
335
Site :rbac .Permissions (map [string ][]policy.Action {
336
336
rbac .ResourceConnectionLog .Type : {policy .ActionUpdate ,policy .ActionRead },
337
337
}),
338
- Org :map [ string ] []rbac.Permission {},
339
- User : [ ]rbac.Permission {},
338
+ User : []rbac.Permission {},
339
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
340
340
},
341
341
}),
342
342
Scope :rbac .ScopeAll ,
@@ -356,8 +356,8 @@ var (
356
356
rbac .ResourceWebpushSubscription .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
357
357
rbac .ResourceDeploymentConfig .Type : {policy .ActionRead ,policy .ActionUpdate },// To read and upsert VAPID keys
358
358
}),
359
- Org :map [ string ] []rbac.Permission {},
360
- User : [ ]rbac.Permission {},
359
+ User : []rbac.Permission {},
360
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
361
361
},
362
362
}),
363
363
Scope :rbac .ScopeAll ,
@@ -375,8 +375,8 @@ var (
375
375
// The workspace monitor needs to be able to update monitors
376
376
rbac .ResourceWorkspaceAgentResourceMonitor .Type : {policy .ActionUpdate },
377
377
}),
378
- Org :map [ string ] []rbac.Permission {},
379
- User : [ ]rbac.Permission {},
378
+ User : []rbac.Permission {},
379
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
380
380
},
381
381
}),
382
382
Scope :rbac .ScopeAll ,
@@ -392,12 +392,10 @@ var (
392
392
Identifier : rbac.RoleIdentifier {Name :"subagentapi" },
393
393
DisplayName :"Sub Agent API" ,
394
394
Site : []rbac.Permission {},
395
- Org :map [string ][]rbac.Permission {
396
- orgID .String (): {},
397
- },
398
395
User :rbac .Permissions (map [string ][]policy.Action {
399
396
rbac .ResourceWorkspace .Type : {policy .ActionRead ,policy .ActionUpdate ,policy .ActionCreateAgent ,policy .ActionDeleteAgent },
400
397
}),
398
+ ByOrgID :map [string ]rbac.OrgPermissions {},
401
399
},
402
400
}),
403
401
Scope :rbac .ScopeAll ,
@@ -436,8 +434,8 @@ var (
436
434
rbac .ResourceOauth2App .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
437
435
rbac .ResourceOauth2AppSecret .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
438
436
}),
439
- Org :map [ string ] []rbac.Permission {},
440
- User : [ ]rbac.Permission {},
437
+ User : []rbac.Permission {},
438
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
441
439
},
442
440
}),
443
441
Scope :rbac .ScopeAll ,
@@ -454,8 +452,8 @@ var (
454
452
Site :rbac .Permissions (map [string ][]policy.Action {
455
453
rbac .ResourceProvisionerDaemon .Type : {policy .ActionRead },
456
454
}),
457
- Org :map [ string ] []rbac.Permission {},
458
- User : [ ]rbac.Permission {},
455
+ User : []rbac.Permission {},
456
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
459
457
},
460
458
}),
461
459
Scope :rbac .ScopeAll ,
@@ -531,8 +529,8 @@ var (
531
529
Site :rbac .Permissions (map [string ][]policy.Action {
532
530
rbac .ResourceFile .Type : {policy .ActionRead },
533
531
}),
534
- Org :map [ string ] []rbac.Permission {},
535
- User : [ ]rbac.Permission {},
532
+ User : []rbac.Permission {},
533
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
536
534
},
537
535
}),
538
536
Scope :rbac .ScopeAll ,
@@ -552,8 +550,8 @@ var (
552
550
// reads/processes them.
553
551
rbac .ResourceUsageEvent .Type : {policy .ActionRead ,policy .ActionUpdate },
554
552
}),
555
- Org :map [ string ] []rbac.Permission {},
556
- User : [ ]rbac.Permission {},
553
+ User : []rbac.Permission {},
554
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
557
555
},
558
556
}),
559
557
Scope :rbac .ScopeAll ,
@@ -576,8 +574,8 @@ var (
576
574
rbac .ResourceApiKey .Type : {policy .ActionRead },// Validate API keys.
577
575
rbac .ResourceAibridgeInterception .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate },
578
576
}),
579
- Org :map [ string ] []rbac.Permission {},
580
- User : [ ]rbac.Permission {},
577
+ User : []rbac.Permission {},
578
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
581
579
},
582
580
}),
583
581
Scope :rbac .ScopeAll ,
@@ -1253,13 +1251,13 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1253
1251
return xerrors .Errorf ("invalid role: %w" ,err )
1254
1252
}
1255
1253
1256
- if len (rbacRole .Org )> 0 && len (rbacRole .Site )> 0 {
1254
+ if len (rbacRole .ByOrgID )> 0 && len (rbacRole .Site )> 0 {
1257
1255
// This is a choice to keep roles simple. If we allow mixing site and org scoped perms, then knowing who can
1258
1256
// do what gets more complicated.
1259
1257
return xerrors .Errorf ("invalid custom role, cannot assign both org and site permissions at the same time" )
1260
1258
}
1261
1259
1262
- if len (rbacRole .Org )> 1 {
1260
+ if len (rbacRole .ByOrgID )> 1 {
1263
1261
// Again to avoid more complexity in our roles
1264
1262
return xerrors .Errorf ("invalid custom role, cannot assign permissions to more than 1 org at a time" )
1265
1263
}
@@ -1272,8 +1270,8 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1272
1270
}
1273
1271
}
1274
1272
1275
- for orgID ,perms := range rbacRole .Org {
1276
- for _ ,orgPerm := range perms {
1273
+ for orgID ,perms := range rbacRole .ByOrgID {
1274
+ for _ ,orgPerm := range perms . Org {
1277
1275
err := q .customRoleEscalationCheck (ctx ,act ,orgPerm , rbac.Object {OrgID :orgID ,Type :orgPerm .ResourceType })
1278
1276
if err != nil {
1279
1277
return xerrors .Errorf ("org=%q: %w" ,orgID ,err )