Skip to content

fix(dns): replace records in place with dns set and confirm the final result - #359

Merged
jpage-godaddy merged 5 commits into
mainfrom
api-dns-set
Nov 16, 2026
Merged

jpage-godaddy merged 5 commits into
mainfrom
api-dns-set

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

What changes for users

gddy dns set now replaces each record it keeps with a single in-place update, instead of creating the new value and then deleting the old record.

  • Safer replace. A replaced record keeps its ID, and a TTL-only change is one call. If an update fails, the existing record is left as it was; it can no longer end up with both the old and new value at the name.
  • unchanged count. A record that already matches what you asked for is reported as unchanged and left alone, so running the same set twice changes nothing the second time. replaced no longer includes these. Anything parsing set's JSON will see replaced drop and a new unchanged field. The dry-run preview reports the same.
  • Matching follows how the API stores records. Names and hostname targets (CNAME, ALIAS, MX, SRV, HTTPS, SVCB) are compared without case or a trailing dot, and CAA data and TLSA hex without case, so Example.COM matches a stored example.com.. Values the API keeps as written (TXT text, AAAA addresses, HTTPS/SVCB parameters, SRV service and protocol) are compared exactly. This PR also uses the same comparison for the final check.
  • TTL is kept. A replaced record keeps its current TTL unless you pass --ttl. Previously it was reset to 3600.
  • Result lists the records. The output includes the records now at the type and name, with their IDs and TTLs, as read back after the change.
  • Final check. After writing, set reads the type and name back and fails if the records there are not the ones you asked for, for example because someone else changed them while it ran. The error lists what is extra and what is missing (with TTLs when --ttl was given) and nothing is removed.
  • --ttl validated up front for dns add and dns set: 600 to 86400 seconds, from the API spec. Out-of-range values fail locally with a clear message instead of an API error.
  • Full SRV/TLSA names are rejected by add and set. --name _sip._tcp.chat could create a record at a nested name nobody asked for, or move an existing record there, because the API composes the DNS name from the record's name plus its service and protocol. Both commands now refuse it before any request and name the --name and flags to use instead. list and delete still accept either form, since they only look records up.
  • Required flags are checked up front. MX, SRV, HTTPS and SVCB need --priority; SRV also needs --weight, --port, --service and --protocol; TLSA needs --port and --protocol as well as usage, selector and matching type. A missing one is reported with the other missing flags before login, instead of as a 400 from the API.
  • --service and --protocol take the plain name. --service sip --protocol tcp and --service _sip mean the same thing: the underscore DNS requires is added when it is left off, and a value that cannot be a label is rejected with an example. Records are shown in the underscore form (--fields service,protocol, or JSON), since that is the DNS name.
  • CAA --flag defaults to 0. The API requires a flag on CAA records, so dns add/dns set without --flag used to fail. An omitted flag now means 0 (non-critical).

Under the hood

