Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v11] Ignore ENOENT error on group check #27229

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/srv/usermgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (u *HostUserManagement) doWithUserLock(f func(types.SemaphoreLease) error)

func (u *HostUserManagement) createGroupIfNotExist(group string) error {
_, err := u.backend.LookupGroup(group)
if err != nil && err != user.UnknownGroupError(group) {
if err != nil && !isUnknownGroupError(err, group) {
return trace.Wrap(err)
}
err = u.backend.CreateGroup(group)
Expand All @@ -287,10 +287,13 @@ func (u *HostUserManagement) createGroupIfNotExist(group string) error {
// isUnknownGroupError returns whether the error from LookupGroup is an unknown group error.
//
// LookupGroup is supposed to return an UnknownGroupError, but due to an existing issue
// may instead return a generic "no such file or directory" error when sssd is installed.
// may instead return a generic "no such file or directory" error when sssd is installed
// or "no such process" as Go std library just forwards errors returned by getgrpnam_r.
// See github issue - https://github.com/golang/go/issues/40334
func isUnknownGroupError(err error, groupName string) bool {
return errors.Is(err, user.UnknownGroupError(groupName)) || strings.HasSuffix(err.Error(), syscall.ENOENT.Error())
return errors.Is(err, user.UnknownGroupError(groupName)) ||
strings.HasSuffix(err.Error(), syscall.ENOENT.Error()) ||
strings.HasSuffix(err.Error(), syscall.ESRCH.Error())
}

// DeleteAllUsers deletes all host users in the teleport service group.
Expand Down