diff --git a/server/config/file.go b/server/config/file.go index 11e239fb0..b3f8c8ec9 100644 --- a/server/config/file.go +++ b/server/config/file.go @@ -29,7 +29,7 @@ ssh: # The path to the server's client private key. This key will be used to # authenticate the server to make git requests to ssh remotes. - client_key_path: "{{ .Internal.ClientKeyPath }}" + client_key_path: "{{ .SSH.ClientKeyPath }}" # The maximum number of seconds a connection can take. # A value of 0 means no timeout. diff --git a/server/server.go b/server/server.go index 012ea0519..66a5488fb 100644 --- a/server/server.go +++ b/server/server.go @@ -132,7 +132,6 @@ func (s *Server) Start() error { return nil }) errg.Go(func() error { - s.logger.Print("Starting cron scheduler") s.Cron.Start() return nil }) diff --git a/server/ssh/ssh.go b/server/ssh/ssh.go index 9c55aea18..42e512226 100644 --- a/server/ssh/ssh.go +++ b/server/ssh/ssh.go @@ -3,12 +3,15 @@ package ssh import ( "context" "errors" + "fmt" "net" + "os" "path/filepath" "strconv" "strings" "time" + "github.com/charmbracelet/keygen" "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/server/backend" cm "github.com/charmbracelet/soft-serve/server/cmd" @@ -81,12 +84,14 @@ type SSHServer struct { // NewSSHServer returns a new SSHServer. func NewSSHServer(ctx context.Context) (*SSHServer, error) { cfg := config.FromContext(ctx) + var err error s := &SSHServer{ cfg: cfg, ctx: ctx, logger: log.FromContext(ctx).WithPrefix("ssh"), } + logger := s.logger.StandardLog(log.StandardLogOptions{ForceLevel: log.DebugLevel}) mw := []wish.Middleware{ rm.MiddlewareWithLogger( @@ -101,6 +106,7 @@ func NewSSHServer(ctx context.Context) (*SSHServer, error) { lm.MiddlewareWithLogger(logger), ), } + s.srv, err = wish.NewServer( ssh.PublicKeyAuth(s.PublicKeyHandler), ssh.KeyboardInteractiveAuth(s.KeyboardInteractiveHandler), @@ -115,10 +121,19 @@ func NewSSHServer(ctx context.Context) (*SSHServer, error) { if cfg.SSH.MaxTimeout > 0 { s.srv.MaxTimeout = time.Duration(cfg.SSH.MaxTimeout) * time.Second } + if cfg.SSH.IdleTimeout > 0 { s.srv.IdleTimeout = time.Duration(cfg.SSH.IdleTimeout) * time.Second } + // Create client ssh key + if _, err := os.Stat(cfg.SSH.ClientKeyPath); err != nil && os.IsNotExist(err) { + _, err := keygen.New(cfg.SSH.ClientKeyPath, keygen.WithKeyType(keygen.Ed25519), keygen.WithWrite()) + if err != nil { + return nil, fmt.Errorf("client ssh key: %w", err) + } + } + return s, nil }