Skip to content

Commit

Permalink
Merge pull request gardener#277 from gardener/fix/at-label-for-azure
Browse files Browse the repository at this point in the history
Tolerate apex label `@` on domain name validation
  • Loading branch information
MartinWeindel authored Sep 7, 2022
2 parents 7945771 + bea0477 commit 249c2a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/dns/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func calcMetaRecordDomainName(name, prefix, base string) string {
if name == base {
prefix += "-base."
}
} else if strings.HasPrefix(name, "@.") {
// special case: allow apex label for Azure
name = name[2:]
prefix += "---at."
}
return add + prefix + name
}
Expand All @@ -94,6 +98,9 @@ func MapFromProvider(name DNSSetName, rs *RecordSet) (DNSSetName, *RecordSet) {
dns = dns[len(prefix):]
if strings.HasPrefix(dns, "-base.") {
dns = dns[6:]
} else if strings.HasPrefix(dns, "---at.") {
dns = dns[6:]
add = "@."
} else if strings.HasPrefix(dns, ".") {
// for backwards compatibility of form *.comment-.basedomain
dns = dns[1:]
Expand Down
1 change: 1 addition & 0 deletions pkg/dns/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestMapToFromProvider(t *testing.T) {
{"a.myzone.de", true, "mycomment-a.myzone.de"},
{"*.a.myzone.de", false, "*.comment-a.myzone.de"},
{"*.myzone.de", false, "*.comment--base.myzone.de"},
{"@.myzone.de", false, "comment----at.myzone.de"},
}

rtype := RS_META
Expand Down
7 changes: 7 additions & 0 deletions pkg/dns/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func ValidateDomainName(name string) error {
var errs []string
if strings.HasPrefix(check, "*.") {
errs = validation.IsWildcardDNS1123Subdomain(check)
} else if strings.HasPrefix(check, "@.") {
// special case: allow apex label for Azure
errs = validation.IsDNS1123Subdomain(check[2:])
} else {
errs = validation.IsDNS1123Subdomain(check)
}
Expand All @@ -53,6 +56,10 @@ func ValidateDomainName(name string) error {

labels := strings.Split(strings.TrimPrefix(check, "*."), ".")
for i, label := range labels {
if i == 0 && label == "@" {
// special case: allow apex label for Azure
continue
}
if errs = validation.IsDNS1123Label(label); len(errs) > 0 {
return fmt.Errorf("%d. label %q of %q is not valid (%v)", i+1, label, name, errs)
}
Expand Down

0 comments on commit 249c2a7

Please sign in to comment.