Skip to content

[release-1.21] fix(digitalocean): paginate TXT record lookups in findTxtRecord - #9244

Open
wallrj wants to merge 1 commit into
cert-manager:release-1.21from
wallrj:cherry-pick-9101-release-1.21
Open

wallrj wants to merge 1 commit into
cert-manager:release-1.21from
wallrj:cherry-pick-9101-release-1.21

Conversation

@wallrj

@wallrj wallrj commented Sep 1, 2026

Copy link
Copy Markdown
Member

Manual cherry-pick of #9101 (fixes #9099) for v1.21.2; the automated cherry-pick failed with conflicts.

The production code change (digitalocean.go) is picked unchanged. The new tests needed adapting, because they were written against the DNS provider options/resolver API that only exists on master:

  • newTestProvider uses NewDNSProviderCredentials, the constructor on release-1.21, instead of NewDNSProviderFromOptions.
  • Dropped TestCleanUpOnlyDeletesMatchingValue and the fake resolver it needs: release-1.21 has no injectable resolver, so exercising CleanUp would perform live DNS lookups via util.FindZoneByFqdn. The value-matching guard that test covers is already present on release-1.21. The three findTxtRecord tests (server-side filter, pagination, no-match) are picked unchanged — findTxtRecord takes the zone directly and needs no DNS resolution.

go vet and go test ./pkg/issuer/acme/dns/digitalocean/... pass locally.

The DigitalOcean DNS-01 solver no longer leaves stale `_acme-challenge` TXT records behind when a zone has more than 20 TXT records. Previously, `CleanUp` silently failed to find (and therefore delete) challenge records in zones above that size because record lookups were not paginated.

/assign wallrj
/kind bug

with claude fable-5

@cert-manager-prow cert-manager-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. area/acme Indicates a PR directly modifies the ACME Issuer code area/acme/dns01 Indicates a PR modifies ACME DNS01 provider code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 1, 2026
@wallrj wallrj mentioned this pull request Sep 1, 2026
39 of 41 tasks
…-manager#9101)

* fix(digitalocean): paginate TXT record lookups in findTxtRecord

The DigitalOcean DNS-01 solver listed a zone's TXT records with nil
godo.ListOptions, so the DigitalOcean API silently capped the response
at its default page size of 20 and only the first page was ever
inspected. Challenge records are always the newest (highest-ID)
records in a zone, so any zone holding more than ~20 TXT records would
never match a challenge record: CleanUp deleted nothing and Present's
duplicate-record check never found an existing record, with no error
surfaced anywhere.

findTxtRecord now pages through the full result set using an explicit
per_page and a loop over Response.Links, so it always inspects every
TXT record in the zone regardless of size.

It also now takes the zone name as a parameter instead of re-resolving
it via DNS internally (Present/CleanUp already know it), which avoids
a redundant lookup and makes the function directly unit-testable
against a mocked DigitalOcean API.

Fixes cert-manager#9099

Signed-off-by: Abmun <[email protected]>

* fixup: address review feedback from @wallrj

- CleanUp now only deletes the TXT record whose value matches the
  challenge being cleaned up, instead of every record sharing its
  name. With pagination now surfacing records beyond page 1, the
  previous behaviour would delete a sibling challenge's record (e.g.
  concurrent example.com + *.example.com orders) out from under it.

- findTxtRecord now uses godo's server-side RecordsByTypeAndName
  filter instead of listing every TXT record in the zone and matching
  client side. This cuts requests against large zones down to
  ~1 per lookup and closes a race where an unsnapshotted, unfiltered
  paginated listing could skip a record if another challenge
  concurrently created/deleted records in the same zone while the
  loop was walking pages.

- Removed the resp == nil dead branch in the pagination loop (godo
  guarantees resp is non-nil whenever err is nil, so this arm could
  only ever silently truncate results were it ever reachable) and
  replaced reliance on Links.CurrentPage() (which pins at 2 forever
  if a page ever has next but no prev) with a simple incrementing
  page counter.

- Test fake DigitalOcean server now enforces the type+name filter
  server-side rather than returning every record for the client to
  filter, so the tests actually exercise production code paths.
  Replaced fmt.Sscanf-based page parsing with strconv.Atoi to match
  how godo itself parses page numbers.

- Added TestCleanUpOnlyDeletesMatchingValue and
  TestFindTxtRecordFiltersServerSide regression tests; adapted the
  pagination test to the server-side-filtered scenario (many records
  sharing one name) since a name filter makes cross-page misses on
  unrelated records impossible by construction.

Signed-off-by: Abmun <[email protected]>

* fixup: satisfy golangci-lint (intrange, unparam)

CI flagged three issues in the new test helpers:

- pkg/issuer/acme/dns/digitalocean/digitalocean_test.go:354: for loop
  can use Go 1.22+ integer range (intrange). Switched
  'for i := 0; i < 25; i++' to 'for i := range 25'.

- newFakeDOServer's domain parameter and newTestProvider's zone
  parameter always received the same value at every call site
  (unparam), since every test in this file uses the same fake zone.
  Replaced both parameters with shared testDomain/testZone constants
  and dropped fakeDORecord.fullName's domain parameter for the same
  reason.

Signed-off-by: Abmun <[email protected]>

---------

Signed-off-by: Abmun <[email protected]>
(cherry picked from commit 578dc72)
Signed-off-by: Richard Wall <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
@wallrj
wallrj force-pushed the cherry-pick-9101-release-1.21 branch from d2fc1a6 to 86749ca Compare September 1, 2026 13:13
@wallrj

wallrj commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Fixed the verify-golangci-lint failure: dropping the CleanUp test in this backport left newFakeDOServer's second return value unused (unparam), so it now returns only the *httptest.Server.

with claude fable-5

@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from wallrj. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@wallrj

wallrj commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

/hold

@cert-manager-prow cert-manager-prow Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/acme/dns01 Indicates a PR modifies ACME DNS01 provider code area/acme Indicates a PR directly modifies the ACME Issuer code dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants