@@ -232,9 +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 {},
237
- OrgMember :map [string ][]rbac.Permission {},
235
+ User : []rbac.Permission {},
236
+ ByOrgID :map [string ]rbac.OrgPermissions {},
238
237
},
239
238
}),
240
239
Scope :rbac .ScopeAll ,
@@ -258,9 +257,8 @@ var (
258
257
rbac .ResourceWorkspace .Type : {policy .ActionDelete ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionWorkspaceStart ,policy .ActionWorkspaceStop },
259
258
rbac .ResourceWorkspaceDormant .Type : {policy .ActionDelete ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionWorkspaceStop },
260
259
}),
261
- Org :map [string ][]rbac.Permission {},
262
- User : []rbac.Permission {},
263
- OrgMember :map [string ][]rbac.Permission {},
260
+ User : []rbac.Permission {},
261
+ ByOrgID :map [string ]rbac.OrgPermissions {},
264
262
},
265
263
}),
266
264
Scope :rbac .ScopeAll ,
@@ -281,9 +279,8 @@ var (
281
279
rbac .ResourceWorkspace .Type : {policy .ActionRead ,policy .ActionUpdate },
282
280
rbac .ResourceProvisionerJobs .Type : {policy .ActionRead ,policy .ActionUpdate },
283
281
}),
284
- Org :map [string ][]rbac.Permission {},
285
- User : []rbac.Permission {},
286
- OrgMember :map [string ][]rbac.Permission {},
282
+ User : []rbac.Permission {},
283
+ ByOrgID :map [string ]rbac.OrgPermissions {},
287
284
},
288
285
}),
289
286
Scope :rbac .ScopeAll ,
@@ -301,9 +298,8 @@ var (
301
298
Site :rbac .Permissions (map [string ][]policy.Action {
302
299
rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
303
300
}),
304
- Org :map [string ][]rbac.Permission {},
305
- User : []rbac.Permission {},
306
- OrgMember :map [string ][]rbac.Permission {},
301
+ User : []rbac.Permission {},
302
+ ByOrgID :map [string ]rbac.OrgPermissions {},
307
303
},
308
304
}),
309
305
Scope :rbac .ScopeAll ,
@@ -321,9 +317,8 @@ var (
321
317
Site :rbac .Permissions (map [string ][]policy.Action {
322
318
rbac .ResourceCryptoKey .Type : {policy .WildcardSymbol },
323
319
}),
324
- Org :map [string ][]rbac.Permission {},
325
- User : []rbac.Permission {},
326
- OrgMember :map [string ][]rbac.Permission {},
320
+ User : []rbac.Permission {},
321
+ ByOrgID :map [string ]rbac.OrgPermissions {},
327
322
},
328
323
}),
329
324
Scope :rbac .ScopeAll ,
@@ -340,9 +335,8 @@ var (
340
335
Site :rbac .Permissions (map [string ][]policy.Action {
341
336
rbac .ResourceConnectionLog .Type : {policy .ActionUpdate ,policy .ActionRead },
342
337
}),
343
- Org :map [string ][]rbac.Permission {},
344
- User : []rbac.Permission {},
345
- OrgMember :map [string ][]rbac.Permission {},
338
+ User : []rbac.Permission {},
339
+ ByOrgID :map [string ]rbac.OrgPermissions {},
346
340
},
347
341
}),
348
342
Scope :rbac .ScopeAll ,
@@ -362,9 +356,8 @@ var (
362
356
rbac .ResourceWebpushSubscription .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
363
357
rbac .ResourceDeploymentConfig .Type : {policy .ActionRead ,policy .ActionUpdate },// To read and upsert VAPID keys
364
358
}),
365
- Org :map [string ][]rbac.Permission {},
366
- User : []rbac.Permission {},
367
- OrgMember :map [string ][]rbac.Permission {},
359
+ User : []rbac.Permission {},
360
+ ByOrgID :map [string ]rbac.OrgPermissions {},
368
361
},
369
362
}),
370
363
Scope :rbac .ScopeAll ,
@@ -382,9 +375,8 @@ var (
382
375
// The workspace monitor needs to be able to update monitors
383
376
rbac .ResourceWorkspaceAgentResourceMonitor .Type : {policy .ActionUpdate },
384
377
}),
385
- Org :map [string ][]rbac.Permission {},
386
- User : []rbac.Permission {},
387
- OrgMember :map [string ][]rbac.Permission {},
378
+ User : []rbac.Permission {},
379
+ ByOrgID :map [string ]rbac.OrgPermissions {},
388
380
},
389
381
}),
390
382
Scope :rbac .ScopeAll ,
@@ -400,13 +392,12 @@ var (
400
392
Identifier : rbac.RoleIdentifier {Name :"subagentapi" },
401
393
DisplayName :"Sub Agent API" ,
402
394
Site : []rbac.Permission {},
403
- Org :map [string ][]rbac.Permission {
404
- orgID .String (): {},
405
- },
406
395
User :rbac .Permissions (map [string ][]policy.Action {
407
396
rbac .ResourceWorkspace .Type : {policy .ActionRead ,policy .ActionUpdate ,policy .ActionCreateAgent ,policy .ActionDeleteAgent },
408
397
}),
409
- OrgMember :map [string ][]rbac.Permission {},
398
+ ByOrgID :map [string ]rbac.OrgPermissions {
399
+ orgID .String (): {},
400
+ },
410
401
},
411
402
}),
412
403
Scope :rbac .ScopeAll ,
@@ -445,9 +436,8 @@ var (
445
436
rbac .ResourceOauth2App .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
446
437
rbac .ResourceOauth2AppSecret .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
447
438
}),
448
- Org :map [string ][]rbac.Permission {},
449
- User : []rbac.Permission {},
450
- OrgMember :map [string ][]rbac.Permission {},
439
+ User : []rbac.Permission {},
440
+ ByOrgID :map [string ]rbac.OrgPermissions {},
451
441
},
452
442
}),
453
443
Scope :rbac .ScopeAll ,
@@ -464,9 +454,8 @@ var (
464
454
Site :rbac .Permissions (map [string ][]policy.Action {
465
455
rbac .ResourceProvisionerDaemon .Type : {policy .ActionRead },
466
456
}),
467
- Org :map [string ][]rbac.Permission {},
468
- User : []rbac.Permission {},
469
- OrgMember :map [string ][]rbac.Permission {},
457
+ User : []rbac.Permission {},
458
+ ByOrgID :map [string ]rbac.OrgPermissions {},
470
459
},
471
460
}),
472
461
Scope :rbac .ScopeAll ,
@@ -542,9 +531,8 @@ var (
542
531
Site :rbac .Permissions (map [string ][]policy.Action {
543
532
rbac .ResourceFile .Type : {policy .ActionRead },
544
533
}),
545
- Org :map [string ][]rbac.Permission {},
546
- User : []rbac.Permission {},
547
- OrgMember :map [string ][]rbac.Permission {},
534
+ User : []rbac.Permission {},
535
+ ByOrgID :map [string ]rbac.OrgPermissions {},
548
536
},
549
537
}),
550
538
Scope :rbac .ScopeAll ,
@@ -564,9 +552,8 @@ var (
564
552
// reads/processes them.
565
553
rbac .ResourceUsageEvent .Type : {policy .ActionRead ,policy .ActionUpdate },
566
554
}),
567
- Org :map [string ][]rbac.Permission {},
568
- User : []rbac.Permission {},
569
- OrgMember :map [string ][]rbac.Permission {},
555
+ User : []rbac.Permission {},
556
+ ByOrgID :map [string ]rbac.OrgPermissions {},
570
557
},
571
558
}),
572
559
Scope :rbac .ScopeAll ,
@@ -589,9 +576,8 @@ var (
589
576
rbac .ResourceApiKey .Type : {policy .ActionRead },// Validate API keys.
590
577
rbac .ResourceAibridgeInterception .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate },
591
578
}),
592
- Org :map [string ][]rbac.Permission {},
593
- User : []rbac.Permission {},
594
- OrgMember :map [string ][]rbac.Permission {},
579
+ User : []rbac.Permission {},
580
+ ByOrgID :map [string ]rbac.OrgPermissions {},
595
581
},
596
582
}),
597
583
Scope :rbac .ScopeAll ,
@@ -1267,13 +1253,13 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1267
1253
return xerrors .Errorf ("invalid role: %w" ,err )
1268
1254
}
1269
1255
1270
- if len (rbacRole .Org )> 0 && len (rbacRole .Site )> 0 {
1256
+ if len (rbacRole .ByOrgID )> 0 && len (rbacRole .Site )> 0 {
1271
1257
// This is a choice to keep roles simple. If we allow mixing site and org scoped perms, then knowing who can
1272
1258
// do what gets more complicated.
1273
1259
return xerrors .Errorf ("invalid custom role, cannot assign both org and site permissions at the same time" )
1274
1260
}
1275
1261
1276
- if len (rbacRole .Org )> 1 {
1262
+ if len (rbacRole .ByOrgID )> 1 {
1277
1263
// Again to avoid more complexity in our roles
1278
1264
return xerrors .Errorf ("invalid custom role, cannot assign permissions to more than 1 org at a time" )
1279
1265
}
@@ -1286,8 +1272,8 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
1286
1272
}
1287
1273
}
1288
1274
1289
- for orgID ,perms := range rbacRole .Org {
1290
- for _ ,orgPerm := range perms {
1275
+ for orgID ,perms := range rbacRole .ByOrgID {
1276
+ for _ ,orgPerm := range perms . Org {
1291
1277
err := q .customRoleEscalationCheck (ctx ,act ,orgPerm , rbac.Object {OrgID :orgID ,Type :orgPerm .ResourceType })
1292
1278
if err != nil {
1293
1279
return xerrors .Errorf ("org=%q: %w" ,orgID ,err )