Skip to content

Fix broken DNS lookups for responses with long TXT records or multiple TXT records#561

Merged
openshift-merge-bot[bot] merged 3 commits intocontainers:mainfrom
fessyfoo:fix-txt-bugs-fess
Oct 24, 2025
Merged

Fix broken DNS lookups for responses with long TXT records or multiple TXT records#561
openshift-merge-bot[bot] merged 3 commits intocontainers:mainfrom
fessyfoo:fix-txt-bugs-fess

Conversation

@fessyfoo
Copy link
Copy Markdown
Contributor

@fessyfoo fessyfoo commented Oct 22, 2025

Any feedback is accepted and appreciated.

This addresses two distinct issues in the same part of the code

  1. Long TXT records:

DNS lookups of long TXT records were timing out and logging "string exceeded 255 bytes in txt".

While (net.Resolver).lookupTXT concatenates multiple underlying strings into a single string per TXT RR, the (dns.TXT).Txt field (miekg/dns) requires a slice of strings, each 255 bytes or less, for correct packing.

The fix ensures the value from lookupTXT is split into a slice of appropriately sized strings before being assigned to (dns.TXT).Txt, preventing the eventual error from dns.packTxtString

  string exceeded 255 bytes in txt
  1. Multiple TXT records:

Multiple TXT records were being concatenated together into one.

Each string returned by (net.Resolver).lookupTXT represents a separate resource record. The old code code was adding each of them to the same resource record as a new character string.

we now correctly create a new resource record for each string

Fixes #562
Fixes #563

@fessyfoo
Copy link
Copy Markdown
Contributor Author

fessyfoo commented Oct 22, 2025

Note: the tests already relied on public dns of redhat.com, and this test adds google.com, and gmail.com to that set. It might be better to refactor pkg/service/dns to be able to pass in an alternate net.Resolver and remove those live dns dependencies from the tests. But i didn't take that on as it would have made for more changes than actual bug fix, so it deserves it's own commit.

Also notiing, I found my way here via using docker on colima, to managing an smtp server doing dkim record lookups. colima, using lima, using gvisor-tap-vsock

@fessyfoo
Copy link
Copy Markdown
Contributor Author

remove those live dns dependencies from the tests

looks like go-mockdns will make that doable

@fessyfoo
Copy link
Copy Markdown
Contributor Author

looks like go-mockdns will make that doable

done.. pushed update.

@cfergeau
Copy link
Copy Markdown
Collaborator

Thanks for the fixes/explanations! the mockdns changes are nice :) We have control over the crc.dev DNS config, so an alternative is to add the records we need for testing there.

Could you use a real name for the Signed-off-by annotations?

/lgtm

This commit addresses two distinct issues in the same part of the code

1. Long TXT records:

DNS lookups of long TXT records were timing out and logging
"string exceeded 255 bytes in txt".

While (net.Resolver).lookupTXT concatenates multiple underlying strings
into a single string per TXT RR, the (dns.TXT).Txt field (miekg/dns)
requires a slice of strings, each 255 bytes or less, for correct packing.

The fix ensures the value from lookupTXT is split into a slice of
appropriately sized strings before being assigned to (dns.TXT).Txt,
preventing the eventual error from dns.packTxtString

      "string exceeded 255 bytes in txt"

2. Multiple TXT records:

Multiple TXT records were being concatenated together into one.

Each string returned by (net.Resolver).lookupTXT represents a separate
resource record. The old code code was adding each of them to the same
resource record as a new character string.

we now correctly create a new resource record for each string

Signed-off-by: John "fess" Fessenden <fess-Z3Zpc29yCg@fess.org>
to be used ins dns_test.go

Signed-off-by: John "fess" Fessenden <fess-Z3Zpc29yCg@fess.org>
no longer relying on external dns for the tests

Signed-off-by: John "fess" Fessenden <fess-Z3Zpc29yCg@fess.org>
@openshift-ci openshift-ci bot removed the lgtm label Oct 23, 2025
@fessyfoo
Copy link
Copy Markdown
Contributor Author

Could you use a real name for the Signed-off-by annotations?

updated.

@fessyfoo
Copy link
Copy Markdown
Contributor Author

fessyfoo commented Oct 23, 2025

the mockdns changes are nice :) We have control over the crc.dev DNS config, so an alternative is to add the records we need for testing there.

putting DNS fixtures into public DNS controlled by the project would work.
It would keep an extra dep (go-mockdns) out of the code.

go-mockdns reduces dependency on the network in general, and allows new tests to be added without coordinating the new public fixtures, or coming up with a way to mock in them before getting new public fixtures. ( Which, admittedly wasn't that hard in this case I just used a live example. )

I think it's a toss up, either way is ok.

I slightly prefer the mockdns approach for less dependency on the external network in general.

LMK how you want to proceed.

@cfergeau
Copy link
Copy Markdown
Collaborator

/retest

@cfergeau
Copy link
Copy Markdown
Collaborator

Could you use a real name for the Signed-off-by annotations?

updated.

Not sure why the DCO check complains, I’ll force it to "pass".

I think it's a toss up, either way is ok.

I slightly prefer the mockdns approach for less dependency on the external network in general.

LMK how you want to proceed.

The mockdns approach is more flexible, and is done already, let’s go this way, we can always switch back to the other option later if we realize mockdns no longer fits our needs.

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Oct 24, 2025
@cfergeau
Copy link
Copy Markdown
Collaborator

Not sure why the DCO check complains, I’ll force it to "pass".

There’s actually an explanation,the check is being very strict in its expectations:

Author: fess, Committer: fess; Expected "fess fess@fess.org", but got "John "fess" Fessenden fess-Z3Zpc29yCg@fess.org".

I’ve told it it’s fine.

@cfergeau
Copy link
Copy Markdown
Collaborator

/approve

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Oct 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau, fessyfoo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit ddbf9a7 into containers:main Oct 24, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants