saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.21k stars 5.48k forks source link

LGPO: Doesn't return policy_elements of type "text" #55642

Closed twangboy closed 4 years ago

twangboy commented 4 years ago

Description of Issue

A Group Policy setting that has an Element that is a text field is not retrieved by lgpo.get.

Setup

Open gpedit.msc Navigate to User Configuration\Administrative Templates\Control Panel\Personalization Set Force specific screen saver to Enabled Set the Screen saver executable name to any text value

Steps to Reproduce Issue

Run salt-call --local lgpo.get user The above policy will not be displayed in the list of configured policies

Now set the policy to Disabled Run salt-call --local lgpo.get user Now the above policy will be correctly displayed as disabled

An additional bug, set the policy back to Enabled Leave the Screen saver executable name blank Run salt-call --local lgpo.get user Observe the following stacktrace:

Traceback (most recent call last):
  File "C:\salt\bin\Scripts\salt-call", line 11, in <module>
    salt_call()
  File "C:\salt\bin\lib\site-packages\salt\scripts.py", line 431, in salt_call
    client.run()
  File "C:\salt\bin\lib\site-packages\salt\cli\call.py", line 57, in run
    caller.run()
  File "C:\salt\bin\lib\site-packages\salt\cli\caller.py", line 138, in run
    ret = self.call()
  File "C:\salt\bin\lib\site-packages\salt\cli\caller.py", line 237, in call
    ret['return'] = self.minion.executors[fname](self.opts, data, func, args, kwargs)
  File "C:\salt\bin\lib\site-packages\salt\executors\direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "C:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 7813, in get
    return_not_configured=return_not_configured))
  File "C:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 6406, in _checkAllAdmxPolicies
    policy_file_data)
  File "C:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 5638, in _getDataFromRegPolData
    match.end())
ValueError: substring not found

Versions Report

master branch

obi-juan-syn commented 4 years ago

would this be screensaver specific? on Windows 10 1903 (minion 2019.2.2):

machine_inactivity_limit:
  lgpo.set:
    - computer_policy:
        "Interactive logon: Machine inactivity limit": '300'
----------
          ID: machine_inactivity_limit
    Function: lgpo.set
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "C:\salt\bin\lib\site-packages\salt\state.py", line 1933, in call
                  **cdata['kwargs'])
                File "C:\salt\bin\lib\site-packages\salt\loader.py", line 1951, in wrapper
                  return f(*args, **kwargs)
                File "C:\salt\bin\lib\site-packages\salt\states\win_lgpo.py", line 267, in set_
                  hierarchical_return=False)
                File "C:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 7784, in get
                  return_not_configured=return_not_configured))
                File "C:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 6519, in _checkAllAdmxPolicies
                  for path_needed in unpathed_dict[policy_namespace]:
              KeyError: 'Microsoft.Policies.WindowsDefender'
     Started: 11:52:33.870000
    Duration: 21585.0 ms
     Changes:
----------
lomeroe commented 4 years ago

haven't looked deeply, but we still use 2018.3.4 in our environment, and I haven't been able to reproduce it for this policy or doing any of the steps listed

seems to be a regression introduced since that release

twangboy commented 4 years ago

We've updated the Administrative Templates, maybe that's why you're not able to reproduce it. https://www.microsoft.com/en-us/download/details.aspx?id=57576

I'm also using win_lgpo files from this PR: https://github.com/saltstack/salt/pull/55431 I'll try with an earlier version of win_lgpo... perhaps I broke something. Then I should be able to do a diff and see where I went wrong. Hopefully, it will be that easy.

twangboy commented 4 years ago

It was a regression... I was able to find it doing a git diff. Thanks @lomeroe