-
Notifications
You must be signed in to change notification settings - Fork 408
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
NEW PROVIDER: Azure Private DNS Zones #2626
Conversation
Greetings! Thanks for submitting this! I didn't know private zones were handled differently.
If I can show you how to make a feature flag, would you consider adopting the AZURE_DNS provider to work with Azure Private DNS Zones? Having one provider instead of 2 has benefits. |
The only issue I see with making them one provider is that they are technically different products from Azure with different API end points, different name spaces, and different supported record types (CAA for example is not supported in Azure Private DNS). For example on the different name spaces, the call to nativeToRecordTypeDiff2 would have to be passed a flag to determine if it's a Azure private zone or an Azure public zone since the result set from Azure for the query are two different types. If you think it's still possible to merge them together I'm open to trying it, just don't yet understand enough about the internals of dnscontrol to see how to make that happen without breaking the existing Azure module. |
Understood. Let's give it a try and see if we can make this work. Basically you will add a field to the azurednsProvider struct that indicates which will be set to true for "private". For example, set azurednsProvider.isPrivateDNSMode to true to enable the new mode. Then recordToNativeDiff2 can look at a.privateDNSmode any time it needs to act differently. There are 2 ways to pass feature flags to a provider. (1) In creds.json:
A good example of this is in (2) Or in dnsconfig.js itself when you declare the provider:
A good example of this is the cloudflareapi driver where it uses It's up to you which user experience makes more sense. Would a typical Azure user have different creds for private zones? Another way to look at this decision would be to consider how the documentation would read: (1) Note: If you are using Azure Private DNS, the entry in creds.json needs Tom P.S. Rather than updating nativeToRecordTypeDiff2, it |
I started looking at making them the same and it's really a mess to combine the two. Take the basic structure of the client. For azure you have this: type azurednsProvider struct { Whereas for Azure Private you have this: type azurePrivateDnsProvider struct { The zonesClient, recordsClient, and zones would all have to be duplicated for private zones, and then everywhere in the code the zones or record client is used an if statement put in to determine which to use. From my point of view given they use two different APIs and record types it's really best to keep them as seperate clients but if after reading this you still think it's worth trying to merge them I can give it a shot. |
Welp, looks like we're going with two separate providers. Thanks for humoring me. I conferred with my co-workers who pointed out: All the tools that interact with Azure DNS seem to separate the two (az cli, az pwsh, terraform, etxternal-dns). At least we're in good company! I'll do a code-review soon. Best, |
{% endcode %} | ||
|
||
## Metadata | ||
This provider does not recognize any special metadata fields unique to Azure DNS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provider does not recognize any special metadata fields unique to Azure DNS. | |
This provider does not recognize any special metadata fields unique to Azure Private DNS. |
} | ||
} else { | ||
panic(fmt.Errorf("nativeToRecords rtype %v unimplemented", *set.Type)) | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these commented out sections of code. (here and elsewhere)
var results []*models.RecordConfig | ||
switch rtype := *set.Type; rtype { | ||
case "Microsoft.Network/privateDnsZones/A": | ||
if set.Properties.ARecords != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more "go style" to reverse the logic:
if set.Properties.ARecords == nil { return nil, fmt.Errorf(..) }
for _, rec := range set.Properties.ARecords {
...
}
This creates more readable code and less indenting.
(same for the other cases)
|
||
// NOTE recordToNativeDiff2 is really "convert []RecordConfig to rrset". | ||
|
||
func (a *azurednsProvider) recordToNativeDiff2(recordKey models.RecordKey, recordConfig []*models.RecordConfig) (*adns.RecordSet, adns.RecordType, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do a global search and replace of recordToNativeDiff2
to recordToNative
func (a *azurednsProvider) recordToNativeDiff2(recordKey models.RecordKey, recordConfig []*models.RecordConfig) (*adns.RecordSet, adns.RecordType, error) { | ||
|
||
recordKeyType := recordKey.Type | ||
// if recordKeyType == "AZURE_ALIAS" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the commented out code (and the comment).
} | ||
|
||
func (a *azurednsProvider) EnsureZoneExists(domain string) error { | ||
if _, ok := a.zones[domain]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns nil either way. Shouldn't it create the zone if it doesn't exist?
A lot has changed on the master banch. I've rebased (using the Github Web UI) so I can review it in light of the new TXT-related helper functions. |
I've committed a new change with the suggested edits to replace .TxtStrings with GetTargetTXTJoined |
Thanks! I'm sure you've seen the checklist at the end of https://docs.dnscontrol.org/service-providers/providers#providers-with-contributor-support but I want to make sure you saw this: Expectations of maintainers:
(I just added the last bullet. I'll update the official docs soon.) Once I get the email from you, I'll merge this PR. Thanks again for contributing this provider! I think it will find a lot of use! Tom |
The current Azure DNS provider does not allow you to manage Azure Private DNS Zones with dnscontrol, which is something I'd like to be able to do since the rest of our DNS infrastructure is managed currently with dnscontrol.
It's mostly based on the existing Azure DNS provider, with the required Azure API changes to modify private DNS zones instead of public ones. The only major limitation of Azure Private DNS is that it does not support NS records (which makes sense) but there currently isn't a feature flag for this in dnscontrol so it will fail if someone attempts to add an NS record using this provider.