StackExchange / dnscontrol

Infrastructure as code for DNS!
https://dnscontrol.org/
MIT License
3.11k stars 396 forks source link

M365_BUILDER Support for Second Level Domains #3162

Open CJFelto opened 4 hours ago

CJFelto commented 4 hours ago

Describe the bug Using the production version of the M365_BUILDER in v4.14.0 produces incorrect output with second level domains

To Reproduce Steps to reproduce the behavior: Below is an example of an affected record

M365_BUILDER("example.co.nz", {
    initialDomain: 'exampleconz.onmicrosoft.com'
    , dkim: true
    , skypeForBusiness: true
    , mdm: true
    , mx: true
    , autodiscover: true
})

This produces the following record selector2-example-co.nz._domainkey.exampleconz.onmicrosoft.com.

Expected behavior Microsoft expects the record to be formatted as below selector2-example-co-nz._domainkey.exampleconz.onmicrosoft.com.

Workaround I have overridden the M365_BUILDER function in my build of DNSControl with the only change being the highlighted line below

    if (!value.domainGUID) {
        // Does not work with dashes in domain name.
        // Microsoft uses its own, (probably) deterministic algorithm to transform these domains.
        // Unfortunately, underlying algorithm is not known to us.
        if (name.indexOf('-') !== -1) {
            throw (
                'M365_BUILDER requires domainGUID for domains with dashes: ' +
                name
            );
        }

        value.domainGUID = name.replace(/\./g, '-'); <- Changed from value.domainGUID = name.replace('.', '-');
    }

Changing to the Regex pattern now produces the expected output below selector2-example-co-nz._domainkey.exampleconz.onmicrosoft.com.

DNS Provider Cloudflare

Additional context I have also tested this for domains deeper than second level, I.E (marketing.example.co.nz) With the regex above this will produce selector2-marketing-example-co-nz._domainkey.exampleconz.onmicrosoft.com. This matched what Microsoft requested

ucdelerium commented 4 hours ago

This was also an issue for me.