Skip to content

Commit 6cc0611

Browse files
committed
chore: meaningful error message when passwordless sudo required on machine provisioning
1 parent 8beb9e2 commit 6cc0611

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/cli/machine.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ func provisionMachine(ctx context.Context, exec sshexec.Executor, version string
4646
return fmt.Errorf("run whoami: %w", err)
4747
}
4848

49+
if user != "root" {
50+
// 'sudo -n' is not used because it fails with 'sudo: a password is required' when the user has no password
51+
// in /etc/shadow even though it may have valid sudo access.
52+
out, err := exec.Run(ctx, "sudo true")
53+
if err != nil {
54+
if strings.Contains(out, "password is required") {
55+
return fmt.Errorf(
56+
"user '%[1]s' requires a password for sudo, but Uncloud needs passwordless sudo or root access "+
57+
"to install and configure the uncloudd daemon on the remote machine.\n\n"+
58+
"Possible solutions:\n"+
59+
"1. Use root user or a user with passwordless sudo instead.\n"+
60+
"2. Configure passwordless sudo for the user '%[1]s' by running on the remote machine:\n"+
61+
" echo '%[1]s ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/%[1]s",
62+
user)
63+
}
64+
return fmt.Errorf("sudo command failed for user '%s': %w. "+
65+
"Please ensure the user has sudo privileges or use root user instead", user, err)
66+
}
67+
}
68+
4969
cmd := installCmd(user, version)
5070

5171
fmt.Println("Downloading Uncloud install script:", installScriptURL)

0 commit comments

Comments
 (0)