@@ -131,8 +131,12 @@ type Server struct {
131
131
// the moon's token.
132
132
SDKClient * wsproxysdk.Client
133
133
134
- WorkspaceAppsEncryptionKeycache cryptokeys.EncryptionKeycache
135
- WorkspaceAppsSigningKeycache cryptokeys.SigningKeycache
134
+ // apiKeyEncryptionKeycache manages the encryption keys for smuggling API
135
+ // tokens to the alternate domain when using workspace apps.
136
+ apiKeyEncryptionKeycache cryptokeys.EncryptionKeycache
137
+ // appTokenSigningKeycache manages the signing keys for signing the app
138
+ // tokens we use for workspace apps.
139
+ appTokenSigningKeycache cryptokeys.SigningKeycache
136
140
137
141
// DERP
138
142
derpMesh * derpmesh.Mesh
@@ -206,6 +210,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
206
210
codersdk .CryptoKeyFeatureWorkspaceAppsAPIKey ,
207
211
)
208
212
if err != nil {
213
+ cancel ()
209
214
return nil , xerrors .Errorf ("create api key encryption cache: %w" , err )
210
215
}
211
216
signingCache , err := cryptokeys .NewSigningCache (ctx ,
@@ -214,6 +219,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
214
219
codersdk .CryptoKeyFeatureWorkspaceAppsToken ,
215
220
)
216
221
if err != nil {
222
+ cancel ()
217
223
return nil , xerrors .Errorf ("create api token signing cache: %w" , err )
218
224
}
219
225
@@ -222,15 +228,17 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
222
228
ctx : ctx ,
223
229
cancel : cancel ,
224
230
225
- Options : opts ,
226
- Handler : r ,
227
- DashboardURL : opts .DashboardURL ,
228
- Logger : opts .Logger .Named ("net.workspace-proxy" ),
229
- TracerProvider : opts .Tracing ,
230
- PrometheusRegistry : opts .PrometheusRegistry ,
231
- SDKClient : client ,
232
- derpMesh : derpmesh .New (opts .Logger .Named ("net.derpmesh" ), derpServer , meshTLSConfig ),
233
- derpMeshTLSConfig : meshTLSConfig ,
231
+ Options : opts ,
232
+ Handler : r ,
233
+ DashboardURL : opts .DashboardURL ,
234
+ Logger : opts .Logger .Named ("net.workspace-proxy" ),
235
+ TracerProvider : opts .Tracing ,
236
+ PrometheusRegistry : opts .PrometheusRegistry ,
237
+ SDKClient : client ,
238
+ derpMesh : derpmesh .New (opts .Logger .Named ("net.derpmesh" ), derpServer , meshTLSConfig ),
239
+ derpMeshTLSConfig : meshTLSConfig ,
240
+ apiKeyEncryptionKeycache : encryptionCache ,
241
+ appTokenSigningKeycache : signingCache ,
234
242
}
235
243
236
244
// Register the workspace proxy with the primary coderd instance and start a
@@ -295,20 +303,21 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
295
303
HostnameRegex : opts .AppHostnameRegex ,
296
304
RealIPConfig : opts .RealIPConfig ,
297
305
SignedTokenProvider : & TokenProvider {
298
- DashboardURL : opts .DashboardURL ,
299
- AccessURL : opts .AccessURL ,
300
- AppHostname : opts .AppHostname ,
301
- Client : client ,
302
- SigningKey : signingCache ,
303
- EncryptingKey : encryptionCache ,
304
- Logger : s .Logger .Named ("proxy_token_provider" ),
306
+ DashboardURL : opts .DashboardURL ,
307
+ AccessURL : opts .AccessURL ,
308
+ AppHostname : opts .AppHostname ,
309
+ Client : client ,
310
+ TokenSigningKey : signingCache ,
311
+ APIKeyEncryptionKey : encryptionCache ,
312
+ Logger : s .Logger .Named ("proxy_token_provider" ),
305
313
},
306
314
307
315
DisablePathApps : opts .DisablePathApps ,
308
316
SecureAuthCookie : opts .SecureAuthCookie ,
309
317
310
- AgentProvider : agentProvider ,
311
- StatsCollector : workspaceapps .NewStatsCollector (opts .StatsCollectorOptions ),
318
+ AgentProvider : agentProvider ,
319
+ StatsCollector : workspaceapps .NewStatsCollector (opts .StatsCollectorOptions ),
320
+ APIKeyEncryptionKey : encryptionCache ,
312
321
}
313
322
314
323
derpHandler := derphttp .Handler (derpServer )
@@ -451,8 +460,8 @@ func (s *Server) Close() error {
451
460
err = multierror .Append (err , agentProviderErr )
452
461
}
453
462
s .SDKClient .SDKClient .HTTPClient .CloseIdleConnections ()
454
- _ = s .WorkspaceAppsSigningKeycache .Close ()
455
- _ = s .WorkspaceAppsEncryptionKeycache .Close ()
463
+ _ = s .appTokenSigningKeycache .Close ()
464
+ _ = s .apiKeyEncryptionKeycache .Close ()
456
465
return err
457
466
}
458
467
0 commit comments