Verification

  • cargo check --workspace, cargo clippy --workspace -- -D warnings, cargo fmt --check, cargo test --workspace (1271 tests in the main crate) and ./rust/scripts/check-module-size.sh all pass.
  • Run live against a throwaway zone in the test environment:
    • a one-record replace changed only that record and kept its ID, with the other records in the zone untouched (the gddy dns set wipes the entire zone — issues a PUT to a non-existent v3 dns-records endpoint that the API executes as a full-collection replace #136 failure did not reproduce);
    • re-running an identical set reported everything unchanged, including a CNAME given as Example.COM and a CAA record given without --flag;
    • --ttl retimed records, and an omitted --ttl kept the stored TTL;
    • a second writer adding a record mid-run was reported by the final check, and the record was left in place;
    • CNAME conflicts with --replace-conflicting-types worked in both directions.
    • SRV records: a replace in place (new data, new name, and no change at all) now succeeds, including at the zone apex; the API returned a 500 for every one of those until it was fixed on the DNS side. A composed-name set is refused with the record untouched, and a plain --service sip --protocol tcp set reports a stored _sip/_tcp record as unchanged.
  • Not verified against production. The change relies on the API's replace operation, and the fixes to it for SRV, behaving the same there as in the test environment. ALIAS could only be covered by a unit test: the test environment's API rejects it on write. TLSA is covered by unit tests only, because the test zone has no DNSSEC and so a TLSA record cannot be created there.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Final-state verification can miss changes to case-sensitive values and return stale record metadata, while inconsistent content comparisons cause unnecessary updates on repeated runs.

3 open issues
What changed in this PR

Updates dns set to replace individual records in place and verify the resulting record set, replacing the create/delete approach introduced after #136.

Changes:

  • Restores single-record PUT updates, preserves existing TTLs when omitted, and reports unchanged records separately.
  • Adds final-state verification and includes records with IDs in successful output.
  • Validates TTLs locally and updates tests and customer guidance.
File Description
rust/​tools/​generate-api-catalog/​src/​domains_spec.rs Stops removing the DNS replace operation during generation.
rust/​src/​dns/​set/​write.rs Uses in-place updates and preserves stored TTLs.
rust/​src/​dns/​set/​write_tests.rs Tests PUT updates, failures, conflicts, and TTL handling.
rust/​src/​dns/​set/​verify.rs Adds final-state comparison and mismatch reporting.
rust/​src/​dns/​set/​verify_tests.rs Covers comparison rules and read-back failures.
rust/​src/​dns/​set/​plan.rs Distinguishes unchanged records from replacements.
rust/​src/​dns/​set/​outcome.rs Adds unchanged counts and resulting records.
rust/​src/​dns/​set/​mod.rs Integrates verification and expanded output.
rust/​src/​dns/​records.rs Enforces TTL bounds and makes record options cloneable.
rust/​src/​dns/​list.rs Exposes record serialization for reuse.
rust/​src/​dns/​guides/​dns.md Simplifies set guidance and documents TTL limits.
rust/​src/​dns/​add.rs Updates TTL help text.
rust/​domains-client/​src/​lib.rs Checks that the replace operation remains exposed.
rust/​domains-client/​openapi/​domains.oas3.json Restores the single-record PUT contract.

Review effort: Balanced

Comment thread rust/src/dns/set/mod.rs Resolved
Comment thread rust/src/dns/set/plan.rs Resolved
Comment thread rust/src/dns/set/verify.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Hostname normalization omits ALIAS records, causing canonical read-backs to fail verification and subsequent runs to issue unnecessary replacements instead of reporting unchanged.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Low severity Include all differing fields in verification errors

rust/​src/​dns/​set/​verify.rs:72

When an explicit TTL differs on read-back, both mismatch lists show the same record label, hiding the reason verification failed. service and protocol are also compared but omitted from the labels. Include those fields and, when compare_ttl is true, the requested and stored TTLs so the error identifies what needs correcting.

3 resolved since last review

Review effort: Balanced

Comment thread rust/src/dns/records.rs Resolved
@jpage-godaddy
jpage-godaddy requested a balanced review from Copilot November 4, 2026 01:54
@jpage-godaddy

Copy link
Copy Markdown
Collaborator Author

Also addressed the finding in the latest review body ("Include all differing fields in verification errors") in 2e58c15: the final-check error now labels records with SRV service/protocol and, when --ttl was passed, the requested and stored TTLs, so a TTL-only mismatch no longer prints two identical lines.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

An omitted CAA flag is not normalized to zero, causing matching read-back records to report a final-state mismatch and preventing subsequent runs from recognizing them as unchanged.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Normalize omitted CAA flag to zero when comparing records

rust/​src/​dns/​records.rs:401

CAA's optional --flag is left absent in the desired record, so a read-back containing the non-critical value flag: 0 compares unequal even when all other fields match. This makes an omitted-flag dns set --type CAA --tag issue report a final-state mismatch and prevents subsequent runs from treating that record as unchanged. Normalize an omitted CAA flag to zero for comparison, and add a regression test for an omitted-flag request against a flag-zero read-back.

1 resolved since last review

Review effort: Balanced

@jpage-godaddy

Copy link
Copy Markdown
Collaborator Author

Addressed the finding in the latest review body ("Normalize omitted CAA flag to zero") in 4d9b558. It turned out to be a bigger problem than the comparison: with no --flag, the CLI sent no flag at all and the API rejects that ("flag is required for CAA records"), so dns add/dns set for CAA only worked with --flag passed. An omitted --flag now defaults to 0, so it is accepted and a repeat set reports the record as unchanged. Confirmed against the test zone.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The re-enabled PUT previously caused whole-zone data loss, and test-only verification plus a final check limited to targeted records leave production safety requiring human confirmation.

No open issues 🎉

Review effort: Balanced

@jpage-godaddy
jpage-godaddy marked this pull request as draft November 4, 2026 18:04
@jpage-godaddy
jpage-godaddy changed the base branch from main to dns-composite-name-filter November 4, 2026 21:12
@jpage-godaddy
jpage-godaddy added this pull request to stack #361 November 4, 2026 21:14
Base automatically changed from dns-composite-name-filter to main November 5, 2026 18:37
jpage-godaddy added a commit that referenced this pull request Nov 5, 2026
…te (#360)

## What changes for users

SRV and TLSA records can now be found by the name they are listed under in `gddy dns list`, `dns set` and `dns delete`.

Before, the API's name filter only understood a composed name (`_service._proto.name` for SRV, `_port._proto.name` for TLSA), while a record is listed under its short name. So with an SRV record `chat` in place:

- `dns list <domain> --type SRV --name chat` returned nothing.
- `dns delete <domain> --type SRV --name chat` reported `deleted: 0`, exited successfully, and left the record in place.
- `dns set` could not see existing records, so it tried to create a duplicate and failed, or (with the in-place `set` in #359) created a new record and then reported it as missing.

Now the CLI fetches records of the type and matches the name itself, ignoring case. Either form of the name works:

- **Short name** (`--name chat`): every SRV record listed under `chat`, whatever its service. For TLSA, every port.
- **Full name** (`--name _sip._tcp.chat`, or `_443._tcp.www` for TLSA): only that service's (or port's) record. At the zone apex the full name has no suffix (`_sip._tcp`). This form keeps working as it did before, including in the commands the CLI suggests when a record already exists.
- If a record is listed under exactly the name given, only that name's records are selected, so `chat` and a record literally named `_sip._tcp.chat` stay separate owners and a delete by one cannot reach the other.

**Behavior to be aware of:** `dns delete --type SRV --name chat` removes every SRV record listed under `chat`. That is what the command says, but it used to remove nothing for these types. The guide says so, shows the full-name form for targeting one service, and recommends `--dry-run` first.

## `dns set` no longer deletes the record you asked to keep

For SRV, `dns set` could delete the target you asked to keep: with `chat` holding `a.example.com.` and `b.example.com.`, `set --data b.example.com` left only `a.example.com.`. The API stores hostname targets with a trailing dot, the pairing compared text exactly, so the request matched the wrong record, failed as a duplicate, and the cleanup then deleted the one that was meant to stay.

Records are now compared the way the API holds them: names and hostname targets (CNAME, ALIAS, MX, SRV, HTTPS, SVCB) without case or a trailing dot, CAA data and TLSA hex without case, and values it keeps as written (TXT, AAAA, HTTPS/SVCB parameters, SRV service and protocol) exactly. #359, which is stacked on this PR, builds on the same comparison. A regression test fails without it.

## Under the hood

- The change is in the shared record fetch, so no new flags are needed. Other record types still filter by name on the server.
- With no `--name` there is nothing to match, so those lists are unchanged.
- #359 reads records back after a `set`, so it relies on this lookup finding SRV and TLSA records.
- The record helper tests moved to their own file (`records_tests.rs`), which the repository's file-size limit requires.

## Also in this PR

- Adds DNS and domains reviewers to `reviewers.json` (and regenerates `CODEOWNERS`, which the drift check requires). This is a separate commit.

## Verification

- `cargo check --workspace`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --check`, `cargo test --workspace` (1172 tests in the main crate) and `./rust/scripts/check-module-size.sh` all pass.
- New unit tests cover SRV and TLSA matching by short and full name, apex names, the two-owner case, other types still filtering on the server, and the `set` regression above.
- Run live against a throwaway zone in the test environment, with SRV:
  - `list --name <name>` finds the record (it returned nothing before) and a name that doesn't exist returns nothing;
  - the full name selects one service, and deleting by it left the other service's record in place;
  - `delete --dry-run` finds records and `delete` removes them (`deleted: 1`);
  - `set` creating a new SRV record creates it, and the `a`/`b` case above now keeps `b.example.com.`;
  - the apex form (`_sip._tcp`) finds and deletes an apex SRV record.
- **TLSA is covered by unit tests only.** The test zone has no DNSSEC, so a TLSA record could not be created. The API spec describes the same composed name, so the same behavior is expected.
- Adding an apex SRV record returns a 400 from the API but still creates the record. That is an API problem and is not changed here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@jpage-godaddy
jpage-godaddy marked this pull request as ready for review November 5, 2026 19:40
.map(|r| (comparable(r, compare_ttl), r))
.collect();
let mut missing = Vec::new();
for want in desired {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing accepts both short and composed forms via listed_name_matches, but this check does not, so a composed-name set can write and then fail verification, or never report unchanged. This should treat short and composed names as equal here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you were right that this was a real hole, though I took the fix in a different direction than the one you suggested. I reproduced it: with a record stored as rts, a set using the composed name _sip._tcp.rts found it through listed_name_matches (as you say), and then the update wrote the composed string back as the record's name, so the record was quietly moved to a nested name and the final check could not match it.

Treating the two names as equal in the final check would have let that rename pass without complaint, so instead dns set (and dns add, which had the same problem) now reject a full SRV/TLSA name up front, before any request, and say which --name and --service/--protocol to use. list and delete still accept both forms, since they only look records up. Fixed in 0d3d856; I confirmed on the test zone that the composed-name set is refused with a validation error and the existing record is left untouched.

jpage-godaddy and others added 5 commits November 16, 2026 13:06
… result

`dns set` now replaces each record it keeps with a single in-place update
instead of creating the new value and then deleting the old record. A
replaced record keeps its ID, a TTL-only change is one call, and a failed
update leaves the existing record untouched rather than leaving two values
at the name.

- Records that already match what you asked for are reported as
  `unchanged` and left alone, so running the same `set` twice changes
  nothing the second time. The result gains an `unchanged` count and
  `replaced` no longer includes them.
- A replaced record keeps its current TTL unless you pass `--ttl`.
- The result lists the records now in place, including their IDs.
- After writing, `set` reads the type and name back and fails if the
  records there are not the ones you asked for, for example because
  someone else changed them while it ran. It lists what is extra and what
  is missing and removes nothing.
- `--ttl` is checked up front for both `dns add` and `dns set`: 600 to
  86400 seconds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`dns set` now judges whether a record already matches, and whether the
final read-back matches, using one comparison that follows how the API
stores each field, so re-running `set` with `Example.COM` for a CNAME that
is stored as `example.com.` reports it unchanged instead of replacing it
again.

- Hostnames (CNAME, MX, SRV, HTTPS, SVCB targets) and record names are
  compared without case or a trailing dot; CAA data and TLSA certificate
  hex are compared without case.
- Values the API keeps as written are compared exactly: TXT text, AAAA
  addresses, HTTPS/SVCB parameters, and SRV service and protocol. A
  concurrent change in case there is now caught by the final check.
- The records in the result come from the final read-back, so the IDs and
  TTLs shown are what is in the zone, not what each write returned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ield in dns set errors

- An ALIAS record's target is compared the way a CNAME's is, without case or
  a trailing dot, so `set` leaves a matching ALIAS alone instead of
  replacing it on every run.
- When the final check finds records that are not the ones requested, each
  one is labelled with its SRV service and protocol, and with its TTL when
  `--ttl` was given, so a TTL-only difference no longer shows two identical
  lines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The API requires a flag on every CAA record, but `--flag` was optional and
left unset when omitted, so adding or setting a CAA record without it
failed with "flag is required for CAA records". An omitted `--flag` now
means 0 (non-critical), which is also what an existing record without an
explicit flag is stored as, so running the same `set` again reports the
record as unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…check required flags up front

For SRV and TLSA records the API composes the DNS name from the record's name and
its service and protocol (or port and protocol). Giving `--name` as the full name
(`_sip._tcp.chat`) could create a record at a nested name nobody asked for with
`dns add`, or move an existing record with `dns set`. Both now reject it before
any request and say which `--name` and flags to use.

The flags each record type needs are now checked when the arguments are parsed,
instead of after login with a 400 from the API:

- MX, SRV, HTTPS and SVCB need `--priority`; SRV also needs `--weight`, `--port`,
  `--service` and `--protocol`; TLSA needs `--port` and `--protocol` in addition
  to its usage, selector and matching type.
- `--service` and `--protocol` take the plain name (`sip`, `tcp`); the leading
  underscore DNS requires is added when it is left off, and a value that cannot
  be a label is rejected with an example.
- Where they are shown (`--fields service,protocol`, or JSON) they appear in the
  underscore form, since that is the DNS name.

The DNS guide describes the required flags per record type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jpage-godaddy
jpage-godaddy merged commit f10b2c4 into main Nov 16, 2026
6 checks passed
@jpage-godaddy
jpage-godaddy deleted the api-dns-set branch November 16, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants