NetworkingDsc icon indicating copy to clipboard operation
NetworkingDsc copied to clipboard

MSFT_HostsFile: Host entries that have multiple entries on a single line fail

Open rchristman89 opened this issue 6 years ago • 2 comments

Details of the scenario you tried and the problem that is occurring

When defining multiple entries on a single line it will write them to the host file every time the LCM kicks off.

Line 233 -259 takes in account for multiple entries per line but then a compare happens later against that array and a string that was passed into the Get-HostEntry.

Suggested solution to the issue

Change line 368 FROM: if ($result.Host -eq $HostName) TO: if ([string]$result.Host -eq HostName)

The DSC configuration that is used to reproduce the issue (as detailed as possible)

HostsFile "Test1"
            {
                HostName  = 'test-ocsp-responder testVM.lab.local'
                IPAddress = '192.168.1.50'
                Ensure    = 'Present'
            }

The operating system the target node is running

OsName               : Microsoft Windows Server 2012 R2 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 9600.19358.amd64fre.winblue_ltsb_escrow.190505-1600
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

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

Version of the DSC module that was used ('dev' if using current dev branch)

6.1.0.0 The code for this issue looks the same.

rchristman89 avatar Sep 23 '19 20:09 rchristman89

The hostname variable is a key property and appears to be intended for use with a single hostname value. If it supported multiple hostname entries then it could create a resource state conflict like the following:

HostsFile "Test1"
{
    HostName  = 'test-ocsp-responder testVM.lab.local'
    IPAddress = '192.168.1.50'
    Ensure    = 'Present'
}

HostFile "Test2"
{
    HostName  = 'test-ocsp-responder'
    IPAddress = '192.168.1.50'
    Ensure    = 'Absent'
}

There would be no errors generated in the configuration block (or in the case of partials by the LCM when published) because the key properties are unique. Then during execution one resource Test1 would attempt to add a host entry while the second Test2 would work to remove it.

I think the resource needs more checks in place if the intended input is supposed to be limited to a single host. In its current form it handles single host entries correctly and needs to be configured iteratively for each hostname that shares an IPAddress to work properly.

39Delta avatar Sep 23 '19 21:09 39Delta

After talking with @39Delta and discovering that every entry after the first is a CNAME I would recommend we add a parameter for CNAME to this resource and not allow multiple entries in the HostName parameter.

test-ocsp-responder
    ----------------------------------------
    Record Name . . . . . : test-ocsp-responder
    Record Type . . . . . : 1
    Time To Live  . . . . : 86400
    Data Length . . . . . : 4
    Section . . . . . . . : Answer
    A (Host) Record . . . : 192.168.0.252


    test-ocsp-responder2
    ----------------------------------------
    Record Name . . . . . : test-ocsp-responder2
    Record Type . . . . . : 5
    Time To Live  . . . . : 86400
    Data Length . . . . . : 8
    Section . . . . . . . : Answer
    CNAME Record  . . . . : test-ocsp-responder

rchristman89 avatar Sep 23 '19 23:09 rchristman89