@@ -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,12 @@ 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 {
399
+ orgID .String (): {},
400
+ },
401
401
},
402
402
}),
403
403
Scope :rbac .ScopeAll ,
@@ -436,8 +436,8 @@ var (
436
436
rbac .ResourceOauth2App .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
437
437
rbac .ResourceOauth2AppSecret .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
438
438
}),
439
- Org :map [ string ] []rbac.Permission {},
440
- User : [ ]rbac.Permission {},
439
+ User : []rbac.Permission {},
440
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
441
441
},
442
442
}),
443
443
Scope :rbac .ScopeAll ,
@@ -454,8 +454,8 @@ var (
454
454
Site :rbac .Permissions (map [string ][]policy.Action {
455
455
rbac .ResourceProvisionerDaemon .Type : {policy .ActionRead },
456
456
}),
457
- Org :map [ string ] []rbac.Permission {},
458
- User : [ ]rbac.Permission {},
457
+ User : []rbac.Permission {},
458
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
459
459
},
460
460
}),
461
461
Scope :rbac .ScopeAll ,
@@ -531,8 +531,8 @@ var (
531
531
Site :rbac .Permissions (map [string ][]policy.Action {
532
532
rbac .ResourceFile .Type : {policy .ActionRead },
533
533
}),
534
- Org :map [ string ] []rbac.Permission {},
535
- User : [ ]rbac.Permission {},
534
+ User : []rbac.Permission {},
535
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
536
536
},
537
537
}),
538
538
Scope :rbac .ScopeAll ,
@@ -552,8 +552,8 @@ var (
552
552
// reads/processes them.
553
553
rbac .ResourceUsageEvent .Type : {policy .ActionRead ,policy .ActionUpdate },
554
554
}),
555
- Org :map [ string ] []rbac.Permission {},
556
- User : [ ]rbac.Permission {},
555
+ User : []rbac.Permission {},
556
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
557
557
},
558
558
}),
559
559
Scope :rbac .ScopeAll ,
@@ -576,8 +576,8 @@ var (
576
576
rbac .ResourceApiKey .Type : {policy .ActionRead },// Validate API keys.
577
577
rbac .ResourceAibridgeInterception .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate },
578
578
}),
579
- Org :map [ string ] []rbac.Permission {},
580
- User : [ ]rbac.Permission {},
579
+ User : []rbac.Permission {},
580
+ ByOrgID : map [ string ]rbac.OrgPermissions {},
581
581
},
582
582
}),
583
583
Scope :rbac .ScopeAll ,
@@ -1253,13 +1253,13 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1253
1253
return xerrors .Errorf ("invalid role: %w" ,err )
1254
1254
}
1255
1255
1256
- if len (rbacRole .Org )> 0 && len (rbacRole .Site )> 0 {
1256
+ if len (rbacRole .ByOrgID )> 0 && len (rbacRole .Site )> 0 {
1257
1257
// This is a choice to keep roles simple. If we allow mixing site and org scoped perms, then knowing who can
1258
1258
// do what gets more complicated.
1259
1259
return xerrors .Errorf ("invalid custom role, cannot assign both org and site permissions at the same time" )
1260
1260
}
1261
1261
1262
- if len (rbacRole .Org )> 1 {
1262
+ if len (rbacRole .ByOrgID )> 1 {
1263
1263
// Again to avoid more complexity in our roles
1264
1264
return xerrors .Errorf ("invalid custom role, cannot assign permissions to more than 1 org at a time" )
1265
1265
}
@@ -1272,8 +1272,8 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1272
1272
}
1273
1273
}
1274
1274
1275
- for orgID ,perms := range rbacRole .Org {
1276
- for _ ,orgPerm := range perms {
1275
+ for orgID ,perms := range rbacRole .ByOrgID {
1276
+ for _ ,orgPerm := range perms . Org {
1277
1277
err := q .customRoleEscalationCheck (ctx ,act ,orgPerm , rbac.Object {OrgID :orgID ,Type :orgPerm .ResourceType })
1278
1278
if err != nil {
1279
1279
return xerrors .Errorf ("org=%q: %w" ,orgID ,err )