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

Add support for entering sudo password interactively #257

Merged
merged 1 commit into from
Feb 16, 2024
Merged

Add support for entering sudo password interactively #257

merged 1 commit into from
Feb 16, 2024

Conversation

n-hass
Copy link

@n-hass n-hass commented Feb 3, 2024

This adds a prompt for entering the sudo password interactively, so that system deployments can be activated when using non-root sshUsers. Fixes #78.

I have chosen to handle this locally (in deploy) and pipe the password to stdin of the ssh session, rather than via psuedo-terminal as this is more reliable. This also means that magicRollback works, unlike the "-t" workaround.

@n-hass
Copy link
Author

n-hass commented Feb 3, 2024

Can I also make a suggestion that some refactoring take place? The same pattern is duplicated like ~5-6 times to build a process::Command with the ssh options etc. I think a factory-style function would be helpful here and would make the code significantly more readable.

I'm happy to do this in this PR or make another.

@n-hass n-hass changed the title Add support for entering sudo password Add support for entering sudo password interactively Feb 4, 2024
@PhilTaken
Copy link
Collaborator

@n-hass

Thanks for your contribution!

I'm not sure how I feel about transmitting passwords for sudo. Generally, you should use ssh keys with attached permissions instead.

As for the refactoring, feel free to open another PR since it is not related to this one.

@n-hass
Copy link
Author

n-hass commented Feb 5, 2024

Agreed, keys are always safer. However, from a security perspective, I believe this technique is sound.

Functionally this is no different than SSH'ing as the non-root user and entering the sudo password interactively through the tty, as deploy-rs would pipe the password to the ssh session after the session has been opened. The password is never transmitted or stored plaintext (apart from when in-memory in deploy-rs).

I think some, myself included, are more comfortable with this than widening SSH permissions for root, or using a sudo pam / ssh-agent forwarding workaround.

Perhaps a warning/'disclaimer' could be included somewhere to encourage use of keys in a production environment?

@n-hass
Copy link
Author

n-hass commented Feb 6, 2024

Sorry, forgot to tag @PhilTaken . See above

Copy link
Member

@rvem rvem left a comment

Choose a reason for hiding this comment

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

First of all, thanks for your contribution:)

Perhaps a warning/'disclaimer' could be included somewhere to encourage use of keys in a production environment?

I agree, it'd be nice to print a warning that interactive sudo is used.

Additionally, I have a single comment regarding the JSON schema update that is affected by your PR

src/cli.rs Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
@n-hass
Copy link
Author

n-hass commented Feb 16, 2024

Thanks @rvem! Is it okay if I squash?

@rvem
Copy link
Member

rvem commented Feb 16, 2024

Yeah, sure

@rvem rvem merged commit 0a01877 into serokell:master Feb 16, 2024
1 check passed
@rvem
Copy link
Member

rvem commented Feb 16, 2024

Thanks!

@n-hass n-hass deleted the feature/interactive-sudo branch February 17, 2024 01:59
zedseven added a commit to zedseven/nixos-configuration that referenced this pull request Feb 24, 2024
@jmatsushita jmatsushita mentioned this pull request Mar 26, 2024
@munnik
Copy link

munnik commented Oct 31, 2024

Hi,

After reading above comments and other documentation, I still don't understand why this message appears when doing a deployment:

🚀 ⚠️ [deploy] [WARN] Interactive sudo is enabled! Using a sudo password is less secure than correctly configured SSH keys.

I use interactive sudo, but why is it less secure than correctly configured SSH keys? For login, I use SSH keys, do I need to set other SSH keys? The only documentation I see is to either allow root to log in with SSH keys or to allow sudo without password. I think both are less secure than needing both an SSH key to login and a password to become root. Am I missing something?

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.

Password based sudo
4 participants