Skip to content

Commit

Permalink
fix(server): check allow-keyless when using git protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent bdd8612 commit 72d793e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion server/backend/sqlite/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func (d *SqliteBackend) AccessLevel(repo string, username string) backend.Access
return backend.ReadOnlyAccess
}

// If the repository doesn't exist, the user has read/write access.
if user != nil {
// If the repository doesn't exist, the user has read/write access.
if anon > backend.ReadWriteAccess {
Expand Down
5 changes: 5 additions & 0 deletions server/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (d *GitDaemon) handleClient(conn net.Conn) {
return
}

if !d.cfg.Backend.AllowKeyless() {
fatal(c, ErrNotAuthed)
return
}

name := utils.SanitizeRepo(string(opts[0]))
logger.Debugf("git: connect %s %s %s", c.RemoteAddr(), cmd, name)
defer logger.Debugf("git: disconnect %s %s %s", c.RemoteAddr(), cmd, name)
Expand Down
7 changes: 6 additions & 1 deletion server/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ func (s *SSHServer) Shutdown(ctx context.Context) error {

// PublicKeyAuthHandler handles public key authentication.
func (s *SSHServer) PublicKeyHandler(ctx ssh.Context, pk ssh.PublicKey) (allowed bool) {
if pk == nil {
return s.cfg.Backend.AllowKeyless()
}

ak := backend.MarshalAuthorizedKey(pk)
defer func() {
publicKeyCounter.WithLabelValues(ak, ctx.User(), strconv.FormatBool(allowed)).Inc()
}()

for _, k := range s.cfg.InitialAdminKeys {
if k == ak {
allowed = true
Expand All @@ -156,7 +161,7 @@ func (s *SSHServer) PublicKeyHandler(ctx ssh.Context, pk ssh.PublicKey) (allowed

// KeyboardInteractiveHandler handles keyboard interactive authentication.
func (s *SSHServer) KeyboardInteractiveHandler(ctx ssh.Context, _ gossh.KeyboardInteractiveChallenge) bool {
ac := s.cfg.Backend.AllowKeyless() && s.PublicKeyHandler(ctx, nil)
ac := s.cfg.Backend.AllowKeyless()
keyboardInteractiveCounter.WithLabelValues(ctx.User(), strconv.FormatBool(ac)).Inc()
return ac
}
Expand Down

0 comments on commit 72d793e

Please sign in to comment.