@@ -388,59 +388,59 @@ var (
388
388
// AsProvisionerd returns a context with an actor that has permissions required
389
389
// for provisionerd to function.
390
390
func AsProvisionerd (ctx context.Context ) context.Context {
391
- return context . WithValue (ctx , authContextKey {} ,subjectProvisionerd )
391
+ return InjectActorToContext (ctx ,subjectProvisionerd )
392
392
}
393
393
394
394
// AsAutostart returns a context with an actor that has permissions required
395
395
// for autostart to function.
396
396
func AsAutostart (ctx context.Context ) context.Context {
397
- return context . WithValue (ctx , authContextKey {} ,subjectAutostart )
397
+ return InjectActorToContext (ctx ,subjectAutostart )
398
398
}
399
399
400
400
// AsHangDetector returns a context with an actor that has permissions required
401
401
// for unhanger.Detector to function.
402
402
func AsHangDetector (ctx context.Context ) context.Context {
403
- return context . WithValue (ctx , authContextKey {} ,subjectHangDetector )
403
+ return InjectActorToContext (ctx ,subjectHangDetector )
404
404
}
405
405
406
406
// AsKeyRotator returns a context with an actor that has permissions required for rotating crypto keys.
407
407
func AsKeyRotator (ctx context.Context ) context.Context {
408
- return context . WithValue (ctx , authContextKey {} ,subjectCryptoKeyRotator )
408
+ return InjectActorToContext (ctx ,subjectCryptoKeyRotator )
409
409
}
410
410
411
411
// AsKeyReader returns a context with an actor that has permissions required for reading crypto keys.
412
412
func AsKeyReader (ctx context.Context ) context.Context {
413
- return context . WithValue (ctx , authContextKey {} ,subjectCryptoKeyReader )
413
+ return InjectActorToContext (ctx ,subjectCryptoKeyReader )
414
414
}
415
415
416
416
// AsNotifier returns a context with an actor that has permissions required for
417
417
// creating/reading/updating/deleting notifications.
418
418
func AsNotifier (ctx context.Context ) context.Context {
419
- return context . WithValue (ctx , authContextKey {} ,subjectNotifier )
419
+ return InjectActorToContext (ctx ,subjectNotifier )
420
420
}
421
421
422
422
// AsResourceMonitor returns a context with an actor that has permissions required for
423
423
// updating resource monitors.
424
424
func AsResourceMonitor (ctx context.Context ) context.Context {
425
- return context . WithValue (ctx , authContextKey {} ,subjectResourceMonitor )
425
+ return InjectActorToContext (ctx ,subjectResourceMonitor )
426
426
}
427
427
428
428
// AsSystemRestricted returns a context with an actor that has permissions
429
429
// required for various system operations (login, logout, metrics cache).
430
430
func AsSystemRestricted (ctx context.Context ) context.Context {
431
- return context . WithValue (ctx , authContextKey {} ,subjectSystemRestricted )
431
+ return InjectActorToContext (ctx ,subjectSystemRestricted )
432
432
}
433
433
434
434
// AsSystemReadProvisionerDaemons returns a context with an actor that has permissions
435
435
// to read provisioner daemons.
436
436
func AsSystemReadProvisionerDaemons (ctx context.Context ) context.Context {
437
- return context . WithValue (ctx , authContextKey {} ,subjectSystemReadProvisionerDaemons )
437
+ return InjectActorToContext (ctx ,subjectSystemReadProvisionerDaemons )
438
438
}
439
439
440
440
// AsPrebuildsOrchestrator returns a context with an actor that has permissions
441
441
// to read orchestrator workspace prebuilds.
442
442
func AsPrebuildsOrchestrator (ctx context.Context ) context.Context {
443
- return context . WithValue (ctx , authContextKey {} ,subjectPrebuildsOrchestrator )
443
+ return InjectActorToContext (ctx ,subjectPrebuildsOrchestrator )
444
444
}
445
445
446
446
var AsRemoveActor = rbac.Subject {
@@ -458,6 +458,16 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
458
458
// should be removed from the context.
459
459
return context .WithValue (ctx ,authContextKey {},nil )
460
460
}
461
+ return InjectActorToContext (ctx ,actor )
462
+ }
463
+
464
+ func InjectActorToContext (ctx context.Context ,actor rbac.Subject ) context.Context {
465
+ // if rlogger := httpmw.RequestLoggerFromContext(ctx); rlogger != nil {
466
+ // rlogger.WithFields(
467
+ // slog.F("requestor_id", actor.ID),
468
+ // slog.F("requestor_email", actor.Email),
469
+ // )
470
+ // }
461
471
return context .WithValue (ctx ,authContextKey {},actor )
462
472
}
463
473