Fix: tunnel route dns creates CNAME in wrong zone when user has multiple domains#1610
Open
StringerBell69 wants to merge 1 commit intocloudflare:masterfrom
Open
Fix: tunnel route dns creates CNAME in wrong zone when user has multiple domains#1610StringerBell69 wants to merge 1 commit intocloudflare:masterfrom
StringerBell69 wants to merge 1 commit intocloudflare:masterfrom
Conversation
When users have multiple domains, tunnel route dns would incorrectly use the default zoneID from the login certificate, creating an invalid CNAME record (e.g. app.domain1.com.domain2.com). This fix introduces ListZones in cfapi to fetch all valid zones for the account and explicitly checks if the provided hostname exactly matches or is a subdomain of a discovered zone, preventing this behavior and dynamically adjusting the endpoint to the correct Zone ID.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug in
cloudflared tunnel route dnswhere the CLI would incorrectly create a CNAME record in the wrong zone if the account manages multiple domains.The Issue
Previously, the RouteTunnel function blindly sent the route PUT request using the ZoneID embedded in the
cert.pemupon login. If a user was logged in withcert.pemtied todomain-A.com, but rancloudflared tunnel route dns <tunnel> app.domain-B.com, the API would attempt to create the DNS record inside thedomain-A.comnamespace (e.g. creatingapp.domain-B.com.domain-A.com).The Fix
cfapito correctly fetch all authorized zones attached to the user's account (leveraging fetchExhaustively to avoid missing pagination records).strings.HasSuffix(route.Hostname(), "."+zone.Name) || route.Hostname() == zone.Name) against the verified zones list from the API./zones/<ZoneID>/tunnels/<id>/routes) instead of falling back to the login certificate's default zone.Added comprehensive automated unit tests covering the exact matching, subdomain suffix mapping, and fallback logic if a zone fails to map.