()
| 349 | } |
| 350 | |
| 351 | func (a *agent) init() { |
| 352 | // pass the "hard" context because we explicitly close the SSH server as part of graceful shutdown. |
| 353 | sshSrv, err := agentssh.NewServer(a.hardCtx, a.logger.Named("ssh-server"), a.prometheusRegistry, a.filesystem, a.execer, &agentssh.Config{ |
| 354 | MaxTimeout: a.sshMaxTimeout, |
| 355 | MOTDFile: func() string { return a.manifest.Load().MOTDFile }, |
| 356 | AnnouncementBanners: func() *[]codersdk.BannerConfig { return a.announcementBanners.Load() }, |
| 357 | UpdateEnv: a.updateCommandEnv, |
| 358 | WorkingDirectory: func() string { return a.manifest.Load().Directory }, |
| 359 | BlockFileTransfer: a.blockFileTransfer, |
| 360 | BlockReversePortForwarding: a.blockReversePortForwarding, |
| 361 | BlockLocalPortForwarding: a.blockLocalPortForwarding, |
| 362 | ReportConnection: func(id uuid.UUID, magicType agentssh.MagicSessionType, ip string) func(code int, reason string) { |
| 363 | var connectionType proto.Connection_Type |
| 364 | switch magicType { |
| 365 | case agentssh.MagicSessionTypeSSH: |
| 366 | connectionType = proto.Connection_SSH |
| 367 | case agentssh.MagicSessionTypeVSCode: |
| 368 | connectionType = proto.Connection_VSCODE |
| 369 | case agentssh.MagicSessionTypeJetBrains: |
| 370 | connectionType = proto.Connection_JETBRAINS |
| 371 | case agentssh.MagicSessionTypeUnknown: |
| 372 | connectionType = proto.Connection_TYPE_UNSPECIFIED |
| 373 | default: |
| 374 | a.logger.Error(a.hardCtx, "unhandled magic session type when reporting connection", slog.F("magic_type", magicType)) |
| 375 | connectionType = proto.Connection_TYPE_UNSPECIFIED |
| 376 | } |
| 377 | |
| 378 | return a.reportConnection(id, connectionType, ip) |
| 379 | }, |
| 380 | |
| 381 | ExperimentalContainers: a.devcontainers, |
| 382 | }) |
| 383 | if err != nil { |
| 384 | panic(err) |
| 385 | } |
| 386 | a.sshServer = sshSrv |
| 387 | a.scriptRunner = agentscripts.New(agentscripts.Options{ |
| 388 | LogDir: a.logDir, |
| 389 | DataDirBase: a.scriptDataDir, |
| 390 | Logger: a.logger, |
| 391 | SSHServer: sshSrv, |
| 392 | Filesystem: a.filesystem, |
| 393 | GetScriptLogger: func(logSourceID uuid.UUID) agentscripts.ScriptLogger { |
| 394 | return a.logSender.GetScriptLogger(logSourceID) |
| 395 | }, |
| 396 | }) |
| 397 | // Register runner metrics. If the prom registry is nil, the metrics |
| 398 | // will not report anywhere. |
| 399 | a.scriptRunner.RegisterMetrics(a.prometheusRegistry) |
| 400 | |
| 401 | containerAPIOpts := []agentcontainers.Option{ |
| 402 | agentcontainers.WithExecer(a.execer), |
| 403 | agentcontainers.WithCommandEnv(a.sshServer.CommandEnv), |
| 404 | agentcontainers.WithScriptLogger(func(logSourceID uuid.UUID) agentcontainers.ScriptLogger { |
| 405 | return a.logSender.GetScriptLogger(logSourceID) |
| 406 | }), |
| 407 | } |
| 408 | containerAPIOpts = append(containerAPIOpts, a.containerAPIOptions...) |
no test coverage detected