Skip to content

Commit

Permalink
fix: create client key and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent 4e67940 commit 5a13e8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
15 changes: 15 additions & 0 deletions server/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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),
Expand All @@ -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
}

Expand Down

0 comments on commit 5a13e8b

Please sign in to comment.