<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Alex March - homelab</title>
    <subtitle>My personal site. Projects, writing and other shenanigans.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://hosaka.cc/alex/tags/homelab/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://hosaka.cc/alex"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-11-20T00:00:00+00:00</updated>
    <id>https://hosaka.cc/alex/tags/homelab/atom.xml</id>
    <entry xml:lang="en">
        <title>Moving from Cloudflare DNS to deSEC</title>
        <published>2026-11-19T00:00:00+00:00</published>
        <updated>2026-11-20T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://hosaka.cc/alex/blog/moving-from-cloudflare-dns-to-desec/"/>
        <id>https://hosaka.cc/alex/blog/moving-from-cloudflare-dns-to-desec/</id>
        
        <content type="html" xml:base="https://hosaka.cc/alex/blog/moving-from-cloudflare-dns-to-desec/">&lt;p&gt;This is a rough walkthrough of how I switched from Cloudflare DNS to deSEC for my homelab with the zone manged in OpenTofu and the domain moved to Porkbun. I also use Caddy as a primary reverse proxy on my cluster and it is now configured to get its certificates with the deSEC module.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https://desec.io&quot;&gt;deSEC&lt;/a&gt; is a free, non-profit DNS host. It signs every zone with DNSSEC, has an API with token auth that can be limited to single records and there is an OpenTofu provider for it which I will be making use of. The domain registration has to move as well, because Cloudflare only allows their own nameservers. &lt;a rel=&quot;external&quot; href=&quot;https://porkbun.com&quot;&gt;Porkbun&lt;/a&gt; includes WHOIS privacy and accepts DS records which you need in order to turn DNSSEC on.&lt;/p&gt;
