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

[v16] Better error messaging when writing invalid sudoer entries #47168

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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: 8 additions & 1 deletion lib/srv/usermgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewHostUsers(ctx context.Context, storage services.PresenceInternal, uuid s
}
cancelCtx, cancelFunc := context.WithCancel(ctx)
return &HostUserManagement{
log: slog.With(teleport.ComponentKey, teleport.Component(teleport.ComponentHostUsers)),
log: slog.With(teleport.ComponentKey, teleport.ComponentHostUsers),
backend: backend,
ctx: cancelCtx,
cancel: cancelFunc,
Expand All @@ -78,6 +78,7 @@ func NewHostSudoers(uuid string) HostSudoers {
}
return &HostSudoersManagement{
backend: backend,
log: slog.With(teleport.ComponentKey, teleport.ComponentHostUsers),
}
}

Expand Down Expand Up @@ -191,6 +192,8 @@ type HostUserManagement struct {
}

type HostSudoersManagement struct {
log *slog.Logger

backend HostSudoersBackend
}

Expand Down Expand Up @@ -222,6 +225,10 @@ func (u *HostSudoersManagement) WriteSudoers(name string, sudoers []string) erro
sudoersOut.WriteString(fmt.Sprintf("%s %s\n", name, entry))
}
err := u.backend.WriteSudoersFile(name, []byte(sudoersOut.String()))
if errors.Is(err, host.ErrInvalidSudoers) {
u.log.WarnContext(context.Background(), "Invalid sudoers entry. If using a login managed by a static host user resource, inspect its configured sudoers field for invalid entries. Otherwise, inspect the host_sudoers field for roles targeting this host.", "error", err, "host_username", name)
return trace.BadParameter("invalid sudoers entry for login %q, inspect roles' host_sudoers field or static host user's sudoers field for invalid syntax", name)
}
return trace.Wrap(err)
}

Expand Down
1 change: 1 addition & 0 deletions lib/srv/usermgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func TestUserMgmtSudoers_CreateTemporaryUser(t *testing.T) {
}
sudoers := HostSudoersManagement{
backend: backend,
log: utils.NewSlogLoggerForTests(),
}

closer, err := users.UpsertUser("bob", services.HostUsersInfo{
Expand Down
Loading