Skip to content

Commit

Permalink
Dont start host user creation if any required binaries are not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex McGrath authored and github-actions committed Jun 12, 2024
1 parent 282dc20 commit 0ea2041
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/srv/sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *SessionRegistry) TryWriteSudoersFile(ctx *ServerContext) error {
}

func (s *SessionRegistry) TryCreateHostUser(ctx *ServerContext) error {
if !ctx.srv.GetCreateHostUser() {
if !ctx.srv.GetCreateHostUser() || s.users == nil {
s.log.Debug("Not creating host user: node has disabled host user creation.")
return nil // not an error to not be able to create host users
}
Expand Down
17 changes: 9 additions & 8 deletions lib/srv/usermgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewHostUsers(ctx context.Context, storage *local.PresenceService, uuid stri
//nolint:staticcheck // SA4023. False positive on macOS.
backend, err := newHostUsersBackend()
switch {
case trace.IsNotImplemented(err):
case trace.IsNotImplemented(err), trace.IsNotFound(err):
log.Debugf("Skipping host user management: %v", err)
return nil
case err != nil: //nolint:staticcheck // linter fails on non-linux system as only linux implementation returns useful values.
Expand Down Expand Up @@ -473,14 +473,15 @@ func (u *HostUserManagement) UserCleanup() {
cleanupTicker := time.NewTicker(time.Minute * 5)
defer cleanupTicker.Stop()
for {
if err := u.DeleteAllUsers(); err != nil {
if trace.IsNotFound(err) {
log.Debugf("Error during temporary user cleanup: %s, stopping cleanup job", err)
return
} else {
log.Error("Error during temporary user cleanup: ", err)
}
err := u.DeleteAllUsers()
switch {
case trace.IsNotFound(err):
log.Debugf("Error during temporary user cleanup: %s, stopping cleanup job", err)
return
case err != nil:
log.Error("Error during temporary user cleanup: ", err)
}

select {
case <-cleanupTicker.C:
case <-u.ctx.Done():
Expand Down
11 changes: 11 additions & 0 deletions lib/srv/usermgmt_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bufio"
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
Expand All @@ -48,6 +49,16 @@ type HostSudoersProvisioningBackend struct {

// newHostUsersBackend initializes a new OS specific HostUsersBackend
func newHostUsersBackend() (HostUsersBackend, error) {
var missing []string
for _, requiredBin := range []string{"usermod", "useradd", "getent", "groupadd", "visudo"} {
if _, err := exec.LookPath(requiredBin); err != nil {
missing = append(missing, requiredBin)
}
}
if len(missing) != 0 {
return nil, trace.NotFound("missing required binaries: %s", strings.Join(missing, ","))
}

return &HostUsersProvisioningBackend{}, nil
}

Expand Down

0 comments on commit 0ea2041

Please sign in to comment.