&lt;h2 id=&quot;the-plan&quot;&gt;The Plan&lt;/h2&gt;
&lt;p&gt;The whole move took me about three days, mostly spent waiting:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Turn of DNSSEC at Cloudflare if it was enabled and wait 24 hours.&lt;/li&gt;
&lt;li&gt;Transfer the domain over to Porkbun. Cloudflare keeps serving the DNS for now.&lt;/li&gt;
&lt;li&gt;Build the zone in deSEC with OpenTofu, inclusing a wildcard record.&lt;/li&gt;
&lt;li&gt;Point the nameservers at deSEC.&lt;/li&gt;
&lt;li&gt;24 hours later, switch Caddy to and use wildcard certificates.&lt;/li&gt;
&lt;li&gt;Another day later, add deSEC DS record at Porkbun and delete the Cloudflare zone.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The waiting is the easiest part to get wrong, so stock up on patience.&lt;/p&gt;
&lt;h2 id=&quot;dnssec-and-waiting&quot;&gt;DNSSEC and Waiting&lt;/h2&gt;
&lt;p&gt;With DNSSEC, the TLD registry hold a DS record for your domain, a hash of the key your zone is signed with. Validating resolvers, which include the big public ones from Google, Cloudflare and Quad 9 check every answer against that record. Cloudflare and deSEC sign with different keys, so a single DS can’t match both. If the nameservers change while the DS still points  at Cloudflare’s key, resolvers would reject deSEC answers and the domain would stop resolving. Multi-signer DNSSEC exists to avoid this, but both providers have to publish each other’s keys. Going unsigned for a couple of days is much simpler.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;first wait&lt;/strong&gt; comes after removing the DS. Disabling DNSSEC in Cloudflare settings removes the DS from the registry, since Cloudflare is also the registrar. Resolvers that fetched the DS prior keep it until its TTL runs out, which can be up to a day. Until then they still expect signatures from Cloudflare owned key, so leave the nameservers alone for a day.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;second wait&lt;/strong&gt; comes after switching the nameservers. From what I understood, resolvers also cache NS records, Cloudflare NS records have a TTL of 24 hours and the delegation at the TLD can be cached for up to two days depending on the registry. Until those expire, some resolvers can keep querying Cloudflare, so the zone has to stay in place. If you add deSEC’s DS too early, the resolvers that ask Cloudflare will treat those unsigned answers as forged. Hence the wait for the DS is 24-48 hours.&lt;/p&gt;
&lt;p&gt;Let’s Encrypt is affected by the same caching. Until its resolvers see deSEC as authoritative, they look for DNS-01 challenge records in the Cloudflare zone instead. That’s why Caddy configuration can be switched only once the nameservers had a day to settle.&lt;/p&gt;
&lt;p&gt;DNS-over-HTTPS is a convenient way to watch both waits from outside of your network, without your local resolver cache:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;# no Answer once the DS is gone&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; -s &amp;#39;https://dns.google/resolve?name=example.com&amp;amp;type=DS&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;# deSEC nameservers once the switch is visible&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; -s &amp;#39;https://dns.google/resolve?name=example.com&amp;amp;type=NS&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; -s -H &amp;#39;accept: application/dns-json&amp;#39; &amp;#39;https://cloudflare-dns.com/dns-query?name=example.com&amp;amp;type=NS&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Check Cloudflare resolver as well. It kept answering from the old zone even though the Google resolver had moved on.&lt;/p&gt;
&lt;h2 id=&quot;domain-transfer&quot;&gt;Domain Transfer&lt;/h2&gt;
&lt;p&gt;Unlock the domain in Cloudflare dashboard, copy the authorization code and start the transfer at Porkbun with it. Approving the outgoing transfer in Cloudflare finishes it right away, you should get an email notification when approve is possible. A transfer to Porkbun adds a year to the registration but you do have to pay to transfer, of course.&lt;/p&gt;
&lt;p&gt;The transfer doesn’t touch the nameservers, so Cloudflare keeps serving the zone during and after it. Nothing changes for the users until you switch the nameservers yourself.&lt;/p&gt;
&lt;h2 id=&quot;zone-in-desec&quot;&gt;Zone in deSEC&lt;/h2&gt;
&lt;p&gt;Cloudflare can export the zone as a BIND file (DNS -&amp;gt; Records -&amp;gt; Import and Export). This gives you a list of what’s there but not everything in it should move:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SOA and NS records&lt;/strong&gt;: leave them out. deSEC manages its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Leftover &lt;code&gt;_acme-challenge&lt;/code&gt; TXT records&lt;/strong&gt;: leave these too. Caddy doesn’t always clean them up, and as I will explain later, they hide names from the wildcard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TTLs&lt;/strong&gt;: raise them. “Auto” TTL in Cloudflare exports as 1 second, which deSEC won’t accept. An hour (3600 seconds) is a good default and it is what deSEC uses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Mail records (MX, SPF and the DKIM keys or CNAMEs) need to come over exactly as they are. After the switch, check that your mail provider still shows the domain as “Verified”.&lt;/p&gt;
&lt;p&gt;For the OpenTofu side, a zone is a dmain plus a set of records managed with the &lt;a href=&quot;https://hosaka.cc/alex/blog/moving-from-cloudflare-dns-to-desec/search.opentofu.org/provider/timofurrer/desec/latest&quot;&gt;timofurrer/desec&lt;/a&gt; provider. It needs an API token from the deSEC web interface. Give the token the “manage tokens” permission and leave “Can create domains” and “Can delete domains” unticked. Here’s what the HCL might look like for a given domain:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;lua&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;terraform&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;  required_providers&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    desec&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      source&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;timofurrer/desec&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;provider&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  api_token&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; var.desec_token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;resource&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec_domain&amp;quot; &amp;quot;main&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  name&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;example.com&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;resource&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec_records&amp;quot; &amp;quot;main&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  domain&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;    =&lt;/span&gt;&lt;span&gt; desec_domain.main.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  exclusive&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  rrsets&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    { subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;, type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;A&amp;quot;&lt;/span&gt;&lt;span&gt;, ttl&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 3600&lt;/span&gt;&lt;span&gt;, rdata&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;203.0.113.10&amp;quot;&lt;/span&gt;&lt;span&gt;] },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    { subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;*&amp;quot;&lt;/span&gt;&lt;span&gt;, type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;A&amp;quot;&lt;/span&gt;&lt;span&gt;, ttl&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 3600&lt;/span&gt;&lt;span&gt;, rdata&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;203.0.113.10&amp;quot;&lt;/span&gt;&lt;span&gt;] },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    { subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;, type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;MX&amp;quot;&lt;/span&gt;&lt;span&gt;, ttl&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 3600&lt;/span&gt;&lt;span&gt;, rdata&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;10 mx1.mail.example.net.&amp;quot;&lt;/span&gt;&lt;span&gt;] },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    { subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;&amp;quot;&lt;/span&gt;&lt;span&gt;, type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;TXT&amp;quot;&lt;/span&gt;&lt;span&gt;, ttl&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 3600&lt;/span&gt;&lt;span&gt;, rdata&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;v=spf1 include:spf.mail.example.net -all&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;] },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    { subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;_dmarc&amp;quot;&lt;/span&gt;&lt;span&gt;, type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;TXT&amp;quot;&lt;/span&gt;&lt;span&gt;, ttl&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 3600&lt;/span&gt;&lt;span&gt;, rdata&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;v=DMARC1; p=none; rua=mailto:dmarc@example.com&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;] },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;TXT values need their own quotes inside the string.&lt;/li&gt;
&lt;li&gt;With &lt;code&gt;exclusive = false&lt;/code&gt;, tofu only creates and updates the records it declares, so other records stay intact. Once the config describes the whole zone, set this to true and the provider will remove everything it doesn’t declare.&lt;/li&gt;
&lt;li&gt;If you’d rather load the BIND file through the deSEC web interface, &lt;code&gt;import&lt;/code&gt; blocks can bring the domain and its record into the OpenTofu state afterwards.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;switching-the-nameservers&quot;&gt;Switching the Nameservers&lt;/h2&gt;
&lt;p&gt;Over at Porkbun, in “Domain Management”, under your domain “Details”, replace the nameservers with &lt;code&gt;ns1.desec.io&lt;/code&gt; and &lt;code&gt;ns2.desec.org&lt;/code&gt;. For the next two days keep the Cloudflare zone, if you make any record changes, make them in both deSEC and CF dashboards. Resolvers might still use the Cloudflare zone and they should get the same answers.&lt;/p&gt;
&lt;h2 id=&quot;caddy-and-wildcard-certs&quot;&gt;Caddy and Wildcard Certs&lt;/h2&gt;
&lt;p&gt;Caddy’s DNS providers are plugins compiled into the binary, so Caddy needs a build with &lt;a rel=&quot;external&quot; href=&quot;https://github.com/caddy-dns/desec&quot;&gt;caddy-dns/dnssec&lt;/a&gt;. With the official image builder variant, that’s a short Containerfile:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;FROM&lt;/span&gt;&lt;span&gt; caddy:2-builder &lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;AS&lt;/span&gt;&lt;span&gt; builder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;RUN&lt;/span&gt;&lt;span&gt; xcaddy build --with github.com/caddy-dns/desec&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;FROM&lt;/span&gt;&lt;span&gt; caddy:2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;COPY&lt;/span&gt;&lt;span&gt; --from=builder /usr/bin/caddy /usr/bin/caddy&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Caddy only needs to write challenge records and not actually update/remove anything else, and deSEC token policies can enforce that. A default policy denies everything and one policy per challenge name allows writing its TXT record. Note that deSEC requires the default policy to exist before other can be created:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;lua&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;resource&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec_token&amp;quot; &amp;quot;caddy&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  name&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;caddy&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;resource&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec_token_policy&amp;quot; &amp;quot;caddy_default&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  token_id&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;   =&lt;/span&gt;&lt;span&gt; desec_token.caddy.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  perm_write&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;resource&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;desec_token_policy&amp;quot; &amp;quot;caddy&amp;quot; &lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  for_each&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; toset&lt;/span&gt;&lt;span&gt;([&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;_acme-challenge&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;_acme-challenge.internal&amp;quot;&lt;/span&gt;&lt;span&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  token_id&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;   =&lt;/span&gt;&lt;span&gt; desec_token.caddy.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  domain&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;     =&lt;/span&gt;&lt;span&gt; desec_domain.main.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  subname&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;    =&lt;/span&gt;&lt;span&gt; each.key&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  type&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;       =&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;quot;TXT&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  perm_write&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  depends_on&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; [desec_token_policy.caddy_default]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, the &lt;code&gt;desec_token.caddy.token&lt;/code&gt; is the value we can hand to Caddy. In the &lt;code&gt;Caddyfile&lt;/code&gt;, the issuer goes in the global options and a catch-all site requests the wildcard certificate:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;lua&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	email admin@example.com&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	cert_issuer&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; acme&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		dns&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; desec&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;			token&lt;/span&gt;&lt;span&gt; {env.DESEC_TOKEN}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		propagation_delay&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 5&lt;/span&gt;&lt;span&gt;m&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		propagation_timeout&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;.example.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;com&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	respond&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 404&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git.example.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;com&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	reverse_proxy&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; localhost&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;3000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The propagation setting matters in my case but might be irrelevant for your network. deSEC serves zones from an &lt;a rel=&quot;external&quot; href=&quot;https://cloudflare.com/learning/cdn/glossary/anycast-network/&quot;&gt;Anycast&lt;/a&gt; network and a change can take more than a minute to reach every node. If Let’s Encrypt asks a node that hasn’t caught up yet, the challenge fails. Caddy can check propagation itself, but only if it can reach the nameservers on port 53, which doesn’t work on networks that intercept DNS (I have a &lt;code&gt;stubby&lt;/code&gt; service hijacking DNS on my OpenWrt router). A fixed five-minute delay with the check turned off is slow but reliable.&lt;/p&gt;
&lt;p&gt;Since &lt;em&gt;Caddy 2.10&lt;/em&gt;, sites for individual subdomains such as &lt;code&gt;git.example.com&lt;/code&gt; reuse the managed wildcard certificates instead of requesting their own, and unknown names get a catch-all 404. The apex isn’t covered by the wildcard and keeps its own certificate. If a site needs its own certificate anyway, &lt;code&gt;tls force_automate&lt;/code&gt; in its site block will ensure that.&lt;/p&gt;
&lt;p&gt;Existing certificates keep working until they renew so applying this Caddy config is not urgent, but a new hostname can’t get a certificate until Caddy is on deSEC. Make the switch once both Google and Cloudflare resolvers return deSEC’s nameserevrs. The wildcard certificates are new, so a few minutes of downtime while they’re are issued is to be expected. Once everything presents the new certs, delete the per-service A records, or set &lt;code&gt;exclusive = true&lt;/code&gt; as mentioned previously and revoke the Cloudflare API token Caddy used previously.&lt;/p&gt;
&lt;h2 id=&quot;why-a-wildcard&quot;&gt;Why a Wildcard?&lt;/h2&gt;
&lt;p&gt;Without a wildcard record, every new service needs it’s own A record. With &lt;code&gt;*.example.com&lt;/code&gt; pointing at the reverse proxy, a new service only needs a site block in Caddy. Paired with a wildcard certificate, it has two more advantages:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;New hostnames stop showing up in &lt;a rel=&quot;external&quot; href=&quot;https://ctlogs.io&quot;&gt;Certificate Transparency Logs&lt;/a&gt; where anyone can look them up. Unfortunately, names that were already logged stay there indefinitely.&lt;/li&gt;
&lt;li&gt;Challenge records also stop hiding names - a name that exists in the zone isn’t covered by the wildcard. Even when it has no records of its own. A per-host DNS-01 challenge for &lt;code&gt;git.example.com&lt;/code&gt; creates &lt;code&gt;_acme-challenge.git.example.com&lt;/code&gt; which makes &lt;code&gt;git.example.com&lt;/code&gt; exist. It then stops resolving until the TXT record is deleted and resolvers cache that empty answer. This happens at every renewal of every per-host certificate and permanently when Caddy leaves the record behind. A wildcard cert challenge lives at &lt;code&gt;_acme-challenge.example.com&lt;/code&gt;, which doesn’t hide anything.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A few rules come with a wildcard though:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Explicit wins over the wildcard&lt;/strong&gt;, and the wildcard doesn’t cover the apex, so the apex needs its own A record, no biggie.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A name with something below it needs its own record&lt;/strong&gt;. If &lt;code&gt;chat.example.com&lt;/code&gt; has &lt;code&gt;upload.chat.example.com&lt;/code&gt; under it, &lt;code&gt;chat&lt;/code&gt; exists and the wildcard no longer covers it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The wildcard also covers deeper domains&lt;/strong&gt;. So &lt;code&gt;*.example.com&lt;/code&gt; matches &lt;code&gt;app.internal.example.com&lt;/code&gt; unless &lt;code&gt;internal.example.com&lt;/code&gt; exists. If some names should only resole on your LAN through your router’s DNS, put a record at the intermediate name to stop the wildcard there. A &lt;code&gt;TXT &quot;v=spf1 -all&quot;&lt;/code&gt; works and also says no mail comes from it. Wildcard certificates only cover one level, so those names need their own &lt;code&gt;*.internal.example.com&lt;/code&gt; cert, which is what the second toke policy in deSEC is for.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every name now resolves to your proxy&lt;/strong&gt;. Should be harmless for web traffic, where unknown names get the catch-all 404. Forged mail from &lt;code&gt;someone@anything.example.com&lt;/code&gt; does look a little more plausible to receiving server, which is one more reason to use DMARC.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;turning-dnssec-back-on&quot;&gt;Turning DNSSEC Back On&lt;/h2&gt;
&lt;p&gt;24-48 hours after the nameserver switch, take the DS record from the deSEC “Setup Instructions” (a little info icon on the domain row) and add it in Porkbun. Once the registry publishes it, validating resolvers mark answers as authenticated:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;# &amp;quot;AD&amp;quot;: true once the chain validates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; -s &amp;#39;https://dns.google/resolve?name=example.com&amp;amp;type=A&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By this point, no resolver can still have Cloudflare nameservers cached, so the zone can be finally let go and domains can be removed from the Cloudflare dashboard.&lt;/p&gt;
&lt;h2 id=&quot;dmarc-as-a-bonus&quot;&gt;DMARC as a Bonus&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https://dmarc.org&quot;&gt;DMARC&lt;/a&gt; tells receiving mail servers what to do with the mail that claims to come from your domain but fails SPF and DKIM. Setting it to &lt;code&gt;p=none&lt;/code&gt; only instructs them to send you email reports, &lt;code&gt;p=quarantine&lt;/code&gt; sends failing mail to spam and &lt;code&gt;p=reject&lt;/code&gt; refuses it.&lt;/p&gt;
&lt;p&gt;You can start with &lt;code&gt;p=none&lt;/code&gt; and a &lt;code&gt;rua&lt;/code&gt; address, and read the daily reports. The reports list every server that sent mail as your domain and whether it passed. Once all your legitimate senders pass, move to &lt;code&gt;p=reject&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;_dmarc.example.com. TXT &amp;quot;v=DMARC1; p=reject; rua=mailto:dmarc@example.com&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Without an &lt;code&gt;sp=&lt;/code&gt; tag the policy covers subdomains too, which is probably what you want. Watch out for self-hosted apps that default to a subdomain sender like &lt;code&gt;noreply@git.example.com&lt;/code&gt;. Your mail provider DKIM key is usually only set up for the main domain. DMARC accepts a DMIN signature for &lt;code&gt;example.com&lt;/code&gt; on mail from a subdomain, but only if the provider actually signs it that way. Moving the sender to an addres on the main domain avoids this issue.&lt;/p&gt;
&lt;h2 id=&quot;selfhost-together&quot;&gt;Selfhost Together&lt;/h2&gt;
&lt;p&gt;If you want to explore my code that I describe here.&lt;/p&gt;
</content>
        
    </entry>
</feed>
