Skip to content
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
2 changes: 1 addition & 1 deletion docs/sources/mx-record.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MX record with CRD source

You can create and manage MX records with the help of [CRD source](../sources/crd.md)
and `DNSEndpoint` CRD. Currently, this feature is only supported by `aws`, `azure`, `cloudflare`, `digitalocean` and `google` providers.
and `DNSEndpoint` CRD. Currently, this feature is only supported by `aws`, `azure`, `cloudflare`, `digitalocean`, `google` and `webhook` providers.

In order to start managing MX records you need to set the `--managed-record-types=MX` flag.

Expand Down
16 changes: 11 additions & 5 deletions source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,20 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
if (ep.RecordType == endpoint.RecordTypeCNAME || ep.RecordType == endpoint.RecordTypeA || ep.RecordType == endpoint.RecordTypeAAAA) && len(ep.Targets) < 1 {
log.Debugf("Endpoint %s with DNSName %s has an empty list of targets, allowing it to pass through for default-targets processing", dnsEndpoint.Name, ep.DNSName)
}
isNAPTR := ep.RecordType == endpoint.RecordTypeNAPTR
isTXT := ep.RecordType == endpoint.RecordTypeTXT
illegalTarget := false
for _, target := range ep.Targets {
hasDot := strings.HasSuffix(target, ".")
// Skip dot validation for TXT records as they can contain arbitrary text
if !isTXT && ((isNAPTR && !hasDot) || (!isNAPTR && hasDot)) {
illegalTarget = true

switch ep.RecordType {
case endpoint.RecordTypeTXT, endpoint.RecordTypeMX:
continue // TXT records allow arbitrary text, skip validation; MX records can have trailing dot but it's not required, skip validation
case endpoint.RecordTypeNAPTR:
illegalTarget = !hasDot // Must have trailing dot
default:
illegalTarget = hasDot // Must NOT have trailing dot
}

if illegalTarget {
break
}
}
Expand Down
42 changes: 42 additions & 0 deletions source/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,48 @@ func testCRDSourceEndpoints(t *testing.T) {
expectEndpoints: false,
expectError: false,
},
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we have test without trailing dot as well

title: "MX Record allowing trailing dot in target",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{"example.com."},
RecordType: endpoint.RecordTypeMX,
RecordTTL: 180,
},
},
expectEndpoints: true,
expectError: false,
},
{
title: "MX Record without trailing dot in target",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
labelFilter: "test=that",
endpoints: []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{"example.com"},
RecordType: endpoint.RecordTypeMX,
RecordTTL: 180,
},
},
expectEndpoints: true,
expectError: false,
},
} {
t.Run(ti.title, func(t *testing.T) {
t.Parallel()
Expand Down
Loading