Skip to content

Commit dbfbd31

Browse files
committed
Correctly handle TXT records with multiple heritages mixed with actual TXT targets
1 parent f0ad68a commit dbfbd31

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

registry/txt.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,41 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
145145
endpoints = append(endpoints, record)
146146
continue
147147
}
148-
// We simply assume that TXT records for the registry will always have only one target.
149148
// If there are no targets (e.g for routing policy based records in google), direct targets will be empty
150149
if len(record.Targets) == 0 {
151150
log.Errorf("TXT record has no targets %s", record.DNSName)
152151
continue
153152
}
154-
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)
155-
if errors.Is(err, endpoint.ErrInvalidHeritage) {
156-
// if no heritage is found or it is invalid
157-
// case when value of txt record cannot be identified
158-
// record will not be removed as it will have empty owner
159-
endpoints = append(endpoints, record)
160-
continue
161-
}
162-
if err != nil {
163-
return nil, err
164-
}
165153

166-
endpointName, recordType := im.mapper.toEndpointName(record.DNSName)
167-
key := endpoint.EndpointKey{
168-
DNSName: endpointName,
169-
RecordType: recordType,
170-
SetIdentifier: record.SetIdentifier,
154+
// Some of the targets in the TXT records may be heritage labels
155+
// filter them out and add them to the txtRecordsMap
156+
txtTargets := record.Targets
157+
record.Targets = endpoint.Targets {}
158+
for _, target := range txtTargets {
159+
labels, err := endpoint.NewLabelsFromString(target, im.txtEncryptAESKey)
160+
if errors.Is(err, endpoint.ErrInvalidHeritage) {
161+
// add target back into record.Targets as
162+
// this is not a heritage/label entry
163+
record.Targets = append(record.Targets, target)
164+
continue
165+
}
166+
if err != nil {
167+
return nil, err
168+
}
169+
170+
endpointName, recordType := im.mapper.toEndpointName(record.DNSName)
171+
key := endpoint.EndpointKey{
172+
DNSName: endpointName,
173+
RecordType: recordType,
174+
SetIdentifier: record.SetIdentifier,
175+
}
176+
labelMap[key] = labels
177+
txtRecordsMap[record.DNSName] = struct{}{}
178+
}
179+
180+
if len(record.Targets) != 0 {
181+
endpoints = append(endpoints, record)
171182
}
172-
labelMap[key] = labels
173-
txtRecordsMap[record.DNSName] = struct{}{}
174183
}
175184

176185
for _, ep := range endpoints {

0 commit comments

Comments
 (0)