- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 445
 
Description
Describe the bug
In a setup where the target precludes execution of files from /tmp and TMPDIR is not yet set (on the target), even with config.TEMP_DIR set to a useful path (and #1424 fixed), the askpass file is still placed in /tmp and thus cannot be executed.
To Reproduce
Try to  execute an operation  with _sudo=True and an already set password against a target that prevents execution of files from /tmp (and without TMPDIR set).  The login will fail because the askpass file can't be executed.  While this is not a useful long-term setup, it can happen when a machine has not yet been configured.
Expected behavior
The operation will work flawlessly.
Meta
System: Darwin
  Platform: macOS-14.7.7-arm64-arm-64bit
  Release: 23.6.0
  Machine: arm64
pyinfra: v3.4.1
  click: v8.2.1
  click: v8.2.1
  click: v8.2.1
  distro: v1.9.0
  gevent: v25.5.1
  jinja2: v3.1.6
  packaging: v25.0
  paramiko: v3.5.1
  python-dateutil: v2.9.0.post0
  pywinrm: v0.5.0
  typeguard: v4.4.4
  typing-extensions: v4.14.1
Executable: /Users/james/.local/bin/pyinfra
Python: 3.12.11 (CPython, Clang 20.1.4 )
Possible cause
'/tmp' is hard-coded as the backstop to TMPDIR below
pyinfra/pyinfra/connectors/util.py
Lines 24 to 35 in c557b99
| SUDO_ASKPASS_ENV_VAR = "PYINFRA_SUDO_PASSWORD" | |
| SUDO_ASKPASS_COMMAND = r""" | |
| temp=$(mktemp "${{TMPDIR:=/tmp}}/pyinfra-sudo-askpass-XXXXXXXXXXXX") | |
| cat >"$temp"<<'__EOF__' | |
| #!/bin/sh | |
| printf '%s\n' "${0}" | |
| __EOF__ | |
| chmod 755 "$temp" | |
| echo "$temp" | |
| """.format( | |
| SUDO_ASKPASS_ENV_VAR, | |
| ) |