Skip to content

Location of "askpass" file respects target's TMPDIR but not config.TEMP_DIR #1425

@morrison12

Description

@morrison12

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

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,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions