fix(connectors.local): fragile sudo handling resulting in faillocks and premature errors.#1689
fix(connectors.local): fragile sudo handling resulting in faillocks and premature errors.#1689Dexmachi wants to merge 11 commits into
Conversation
| temp=$(mktemp "${{TMPDIR:={0}}}/pyinfra-sudo-askpass-XXXXXXXXXXXX") | ||
| cat >"$temp"<<'__EOF__' | ||
| #!/bin/sh | ||
| if [ -f "$0.${{PPID}}.called" ]; then |
There was a problem hiding this comment.
Doesn't making this check at the top break any retry attempts? If the first password is wrong we'll never actually retry any password provided later because the .called file will still exist?
There was a problem hiding this comment.
yes, that was how I was trying to make it
If the user forgot the sudo password, it keeps the retry attempt, then if the user inputs it wrong, it breaks
This was done like this in order to prevent faillocks
Any suggestion as to how to change this? I also don't quite like putting a marker, but it looks like the best solution in this scenario (python calling multiple sudo scripts)
There was a problem hiding this comment.
Yeah this is complicated because we want to allow retries with different passwords. Currently we'll never go over one attempt ever for the duration of the askpass file. I think that breaks the while loop entirely after the first failure?
What if we just removed the .called file after the echo error before return 1? That'd shortcut sudo retries and keep the file only for the duration of that command (I think, untested).
There was a problem hiding this comment.
Makes sense, I'll try to check out some possible fixes for this
|
I'm currently fixing the merge-based errorrs, 1 sec |
Closes #1043
Closes #1688
How:
Added a {0}.{PPID}.called marker + env LC_ALL=C to sudo calls, allowing Pyinfra to keep track of sudo call attempts and to have a standardized retry catch.
the marker gets removed alongside the sudo password file, in the same call.
Why:
@Local sudo handling was fragile, requiring a specific locale and not dealing with auto sudo retries, resulting in faillocks and premature errors.
Test Changes:
Had to change test_ssh and test_util to assert "env LC_ALL=C " at the start of sudo and su calls.
Before/After:
Before(normal usage):
After(normal usage):
Before(ad-hoc):
After(ad-hoc):
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)