Skip to content

Commit 1d536e5

Browse files
committed
feat(endpoint): reject alias property on unsupported record types
Signed-off-by: u-kai <76635578+u-kai@users.noreply.github.com>
1 parent d38daef commit 1d536e5

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

endpoint/endpoint.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,13 @@ func RemoveDuplicates(endpoints []*Endpoint) []*Endpoint {
444444
// TODO: rename to Validate
445445
// CheckEndpoint Check if endpoint is properly formatted according to RFC standards
446446
func (e *Endpoint) CheckEndpoint() bool {
447+
if !e.supportAlias() {
448+
if _, ok := e.GetBoolProviderSpecificProperty("alias"); ok {
449+
log.Debugf("Endpoint %s of type %s does not support alias records in ExternalDNS", e.DNSName, e.RecordType)
450+
return false
451+
}
452+
}
453+
447454
switch recordType := e.RecordType; recordType {
448455
case RecordTypeMX:
449456
return e.Targets.ValidateMXRecord()
@@ -453,6 +460,15 @@ func (e *Endpoint) CheckEndpoint() bool {
453460
return true
454461
}
455462

463+
func (e *Endpoint) supportAlias() bool {
464+
switch e.RecordType {
465+
case RecordTypeA, RecordTypeAAAA, RecordTypeCNAME:
466+
return true
467+
default:
468+
return false
469+
}
470+
}
471+
456472
// WithMinTTL sets the endpoint's TTL to the given value if the current TTL is not configured.
457473
func (e *Endpoint) WithMinTTL(ttl int64) {
458474
if !e.RecordTTL.IsConfigured() && ttl > 0 {

endpoint/endpoint_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,95 @@ func TestCheckEndpoint(t *testing.T) {
926926
},
927927
expected: true,
928928
},
929+
{
930+
description: "A record with alias=true is valid",
931+
endpoint: Endpoint{
932+
DNSName: "example.com",
933+
RecordType: RecordTypeA,
934+
Targets: Targets{"my-elb-123.us-east-1.elb.amazonaws.com"},
935+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
936+
},
937+
expected: true,
938+
},
939+
{
940+
description: "AAAA record with alias=true is valid",
941+
endpoint: Endpoint{
942+
DNSName: "example.com",
943+
RecordType: RecordTypeAAAA,
944+
Targets: Targets{"dualstack.my-elb-123.us-east-1.elb.amazonaws.com"},
945+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
946+
},
947+
expected: true,
948+
},
949+
{
950+
description: "CNAME record with alias=true is valid",
951+
endpoint: Endpoint{
952+
DNSName: "example.com",
953+
RecordType: RecordTypeCNAME,
954+
Targets: Targets{"d111111abcdef8.cloudfront.net"},
955+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
956+
},
957+
expected: true,
958+
},
959+
{
960+
description: "MX record with alias=true is invalid",
961+
endpoint: Endpoint{
962+
DNSName: "example.com",
963+
RecordType: RecordTypeMX,
964+
Targets: Targets{"10 mail.example.com"},
965+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
966+
},
967+
expected: false,
968+
},
969+
{
970+
description: "TXT record with alias=true is invalid",
971+
endpoint: Endpoint{
972+
DNSName: "example.com",
973+
RecordType: RecordTypeTXT,
974+
Targets: Targets{"v=spf1 ~all"},
975+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
976+
},
977+
expected: false,
978+
},
979+
{
980+
description: "NS record with alias=true is invalid",
981+
endpoint: Endpoint{
982+
DNSName: "example.com",
983+
RecordType: RecordTypeNS,
984+
Targets: Targets{"ns1.example.com"},
985+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
986+
},
987+
expected: false,
988+
},
989+
{
990+
description: "SRV record with alias=true is invalid",
991+
endpoint: Endpoint{
992+
DNSName: "_sip._tcp.example.com",
993+
RecordType: RecordTypeSRV,
994+
Targets: Targets{"10 5 5060 sip.example.com."},
995+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "true"}},
996+
},
997+
expected: false,
998+
},
999+
{
1000+
description: "MX record with alias=false is also invalid",
1001+
endpoint: Endpoint{
1002+
DNSName: "example.com",
1003+
RecordType: RecordTypeMX,
1004+
Targets: Targets{"10 mail.example.com"},
1005+
ProviderSpecific: ProviderSpecific{{Name: "alias", Value: "false"}},
1006+
},
1007+
expected: false,
1008+
},
1009+
{
1010+
description: "MX record without alias property is valid",
1011+
endpoint: Endpoint{
1012+
DNSName: "example.com",
1013+
RecordType: RecordTypeMX,
1014+
Targets: Targets{"10 mail.example.com"},
1015+
},
1016+
expected: true,
1017+
},
9291018
}
9301019

9311020
for _, tt := range tests {

0 commit comments

Comments
 (0)