-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Return better error during group creation with invalid group name #46031
Return better error during group creation with invalid group name #46031
Conversation
The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with |
b30f5d2
to
41a4b25
Compare
41a4b25
to
996c9a2
Compare
996c9a2
to
9dcf95d
Compare
lib/utils/host/hostusers.go
Outdated
@@ -53,9 +54,18 @@ func GroupAdd(groupname string, gid string) (exitCode int, err error) { | |||
cmd := exec.Command(groupaddBin, args...) | |||
output, err := cmd.CombinedOutput() | |||
log.Debugf("%s output: %s", cmd.Path, string(output)) | |||
if cmd.ProcessState.ExitCode() == GroupExistExit { | |||
|
|||
switch cmd.ProcessState.ExitCode() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch cmd.ProcessState.ExitCode() { | |
switch code := cmd.ProcessState.ExitCode(); code { |
Then you don't have to call cmd.ProcessState.ExitCode()
3 more times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I totally forgot you could do that in a switch 😅
9dcf95d
to
139b38b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight nit: the error message returned to users is a bit repetitive
ERROR: ssh: rejected: administratively prohibited (creating configured groups
creating group "a13089da-29df-448a-b997-9029243d419c!@#$"
invalid group name)
139b38b
to
711bae1
Compare
Fixes #21165
Returns a
trace.BadParameter
error whengroupadd
fails with exit code 3 ("invalid argument to option"). If the command output contains "not a valid group name" then the message wrapped bytrace.BadParameter
specifies that. Otherwise we just report there was an invalid parameter. Regardless of which specific error message is resolved, adding the group name to the error returned increateGroupIfNotExists
should help make it more obvious that a role'shost_groups
array has an invalid entry when session creation fails.