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 _sudo_set_home=True global argument to disable setting sudo home #1205

Open
DrSensor opened this issue Sep 16, 2024 · 1 comment
Open
Labels
connectors Connector issues - builtin integrations with other tools.

Comments

@DrSensor
Copy link

Is your feature request related to a problem? Please describe

Discussed in #1204

Originally posted by DrSensor September 14, 2024
Hi, how to disable -H/--set-home flag when using _sudo=True?

a bit of context

# group_data/local.py

_sudo = True
_preserve_sudo_env = True
# deploy.py

from pyinfra.operations.server import shell, packages

packages(["direnv"]) # run as root

# I want to write the output to /home/$USER/... ; not /root/...
shell(["direnv hook fish > ~/.config/fish/conf.d/direnv.fish"])

after some inspection with pyinfra --debug inventory.py deploy.py

[pyinfra.connectors.local] --> Running command on localhost: env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-vQ3t4mfcxJrY *** sudo -H -A -k -E sh -c 'direnv hook fish > ~/.config/fish/conf.d/direnv.fish'
[pyinfra.connectors.util] --> Waiting for exit status...
[pyinfra.connectors.util] --> Command exit status: 1

I notice it use -H

Describe the solution you'd like

I propose to add global argument _sudo_always_set_home1 where the default is True (for backward compatibility)

with this change, the group_data would be

# group_data/local.py

_sudo = True
_preserve_sudo_env = True
+ _sudo_always_set_home = False

Footnotes

  1. /etc/sudoers has an option called always_set_home

@Fizzadar Fizzadar added API API mode specific issues. connectors Connector issues - builtin integrations with other tools. and removed API API mode specific issues. labels Nov 17, 2024
@Fizzadar
Copy link
Member

Good shout, I think _sudo_set_home is probably the right name.

@Fizzadar Fizzadar changed the title Global argument to _disable_ "setting HOME to sudo target user" Add _sudo_set_home=True global argument to disable setting sudo home Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
connectors Connector issues - builtin integrations with other tools.
Projects
None yet
Development

No branches or pull requests

2 participants