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

[BUG] salt-ssh pre-flight may fail if $TMPDIR is set #58996

Open
satwell opened this issue Nov 21, 2020 · 0 comments
Open

[BUG] salt-ssh pre-flight may fail if $TMPDIR is set #58996

satwell opened this issue Nov 21, 2020 · 0 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior Salt-SSH severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
Milestone

Comments

@satwell
Copy link

satwell commented Nov 21, 2020

Description
salt-ssh pre-flight scripts will fail if $TMPDIR is set and does not exist on the remote host.

salt.client.ssh.run_ssh_pre_flight constructs the remote path for the pre-flight script using tempfile.gettempdir(), which will return the value of $TMPDIR if it's defined. If this directory doesn't exist on the remote host, the script copy will fail.

I ran into this on Linux, but users running salt-ssh from MacOS are also very likely to hit this bug because MacOS sets a per-user $TMPDIR under /var/folders.

Setup
Configure salt-ssh to use any pre-flight script.

Steps to Reproduce the behavior

export TMPDIR="$XDG_RUNTIME_DIR/salt"
mkdir -p "$TMPDIR"
salt-ssh --pre-flight -l debug testhost test.ping

Debug shows an scp to a path constructed from local $TMPDIR:

[DEBUG   ] Terminal Command: scp -o KbdInteractiveAuthentication=no -o PasswordAuthentication=no -o GSSAPIAuthentication=no -o ConnectTimeout=65 -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile=/tmp/salt-master-root/etc/salt/pki/master/ssh/salt-ssh.rsa -o User=root ../states/salt/files/install_salt.sh testhost:/run/user/10551/salt/install_salt.sh

And fails to run at that path because the scp actually failed.

testhost:                                                                                     
    ----------                                                                            
    retcode:                                                                              
        2                                                                                 
    stderr:                                  
        /bin/sh: cannot open /run/user/10551/salt/install_salt.sh: No such file or directory                                                                                        
    stdout:

Expected behavior
salt-ssh should probably always use /tmp as the destination path for the pre-flight script.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3002.2
 
Dependency Versions:
          cffi: 1.14.3
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: 4.1.0
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.2
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.3
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: 2.6.1
  pycryptodome: 3.9.7
        pygit2: Not Installed
        Python: 3.8.6 (default, Sep 25 2020, 09:36:53)
  python-gnupg: 0.4.6
        PyYAML: 5.3.1
         PyZMQ: 20.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.3
 
System Versions:
          dist: debian testing bullseye
        locale: utf-8
       machine: x86_64
       release: 5.9.0-1-amd64
        system: Linux
       version: Debian GNU/Linux testing bullseye
@satwell satwell added the Bug broken, incorrect, or confusing behavior label Nov 21, 2020
@Ch3LL Ch3LL added Salt-SSH severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around and removed needs-triage labels Dec 4, 2020
@Ch3LL Ch3LL added this to the Approved milestone Dec 4, 2020
@sagetherage sagetherage added this to Severity-Medium in Salt-SSH May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Salt-SSH severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
Salt-SSH
  
Severity-Medium
Development

No branches or pull requests

3 participants