@@ -301,6 +301,7 @@ func (s *Server) HandleConn(c net.Conn) {
301
301
log .WithField ("workspaceId" , workspaceId ).WithError (err ).Error ("failed to get workspace info" )
302
302
return
303
303
}
304
+ log := log .WithField ("instanceId" , wsInfo .InstanceID ).WithField ("isMk2" , wsInfo .IsManagedByMk2 )
304
305
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
305
306
supervisorPort := "22999"
306
307
if debugWorkspace {
@@ -318,37 +319,40 @@ func (s *Server) HandleConn(c net.Conn) {
318
319
OwnerUserId : wsInfo .OwnerUserId ,
319
320
}
320
321
321
- if wsInfo .SSHKey != nil {
322
- key , err = ssh .ParsePrivateKey ([]byte (wsInfo .SSHKey .Private ))
323
- if err != nil {
322
+ if ! wsInfo .IsManagedByMk2 {
323
+ if s .caKey == nil || ! wsInfo .IsEnabledSSHCA {
324
+ err = xerrors .Errorf ("workspace not managed by mk2, but didn't have SSH CA enabled" )
325
+ s .TrackSSHConnection (wsInfo , "connect" , ErrCreateSSHKey )
326
+ ReportSSHAttemptMetrics (ErrCreateSSHKey )
327
+ log .WithError (err ).Error ("failed to generate ssh cert" )
324
328
cancel ()
325
329
return
326
330
}
327
-
328
- session .WorkspacePrivateKey = key
329
-
330
331
// obtain the SSH username from workspacekit.
331
332
workspacekitPort := "22998"
332
333
userName , err = workspaceSSHUsername (ctx , wsInfo .IPAddress , workspacekitPort )
333
334
if err != nil {
334
- log .WithField ( "instanceId" , wsInfo . InstanceID ). WithError (err ).Warn ("failed to retrieve the SSH username. Using the default." )
335
+ log .WithError (err ).Warn ("failed to retrieve the SSH username. Using the default." )
335
336
}
336
- } else if s .caKey != nil && wsInfo .IsEnabledSSHCA {
337
+ }
338
+
339
+ if s .caKey != nil && wsInfo .IsEnabledSSHCA {
337
340
key , err = s .GenerateSSHCert (ctx , userName )
338
341
if err != nil {
339
- log .WithField ("workspaceId" , workspaceId ).WithError (err ).Error ("failed to generate ssh cert" )
342
+ s .TrackSSHConnection (wsInfo , "connect" , ErrCreateSSHKey )
343
+ ReportSSHAttemptMetrics (ErrCreateSSHKey )
344
+ log .WithError (err ).Error ("failed to generate ssh cert" )
340
345
cancel ()
341
346
return
342
347
}
343
-
344
348
session .WorkspacePrivateKey = key
345
349
} else {
346
350
key , userName , err = s .GetWorkspaceSSHKey (ctx , wsInfo .IPAddress , supervisorPort )
347
351
if err != nil {
348
352
cancel ()
349
353
s .TrackSSHConnection (wsInfo , "connect" , ErrCreateSSHKey )
350
354
ReportSSHAttemptMetrics (ErrCreateSSHKey )
351
- log .WithField ( "instanceId" , wsInfo . InstanceID ). WithError (err ).Error ("failed to create private pair in workspace" )
355
+ log .WithError (err ).Error ("failed to create private pair in workspace" )
352
356
return
353
357
}
354
358
@@ -366,7 +370,7 @@ func (s *Server) HandleConn(c net.Conn) {
366
370
if err != nil {
367
371
s .TrackSSHConnection (wsInfo , "connect" , ErrConnFailed )
368
372
ReportSSHAttemptMetrics (ErrConnFailed )
369
- log .WithField ("instanceId" , wsInfo . InstanceID ). WithField ( " workspaceIP" , wsInfo .IPAddress ).WithError (err ).Error ("dail failed" )
373
+ log .WithField ("workspaceIP" , wsInfo .IPAddress ).WithError (err ).Error ("dial failed" )
370
374
return
371
375
}
372
376
defer conn .Close ()
@@ -384,7 +388,7 @@ func (s *Server) HandleConn(c net.Conn) {
384
388
if err != nil {
385
389
s .TrackSSHConnection (wsInfo , "connect" , ErrConnFailed )
386
390
ReportSSHAttemptMetrics (ErrConnFailed )
387
- log .WithField ("instanceId" , wsInfo . InstanceID ). WithField ( " workspaceIP" , wsInfo .IPAddress ).WithError (err ).Error ("connect failed" )
391
+ log .WithField ("workspaceIP" , wsInfo .IPAddress ).WithError (err ).Error ("connect failed" )
388
392
return
389
393
}
390
394
s .Heartbeater .SendHeartbeat (wsInfo .InstanceID , false , true )
0 commit comments