StackExchange / dnscontrol

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

Add a REDIRECT record, deprecate URL/URL301/FRAME records #1842

Open j-f1 opened 1 year ago

j-f1 commented 1 year ago

Several providers support configuring a domain name to be redirected to another URL:

As discussed by @tlimoncelli in https://github.com/StackExchange/dnscontrol/issues/1539#issuecomment-1160733399 and https://github.com/StackExchange/dnscontrol/pull/1827#issuecomment-1331417650, this is problematic. Based on my research:

Proposed API:

REDIRECT("foo", "https://example.com") // invalid
REDIRECT("foo", "https://example.com", TEMPORARY_REDIRECT) // valid for Namecheap/CF/NS1/ClouDNS
REDIRECT("foo", "https://example.com", PERMANENT_REDIRECT) // valid for Namecheap/CF/DNSimple/NS1/ClouDNS
REDIRECT("foo", "https://example.com", MASKED_REDIRECT) // valid for Namecheap/NS1/ClouDNS

Some options for how path redirects could be handled:

REDIRECT("foo", "https://example.com",
    TEMPORARY_REDIRECT,
    CF_REDIRECT_PATH("/foo/bar/*"))
REDIRECT("foo", "https://example.com",
    TEMPORARY_REDIRECT,
    CF_REDIRECT({ path: "/foo/bar/*" }))
REDIRECT("foo", "https://example.com",
    TEMPORARY_REDIRECT,
    CF_REDIRECT({ from: "/foo/bar/*" }))
tlimoncelli commented 1 year ago

This is definitely in the right direction.

What do we do if (for example) a DNS provider doesn't support "masked" domains? Should that silently fail or should the provider return an error if it sees any flags/options it doesn't recognize?

I think the answer is that it should error if it sees a flag it doesn't recognize. That way we can even add flags for provider-specific things like CF_REDIRECT().

(Implementation detail: This is easy to implement. We can use the auditrecord.go system, or require the providers to return an error if they don't recognize an option. Option names would be in the form redirect_* to make it easy to implement.)