Skip to content

Add opt-in records endpoint with CNAME and SRV support - #122

Merged
0xFelix merged 2 commits into
0xFelix:mainfrom
xhess:feat/cname-srv
Nov 5, 2026
Merged

0xFelix merged 2 commits into
0xFelix:mainfrom
xhess:feat/cname-srv

Conversation

@xhess

@xhess xhess commented Oct 30, 2026

Copy link
Copy Markdown

Summary

Adds a new, opt-in endpoint group records with two endpoints:

  • POST /records/present
  • POST /records/cleanup

Both take a JSON body with fqdn, type and value. Supported types are
A, AAAA, TXT, CNAME and SRV, so CNAME and SRV records can now be managed
through the proxy. The existing endpoints are unchanged and still only
accept A, AAAA and TXT.

The group is not enabled by default. It has to be listed explicitly via
endpoints in the config file or ENDPOINTS in the environment, so
existing setups are not affected.

Behaviour

  • CNAME: the target is validated as a hostname, lowercased and made
    absolute (target.example.com -> target.example.com.). A CNAME at the
    zone apex is rejected. present replaces an existing CNAME, since only
    one CNAME per name is allowed.
  • SRV: the value is priority weight port target. Priority, weight and
    port must be 0-65535 and are normalized (05060 -> 5060); the target
    is validated and made absolute, and .
    is accepted as "service not available". present adds the record to
    an existing RRSet instead of replacing it, so several targets can share
    one name (e.g. a primary and a backup server). Adding a record that
    already exists is a no-op. cleanup removes only the matching record.
  • A, AAAA, TXT: same validation and replace semantics as the existing
    endpoints.

Example:

curl -u user:pass -H 'Content-Type: application/json' \
  -d '{"fqdn":"_minecraft._tcp.survival.example.com","type":"SRV","value":"0 5 25565 mc1.example.com"}' \
  https://proxy.example.com/records/present

Tests

  • Unit tests for binding and validation of all record types in
    pkg/middleware/bind_test.go.
  • Unit tests for ENDPOINTS parsing and for records being off by
    default in pkg/config/config_test.go.
  • Functional tests in tests/records_test.go for creating, replacing
    (CNAME), adding (SRV, with and without a TTL change), skipping an
    existing SRV record, cleanup of CNAME and SRV records, invalid input,
    denied access (401) and the endpoint being disabled (404).
  • make lint, make test and make functest pass.
  • Tested manually against the real Hetzner Cloud API: creating a CNAME
    and an SRV record, adding a second SRV record to the same name,
    re-sending an existing record (no-op, also with leading zeros), and
    cleaning up single SRV and CNAME records. All results were verified on
    the Hetzner nameservers.

🤖 Generated with Claude Code

@0xFelix

0xFelix commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution. Interesting stuff! I'll have a look at this tomorrow afternoon!

@0xFelix 0xFelix left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good overall, thanks!

Added some comments. Could you prefix the commit with feat:?

Comment thread pkg/app/app.go Resolved
Comment thread tests/records_test.go Resolved
Comment thread pkg/config/config_test.go Resolved
Comment thread pkg/config/config_test.go Resolved
Comment thread pkg/middleware/update/cloud/cloud.go Resolved
Comment thread pkg/middleware/bind_test.go Resolved
Comment thread tests/records_test.go Resolved
Comment thread pkg/middleware/bind_test.go Resolved
Comment thread tests/records_test.go Resolved
Comment thread README.md Resolved
@xhess

xhess commented Nov 1, 2026

Copy link
Copy Markdown
Author

While addressing the review I ran an additional review pass over the records endpoint and found a few issues in the new code, which are fixed in the updated commit as well:

  • SRV records could not be changed. Present always appended, so changing priority, weight or port left the old record behind. The binder now sets an explicit mode in ReqData instead of the updater checking for SRV. SRV still appends by default, all other types replace as before, and "replace": true in the request body sets the RRSet to exactly the given value.
  • CNAME conflicts. Creating a CNAME on a name that has other record sets, or A/AAAA/TXT/SRV on a name that has a CNAME, failed with an opaque 500 from the API. The records endpoint now checks this before creating (one list call by name) and responds with 409 Conflict. Other endpoints are unaffected.
  • Formatting-sensitive SRV/CNAME matching. Dedup on present and cleanup compared raw strings, so stored values formatted differently (no trailing dot, extra whitespace, leading zeros, case) were added twice or never removed. SRV and CNAME values are now compared normalized, and cleanup removes the record in its stored form. A/AAAA/TXT cleanup is unchanged.
  • Multiple trailing dots in CNAME/SRV targets (a.example.com..) were accepted and are now rejected.
  • RECORD_TYPES could stop startup even with the records endpoint disabled. An empty value now keeps the default, and the list is only validated when the records endpoint is enabled.
  • Strengthened the nic zone test to also assert the response token.

I also noticed a few things that already exist on main and are not specific to this PR (names are not validated against hostname rules before they end up in API paths, present replaces the whole RRSet while cleanup removes a single value, TXT values are quoted with Go rather than DNS escaping, and concurrent creates of the same RRSet race). I left them out to keep this PR focused. Happy to open issues or follow-up PRs for them.

@0xFelix 0xFelix left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, added some more comments.

The issues you found are tracked in #123 and #124, I'll take care of them after this is merged.

Comment thread pkg/middleware/bind.go Resolved
Comment thread pkg/middleware/bind.go Resolved
Comment thread pkg/hetzner/records.go Resolved
Comment thread README.md Resolved
Comment thread pkg/config/config_test.go Resolved
Comment thread pkg/config/config.go Resolved
Comment thread pkg/config/config.go Resolved
Comment thread pkg/middleware/bind.go Resolved
Parse IP addresses of the plain, nic and directadmin endpoints with a
shared helper that rejects zones and unmaps IPv4-mapped IPv6 addresses,
and pass the canonical address on instead of the raw input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: xhess <github@die-hessens.de>

@0xFelix 0xFelix left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! We're getting close. A few more comments, mostly nits apart from the SRV . target.

Comment thread README.md Resolved
Comment thread pkg/config/config.go Resolved
Comment thread pkg/middleware/clean/cloud/cloud.go Resolved
Comment thread pkg/middleware/update/cloud/cloud.go Resolved
Comment thread pkg/middleware/bind.go Resolved
Comment thread pkg/middleware/bind.go Resolved
Comment thread pkg/data/data.go Resolved
Comment thread pkg/middleware/bind.go Resolved
Comment thread README.md Resolved

@0xFelix 0xFelix left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! Could you squash the fix commit into the feat commit? Two small comments otherwise.

Comment thread pkg/middleware/update/cloud/cloud.go Resolved
Comment thread pkg/middleware/clean/cloud/cloud.go Resolved
Add /records/present and /records/cleanup, which accept A, AAAA, TXT,
CNAME and SRV records. The endpoint is disabled by default. SRV values
are appended to the record set unless a replace is requested, CNAME
conflicts are rejected and RECORD_TYPES/recordTypes restricts the
accepted types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: xhess <github@die-hessens.de>
@0xFelix

0xFelix commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks for all the iterations!

@0xFelix
0xFelix merged commit 5634898 into 0xFelix:main Nov 5, 2026
5 checks passed
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.

2 participants