salt icon indicating copy to clipboard operation
salt copied to clipboard

Why can't Windows usernames is numbers?[BUG]

Open Zziwen opened this issue 4 years ago • 4 comments

runas is int type

[root@saltstack file]# salt 'MyWindows' cmd.powershell '(Get-Process | Where-Object {$_.ProcessName -like 'Photoshop'} | Stop-Process)' runas='1201' MyWindows: Passed invalid arguments to cmd.powershell: argument of type 'int' is not iterable

    Execute the passed PowerShell command and return the output as a dictionary.

    Other ``cmd.*`` functions (besides ``cmd.powershell_all``)
    return the raw text output of the command. This
    function appends ``| ConvertTo-JSON`` to the command and then parses the
    JSON into a Python dictionary. If you want the raw textual result of your
    PowerShell command you should use ``cmd.run`` with the ``shell=powershell``
    option.

    For example:

    .. code-block:: bash

        salt '*' cmd.run '$PSVersionTable.CLRVersion' shell=powershell
        salt '*' cmd.run 'Get-NetTCPConnection' shell=powershell

Zziwen avatar Jan 22 '21 09:01 Zziwen

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

welcome[bot] avatar Jan 22 '21 09:01 welcome[bot]

Hi @Zziwen What is your version of salt? I ran this on 3002.2 salt-call --local cmd.run '$PSVersionTable.CLRVersion' shell=powershell runas='1201' -l debug

It worked and gave me this:

[INFO    ] Executing command 'Powershell -NonInteractive -NoProfile "$PSVersionTable.CLRVersion"' as user '1201' in directory 'C:\'
[DEBUG   ] Unable to OpenProcess pid=4 name=System
[DEBUG   ] Unable to OpenProcess pid=148 name=Registry
[DEBUG   ] Token for pid does not match user sid: S-1-5-18
[DEBUG   ] Unable to OpenProcess pid=564 name=smss.exe
[DEBUG   ] OpenProcessToken failed pid=672 name=svchost.exe userNT AUTHORITY\SYSTEM
[DEBUG   ] Unable to OpenProcess pid=780 name=csrss.exe
[DEBUG   ] Unable to OpenProcess pid=884 name=wininit.exe
[DEBUG   ] Unable to OpenProcess pid=900 name=csrss.exe
[DEBUG   ] Unable to OpenProcess pid=984 name=services.exe
Exception ignored in: <bound method HANDLE.Close of HANDLE(0)>
Traceback (most recent call last):
  File "c:\dev\salt\salt\platform\win.py", line 188, in Close
    CloseHandle(self.Detach())
  File "c:\dev\salt\salt\platform\win.py", line 633, in errcheck_bool
    raise ctypes.WinError(ctypes.get_last_error())
OSError: [WinError 6] The handle is invalid.
[DEBUG   ] output:
Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      30319  42000



[DEBUG   ] LazyLoaded nested.output
local:

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    4      0      30319  42000

xeacott avatar Jan 22 '21 23:01 xeacott

Hi @Zziwen What is your version of salt? I ran this on 3002.2 salt-call --local cmd.run '$PSVersionTable.CLRVersion' shell=powershell runas='1201' -l debug

It worked and gave me this:

[INFO    ] Executing command 'Powershell -NonInteractive -NoProfile "$PSVersionTable.CLRVersion"' as user '1201' in directory 'C:\'
[DEBUG   ] Unable to OpenProcess pid=4 name=System
[DEBUG   ] Unable to OpenProcess pid=148 name=Registry
[DEBUG   ] Token for pid does not match user sid: S-1-5-18
[DEBUG   ] Unable to OpenProcess pid=564 name=smss.exe
[DEBUG   ] OpenProcessToken failed pid=672 name=svchost.exe userNT AUTHORITY\SYSTEM
[DEBUG   ] Unable to OpenProcess pid=780 name=csrss.exe
[DEBUG   ] Unable to OpenProcess pid=884 name=wininit.exe
[DEBUG   ] Unable to OpenProcess pid=900 name=csrss.exe
[DEBUG   ] Unable to OpenProcess pid=984 name=services.exe
Exception ignored in: <bound method HANDLE.Close of HANDLE(0)>
Traceback (most recent call last):
  File "c:\dev\salt\salt\platform\win.py", line 188, in Close
    CloseHandle(self.Detach())
  File "c:\dev\salt\salt\platform\win.py", line 633, in errcheck_bool
    raise ctypes.WinError(ctypes.get_last_error())
OSError: [WinError 6] The handle is invalid.
[DEBUG   ] output:
Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      30319  42000



[DEBUG   ] LazyLoaded nested.output
local:

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    4      0      30319  42000

My version is 3000.6, but I upgraded to 3002.2 and still have problems image image

Zziwen avatar Jan 25 '21 08:01 Zziwen

Confirmed this is an issue:

  • when executing the command from salt-call script, here's the rendered kwargs {'__kwarg__': True, 'shell': 'powershell', 'runas': '1201'}]
  • when executing the command from salt script, here's the rendered kwargs {'__kwarg__': True, 'shell': 'powershell', 'runas': 1201}], 'tgt': 'windows', 'jid': '20210125204551657963', 'ret': '', 'tgt_type': 'glob', 'user': 'sudo_eacott'}

so somewhere the runas param isn't being wrapped in a string. Will have to find that spot and we'll get a PR up for ya.

xeacott avatar Jan 25 '21 20:01 xeacott

The above PR addresses this issue

twangboy avatar Mar 12 '25 16:03 twangboy