dsccommunity / xPSDesiredStateConfiguration

DSC resources for configuring common operating systems features, files and settings.
https://dsccommunity.org
MIT License
209 stars 134 forks source link

[Bug] xGroupResource: Failing if current members list is empty #772

Open webalexeu opened 1 day ago

webalexeu commented 1 day ago

Problem description

DSC Get function is failing if members list is empty as he is expecting to receive an array and is receiving a null object

Verbose logs

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = Resourceget,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer NODE with user sid S-1-5-21-299789552-3643019550-3306914009-2117.
VERBOSE: [NODE]:                            [[xGroup]DirectResourceAccess] Invoking the function Get-TargetResourceOnFullSKU for the group Remote Management Users.
A general error occurred that is not covered by a more specific error code.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.61 seconds

DSC configuration

xGroupResource RemoteManagementUsers
        {
            GroupName        = @("Remote Management Users")
            Ensure           = "Present"
            MembersToInclude = @("administrator")
        }

Suggested solution

This old proposition is resolving the issue https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/353#issuecomment-367636987 and will handle all cases possible (empty, single member, multiple members)

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = Resourceget,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer NODE with user sid S-1-5-21-299789552-3643019550-3306914009-2117.
VERBOSE: [NODE]:                            [[xGroup]DirectResourceAccess] Invoking the function Get-TargetResourceOnFullSKU for the group Remote Management Users.
VERBOSE: [NODE]: LCM:  [ End    Get      ]  [[xGroup]DirectResourceAccess]  in 0.3240 seconds.
VERBOSE: [NODE]: LCM:  [ End    Set      ]    in  1.4680 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.

ConfigurationName    :
DependsOn            :
ModuleName           : C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet_x/xpsdesiredstateconfiguration/dsc_resources/xPSDesiredStateConfiguration/xPSDesiredStateConfiguration.psd1
ModuleVersion        : 9.2.0
PsDscRunAsCredential :
ResourceId           :
SourceInfo           :
Credential           :
Description          : Members of this group can access WMI resources over management protocols (such as WS-Management via the Windows Remote Management service). This applies only to WMI namespaces that grant access to the user.
Ensure               : Present
GroupName            : Remote Management Users
Members              :
MembersToExclude     :
MembersToInclude     :
PSComputerName       : localhost

VERBOSE: Time taken for configuration job to complete is 1.876 seconds

What is your opinion on this so I can prepare the PR according and also add unit testing for this scenario

Thank you

Operating system the target node is running

OsName               : Microsoft Windows Server 2022 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 20348.859.amd64fre.fe_release_svc_prod2.220707-1832
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.20348.2652
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.2652
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

xPSDesiredStateConfiguration version

Name                         Version Path
----                         ------- ----
xPSDesiredStateConfiguration 9.2.0   C:\ProgramData\PuppetLabs\puppet\cache\lib\puppet_x\xpsdesiredstateconfiguration\dsc_resources\xPSDesiredStateConfiguration\xPSDesiredStateConfiguration.psd1
johlju commented 21 hours ago

Send in a PR for it, also add tests that validates the change 🙂