@@ -93,9 +93,7 @@ type Options struct {
93
93
// from the dashboardURL. This should only be used in development.
94
94
AllowAllCors bool
95
95
96
- StatsCollectorOptions workspaceapps.StatsCollectorOptions
97
- WorkspaceAppsEncryptionKeycache cryptokeys.EncryptionKeycache
98
- WorkspaceAppsSigningKeycache cryptokeys.SigningKeycache
96
+ StatsCollectorOptions workspaceapps.StatsCollectorOptions
99
97
}
100
98
101
99
func (o * Options ) Validate () error {
@@ -133,6 +131,9 @@ type Server struct {
133
131
// the moon's token.
134
132
SDKClient * wsproxysdk.Client
135
133
134
+ WorkspaceAppsEncryptionKeycache cryptokeys.EncryptionKeycache
135
+ WorkspaceAppsSigningKeycache cryptokeys.SigningKeycache
136
+
136
137
// DERP
137
138
derpMesh * derpmesh.Mesh
138
139
derpMeshTLSConfig * tls.Config
@@ -199,8 +200,28 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
199
200
200
201
ctx , cancel := context .WithCancel (context .Background ())
201
202
203
+ encryptionCache , err := cryptokeys .NewEncryptionCache (ctx ,
204
+ opts .Logger ,
205
+ & ProxyFetcher {Client : client },
206
+ codersdk .CryptoKeyFeatureWorkspaceAppsAPIKey ,
207
+ )
208
+ if err != nil {
209
+ return nil , xerrors .Errorf ("create api key encryption cache: %w" , err )
210
+ }
211
+ signingCache , err := cryptokeys .NewSigningCache (ctx ,
212
+ opts .Logger ,
213
+ & ProxyFetcher {Client : client },
214
+ codersdk .CryptoKeyFeatureWorkspaceAppsToken ,
215
+ )
216
+ if err != nil {
217
+ return nil , xerrors .Errorf ("create api token signing cache: %w" , err )
218
+ }
219
+
202
220
r := chi .NewRouter ()
203
221
s := & Server {
222
+ ctx : ctx ,
223
+ cancel : cancel ,
224
+
204
225
Options : opts ,
205
226
Handler : r ,
206
227
DashboardURL : opts .DashboardURL ,
@@ -210,8 +231,6 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
210
231
SDKClient : client ,
211
232
derpMesh : derpmesh .New (opts .Logger .Named ("net.derpmesh" ), derpServer , meshTLSConfig ),
212
233
derpMeshTLSConfig : meshTLSConfig ,
213
- ctx : ctx ,
214
- cancel : cancel ,
215
234
}
216
235
217
236
// Register the workspace proxy with the primary coderd instance and start a
@@ -280,8 +299,8 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
280
299
AccessURL : opts .AccessURL ,
281
300
AppHostname : opts .AppHostname ,
282
301
Client : client ,
283
- SigningKey : opts . WorkspaceAppsSigningKeycache ,
284
- EncryptingKey : opts . WorkspaceAppsEncryptionKeycache ,
302
+ SigningKey : signingCache ,
303
+ EncryptingKey : encryptionCache ,
285
304
Logger : s .Logger .Named ("proxy_token_provider" ),
286
305
},
287
306
@@ -432,6 +451,8 @@ func (s *Server) Close() error {
432
451
err = multierror .Append (err , agentProviderErr )
433
452
}
434
453
s .SDKClient .SDKClient .HTTPClient .CloseIdleConnections ()
454
+ _ = s .WorkspaceAppsSigningKeycache .Close ()
455
+ _ = s .WorkspaceAppsEncryptionKeycache .Close ()
435
456
return err
436
457
}
437
458
0 commit comments