@@ -448,6 +448,44 @@ func New(options *Options) *API {
448
448
if err != nil {
449
449
panic (xerrors .Errorf ("get deployment ID: %w" , err ))
450
450
}
451
+
452
+ // Start a background process that rotates keys.
453
+ err = cryptokeys .StartRotator (ctx , options .Logger .Named ("keyrotator" ), options .Database )
454
+ if err != nil {
455
+ options .Logger .Fatal (ctx , "start key rotator" , slog .Error (err ))
456
+ }
457
+
458
+ fetcher := & cryptokeys.DBFetcher {
459
+ DB : options .Database ,
460
+ }
461
+
462
+ if options .OIDCConvertKeyCache == nil {
463
+ options .OIDCConvertKeyCache , err = cryptokeys .NewSigningCache (ctx ,
464
+ options .Logger .Named ("oidc_convert_keycache" ),
465
+ fetcher ,
466
+ codersdk .CryptoKeyFeatureOIDCConvert ,
467
+ )
468
+ must (options .Logger , "start oidc convert key cache" , err )
469
+ }
470
+
471
+ if options .AppSigningKeyCache == nil {
472
+ options .AppSigningKeyCache , err = cryptokeys .NewSigningCache (ctx ,
473
+ options .Logger .Named ("app_signing_keycache" ),
474
+ fetcher ,
475
+ codersdk .CryptoKeyFeatureWorkspaceAppsToken ,
476
+ )
477
+ must (options .Logger , "start app signing key cache" , err )
478
+ }
479
+
480
+ if options .AppEncryptionKeyCache == nil {
481
+ options .AppEncryptionKeyCache , err = cryptokeys .NewEncryptionCache (ctx ,
482
+ options .Logger .Named ("app_encryption_keycache" ),
483
+ fetcher ,
484
+ codersdk .CryptoKeyFeatureWorkspaceAppsAPIKey ,
485
+ )
486
+ must (options .Logger , "start app encryption key cache" , err )
487
+ }
488
+
451
489
api := & API {
452
490
ctx : ctx ,
453
491
cancel : cancel ,
@@ -484,7 +522,7 @@ func New(options *Options) *API {
484
522
options .Database ,
485
523
options .Pubsub ,
486
524
),
487
- dbRolluper : options .DatabaseRolluper ,
525
+ dbRolluper : options .DatabaseRolluper ,
488
526
}
489
527
490
528
f := appearance .NewDefaultFetcher (api .DeploymentValues .DocsURL .String ())
@@ -613,12 +651,6 @@ func New(options *Options) *API {
613
651
api .Logger .Fatal (api .ctx , "failed to initialize tailnet client service" , slog .Error (err ))
614
652
}
615
653
616
- // Start a background process that rotates keys.
617
- err = cryptokeys .StartRotator (api .ctx , api .Logger .Named ("keyrotator" ), api .Database )
618
- if err != nil {
619
- api .Logger .Fatal (api .ctx , "start key rotator" , slog .Error (err ))
620
- }
621
-
622
654
api .statsReporter = workspacestats .NewReporter (workspacestats.ReporterOptions {
623
655
Database : options .Database ,
624
656
Logger : options .Logger .Named ("workspacestats" ),
@@ -1612,3 +1644,9 @@ func ReadExperiments(log slog.Logger, raw []string) codersdk.Experiments {
1612
1644
}
1613
1645
return exps
1614
1646
}
1647
+
1648
+ func must (logger slog.Logger , msg string , err error ) {
1649
+ if err != nil {
1650
+ logger .Fatal (context .Background (), msg , slog .Error (err ))
1651
+ }
1652
+ }
0 commit comments