saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.16k stars 5.48k forks source link

[BUG] win_lgpo exception during unpack #59059

Open prensing opened 3 years ago

prensing commented 3 years ago

Description I am trying to set a policy on a Windows 10 machine. Most machines are fine, but 1 particular machine throws an exception on many of policies. The error is: File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\modules\win_lgpo.py", line 5675, in _getDataFromRegPolData for v in struct.unpack(b"I", value): struct.error: unpack requires a buffer of 4 bytes

(run with debug is attached)

Setup Win 10 machine, version (Please provide relevant configs and/or SLS files (be sure to remove sensitive info).

Steps to Reproduce the behavior Run: salt lgpo.set_policy DriverSearchPlaces_DontSearchWindowsUpdate Enabled Currently that policy is not set on that machine.

Expected behavior Most machines enable the policy just fine.

Versions Report

salt --versions-report ``` Taylor-laptop: Salt Version: Salt: 3002.2 Dependency Versions: cffi: 1.12.2 cherrypy: 17.4.1 dateutil: 2.8.0 docker-py: Not Installed gitdb: 2.0.5 gitpython: Not Installed Jinja2: 2.10.1 libgit2: Not Installed M2Crypto: Not Installed Mako: 1.0.7 msgpack: 1.0.0 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.19 pycrypto: Not Installed pycryptodome: 3.9.8 pygit2: Not Installed Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] python-gnupg: 0.4.4 PyYAML: 5.3.1 PyZMQ: 18.0.1 smmap: 2.0.5 timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.1 System Versions: dist: locale: cp1252 machine: AMD64 release: 10 system: Windows version: 10 10.0.19041 SP0 ``` [salt-lgpo-crash.txt](https://github.com/saltstack/salt/files/5623619/salt-lgpo-crash.txt)

Additional context Add any other context about the problem here.

Ch3LL commented 3 years ago

What is different about this VM compared to the others. Is it the only windows 10 box?

prensing commented 3 years ago

As far as I can tell, nothing, but clearly that is not right. There are about 8 similar Win 10 boxes. They should be very similar, but are different (ie they don't use a uniform base image). I looked at obvious things like patch level, and I did not find differences.

I appreciate you looking at this. I will try to look more carefully at the code, but I don't know the guts of Salt. I am happy to run any debug tests. Also, if someone knows what PowerShell script the Python is running (does it work that way??), I could see if the output is different and interesting.

prensing commented 3 years ago

Still getting this with version 3003. Here is a run with just the command line:

# salt Taylor-laptop lgpo.get_policy 'Minimum PIN length' machine
Taylor-laptop:
    The minion function caused an exception: Traceback (most recent call last):
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\minion.py", line 1905, in _thread_return
        function_name, function_args, executors, opts, data
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\minion.py", line 1861, in _execute_job_function
        return_data = self.executors[fname](opts, data, func, args, kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 1235, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 2268, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 2283, in _run_as
        return _func_or_method(*args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\executors\direct_call.py", line 12, in execute
        return func(*args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 1235, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 2268, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\loader.py", line 2283, in _run_as
        return _func_or_method(*args, **kwargs)
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\modules\win_lgpo.py", line 9463, in get_policy
        hierarchical_return=hierarchical_return,
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\modules\win_lgpo.py", line 9044, in _get_policy_adm_setting
        policy_data=policy_file_data,
      File "c:\salt\bin\lib\site-packages\salt-3003-py3.7.egg\salt\modules\win_lgpo.py", line 5675, in _getDataFromRegPolData
        for v in struct.unpack(b"I", value):
    struct.error: unpack requires a buffer of 4 bytes
ERROR: Minions returned with non-zero exit code

If you know of something to run which will help diagnose this (python, powershell), happy to help.

twangboy commented 2 years ago

Could you share a copy of the registry.pol file in C:\Windows\System32\GroupPolicy\Machine I would imagine that is possibly corrupted. You could try backing up that file and seeing if you can then create group policy.

prensing commented 2 years ago

I checked and I still get the crash with that machine. It is currently running Salt Minion 3004. The registry.pol file is attached, in the zip. registry.zip