Closed Renerick closed 2 years ago
Thank you for raising this @Renerick! I think the updated askpass handling from #852 should indeed respect the temp dir config.
Oh no, since my PR broke this I'll submit a PR to fix it.
@jaysoffian Thanks! For the record, you didn't "break" it necessarily (in fact, your PR was 110% reasonable), more like an unintended consequence that only appears in VERY specific circumstances.
@Renerick please check whether #905 fixes the issue for you.
Thanks for the heads up! I'll have a look on this weekend
@jaysoffian Unfortunately, this change breaks sudo completely as Synology default shell does not seem to support these string substituions
[REDACTED]@synology-1:~$ mktemp "${{TMPDIR:=/tmp}}/pyinfra-sudo-askpass-XXXXXXXXXXXX"
-sh: ${{TMPDIR:=/tmp}}/pyinfra-sudo-askpass-XXXXXXXXXXXX: bad substitution
[REDACTED]@synology-1:~$ echo "${{HOME}}"
-sh: ${{HOME}}: bad substitution
[REDACTED]@synology-1:~$ echo $HOME
/[REDACTED] # correct directory
$ sh --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@Renerick it looks like you're copy/pasting the code from the diff instead of running the new code.
The issue there is that the double braces are a Python escape mechanism for formatting strings, so the correct code is actually this:
mktemp "${TMPDIR:=/tmp}/pyinfra-sudo-askpass-XXXXXXXXXXXX"
I know that the new code works correctly with bash (even when run in POSIX mode as sh) because I tested it.
Please install pyinfra from my PR and test it that way. e.g.
python3 -m venv pyinfra-test
pyinfra-test/bin/python -m pip install 'git+https://github.com/jaysoffian/pyinfra@make-sudo-askpass-command-respect-tmpdir-env-var'
pyinfra-test/bin/pyinfra ...
yes, you are absolutely correct, my bad.
I did install pyifnra from your commit via nix-shell, so there was no problem on this side
let pkgs = import <nixpkgs> {
overlays = [
(self: super: {
pyinfra = super.pyinfra.overrideAttrs (old: {
src = super.fetchFromGitHub {
owner = "Fizzadar";
repo = old.pname;
rev = "7ce69211d840a5712969e55abcf16576db258e05";
hash = "sha256-p8goMspSC+XuuPyXM5SmV4LpW+JYQ8TA/HuOEV7BgCc=";
};
});
})
];
};
What happened is, after installation it did not work. sudo password prompt still appeared and I tried to debug the installation. In the process, as you correctly noted, I erroneously tried to run the command by copying it from the diff and came to the wrong conclusion about this patch being broken.
I just retested it again and It works! I'm not quite sure why it did not work the first time, but the fix is 100% working for me right now, so I will blame this on some environment related fluke.
Huge thanks for your help!
cc: @Fizzadar
Thank you for the confirmation.
Describe the bug
When running a task with
_sudo=True, _ask_sudo_password=<password>
in restricted environments where script execution from/tmp
is prohibited, sudo password prompt appears. Settingconfig.TEMP_DIR
in an attempt to place the file in other directory does not affect this behavior.Related to #852
To Reproduce
In my particular case, this happens on a Synology NAS with DSM 7. There is only a single reference to this restriction in the entire Internet (https://community.synology.com/enu/forum/1/post/153704), and I have yet to find how to configure that. Nevertheless, this would happen on hosts with
noexec
tmp mounts, so probably worth checking this out.Expected behavior
Being able to configure the location of the password script with
TEMP_DIR
config value or a new config value (likeASK_SUDO_PASSWORD_EXE_LOCATION
)Meta
pyinfra --support
.Nix (nix-shell to be specific), built from 2.4 source
-vv
and--debug
.(there are some weird directory structure in the logs above, please disregard, most likely a bug in my scripts)