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

Return better error during group creation with invalid group name #46031

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

eriktate
Copy link
Contributor

Fixes #21165

Returns a trace.BadParameter error when groupadd fails with exit code 3 ("invalid argument to option"). If the command output contains "not a valid group name" then the message wrapped by trace.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 in createGroupIfNotExists should help make it more obvious that a role's host_groups array has an invalid entry when session creation fails.

Copy link

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 changelog: followed by the changelog entries for the PR.

@eriktate eriktate added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v14 backport/branch/v15 backport/branch/v16 labels Aug 29, 2024
@eriktate eriktate force-pushed the eriktate/21165/better-host-group-creation-error branch from b30f5d2 to 41a4b25 Compare August 29, 2024 16:51
lib/srv/usermgmt.go Outdated Show resolved Hide resolved
@eriktate eriktate force-pushed the eriktate/21165/better-host-group-creation-error branch from 41a4b25 to 996c9a2 Compare August 29, 2024 17:19
lib/utils/host/hostusers.go Outdated Show resolved Hide resolved
@eriktate eriktate force-pushed the eriktate/21165/better-host-group-creation-error branch from 996c9a2 to 9dcf95d Compare August 29, 2024 17:49
@@ -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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch cmd.ProcessState.ExitCode() {
switch code := cmd.ProcessState.ExitCode(); code {

Then you don't have to call cmd.ProcessState.ExitCode() 3 more times.

Copy link
Contributor Author

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 😅

@eriktate eriktate force-pushed the eriktate/21165/better-host-group-creation-error branch from 9dcf95d to 139b38b Compare August 29, 2024 18:23
Copy link
Contributor

@rosstimothy rosstimothy left a 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)

@eriktate eriktate force-pushed the eriktate/21165/better-host-group-creation-error branch from 139b38b to 711bae1 Compare August 30, 2024 20:01
@eriktate eriktate added this pull request to the merge queue Aug 30, 2024
Merged via the queue into master with commit 087c680 Aug 30, 2024
39 checks passed
@eriktate eriktate deleted the eriktate/21165/better-host-group-creation-error branch August 30, 2024 20:37
@public-teleport-github-review-bot

@eriktate See the table below for backport results.

Branch Result
branch/v14 Create PR
branch/v15 Create PR
branch/v16 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Error Message for User Host Creation
3 participants