-
Notifications
You must be signed in to change notification settings - Fork 504
NEW PROVIDER: Netnod primary DNS #4191
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
base: main
Are you sure you want to change the base?
Changes from all commits
ed5ff58
0c97255
0b7b790
4eb0317
72a4b16
baa2925
2211401
973361b
94b7ae1
605d1e1
f873f38
de82216
dc32333
75368fb
b53ed0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| ## Configuration | ||
|
|
||
| To use this provider, add an entry to `creds.json` with `TYPE` set to `NETNOD` along with your API URL and API Key. The API URL can be omitted to use the default value `https://primarydnsapi.netnod.se`. | ||
|
|
||
| Example: | ||
|
|
||
| {% code title="creds.json" %} | ||
|
|
||
| ```json | ||
| { | ||
| "netnod": { | ||
| "TYPE": "NETNOD", | ||
| "apiKey": "your-key", | ||
| "apiUrl": "https://primarydnsapi.netnod.se" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ## Metadata | ||
|
|
||
| The following provider metadata is available: | ||
|
|
||
| {% code title="dnsconfig.js" %} | ||
|
|
||
| ```javascript | ||
| var DSP_NETNOD = NewDnsProvider('netnod', { | ||
| default_ns: ['a.example.com.', 'b.example.com.'], | ||
| also_notify: ['192.36.148.17', '2001:7fe::53'], | ||
| allow_transfer_keys: ['netnod-key1.'], | ||
| }); | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| - `default_ns` sets the nameservers used when creating zones. | ||
| - `also_notify` sets a list of IP addresses that will receive DNS NOTIFY messages when a zone is created. This is the provider-level default and applies to all zones unless overridden per zone. | ||
| - `allow_transfer_keys` sets the TSIG key IDs permitted to perform zone transfers from the distribution servers when a zone is created. | ||
| This should include all keys used for DNS secondary replication, including those used by the Netnod secondary DNS service. This is the provider-level default and applies to all zones unless overridden per zone. | ||
|
|
||
| ## Usage | ||
|
|
||
| An example configuration: | ||
|
|
||
| {% code title="dnsconfig.js" %} | ||
|
|
||
| ```javascript | ||
| var REG_NONE = NewRegistrar('none'); | ||
| var DSP_NETNOD = NewDnsProvider('netnod'); | ||
|
|
||
| D('example.com', REG_NONE, DnsProvider(DSP_NETNOD), A('test', '1.2.3.4')); | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ## Activation | ||
|
|
||
| See the [Netnod DNS](https://www.netnod.se/dns/dns-enterprise-services). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a sentence fragment. Consider expanding it to explain how users obtain API credentials, similar to how other provider docs handle this section.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API credentials are obtained by contacting Netnod using the details on the linked page. Is there any specific detail you think should be added? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package netnod | ||
|
|
||
| import ( | ||
| "github.com/DNSControl/dnscontrol/v4/models" | ||
| "github.com/DNSControl/dnscontrol/v4/pkg/rejectif" | ||
| ) | ||
|
|
||
| // AuditRecords returns a list of errors corresponding to the records | ||
| // that aren't supported by this provider. If all records are | ||
| // supported, an empty list is returned. | ||
| func AuditRecords(records []*models.RecordConfig) []error { | ||
| a := rejectif.Auditor{} | ||
|
|
||
| a.Add("TXT", rejectif.TxtHasDoubleQuotes) // Last verified 2026-05-19 | ||
| a.Add("TXT", rejectif.TxtHasBackslash) // Last verified 2026-05-19 | ||
|
|
||
| return a.Audit(records) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package netnod | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/DNSControl/dnscontrol/v4/models" | ||
| netnodPrimaryDNS "github.com/netnod/netnod-primary-dns-client" | ||
| ) | ||
|
|
||
| // toRecordConfig converts a Netnod DNS Record to a RecordConfig. #rtype_variations | ||
| func toRecordConfig(domain string, r netnodPrimaryDNS.Record, ttl int, name string, rtype string) (*models.RecordConfig, error) { | ||
| // trimming trailing dot and domain from name | ||
| name = strings.TrimSuffix(name, domain+".") | ||
| name = strings.TrimSuffix(name, ".") | ||
|
|
||
| rc := &models.RecordConfig{ | ||
| TTL: uint32(ttl), | ||
| Original: r, | ||
| Type: rtype, | ||
| } | ||
| rc.SetLabel(name, domain) | ||
|
|
||
| switch rtype { | ||
| case "TXT": | ||
| // API accepts long TXTs without requiring to split them. | ||
| // The API then returns them as they initially came in, e.g. "averylooooooo[...]oooooongstring" or "string" "string" | ||
| // So we need to strip away " and split into multiple string | ||
| // We can't use SetTargetRFC1035Quoted, it would split the long strings into multiple parts | ||
| return rc, rc.SetTargetTXTs(parseTxt(r.Content)) | ||
| default: | ||
| return rc, rc.PopulateFromString(rtype, r.Content, domain) | ||
| } | ||
| } | ||
|
|
||
| func parseTxt(content string) (result []string) { | ||
| for r := range strings.SplitSeq(content, "\" ") { | ||
| result = append(result, strings.Trim(r, "\"")) | ||
| } | ||
| return | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package netnod | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| netnodPrimaryDNS "github.com/netnod/netnod-primary-dns-client" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestToRecordConfig(t *testing.T) { | ||
| record := netnodPrimaryDNS.Record{ | ||
| Content: "simple", | ||
| } | ||
| recordConfig, err := toRecordConfig("example.com", record, 120, "test", "TXT") | ||
|
|
||
| assert.NoError(t, err) | ||
| assert.Equal(t, "test.example.com", recordConfig.NameFQDN) | ||
| assert.Equal(t, "\"simple\"", recordConfig.String()) | ||
| assert.Equal(t, uint32(120), recordConfig.TTL) | ||
| assert.Equal(t, "TXT", recordConfig.Type) | ||
|
|
||
| largeContent := fmt.Sprintf("\"%s\" \"%s\"", strings.Repeat("A", 300), strings.Repeat("B", 300)) | ||
| largeRecord := netnodPrimaryDNS.Record{ | ||
| Content: largeContent, | ||
| } | ||
| recordConfig, err = toRecordConfig("example.com", largeRecord, 5, "large", "TXT") | ||
|
|
||
| assert.NoError(t, err) | ||
| assert.Equal(t, "large.example.com", recordConfig.NameFQDN) | ||
| assert.Equal(t, `"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"`, | ||
| recordConfig.String()) | ||
| assert.Equal(t, uint32(5), recordConfig.TTL) | ||
| assert.Equal(t, "TXT", recordConfig.Type) | ||
|
|
||
| luaRecord := netnodPrimaryDNS.Record{ | ||
| Content: "TXT \"return 'Hello, world!'\"", | ||
| } | ||
| recordConfig, err = toRecordConfig("example.com", luaRecord, 3600, "script", "LUA") | ||
|
|
||
| assert.NoError(t, err) | ||
| assert.Equal(t, "script.example.com", recordConfig.NameFQDN) | ||
| assert.Equal(t, "LUA", recordConfig.Type) | ||
| assert.Equal(t, "TXT", recordConfig.LuaRType) | ||
| assert.Equal(t, "return 'Hello, world!'", recordConfig.GetTargetTXTJoined()) | ||
| assert.Equal(t, "TXT \"return 'Hello, world!'\"", recordConfig.GetTargetCombined()) | ||
| assert.Equal(t, uint32(3600), recordConfig.TTL) | ||
| } | ||
|
|
||
| func TestParseText(t *testing.T) { | ||
| // short TXT record | ||
| short := parseTxt("\"simple\"") | ||
| assert.Equal(t, []string{"simple"}, short) | ||
|
|
||
| // TXT record with multiple parts | ||
| multiple := parseTxt("\"simple\" \"simple2\"") | ||
| assert.Equal(t, []string{"simple", "simple2"}, multiple) | ||
|
|
||
| // long TXT record | ||
| long := parseTxt(fmt.Sprintf("\"%s\"", strings.Repeat("A", 300))) | ||
| assert.Equal(t, []string{strings.Repeat("A", 300)}, long) | ||
|
|
||
| // multiple long TXT record | ||
| multipleLong := parseTxt(fmt.Sprintf("\"%s\" \"%s\"", strings.Repeat("A", 300), strings.Repeat("B", 300))) | ||
| assert.Equal(t, []string{strings.Repeat("A", 300), strings.Repeat("B", 300)}, multipleLong) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.