Open eehret opened 5 months ago
I believe I have found the root cause of this one.
On Ubuntu 22+, the output of systemctl is including some white space before the service unit ID.
For example , using the same command syntax that would be used by the code here , on Ubuntu 18 we see output like the following:
azops.eric.ehret@022gc.onmicrosoft.com@epic-dv-wb-01:~$ sudo systemctl list-units --type=service --no-legend --all --no-pager cron.service
cron.service loaded active running Regular background program processing daemon
Whereas on Ubuntu 22+ , we see output like this:
azops.eric.ehret@022gc.onmicrosoft.com@atlas-sb-apps-01:~$ sudo systemctl list-units --type=service --no-legend --all --no-pager cron.service
cron.service loaded active running Regular background program processing daemon
I did the following to test how the nxService code (and its private dependency) would process this, I did the following:
PS C:\Users\EEHRET> $services = " cron.service loaded active running Regular background program processing daemon"
PS C:\Users\EEHRET> $id, $Load, $Active, $Status, $Description = $services -split '\s+',5
PS C:\Users\EEHRET> $id
PS C:\Users\EEHRET> $Load
cron.service
PS C:\Users\EEHRET> $Active
loaded
PS C:\Users\EEHRET> $Status
active
PS C:\Users\EEHRET> $Description
running Regular background program processing daemon
As you can see, the columns are offset due to the white space at the beginning of the systemctl output.
I believe an easy fix to this would be to simply trim whitespace from the beginning and ends of the systemctl output before attempting to split out the columns into each variable.
It appears that the above issue can also be avoided by adding an additional parameter to the --list-units command: '--plain'.
Here is the before and after:
azops.eric.ehret@022gc.onmicrosoft.com@atlas-sb-apps-01:~$ sudo systemctl list-units --type=service --no-legend --all --no-pager cron.service
cron.service loaded active running Regular background program processing daemon
azops.eric.ehret@022gc.onmicrosoft.com@atlas-sb-apps-01:~$ sudo systemctl list-units --type=service --no-legend --all --plain --no-pager cron.service
cron.service loaded active running Regular background program processing daemon
Details of the scenario you tried and the problem that is occurring
Our hardening configurations have some instances where we need to ensure that a given service is enabled and running. We've found that on Ubuntu Server 22.04 LTS, the nxService resource is reporting that these services are not running when in fact they are.
Verbose logs showing the problem
I don't know how to cause the GC agent to use verbose logs, but here is what it's outputting for one of the example resources that is returning the wrong status:
Then later, we see:
Meanwhile, systemctl shows that it actually is running:
Suggested solution to the issue
I don't know. This same configuration works for Ubuntu 20.04 LTS. I have not yet determined the reason it fails on 22.04 LTS.
The DSC configuration that is used to reproduce the issue (as detailed as possible)
The operating system the target node is running
Ubuntu Server 22.04 LTS
Version and build of PowerShell the target node is running
Not sure, I guess it's 7.2.0-preview3, judging by this information I found in the
powershell_check_supported_os.sh
script:Version of the DSC module that was used
1.4.0