Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rchristman89 opened this issue Sep 23, 2019 · 2 comments
Labels
discussion The issue is a discussion.

Comments

@rchristman89
Copy link

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.

@39Delta
Copy link
Contributor

39Delta commented Sep 23, 2019

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.

@rchristman89
Copy link
Author

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

@PlagueHO PlagueHO added the discussion The issue is a discussion. label Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion The issue is a discussion.
Projects
None yet
Development

No branches or pull requests

3 participants