Skip to content

Fix sudo password prompt #573

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Qubasa
Copy link
Contributor

@Qubasa Qubasa commented Jul 29, 2025

Problem

  • Currently nixos-anywhere fails if you test it with the default ubuntu server image. As it configures a normal user that has sudo with password access to root.
TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags $(printf '%q ' "$kexecExtraFlags") 

the problem / bug is in the line above where we run kexec with sudo inside a setsid terminal, that sudo needs to re-prompt for the password, and doesn't have access to stdin so it fails.

  • Another problem is that errors happening in the kexec step are not propagated through to the shell

My Changes

  • Add a breakpoint function, it halts execution and gives you an interactive bash shell with all the internal variables in scope

  • Reduce log spamming by adding set +x to for loops

  • Make remoteCommand write a shell script that then get's called once with sudo, instead of calling sudo inside the setsid shell

Qubasa and others added 4 commits July 29, 2025 14:28
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Suppress verbose output during fact checking loops
- Quiet SSH command execution to reduce log clutter
- Fix sudo detection to only apply when not running as root
- Add cleanup of temporary log files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Create separate command templates for TTY vs non-TTY scenarios
- Use script-based approach for sudo commands when TTY is available
- Add proper error handling and success detection for kexec operations
- Capture and display remote command output for debugging
- Handle connection disconnection during kexec execution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
KEXEC_SCRIPT
chmod +x /tmp/kexec-script.sh
# Run the script and let output flow naturally
${maybeSudo} /tmp/kexec-script.sh 2>&1 | tee /tmp/kexec-output.log || true
Copy link
Member

Choose a reason for hiding this comment

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

insecure tempfile handling. Why do we need this file?

Copy link
Contributor Author

@Qubasa Qubasa Jul 29, 2025

Choose a reason for hiding this comment

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

@Mic92 Ah because of a potential race condition with an attacker you are right, I didn't think of that.

The output log is static because then we can get the logs from the host easily without needing to back communicate the path

Qubasa and others added 2 commits July 31, 2025 12:17
Co-authored-by: Jörg Thalheim <[email protected]>
Co-authored-by: Jörg Thalheim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants