@@ -60,8 +60,13 @@ func ValidateInstanceImage(ctx context.Context, instance Instance, privateKey st
6060 return err
6161 }
6262
63- fmt .Printf ("Instance image validation passed for %s: architecture=%s, os=%s, home=%s, systemd=%s\n " ,
64- instance .CloudID , arch , osVersion , homeDir , systemdStatus )
63+ sudoStatus , err := validateSudoAccess (ctx , sshClient )
64+ if err != nil {
65+ return err
66+ }
67+
68+ fmt .Printf ("Instance image validation passed for %s: architecture=%s, os=%s, home=%s, systemd=%s, sudo=%s\n " ,
69+ instance .CloudID , arch , osVersion , homeDir , systemdStatus , sudoStatus )
6570
6671 return nil
6772}
@@ -152,3 +157,15 @@ func validateSystemd(ctx context.Context, sshClient *ssh.Client) (string, error)
152157
153158 return "" , fmt .Errorf ("expected systemd to be running or degraded, got: %s" , systemdStatus )
154159}
160+
161+ func validateSudoAccess (ctx context.Context , sshClient * ssh.Client ) (string , error ) {
162+ // Test if sudo is available and can run without a password
163+ // -n flag means non-interactive (no password prompt)
164+ stdout , stderr , err := sshClient .RunCommand (ctx , "sudo -n true" )
165+ if err != nil {
166+ return "" , fmt .Errorf ("failed to verify sudo access: %w, stdout: %s, stderr: %s" , err , stdout , stderr )
167+ }
168+
169+ // If the command succeeded, we have passwordless sudo access
170+ return "available" , nil
171+ }
0 commit comments