salt icon indicating copy to clipboard operation
salt copied to clipboard

cmd.run fails when not running as Admin on Windows 7

Open CapBananoid opened this issue 10 years ago • 6 comments

Description of Issue/Question

Using cmd.run on Windows 7 fails with "The current directory is invalid." when a non admin user is used in runas. Probably due to the user not having read access to salt install directory Note that using cwd doesn't work

Setup

Create a test user and launch the following state

test.vbs:
  cmd.run:
    - name: cscript.exe C:/tmp/test.vbs
    - runas: test
    - password: test

with test.vbs Wscript.echo "coin"

Steps to Reproduce Issue

sudo salt '*' state.apply test
worker_7:
----------
          ID: test.vbs
    Function: cmd.run
        Name: cscript.exe C:/tmp/test.vbs
      Result: False
     Comment: Command "cscript.exe C:/tmp/test.vbs" run
     Started: 11:00:44.736000
    Duration: 23.0 ms
     Changes:
              ----------
              pid:
                  5160
              retcode:
                  1
              stderr:
                  The current directory is invalid.
              stdout:

Summary for worker_7
------------
Succeeded: 0 (changed=1)
Failed:    1
------------
Total states run:     1
Total run time:  23.000 ms
ERROR: Minions returned with non-zero exit code

Versions Report

[vagrant@saltmaster ~]$ salt --versions-report
Salt Version:
           Salt: 2016.3.4

Dependency Versions:
           cffi: 0.8.6
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.21.0
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.21.4
         Python: 2.7.5 (default, Sep 15 2016, 22:37:39)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.el7.x86_64
         system: Linux
        version: CentOS Linux 7.2.1511 Core

On minion

C:\salt>salt-call.bat --versions-report
Salt Version:
           Salt: 2016.3.2

Dependency Versions:
           cffi: 1.6.0
       cherrypy: 5.3.0
       dateutil: 2.5.3
          gitdb: 0.6.4
      gitpython: 2.0.2
          ioflo: 1.5.3
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: 1.4.5
       M2Crypto: Not Installed
           Mako: 1.0.4
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.150
0 64 bit (AMD64)]
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: 0.2.4
        Tornado: 4.3
            ZMQ: 4.1.2

System Versions:
           dist:
        machine: AMD64
        release: 7
         system: Windows
        version: 7 6.1.7601 SP1 Multiprocessor Free

CapBananoid avatar Nov 24 '16 10:11 CapBananoid

Workaround:

test.vbs:
  cmd.run:
    - name: cd C:/ && cscript.exe C:/tmp/test.vbs
    - runas: test
    - password: test

CapBananoid avatar Nov 24 '16 10:11 CapBananoid

I'm seeing the same problem just running the modules directly, with cmd.run and cmd.shell. It looks like cwd is ignored if using runas.

salt testmachine cmd.run 'dir' runas=testmachine\\user password=password cwd='C:/test'

testmachine:
     Volume in drive C is Local Disk
     Volume Serial Number is CE4B-65F2
    
     Directory of C:\salt

salt testmachine cmd.shell 'dir' runas=testmachine\\user password=password cwd='C:/test'

testmachine:
     Volume in drive C is Local Disk
     Volume Serial Number is CE4B-65F2
    
     Directory of C:\salt

Have tried cwd='C:\test' and cwd='C:\\test' as well, just to check it's not an issue with the slash direction.

morganwillcock avatar Nov 24 '16 15:11 morganwillcock

@CapBananoid looks like i'm able to replicate this on windows 2012:

win2012:
----------
          ID: test.vbs
    Function: cmd.run
        Name: cscript.exe C:/tmp/test.vbs
      Result: False
     Comment: Command "cscript.exe C:/tmp/test.vbs" run
     Started: 15:12:12.815000
    Duration: 157.0 ms
     Changes:   
              ----------
              pid:
                  700
              retcode:
                  1
              stderr:
                  The current directory is invalid.
              stdout:

Summary for win2012
------------
Succeeded: 0 (changed=1)
Failed:    1
------------
Total states run:     1
Total run time: 157.000 ms

To note it looks to be working in 2016.11.0 so seems there is a patch we might need to backport to 2016.3. Thanks we will need to get this fixed up.

Ch3LL avatar Nov 29 '16 20:11 Ch3LL

Same here - if using user or runas cwd stops working on windows.

mbochenk avatar Dec 26 '16 15:12 mbochenk

Thanks for the workaround :)

martintamare avatar Feb 09 '17 14:02 martintamare

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Sep 02 '18 14:09 stale[bot]