Skip to content
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

Don't create endpoint if attempting to create one with invalid dns name #3017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ func NewEndpointWithTTL(dnsName, recordType string, ttl TTL, targets ...string)
cleanTargets[idx] = strings.TrimSuffix(target, ".")
}

for _, label := range strings.Split(dnsName, ".") {
if len(label) > 63 {
log.Errorf("label %s in %s is longer than 63 characters. Cannot create endpoint", label, dnsName)
return nil
}
}

return &Endpoint{
DNSName: strings.TrimSuffix(dnsName, "."),
Targets: cleanTargets,
Expand Down
9 changes: 7 additions & 2 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpo
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true)).WithSetIdentifier(r.SetIdentifier)
txt.ProviderSpecific = r.ProviderSpecific
// new TXT record format (containing record type)
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true)).WithSetIdentifier(r.SetIdentifier)
txtNew.ProviderSpecific = r.ProviderSpecific
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true))
if txtNew != nil {
txtNew.WithSetIdentifier(r.SetIdentifier)
txtNew.ProviderSpecific = r.ProviderSpecific
} else {
return []*endpoint.Endpoint{txt}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we warn about this fallback is used?
I am not completely sure anymore about what behavior this will introduce in the long run.
I guess we loose only the ability to create other records of the same name, which seems ok for these kind of long records.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using a subdomain for the prefix was a mistake, I think. And I guess that is the migration path for those that need e.g AAAA-records.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already warn in NewEndpoingWithTTL. Warning again is perhaps redundant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you are right with the return nil it's the same case :)
Subdomain can be used as far as I see by using --txt-prefix or --txt-suffix or example similar to what was written in #2839 (comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

}

return []*endpoint.Endpoint{txt, txtNew}
}
Expand Down
10 changes: 10 additions & 0 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
newEndpointWithOwner("oldformat-otherowner.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=otherowner\"", endpoint.RecordTypeTXT, ""),
endpoint.NewEndpoint("unmanaged1.test-zone.example.org", endpoint.RecordTypeA, "unmanaged1.loadbalancer.com"),
endpoint.NewEndpoint("unmanaged2.test-zone.example.org", endpoint.RecordTypeCNAME, "unmanaged2.loadbalancer.com"),
newEndpointWithOwner("this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -847,6 +849,14 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
},
{
DNSName: "this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org",
Targets: endpoint.Targets{"foo.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
}

expectedMissingRecords := []*endpoint.Endpoint{
Expand Down