@@ -162,7 +162,7 @@ var (
162
162
ID : uuid .Nil .String (),
163
163
Roles : rbac .Roles ([]rbac.Role {
164
164
{
165
- Name : rbac.RoleName {Name : "provisionerd" },
165
+ Name : rbac.RoleIdentifier {Name : "provisionerd" },
166
166
DisplayName : "Provisioner Daemon" ,
167
167
Site : rbac .Permissions (map [string ][]policy.Action {
168
168
// TODO: Add ProvisionerJob resource type.
@@ -191,7 +191,7 @@ var (
191
191
ID : uuid .Nil .String (),
192
192
Roles : rbac .Roles ([]rbac.Role {
193
193
{
194
- Name : rbac.RoleName {Name : "autostart" },
194
+ Name : rbac.RoleIdentifier {Name : "autostart" },
195
195
DisplayName : "Autostart Daemon" ,
196
196
Site : rbac .Permissions (map [string ][]policy.Action {
197
197
rbac .ResourceSystem .Type : {policy .WildcardSymbol },
@@ -213,7 +213,7 @@ var (
213
213
ID : uuid .Nil .String (),
214
214
Roles : rbac .Roles ([]rbac.Role {
215
215
{
216
- Name : rbac.RoleName {Name : "hangdetector" },
216
+ Name : rbac.RoleIdentifier {Name : "hangdetector" },
217
217
DisplayName : "Hang Detector Daemon" ,
218
218
Site : rbac .Permissions (map [string ][]policy.Action {
219
219
rbac .ResourceSystem .Type : {policy .WildcardSymbol },
@@ -232,7 +232,7 @@ var (
232
232
ID : uuid .Nil .String (),
233
233
Roles : rbac .Roles ([]rbac.Role {
234
234
{
235
- Name : rbac.RoleName {Name : "system" },
235
+ Name : rbac.RoleIdentifier {Name : "system" },
236
236
DisplayName : "Coder" ,
237
237
Site : rbac .Permissions (map [string ][]policy.Action {
238
238
rbac .ResourceWildcard .Type : {policy .ActionRead },
@@ -307,9 +307,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
307
307
// running the insertFunc. The insertFunc is expected to return the object that
308
308
// was inserted.
309
309
func insert [
310
- ObjectType any ,
311
- ArgumentType any ,
312
- Insert func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
310
+ ObjectType any ,
311
+ ArgumentType any ,
312
+ Insert func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
313
313
](
314
314
logger slog.Logger ,
315
315
authorizer rbac.Authorizer ,
@@ -320,9 +320,9 @@ func insert[
320
320
}
321
321
322
322
func insertWithAction [
323
- ObjectType any ,
324
- ArgumentType any ,
325
- Insert func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
323
+ ObjectType any ,
324
+ ArgumentType any ,
325
+ Insert func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
326
326
](
327
327
logger slog.Logger ,
328
328
authorizer rbac.Authorizer ,
@@ -349,10 +349,10 @@ func insertWithAction[
349
349
}
350
350
351
351
func deleteQ [
352
- ObjectType rbac.Objecter ,
353
- ArgumentType any ,
354
- Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
355
- Delete func (ctx context.Context , arg ArgumentType ) error ,
352
+ ObjectType rbac.Objecter ,
353
+ ArgumentType any ,
354
+ Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
355
+ Delete func (ctx context.Context , arg ArgumentType ) error ,
356
356
](
357
357
logger slog.Logger ,
358
358
authorizer rbac.Authorizer ,
@@ -364,10 +364,10 @@ func deleteQ[
364
364
}
365
365
366
366
func updateWithReturn [
367
- ObjectType rbac.Objecter ,
368
- ArgumentType any ,
369
- Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
370
- UpdateQuery func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
367
+ ObjectType rbac.Objecter ,
368
+ ArgumentType any ,
369
+ Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
370
+ UpdateQuery func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
371
371
](
372
372
logger slog.Logger ,
373
373
authorizer rbac.Authorizer ,
@@ -378,10 +378,10 @@ func updateWithReturn[
378
378
}
379
379
380
380
func update [
381
- ObjectType rbac.Objecter ,
382
- ArgumentType any ,
383
- Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
384
- Exec func (ctx context.Context , arg ArgumentType ) error ,
381
+ ObjectType rbac.Objecter ,
382
+ ArgumentType any ,
383
+ Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
384
+ Exec func (ctx context.Context , arg ArgumentType ) error ,
385
385
](
386
386
logger slog.Logger ,
387
387
authorizer rbac.Authorizer ,
@@ -399,9 +399,9 @@ func update[
399
399
// user cannot read the resource. This is because the resource details are
400
400
// required to run a proper authorization check.
401
401
func fetchWithAction [
402
- ArgumentType any ,
403
- ObjectType rbac.Objecter ,
404
- DatabaseFunc func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
402
+ ArgumentType any ,
403
+ ObjectType rbac.Objecter ,
404
+ DatabaseFunc func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
405
405
](
406
406
logger slog.Logger ,
407
407
authorizer rbac.Authorizer ,
@@ -432,9 +432,9 @@ func fetchWithAction[
432
432
}
433
433
434
434
func fetch [
435
- ArgumentType any ,
436
- ObjectType rbac.Objecter ,
437
- DatabaseFunc func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
435
+ ArgumentType any ,
436
+ ObjectType rbac.Objecter ,
437
+ DatabaseFunc func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
438
438
](
439
439
logger slog.Logger ,
440
440
authorizer rbac.Authorizer ,
@@ -447,10 +447,10 @@ func fetch[
447
447
// from SQL 'exec' functions which only return an error.
448
448
// See fetchAndQuery for more information.
449
449
func fetchAndExec [
450
- ObjectType rbac.Objecter ,
451
- ArgumentType any ,
452
- Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
453
- Exec func (ctx context.Context , arg ArgumentType ) error ,
450
+ ObjectType rbac.Objecter ,
451
+ ArgumentType any ,
452
+ Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
453
+ Exec func (ctx context.Context , arg ArgumentType ) error ,
454
454
](
455
455
logger slog.Logger ,
456
456
authorizer rbac.Authorizer ,
@@ -473,10 +473,10 @@ func fetchAndExec[
473
473
// **before** the query runs. The returns from the fetch are only used to
474
474
// assert rbac. The final return of this function comes from the Query function.
475
475
func fetchAndQuery [
476
- ObjectType rbac.Objecter ,
477
- ArgumentType any ,
478
- Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
479
- Query func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
476
+ ObjectType rbac.Objecter ,
477
+ ArgumentType any ,
478
+ Fetch func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
479
+ Query func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
480
480
](
481
481
logger slog.Logger ,
482
482
authorizer rbac.Authorizer ,
@@ -510,9 +510,9 @@ func fetchAndQuery[
510
510
// fetchWithPostFilter is like fetch, but works with lists of objects.
511
511
// SQL filters are much more optimal.
512
512
func fetchWithPostFilter [
513
- ArgumentType any ,
514
- ObjectType rbac.Objecter ,
515
- DatabaseFunc func (ctx context.Context , arg ArgumentType ) ([]ObjectType , error ),
513
+ ArgumentType any ,
514
+ ObjectType rbac.Objecter ,
515
+ DatabaseFunc func (ctx context.Context , arg ArgumentType ) ([]ObjectType , error ),
516
516
](
517
517
authorizer rbac.Authorizer ,
518
518
action policy.Action ,
@@ -584,33 +584,33 @@ func (q *querier) authorizeUpdateFileTemplate(ctx context.Context, file database
584
584
585
585
// convertToOrganizationRoles converts a set of scoped role names to their unique
586
586
// scoped names.
587
- func (q * querier ) convertToOrganizationRoles (organizationID uuid.UUID , names []string ) ([]rbac.RoleName , error ) {
588
- uniques := make ([]rbac.RoleName , 0 , len (names ))
587
+ func (q * querier ) convertToOrganizationRoles (organizationID uuid.UUID , names []string ) ([]rbac.RoleIdentifier , error ) {
588
+ uniques := make ([]rbac.RoleIdentifier , 0 , len (names ))
589
589
for _ , name := range names {
590
590
// This check is a developer safety check. Old code might try to invoke this code path with
591
591
// organization id suffixes. Catch this and return a nice error so it can be fixed.
592
592
if strings .Contains (name , ":" ) {
593
593
return nil , xerrors .Errorf ("attempt to assign a role %q, remove the ':<organization_id> suffix" , name )
594
594
}
595
595
596
- uniques = append (uniques , rbac.RoleName {Name : name , OrganizationID : organizationID })
596
+ uniques = append (uniques , rbac.RoleIdentifier {Name : name , OrganizationID : organizationID })
597
597
}
598
598
599
599
return uniques , nil
600
600
}
601
601
602
602
// convertToDeploymentRoles converts string role names into deployment wide roles.
603
- func (q * querier ) convertToDeploymentRoles (names []string ) []rbac.RoleName {
604
- uniques := make ([]rbac.RoleName , 0 , len (names ))
603
+ func (q * querier ) convertToDeploymentRoles (names []string ) []rbac.RoleIdentifier {
604
+ uniques := make ([]rbac.RoleIdentifier , 0 , len (names ))
605
605
for _ , name := range names {
606
- uniques = append (uniques , rbac.RoleName {Name : name })
606
+ uniques = append (uniques , rbac.RoleIdentifier {Name : name })
607
607
}
608
608
609
609
return uniques
610
610
}
611
611
612
612
// canAssignRoles handles assigning built in and custom roles.
613
- func (q * querier ) canAssignRoles (ctx context.Context , orgID * uuid.UUID , added , removed []rbac.RoleName ) error {
613
+ func (q * querier ) canAssignRoles (ctx context.Context , orgID * uuid.UUID , added , removed []rbac.RoleIdentifier ) error {
614
614
actor , ok := ActorFromContext (ctx )
615
615
if ! ok {
616
616
return NoActorError
@@ -624,7 +624,7 @@ func (q *querier) canAssignRoles(ctx context.Context, orgID *uuid.UUID, added, r
624
624
}
625
625
626
626
grantedRoles := append (added , removed ... )
627
- customRoles := make ([]rbac.RoleName , 0 )
627
+ customRoles := make ([]rbac.RoleIdentifier , 0 )
628
628
// Validate that the roles being assigned are valid.
629
629
for _ , r := range grantedRoles {
630
630
isOrgRole := r .OrganizationID != uuid .Nil
@@ -652,7 +652,7 @@ func (q *querier) canAssignRoles(ctx context.Context, orgID *uuid.UUID, added, r
652
652
}
653
653
}
654
654
655
- customRolesMap := make (map [rbac.RoleName ]struct {}, len (customRoles ))
655
+ customRolesMap := make (map [rbac.RoleIdentifier ]struct {}, len (customRoles ))
656
656
for _ , r := range customRoles {
657
657
customRolesMap [r ] = struct {}{}
658
658
}
@@ -2501,7 +2501,7 @@ func (q *querier) InsertOrganizationMember(ctx context.Context, arg database.Ins
2501
2501
2502
2502
// All roles are added roles. Org member is always implied.
2503
2503
addedRoles := append (orgRoles , rbac .ScopedRoleOrgMember (arg .OrganizationID ))
2504
- err = q .canAssignRoles (ctx , & arg .OrganizationID , addedRoles , []rbac.RoleName {})
2504
+ err = q .canAssignRoles (ctx , & arg .OrganizationID , addedRoles , []rbac.RoleIdentifier {})
2505
2505
if err != nil {
2506
2506
return database.OrganizationMember {}, err
2507
2507
}
@@ -2587,8 +2587,8 @@ func (q *querier) InsertTemplateVersionWorkspaceTag(ctx context.Context, arg dat
2587
2587
2588
2588
func (q * querier ) InsertUser (ctx context.Context , arg database.InsertUserParams ) (database.User , error ) {
2589
2589
// Always check if the assigned roles can actually be assigned by this actor.
2590
- impliedRoles := append ([]rbac.RoleName {rbac .RoleMember ()}, q .convertToDeploymentRoles (arg .RBACRoles )... )
2591
- err := q .canAssignRoles (ctx , nil , impliedRoles , []rbac.RoleName {})
2590
+ impliedRoles := append ([]rbac.RoleIdentifier {rbac .RoleMember ()}, q .convertToDeploymentRoles (arg .RBACRoles )... )
2591
+ err := q .canAssignRoles (ctx , nil , impliedRoles , []rbac.RoleIdentifier {})
2592
2592
if err != nil {
2593
2593
return database.User {}, err
2594
2594
}
0 commit comments