Merge branch 'dnssec'
The DNSSEC notes in CHANGELOG.md belong under Unreleased; git had put them into the 0.1.0 section, which didn't exist when the branch was made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
24a2c875fa
72 files changed
+5759
-153
No files matched your search
@@ -8,6 +8,41 @@ All notable changes to Jarl are documented here. The format follows
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- DNSSEC signing per zone (docs/dnssec.md): `jarl zone dnssec
|
||||||
|
enable|status|check-ds|disable|wipe` and the zone page's DNSSEC tab, or
|
||||||
|
the zone's new `dnssec_policy` field in the API. named signs the zone
|
||||||
|
with BIND's `default` policy (one ECDSA P-256 key that is never replaced)
|
||||||
|
or a custom one, using inline signing, with keys in a per-view directory
|
||||||
|
under `/var/lib/bind/jarl/dnssec-keys`. Jarl shows the keys and the DS
|
||||||
|
record to give the registrar, says when it's safe to publish it, and
|
||||||
|
checks the parent's DS records (`check-ds`, which also tells named with
|
||||||
|
`rndc dnssec -checkds`). It refuses steps that would break a signed
|
||||||
|
domain: switching straight to unsigned (it goes through BIND's
|
||||||
|
`insecure` policy instead, and finishes only once named is done),
|
||||||
|
deleting a signed zone or moving it to another view, and TTLs above the
|
||||||
|
policy's `max-zone-ttl`. `wipe` starts over with a clean slate once the
|
||||||
|
parent has no DS. Each step in the web UI opens a dialog that says what it
|
||||||
|
needs first. `jarl zone delegation` now also compares the parent's DS
|
||||||
|
records with the zone's keys.
|
||||||
|
- Porkbun support (optional, docs/dnssec.md#porkbun): with an API key in
|
||||||
|
the new `porkbun:` section of jarl.yaml (and nowhere else), `jarl zone
|
||||||
|
registrar status|sync-glue|set-ns|publish-ds|remove-ds` and the zone
|
||||||
|
page's Registrar tab show and change the domain's name servers, glue
|
||||||
|
records (one per name server inside the domain, with all its IPv4 and
|
||||||
|
IPv6 addresses) and DS records at Porkbun. Every change first checks that
|
||||||
|
it won't take the domain offline (the name servers answer for the zone,
|
||||||
|
glue matches, a DS goes out only once the domain is delegated to servers
|
||||||
|
that serve the signed zone, DS records match the zone's keys before the
|
||||||
|
name servers change); `--dry-run` shows the checks and `--force` skips
|
||||||
|
them. Administrators only.
|
||||||
|
- Backups include the DNSSEC keys (private keys too), stored inside the
|
||||||
|
backup file, and `jarld restore` puts them back for named
|
||||||
|
(`bind.named_user`, default `bind`). `jarl-backup.service` has
|
||||||
|
`CAP_DAC_READ_SEARCH` to read them; `--without-keys` skips them.
|
||||||
|
- Jarl raises a zone's serial above the one named has loaded whenever it
|
||||||
|
writes a zone file whose serial isn't higher (after restoring an older
|
||||||
|
database, say), so named loads it (it refuses otherwise for a signed
|
||||||
|
zone) and secondaries pick it up.
|
||||||
- `scripts/testenv.sh`: turns a fresh Debian/Ubuntu machine into a test bed.
|
- `scripts/testenv.sh`: turns a fresh Debian/Ubuntu machine into a test bed.
|
||||||
It installs BIND and the build tools (Go from go.dev), writes a hand-made
|
It installs BIND and the build tools (Go from go.dev), writes a hand-made
|
||||||
style configuration with internal and external views, a split-horizon
|
style configuration with internal and external views, a split-horizon
|
||||||
@@ -17,6 +52,16 @@ All notable changes to Jarl are documented here. The format follows
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- `jarl zone serials` compares the serial named serves, which for a signed
|
||||||
|
zone is the signed zone's (ahead of Jarl's).
|
||||||
|
- `jarld import` turns `dnssec-policy` in an existing configuration into
|
||||||
|
the zones' DNSSEC setting, and warns that their keys must be moved into
|
||||||
|
Jarl's key directory before adopting.
|
||||||
|
- `dnssec-policy` is no longer accepted as a zone, view or server option
|
||||||
|
(zones have a DNSSEC setting instead), nor `key-directory` as a zone
|
||||||
|
option.
|
||||||
|
- Deleting a zone also removes the journal and signed files named kept
|
||||||
|
next to it.
|
||||||
- Release candidates (tags like `v0.2.0-rc.1`) publish their `.deb`s to a
|
- Release candidates (tags like `v0.2.0-rc.1`) publish their `.deb`s to a
|
||||||
separate `testing` distribution of the package registry instead of
|
separate `testing` distribution of the package registry instead of
|
||||||
`stable`. Servers that follow `stable` can't pick up an RC with
|
`stable`. Servers that follow `stable` can't pick up an RC with
|
||||||
|
|||||||
@@ -45,12 +45,20 @@ error: www.adbraun.lol has a CNAME, so it can't have any other records (found A)
|
|||||||
limited.
|
limited.
|
||||||
* **Audit log** of every login, change and token, with user, token, IP and
|
* **Audit log** of every login, change and token, with user, token, IP and
|
||||||
outcome.
|
outcome.
|
||||||
* **Daily backups** of the database by a systemd timer, checked as they are
|
* **Daily backups** of the database and the DNSSEC keys by a systemd timer,
|
||||||
written, with retention that never deletes the last few; `jarld restore`
|
checked as they are written, with retention that never deletes the last
|
||||||
puts one back safely.
|
few; `jarld restore` puts one back safely, and raises zone serials so
|
||||||
|
named and the secondaries take the restored data.
|
||||||
* **Name server checks**: whether the secondaries serve the current serial,
|
* **Name server checks**: whether the secondaries serve the current serial,
|
||||||
and, for zones on the internet, whether the parent zone delegates them
|
and, for zones on the internet, whether the parent zone delegates them
|
||||||
to the right name servers with the right glue.
|
to the right name servers with the right glue and DS records.
|
||||||
|
* **DNSSEC signing** per zone, by BIND itself, with every step that involves
|
||||||
|
the parent zone guarded: Jarl says when the DS record can be published,
|
||||||
|
refuses to make a zone unsigned while its DS may still be out there, turns
|
||||||
|
signing off in safe steps, and can wipe the slate clean.
|
||||||
|
* **Porkbun support** (optional): the domain's name servers, glue records
|
||||||
|
(any number, IPv4 and IPv6) and DS records at the registrar, set from Jarl
|
||||||
|
after checks that the change won't take the domain offline.
|
||||||
* **No token needed on the server**: root's `sudo jarl ...` talks to jarld
|
* **No token needed on the server**: root's `sudo jarl ...` talks to jarld
|
||||||
over a local unix socket, so a lost token or password never locks you
|
over a local unix socket, so a lost token or password never locks you
|
||||||
out.
|
out.
|
||||||
@@ -101,6 +109,7 @@ in `/etc/jarl/jarl.yaml` to reach it from your management network.
|
|||||||
| [docs/api.md](docs/api.md) | REST API reference |
|
| [docs/api.md](docs/api.md) | REST API reference |
|
||||||
| [docs/permissions.md](docs/permissions.md) | Users, tokens, grants and roles |
|
| [docs/permissions.md](docs/permissions.md) | Users, tokens, grants and roles |
|
||||||
| [docs/views.md](docs/views.md) | Split DNS: adding views to a server that has none |
|
| [docs/views.md](docs/views.md) | Split DNS: adding views to a server that has none |
|
||||||
|
| [docs/dnssec.md](docs/dnssec.md) | DNSSEC signing, going public with your own name servers, Porkbun |
|
||||||
| [docs/acme.md](docs/acme.md) | Let's Encrypt DNS-01 with certbot, acme.sh, lego and Traefik |
|
| [docs/acme.md](docs/acme.md) | Let's Encrypt DNS-01 with certbot, acme.sh, lego and Traefik |
|
||||||
| [docs/stats.md](docs/stats.md) | Query statistics: enabling, what is collected, retention |
|
| [docs/stats.md](docs/stats.md) | Query statistics: enabling, what is collected, retention |
|
||||||
| [docs/validation.md](docs/validation.md) | Every check Jarl makes |
|
| [docs/validation.md](docs/validation.md) | Every check Jarl makes |
|
||||||
@@ -123,8 +132,10 @@ these pages:
|
|||||||
fields adapt to the zone type), per-zone records
|
fields adapt to the zone type), per-zone records
|
||||||
with inline editing, type-specific hints and a preview of the exact record
|
with inline editing, type-specific hints and a preview of the exact record
|
||||||
that will be added (reverse zones take addresses and suggest host names), settings (SOA, TTL, serial
|
that will be added (reverse zones take addresses and suggest host names), settings (SOA, TTL, serial
|
||||||
policy, view), options, the generated zone file, and pasting a zone file
|
policy, view), options, the generated zone file, pasting a zone file
|
||||||
to merge or replace records.
|
to merge or replace records, name server checks, DNSSEC (keys, the DS
|
||||||
|
record to copy, and each step with what it needs first) and, with a
|
||||||
|
Porkbun key, the registrar.
|
||||||
* **Views, ACLs, TSIG keys, Server options**: wherever an address match list
|
* **Views, ACLs, TSIG keys, Server options**: wherever an address match list
|
||||||
is entered, the existing ACLs and keys are offered and unknown names are
|
is entered, the existing ACLs and keys are offered and unknown names are
|
||||||
flagged. The options editor knows every
|
flagged. The options editor knows every
|
||||||
|
|||||||
@@ -0,0 +1,365 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"jarl/internal/api"
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func zoneDNSSECCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "dnssec",
|
||||||
|
Short: "Sign a zone with DNSSEC, and turn signing off safely",
|
||||||
|
Long: `named signs the zone itself (BIND's dnssec-policy with inline signing): Jarl
|
||||||
|
keeps writing the unsigned zone, and named keeps a signed copy next to it
|
||||||
|
and its keys in Jarl's key directory. See docs/dnssec.md.
|
||||||
|
|
||||||
|
Turning signing on is safe at any time; validation only starts once you add
|
||||||
|
the zone's DS record at the parent zone (your registrar), and 'status' says
|
||||||
|
when that is safe. Turning it off goes through BIND's insecure policy, which
|
||||||
|
keeps the zone signed until the DS is gone from the parent.`,
|
||||||
|
}
|
||||||
|
var view string
|
||||||
|
status := &cobra.Command{
|
||||||
|
Use: "status ZONE",
|
||||||
|
Short: "Show the zone's keys, its DS record and the next step",
|
||||||
|
Example: " jarl zone dnssec status adbraun.lol --view external",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
resp, err := dnssecStatus(args[0], view)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return output(resp, func(w io.Writer) { printDNSSEC(w, resp) })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
status.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
|
||||||
|
var policy string
|
||||||
|
enable := &cobra.Command{
|
||||||
|
Use: "enable ZONE",
|
||||||
|
Short: "Start signing the zone",
|
||||||
|
Long: `Starts signing the zone with BIND's default policy (one ECDSA P-256 key that
|
||||||
|
is never replaced, so the DS record at the parent never has to change) or a
|
||||||
|
custom dnssec-policy statement.
|
||||||
|
|
||||||
|
Nothing changes for resolvers until the zone's DS record is added at the
|
||||||
|
parent zone. named first publishes the key for long enough that every cache
|
||||||
|
has it ('status' shows when: about a day with the default policy); add the
|
||||||
|
DS after that.`,
|
||||||
|
Example: " jarl zone dnssec enable adbraun.lol --view external",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
resp, err := c.Mutate(ctx(), "PATCH", path, qv, map[string]any{"dnssec_policy": policy})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := report(resp); err != nil || !resp.Applied {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !flagQuiet {
|
||||||
|
fmt.Printf("\nnamed is signing %s now. Add the DS record at your registrar only when\n'jarl zone dnssec status %s' says the zone is ready.\n", strings.TrimSuffix(args[0], "."), args[0]+viewFlag(view))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
enable.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
enable.Flags().StringVar(&policy, "policy", "default", "dnssec-policy: default, or a custom policy defined as a top-level dnssec-policy statement")
|
||||||
|
|
||||||
|
var yes bool
|
||||||
|
disable := &cobra.Command{
|
||||||
|
Use: "disable ZONE",
|
||||||
|
Short: "Turn signing off, one safe step at a time",
|
||||||
|
Long: `Turns signing off in two steps, so the zone never goes unsigned while the
|
||||||
|
parent zone still has its DS record:
|
||||||
|
|
||||||
|
1. The first run switches the zone to BIND's insecure policy. named keeps it
|
||||||
|
signed and publishes a CDS "delete" record. Remove the DS record at your
|
||||||
|
registrar, then run 'jarl zone dnssec check-ds' so named knows. named
|
||||||
|
waits until resolvers have forgotten the DS (the parent's DS TTL, often a
|
||||||
|
day) and then removes the keys and signatures.
|
||||||
|
2. Run it again when 'status' says turning off has finished: DNSSEC is then
|
||||||
|
switched off for the zone.
|
||||||
|
|
||||||
|
A zone whose DS never reached the parent can be wiped at once instead
|
||||||
|
('jarl zone dnssec wipe').`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
st, err := dnssecStatus(args[0], view)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var next string
|
||||||
|
switch {
|
||||||
|
case st.Policy == "":
|
||||||
|
fmt.Println("DNSSEC is already off for this zone.")
|
||||||
|
if st.Phase.Code == dnssec.PhaseLeftover {
|
||||||
|
fmt.Println("Old keys are still in its key directory; 'jarl zone dnssec wipe' removes them.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case st.Policy != "insecure":
|
||||||
|
if !confirm(fmt.Sprintf("Start turning DNSSEC off for %s? named keeps it signed until you've removed the DS record at your registrar.", displayName(st.Zone)), yes) {
|
||||||
|
return fmt.Errorf("canceled")
|
||||||
|
}
|
||||||
|
next = "insecure"
|
||||||
|
case !st.Phase.CanFinish:
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", st.Phase.Summary)
|
||||||
|
if st.Phase.Next != "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", st.Phase.Next)
|
||||||
|
}
|
||||||
|
return &checkFailed{"turning DNSSEC off hasn't finished yet"}
|
||||||
|
}
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
resp, err := c.Mutate(ctx(), "PATCH", path, qv, map[string]any{"dnssec_policy": next})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := report(resp); err != nil || !resp.Applied || flagQuiet {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if next == "insecure" {
|
||||||
|
fmt.Printf("\nNext: remove the DS record for %s at your registrar, then run\n jarl zone dnssec check-ds %s\nRun 'jarl zone dnssec disable %s' again when 'status' says it has finished.\n", displayName(st.Zone), args[0]+viewFlag(view), args[0]+viewFlag(view))
|
||||||
|
} else {
|
||||||
|
fmt.Println("\nDNSSEC is off. The old keys stay in the key directory until you wipe them ('jarl zone dnssec wipe').")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
disable.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
disable.Flags().BoolVarP(&yes, "yes", "y", false, "don't ask for confirmation")
|
||||||
|
|
||||||
|
var resolver string
|
||||||
|
checkDS := &cobra.Command{
|
||||||
|
Use: "check-ds ZONE",
|
||||||
|
Short: "Check the parent zone's DS records and tell named",
|
||||||
|
Long: `Asks every server of the parent zone for the zone's DS records, and tells
|
||||||
|
named (rndc dnssec -checkds) when its key's DS has appeared there (after you
|
||||||
|
added it at the registrar) or is gone (while turning DNSSEC off). named
|
||||||
|
moves to the next step only once it knows.
|
||||||
|
|
||||||
|
The parent is found through jarld's resolver, or --resolver. Exits with 2
|
||||||
|
when the parent couldn't be checked.`,
|
||||||
|
Example: " jarl zone dnssec check-ds adbraun.lol --view external",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
if resolver != "" {
|
||||||
|
qv.Set("resolver", resolver)
|
||||||
|
}
|
||||||
|
var resp api.CheckDSResponse
|
||||||
|
if err := c.Do(ctx(), "POST", path+"/dnssec/check-ds", qv, nil, &resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = output(resp, func(w io.Writer) {
|
||||||
|
p := resp.Parent
|
||||||
|
if p.Error != "" {
|
||||||
|
fmt.Fprintf(w, "error: %s\n", p.Error)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "Parent zone:\t%s (%d of %d servers answered, found through %s)\n", displayName(p.Parent), p.Reached, len(p.Servers), p.Resolver)
|
||||||
|
if !p.Delegated {
|
||||||
|
fmt.Fprintf(w, "Delegation:\tnone (the zone isn't delegated from %s)\n", displayName(p.Parent))
|
||||||
|
}
|
||||||
|
if len(p.DS) == 0 {
|
||||||
|
fmt.Fprintln(w, "DS records:\tnone")
|
||||||
|
}
|
||||||
|
for _, d := range p.DS {
|
||||||
|
fmt.Fprintf(w, "DS record:\tkey %d, algorithm %d, digest type %d\n", d.KeyTag, d.Algorithm, d.DigestType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flush(w)
|
||||||
|
for _, m := range resp.Marked {
|
||||||
|
fmt.Printf("named told: %s\n", m)
|
||||||
|
}
|
||||||
|
for _, n := range resp.Notes {
|
||||||
|
fmt.Printf("note: %s\n", n)
|
||||||
|
}
|
||||||
|
if resp.Status != nil {
|
||||||
|
fmt.Printf("\n%s\n", resp.Status.Phase.Summary)
|
||||||
|
if resp.Status.Phase.Next != "" {
|
||||||
|
fmt.Println(resp.Status.Phase.Next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.Parent.Error != "" {
|
||||||
|
return &checkFailed{"the parent zone couldn't be checked"}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
checkDS.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
checkDS.Flags().StringVar(&resolver, "resolver", "", "resolver to find the parent zone with, e.g. 9.9.9.9 (default: the server's)")
|
||||||
|
|
||||||
|
var force bool
|
||||||
|
wipe := &cobra.Command{
|
||||||
|
Use: "wipe ZONE",
|
||||||
|
Short: "Switch signing off at once and delete the zone's keys (a clean slate)",
|
||||||
|
Long: `Switches DNSSEC off for the zone at once (skipping the insecure policy) and
|
||||||
|
deletes its keys and named's signed copy, so that signing it again starts
|
||||||
|
from scratch. Also cleans up a zone that is off but still has old keys.
|
||||||
|
|
||||||
|
This is only safe when the parent zone has no DS record for the zone: Jarl
|
||||||
|
checks the parent first and refuses while it has one. When the parent can't
|
||||||
|
be checked (a zone that isn't on the internet, or no internet access),
|
||||||
|
--force wipes anyway. Needs an administrator.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !confirm(fmt.Sprintf("Switch DNSSEC off for %s and delete its keys? Make sure the parent zone has no DS record for it.", strings.TrimSuffix(args[0], ".")), yes) {
|
||||||
|
return fmt.Errorf("canceled")
|
||||||
|
}
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
if resolver != "" {
|
||||||
|
qv.Set("resolver", resolver)
|
||||||
|
}
|
||||||
|
if flagDryRun {
|
||||||
|
qv.Set("dry_run", "1")
|
||||||
|
}
|
||||||
|
var resp api.DNSSECWipeResponse
|
||||||
|
if err := c.Do(ctx(), "POST", path+"/dnssec/wipe", qv, api.DNSSECWipe{Force: force, DryRun: flagDryRun}, &resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return output(resp, func(w io.Writer) {
|
||||||
|
verb := "removed"
|
||||||
|
if resp.DryRun {
|
||||||
|
verb = "would remove"
|
||||||
|
}
|
||||||
|
for _, f := range resp.Removed {
|
||||||
|
fmt.Printf("%s %s\n", verb, f)
|
||||||
|
}
|
||||||
|
if resp.DryRun {
|
||||||
|
fmt.Println("dry run: nothing was changed")
|
||||||
|
} else {
|
||||||
|
fmt.Println("DNSSEC is off and the zone's keys are gone.")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
wipe.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
wipe.Flags().BoolVar(&force, "force", false, "wipe although the parent zone couldn't be checked")
|
||||||
|
wipe.Flags().StringVar(&resolver, "resolver", "", "resolver to find the parent zone with (default: the server's)")
|
||||||
|
wipe.Flags().BoolVarP(&yes, "yes", "y", false, "don't ask for confirmation")
|
||||||
|
|
||||||
|
cmd.AddCommand(status, enable, disable, checkDS, wipe)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func viewFlag(view string) string {
|
||||||
|
if view == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return " --view " + view
|
||||||
|
}
|
||||||
|
|
||||||
|
func dnssecStatus(zone, view string) (*api.DNSSECResponse, error) {
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(zone, view)
|
||||||
|
var resp api.DNSSECResponse
|
||||||
|
if err := c.Get(ctx(), path+"/dnssec", qv, &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printDNSSEC(w io.Writer, r *api.DNSSECResponse) {
|
||||||
|
head := displayName(r.Zone)
|
||||||
|
if r.View != "" {
|
||||||
|
head += " [view " + r.View + "]"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "Zone:\t%s\n", head)
|
||||||
|
policy := r.Policy
|
||||||
|
switch policy {
|
||||||
|
case "":
|
||||||
|
policy = "none (not signed)"
|
||||||
|
case "insecure":
|
||||||
|
policy = "insecure (turning DNSSEC off)"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "Policy:\t%s\n", policy)
|
||||||
|
fmt.Fprintf(w, "Status:\t%s\n", r.Phase.Summary)
|
||||||
|
if r.Phase.Next != "" {
|
||||||
|
fmt.Fprintf(w, "Next:\t%s\n", r.Phase.Next)
|
||||||
|
}
|
||||||
|
if r.Named != nil && r.Named.Secure {
|
||||||
|
fmt.Fprintf(w, "named:\tsigned serial %d (zone file %d)", r.Named.SignedSerial, r.Named.Serial)
|
||||||
|
if r.Named.NextKeyEvent != "" {
|
||||||
|
fmt.Fprintf(w, ", next key event %s", r.Named.NextKeyEvent)
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w)
|
||||||
|
}
|
||||||
|
if r.NamedError != "" {
|
||||||
|
fmt.Fprintf(w, "named:\t%s\n", r.NamedError)
|
||||||
|
}
|
||||||
|
if r.Policy != "" || len(r.Keys) > 0 {
|
||||||
|
fmt.Fprintf(w, "Key directory:\t%s\n", r.KeyDir)
|
||||||
|
}
|
||||||
|
if r.KeyError != "" {
|
||||||
|
fmt.Fprintf(w, "Keys:\tcan't be read: %s\n", r.KeyError)
|
||||||
|
}
|
||||||
|
flush(w)
|
||||||
|
if len(r.Keys) > 0 {
|
||||||
|
fmt.Fprintln(w, "\nKEY\tROLE\tALGORITHM\tGOAL\tDNSKEY\tDS AT PARENT\tCREATED")
|
||||||
|
for _, k := range r.Keys {
|
||||||
|
created := "-"
|
||||||
|
if k.Created != nil {
|
||||||
|
created = k.Created.Local().Format("2006-01-02 15:04")
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t%s\t%s\n", k.Tag, k.Role, k.AlgorithmName, dash(k.Goal), dash(k.DNSKEYState), dash(k.DSState), created)
|
||||||
|
}
|
||||||
|
flush(w)
|
||||||
|
}
|
||||||
|
var ds []*dnssec.Key
|
||||||
|
for _, k := range r.Keys {
|
||||||
|
if k.DS != nil && k.Goal == dnssec.Omnipresent {
|
||||||
|
ds = append(ds, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(ds) > 0 && r.Policy != "insecure" {
|
||||||
|
where := "at your registrar"
|
||||||
|
if r.ParentZone != "" {
|
||||||
|
where = "in the parent zone " + displayName(r.ParentZone) + " (in Jarl: add it as a DS record there)"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "\nDS record for the parent zone (%s):\n", where)
|
||||||
|
if !r.Phase.CanPublishDS && r.Phase.DSReadyAt != nil {
|
||||||
|
fmt.Fprintf(w, " (not yet: wait until %s)\n", r.Phase.DSReadyAt.Local().Format(time.RFC1123))
|
||||||
|
}
|
||||||
|
for _, k := range ds {
|
||||||
|
fmt.Fprintf(w, " %s\n", strings.ReplaceAll(k.DS.Record, "\t", " "))
|
||||||
|
fmt.Fprintf(w, " key tag %d, algorithm %d (%s), digest type %d (SHA-256), digest %s\n", k.DS.KeyTag, k.DS.Algorithm, k.AlgorithmName, k.DS.DigestType, k.DS.Digest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dash(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"jarl/internal/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
func zoneRegistrarCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "registrar",
|
||||||
|
Short: "The domain's name servers, glue and DS records at the registrar (Porkbun)",
|
||||||
|
Long: `Shows and changes a domain's delegation at the registrar Porkbun: its name
|
||||||
|
servers, the glue records of name servers inside the domain, and its DNSSEC
|
||||||
|
DS records. Needs a Porkbun API key in jarl.yaml (porkbun:, see
|
||||||
|
docs/dnssec.md#porkbun) and an administrator.
|
||||||
|
|
||||||
|
Every change checks first that it won't break the domain (for example that
|
||||||
|
the new name servers serve the zone, or that the zone is signed with the
|
||||||
|
key a DS record points at) and is refused otherwise; --dry-run shows those
|
||||||
|
checks, --force skips them.`,
|
||||||
|
}
|
||||||
|
var view string
|
||||||
|
status := &cobra.Command{
|
||||||
|
Use: "status ZONE",
|
||||||
|
Short: "Compare the registrar's name servers, glue and DS records with the zone",
|
||||||
|
Example: " jarl zone registrar status adbraun.lol --view external",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
c, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
var resp api.RegistrarResponse
|
||||||
|
if err := c.Get(ctx(), path+"/registrar", qv, &resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = output(resp, func(w io.Writer) {
|
||||||
|
if resp.Error != "" {
|
||||||
|
fmt.Fprintf(w, "error: %s\n", resp.Error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "Domain:\t%s at %s\n", resp.Domain, resp.Registrar)
|
||||||
|
fmt.Fprintf(w, "Name servers:\t%s\n", strings.Join(resp.NS, ", "))
|
||||||
|
fmt.Fprintf(w, "Zone's NS records:\t%s\n", strings.Join(resp.JarlNS, ", "))
|
||||||
|
flush(w)
|
||||||
|
if len(resp.Glue) > 0 {
|
||||||
|
fmt.Fprintln(w, "\nGLUE FOR\tAT REGISTRAR\tIN THE ZONE\tTO DO")
|
||||||
|
for _, g := range resp.Glue {
|
||||||
|
todo := g.Action
|
||||||
|
if todo == "" {
|
||||||
|
todo = "-"
|
||||||
|
if !g.Needed && !g.InUse {
|
||||||
|
todo = "unused"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", g.Host, firstNonEmpty(strings.Join(g.Registry, ", "), "none"), firstNonEmpty(strings.Join(g.Jarl, ", "), "-"), todo)
|
||||||
|
}
|
||||||
|
flush(w)
|
||||||
|
}
|
||||||
|
if len(resp.DS) > 0 {
|
||||||
|
fmt.Fprintln(w, "\nDS KEY TAG\tALGORITHM\tDIGEST TYPE\tMATCHES THE ZONE")
|
||||||
|
for _, d := range resp.DS {
|
||||||
|
fmt.Fprintf(w, "%d\t%d\t%d\t%v\n", d.KeyTag, d.Algorithm, d.DigestType, d.Matches)
|
||||||
|
}
|
||||||
|
flush(w)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
for _, f := range resp.Findings {
|
||||||
|
fmt.Printf("%-8s %s\n", f.Level+":", f.Message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.Error != "" {
|
||||||
|
return &checkFailed{"the registrar couldn't be asked"}
|
||||||
|
}
|
||||||
|
for _, f := range resp.Findings {
|
||||||
|
if f.Level == "error" {
|
||||||
|
return &checkFailed{"the registrar's records don't match the zone"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
status.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
|
||||||
|
var force bool
|
||||||
|
change := func(use, short, long, method, sub string, args cobra.PositionalArgs, body func(args []string) (string, any, error)) *cobra.Command {
|
||||||
|
c := &cobra.Command{
|
||||||
|
Use: use,
|
||||||
|
Short: short,
|
||||||
|
Long: long,
|
||||||
|
Args: args,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
cl, err := newClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, qv := zonePath(args[0], view)
|
||||||
|
if flagDryRun {
|
||||||
|
qv.Set("dry_run", "1")
|
||||||
|
}
|
||||||
|
extra, b, err := body(args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var resp api.RegistrarChangeResponse
|
||||||
|
if err := cl.Do(ctx(), method, path+"/registrar/"+sub+extra, qv, b, &resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return output(resp, func(w io.Writer) {
|
||||||
|
for _, f := range resp.Checks {
|
||||||
|
fmt.Printf("%-8s %s\n", f.Level+":", f.Message)
|
||||||
|
}
|
||||||
|
verb := "done:"
|
||||||
|
if resp.DryRun {
|
||||||
|
verb = "would:"
|
||||||
|
}
|
||||||
|
for _, d := range resp.Done {
|
||||||
|
fmt.Printf("%-8s %s\n", verb, d)
|
||||||
|
}
|
||||||
|
if len(resp.Done) == 0 {
|
||||||
|
fmt.Println("nothing to change")
|
||||||
|
}
|
||||||
|
for _, wn := range resp.Warnings {
|
||||||
|
fmt.Printf("note: %s\n", wn)
|
||||||
|
}
|
||||||
|
if resp.DryRun {
|
||||||
|
fmt.Println("dry run: nothing was changed")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.Flags().StringVar(&view, "view", "", "view of the zone")
|
||||||
|
c.Flags().BoolVar(&force, "force", false, "skip the checks that the change won't break the domain")
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
syncGlue := change("sync-glue ZONE", "Create or update glue records for the zone's name servers inside the domain",
|
||||||
|
`Gives every name server in the zone's NS records that is inside the domain
|
||||||
|
(ns1.adbraun.lol for adbraun.lol) a glue record at the registrar with the
|
||||||
|
zone's A and AAAA records for it: one glue record per name server, each with
|
||||||
|
all its addresses. Resolvers need glue to find such a server at all.
|
||||||
|
|
||||||
|
Changing the glue of a name server the domain is delegated to sends
|
||||||
|
resolvers to the new addresses, so they must answer for the zone first.`,
|
||||||
|
"POST", "glue", cobra.ExactArgs(1), func([]string) (string, any, error) {
|
||||||
|
return "", api.RegistrarChange{Force: force, DryRun: flagDryRun}, nil
|
||||||
|
})
|
||||||
|
var key uint16
|
||||||
|
publishDS := change("publish-ds ZONE", "Publish the zone's DS record at the registrar (turns DNSSEC validation on)",
|
||||||
|
`Adds the DS record of the zone's key at the registrar, which publishes it in
|
||||||
|
the parent zone: from then on validating resolvers check the zone's
|
||||||
|
signatures. Refused until named says the zone is ready, and unless the
|
||||||
|
domain is delegated to name servers that serve the signed zone.
|
||||||
|
|
||||||
|
Afterwards run 'jarl zone dnssec check-ds ZONE' once the parent zone has it.`,
|
||||||
|
"POST", "ds", cobra.ExactArgs(1), func([]string) (string, any, error) {
|
||||||
|
return "", api.RegistrarChange{KeyTag: key, Force: force, DryRun: flagDryRun}, nil
|
||||||
|
})
|
||||||
|
publishDS.Flags().Uint16Var(&key, "key", 0, "key tag (default: every key that needs a DS)")
|
||||||
|
removeDS := change("remove-ds ZONE KEYTAG", "Remove a DS record at the registrar",
|
||||||
|
`Removes a DS record at the registrar. Without the zone's DS record, resolvers
|
||||||
|
stop validating it (it stays signed). This is the step 'jarl zone dnssec
|
||||||
|
disable' asks for; a DS record that matches none of the zone's keys breaks
|
||||||
|
the domain and should go at once.`,
|
||||||
|
"DELETE", "ds/", cobra.ExactArgs(2), func(args []string) (string, any, error) {
|
||||||
|
return args[1], nil, nil
|
||||||
|
})
|
||||||
|
setNS := change("set-ns ZONE [NAMESERVER...]", "Delegate the domain to the zone's name servers (or the ones given)",
|
||||||
|
`Sets the domain's name servers at the registrar: by default to the zone's NS
|
||||||
|
records. Checked first: each name server answers for the zone with the
|
||||||
|
current serial, name servers inside the domain have glue records that match
|
||||||
|
the zone (run sync-glue before), and DS records at the registrar match the
|
||||||
|
zone's keys (otherwise the domain goes dark for validating resolvers).`,
|
||||||
|
"PUT", "ns", cobra.MinimumNArgs(1), func(args []string) (string, any, error) {
|
||||||
|
return "", api.RegistrarChange{NS: args[1:], Force: force, DryRun: flagDryRun}, nil
|
||||||
|
})
|
||||||
|
cmd.AddCommand(status, syncGlue, publishDS, removeDS, setNS)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
+1
-1
@@ -367,7 +367,7 @@ equal to the file: records not in the file are deleted.`,
|
|||||||
importCmd.Flags().BoolVar(&replace, "replace", false, "delete records that are not in the file")
|
importCmd.Flags().BoolVar(&replace, "replace", false, "delete records that are not in the file")
|
||||||
importCmd.Flags().BoolVar(&useSOA, "use-soa", false, "also take SOA timers and $TTL from the file")
|
importCmd.Flags().BoolVar(&useSOA, "use-soa", false, "also take SOA timers and $TTL from the file")
|
||||||
|
|
||||||
cmd.AddCommand(list, show, create, update, del, fileCmd, importCmd, zoneSerialsCmd(), zoneDelegationCmd())
|
cmd.AddCommand(list, show, create, update, del, fileCmd, importCmd, zoneSerialsCmd(), zoneDelegationCmd(), zoneDNSSECCmd(), zoneRegistrarCmd())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+167
-14
@@ -7,8 +7,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -18,11 +21,13 @@ import (
|
|||||||
"jarl/internal/auth"
|
"jarl/internal/auth"
|
||||||
"jarl/internal/backup"
|
"jarl/internal/backup"
|
||||||
"jarl/internal/config"
|
"jarl/internal/config"
|
||||||
|
"jarl/internal/render"
|
||||||
"jarl/internal/store"
|
"jarl/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func backupCmd() *cobra.Command {
|
func backupCmd() *cobra.Command {
|
||||||
return &cobra.Command{
|
var withoutKeys bool
|
||||||
|
cmd := &cobra.Command{
|
||||||
Use: "backup [FILE]",
|
Use: "backup [FILE]",
|
||||||
Short: "Back up the database (safe while jarld runs)",
|
Short: "Back up the database (safe while jarld runs)",
|
||||||
Long: `Writes a consistent copy of Jarl's database and checks it.
|
Long: `Writes a consistent copy of Jarl's database and checks it.
|
||||||
@@ -35,10 +40,18 @@ say. This is what the jarl-backup.timer systemd timer runs every day.
|
|||||||
With FILE it writes a single copy there, which is never deleted
|
With FILE it writes a single copy there, which is never deleted
|
||||||
automatically.
|
automatically.
|
||||||
|
|
||||||
|
Each backup also holds the DNSSEC keys of signed zones (from Jarl's key
|
||||||
|
directory, private keys included), so that 'jarld restore' can put them
|
||||||
|
back: a zone whose keys are lost stops validating while its parent still
|
||||||
|
has a DS record for them. named's private keys are readable only by named's
|
||||||
|
user, so run this as root; jarl-backup.service has the capability to read
|
||||||
|
them. --without-keys backs up only the database.
|
||||||
|
|
||||||
Every backup is recorded in the database, and the dashboard shows the newest.
|
Every backup is recorded in the database, and the dashboard shows the newest.
|
||||||
Restore one with 'jarld restore'.`,
|
Restore one with 'jarld restore'.`,
|
||||||
Example: ` sudo -u jarl jarld backup
|
Example: ` sudo jarld backup
|
||||||
sudo -u jarl jarld backup /root/jarl-before-upgrade.db`,
|
sudo jarld backup /root/jarl-before-upgrade.db
|
||||||
|
sudo systemctl start jarl-backup.service`,
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cfg, err := config.Load(configPath, true)
|
cfg, err := config.Load(configPath, true)
|
||||||
@@ -59,7 +72,14 @@ Restore one with 'jarld restore'.`,
|
|||||||
defer newDirOwner(filepath.Dir(cfg.Database)).fix(filepath.Dir(cfg.Database))
|
defer newDirOwner(filepath.Dir(cfg.Database)).fix(filepath.Dir(cfg.Database))
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
keysDir := render.Paths{ZoneDir: cfg.BIND.ZoneDir}.KeysDir()
|
||||||
|
if withoutKeys {
|
||||||
|
keysDir = ""
|
||||||
|
}
|
||||||
fail := func(err error) error {
|
fail := func(err error) error {
|
||||||
|
if strings.Contains(err.Error(), "DNSSEC keys") {
|
||||||
|
err = fmt.Errorf("%w; or back up only the database with --without-keys", err)
|
||||||
|
}
|
||||||
if rerr := st.RecordBackup(ctx, store.BackupRecord{At: now, Error: err.Error()}); rerr != nil {
|
if rerr := st.RecordBackup(ctx, store.BackupRecord{At: now, Error: err.Error()}); rerr != nil {
|
||||||
fmt.Fprintln(os.Stderr, "warning: couldn't record the failure in the database:", rerr)
|
fmt.Fprintln(os.Stderr, "warning: couldn't record the failure in the database:", rerr)
|
||||||
}
|
}
|
||||||
@@ -74,27 +94,33 @@ Restore one with 'jarld restore'.`,
|
|||||||
os.Remove(dst)
|
os.Remove(dst)
|
||||||
return fail(fmt.Errorf("backing up %s: %w", cfg.Database, err))
|
return fail(fmt.Errorf("backing up %s: %w", cfg.Database, err))
|
||||||
}
|
}
|
||||||
|
if keysDir != "" {
|
||||||
|
if _, err := backup.AddFiles(ctx, dst, keysDir); err != nil {
|
||||||
|
os.Remove(dst)
|
||||||
|
return fail(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := backup.Verify(ctx, dst); err != nil {
|
if err := backup.Verify(ctx, dst); err != nil {
|
||||||
os.Remove(dst)
|
os.Remove(dst)
|
||||||
return fail(fmt.Errorf("the backup failed its check: %w", err))
|
return fail(fmt.Errorf("the backup failed its check: %w", err))
|
||||||
}
|
}
|
||||||
fi, _ := os.Stat(dst)
|
fi, _ := os.Stat(dst)
|
||||||
st.RecordBackup(ctx, store.BackupRecord{At: now, File: dst, Size: fi.Size()})
|
st.RecordBackup(ctx, store.BackupRecord{At: now, File: dst, Size: fi.Size()})
|
||||||
fmt.Printf("Database backed up to %s (%s)\n", dst, size(fi.Size()))
|
fmt.Printf("Database backed up to %s (%s)%s\n", dst, size(fi.Size()), keysNote(ctx, dst))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := cfg.Backup.Dir
|
dir := cfg.Backup.Dir
|
||||||
defer newDirOwner(dir).fix(dir)
|
defer newDirOwner(dir).fix(dir)
|
||||||
f, err := backup.Write(ctx, cfg.Database, dir, backup.KindJarl, now)
|
f, err := backup.Write(ctx, cfg.Database, dir, backup.KindJarl, now, keysDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fail(fmt.Errorf("backing up %s: %w", cfg.Database, err))
|
return fail(fmt.Errorf("backing up %s: %w", cfg.Database, err))
|
||||||
}
|
}
|
||||||
fmt.Printf("Database backed up to %s (%s)\n", f.Path, size(f.Size))
|
fmt.Printf("Database backed up to %s (%s)%s\n", f.Path, size(f.Size), keysNote(ctx, f.Path))
|
||||||
kinds := []string{backup.KindJarl}
|
kinds := []string{backup.KindJarl}
|
||||||
if cfg.Backup.Stats {
|
if cfg.Backup.Stats {
|
||||||
if _, err := os.Stat(cfg.Stats.Database); err == nil {
|
if _, err := os.Stat(cfg.Stats.Database); err == nil {
|
||||||
sf, err := backup.Write(ctx, cfg.Stats.Database, dir, backup.KindStats, now)
|
sf, err := backup.Write(ctx, cfg.Stats.Database, dir, backup.KindStats, now, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fail(fmt.Errorf("backing up the statistics database %s: %w", cfg.Stats.Database, err))
|
return fail(fmt.Errorf("backing up the statistics database %s: %w", cfg.Stats.Database, err))
|
||||||
}
|
}
|
||||||
@@ -117,10 +143,20 @@ Restore one with 'jarld restore'.`,
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cmd.Flags().BoolVar(&withoutKeys, "without-keys", false, "back up only the database, not the DNSSEC keys")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// keysNote says how many DNSSEC key files a backup holds.
|
||||||
|
func keysNote(ctx context.Context, path string) string {
|
||||||
|
if in, err := backup.Inspect(ctx, path); err == nil && in.KeyFiles > 0 {
|
||||||
|
return ", with " + plural(in.KeyFiles, "DNSSEC key file")
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreCmd() *cobra.Command {
|
func restoreCmd() *cobra.Command {
|
||||||
var yes bool
|
var yes, withoutKeys bool
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "restore [FILE | latest]",
|
Use: "restore [FILE | latest]",
|
||||||
Short: "Replace the database with a backup (jarld must be stopped)",
|
Short: "Replace the database with a backup (jarld must be stopped)",
|
||||||
@@ -132,13 +168,20 @@ confirm replaces the database with it. jarld must be stopped first. The
|
|||||||
current database is kept as DATABASE.before-restore-<UTC time>, and the
|
current database is kept as DATABASE.before-restore-<UTC time>, and the
|
||||||
restore is recorded in the restored database's audit log.
|
restore is recorded in the restored database's audit log.
|
||||||
|
|
||||||
|
The DNSSEC keys stored in the backup go back into Jarl's key directory,
|
||||||
|
owned by named's user (bind.named_user), which needs root. Key files that
|
||||||
|
are there but not in the backup are left alone. --without-keys restores
|
||||||
|
only the database.
|
||||||
|
|
||||||
Then start jarld and bring named's files in line with the restored database:
|
Then start jarld and bring named's files in line with the restored database:
|
||||||
|
|
||||||
systemctl start jarl
|
systemctl start jarl
|
||||||
jarl resync --dry-run # what differs
|
jarl resync --dry-run # what differs
|
||||||
jarl resync --force # write everything and reload named
|
jarl resync --force # write everything and reload named
|
||||||
|
|
||||||
See "Restoring" in docs/operations.md, also for zone serials and secondaries.`,
|
Jarl raises the serials of zones whose data goes back to an older state
|
||||||
|
above what named and the secondaries have, so they pick it up. See
|
||||||
|
"Restoring" in docs/operations.md.`,
|
||||||
Example: ` sudo jarld restore
|
Example: ` sudo jarld restore
|
||||||
sudo systemctl stop jarl
|
sudo systemctl stop jarl
|
||||||
sudo jarld restore latest
|
sudo jarld restore latest
|
||||||
@@ -180,6 +223,24 @@ See "Restoring" in docs/operations.md, also for zone serials and secondaries.`,
|
|||||||
if info.Schema > store.SchemaVersion() {
|
if info.Schema > store.SchemaVersion() {
|
||||||
return fmt.Errorf("%s was made by a newer Jarl (schema %d, this one knows %d); install that version to restore it", src, info.Schema, store.SchemaVersion())
|
return fmt.Errorf("%s was made by a newer Jarl (schema %d, this one knows %d); install that version to restore it", src, info.Schema, store.SchemaVersion())
|
||||||
}
|
}
|
||||||
|
keysDir := render.Paths{ZoneDir: cfg.BIND.ZoneDir}.KeysDir()
|
||||||
|
var keyFiles []backup.StoredFile
|
||||||
|
if !withoutKeys {
|
||||||
|
var root string
|
||||||
|
root, keyFiles, err = backup.Files(ctx, src)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("reading the DNSSEC keys in %s: %w", src, err)
|
||||||
|
}
|
||||||
|
if len(keyFiles) > 0 && os.Geteuid() != 0 && !runningAs(cfg.BIND.NamedUser) {
|
||||||
|
return fmt.Errorf("the backup holds %s, and putting them back for named needs root: run this as root (or add --without-keys to restore only the database)", plural(len(keyFiles), "DNSSEC key file"))
|
||||||
|
}
|
||||||
|
if root != "" && root != keysDir && len(keyFiles) > 0 {
|
||||||
|
fmt.Printf("The keys were backed up from %s; they go to %s now.\n", root, keysDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if info.SignedZones > 0 && len(keyFiles) == 0 && !withoutKeys {
|
||||||
|
fmt.Fprintf(os.Stderr, "warning: the backup has %s but no DNSSEC keys (it was made with --without-keys, or before Jarl backed them up). Unless the keys are still in %s, named makes new ones, and a DS record for the old ones at the parent stops matching.\n", plural(info.SignedZones, "signed zone"), keysDir)
|
||||||
|
}
|
||||||
unlock, err := lockDatabase(cfg.Database)
|
unlock, err := lockDatabase(cfg.Database)
|
||||||
if errors.Is(err, errInUse) {
|
if errors.Is(err, errInUse) {
|
||||||
return fmt.Errorf("jarld is running; stop it first (systemctl stop jarl), then run this again")
|
return fmt.Errorf("jarld is running; stop it first (systemctl stop jarl), then run this again")
|
||||||
@@ -192,6 +253,9 @@ See "Restoring" in docs/operations.md, also for zone serials and secondaries.`,
|
|||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
fmt.Fprintf(w, "Backup:\t%s\n", src)
|
fmt.Fprintf(w, "Backup:\t%s\n", src)
|
||||||
describe(w, info, backupTime(src))
|
describe(w, info, backupTime(src))
|
||||||
|
if len(keyFiles) > 0 {
|
||||||
|
fmt.Fprintf(w, " DNSSEC keys\t%s (go back to %s)\n", plural(len(keyFiles), "file"), keysDir)
|
||||||
|
}
|
||||||
if cur, err := backup.Inspect(ctx, cfg.Database); err == nil {
|
if cur, err := backup.Inspect(ctx, cfg.Database); err == nil {
|
||||||
fmt.Fprintf(w, "\nCurrent database:\t%s\n", cfg.Database)
|
fmt.Fprintf(w, "\nCurrent database:\t%s\n", cfg.Database)
|
||||||
describe(w, cur, time.Time{})
|
describe(w, cur, time.Time{})
|
||||||
@@ -224,13 +288,27 @@ See "Restoring" in docs/operations.md, also for zone serials and secondaries.`,
|
|||||||
moved = true
|
moved = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := copyFile(src, db, 0o640); err != nil {
|
restoreErr := copyFile(src, db, 0o640)
|
||||||
|
if restoreErr == nil {
|
||||||
|
// The keys go back to their own files, not into the
|
||||||
|
// live database.
|
||||||
|
restoreErr = backup.DropFiles(ctx, db)
|
||||||
|
}
|
||||||
|
if restoreErr != nil {
|
||||||
|
os.Remove(db)
|
||||||
if moved {
|
if moved {
|
||||||
os.Rename(aside, db)
|
os.Rename(aside, db)
|
||||||
os.Rename(aside+"-wal", db+"-wal")
|
os.Rename(aside+"-wal", db+"-wal")
|
||||||
os.Rename(aside+"-shm", db+"-shm")
|
os.Rename(aside+"-shm", db+"-shm")
|
||||||
}
|
}
|
||||||
return fmt.Errorf("restoring: %w (the current database was left in place)", err)
|
return fmt.Errorf("restoring: %w (the current database was left in place)", restoreErr)
|
||||||
|
}
|
||||||
|
if len(keyFiles) > 0 {
|
||||||
|
n, err := restoreKeys(cfg, keysDir, keyFiles)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("the database was restored, but putting back the DNSSEC keys failed after %d files: %w", n, err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Put back %s in %s.\n", plural(n, "DNSSEC key file"), keysDir)
|
||||||
}
|
}
|
||||||
// Open it as jarld will: an older backup gets the current
|
// Open it as jarld will: an older backup gets the current
|
||||||
// schema now, and the restore goes into its audit log.
|
// schema now, and the restore goes into its audit log.
|
||||||
@@ -255,17 +333,89 @@ Next:
|
|||||||
jarl resync --dry-run # what differs between the restored database and named's files
|
jarl resync --dry-run # what differs between the restored database and named's files
|
||||||
jarl resync --force # write them and reload named
|
jarl resync --force # write them and reload named
|
||||||
|
|
||||||
If you have secondary servers, zone serials older than what they last saw
|
Zones whose data goes back to an older state get a serial above the one
|
||||||
are ignored by them: raise them with 'jarl zone update ZONE --serial N'
|
named has, so named and the secondaries load them (see "Restoring" in
|
||||||
(see "Restoring" in docs/operations.md).
|
docs/operations.md).
|
||||||
`)
|
`)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().BoolVarP(&yes, "yes", "y", false, "don't ask for confirmation")
|
cmd.Flags().BoolVarP(&yes, "yes", "y", false, "don't ask for confirmation")
|
||||||
|
cmd.Flags().BoolVar(&withoutKeys, "without-keys", false, "restore only the database, not the DNSSEC keys")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runningAs reports whether this process runs as the named user.
|
||||||
|
func runningAs(name string) bool {
|
||||||
|
u, err := user.Lookup(name)
|
||||||
|
return err == nil && u.Uid == strconv.Itoa(os.Geteuid())
|
||||||
|
}
|
||||||
|
|
||||||
|
// restoreKeys writes DNSSEC key files from a backup into keysDir, owned
|
||||||
|
// by named's user and Jarl's file group with their backed-up modes, so
|
||||||
|
// named can use them. Directories get the owner of the zone directory
|
||||||
|
// (jarld's user), like the ones jarld makes. Files already there are
|
||||||
|
// replaced; others are left alone.
|
||||||
|
func restoreKeys(cfg *config.Config, keysDir string, files []backup.StoredFile) (int, error) {
|
||||||
|
uid, gid := -1, -1
|
||||||
|
if u, err := user.Lookup(cfg.BIND.NamedUser); err == nil {
|
||||||
|
uid, _ = strconv.Atoi(u.Uid)
|
||||||
|
} else {
|
||||||
|
return 0, fmt.Errorf("named's user %q (bind.named_user): %w", cfg.BIND.NamedUser, err)
|
||||||
|
}
|
||||||
|
if g, err := user.LookupGroup(cfg.BIND.FileGroup); err == nil {
|
||||||
|
gid, _ = strconv.Atoi(g.Gid)
|
||||||
|
}
|
||||||
|
dirUID, dirGID := -1, gid
|
||||||
|
if fi, err := os.Stat(cfg.BIND.ZoneDir); err == nil {
|
||||||
|
if st, ok := fi.Sys().(*syscall.Stat_t); ok {
|
||||||
|
dirUID = int(st.Uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var mkdir func(dir string) error
|
||||||
|
mkdir = func(dir string) error {
|
||||||
|
if _, err := os.Stat(dir); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := mkdir(filepath.Dir(dir)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.Mkdir(dir, 0o770); err != nil && !os.IsExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Chown(dir, dirUID, dirGID)
|
||||||
|
return os.Chmod(dir, 0o770|os.ModeSetgid)
|
||||||
|
}
|
||||||
|
n := 0
|
||||||
|
for _, f := range files {
|
||||||
|
if filepath.IsAbs(f.Path) || strings.HasPrefix(filepath.Clean(f.Path), "..") {
|
||||||
|
return n, fmt.Errorf("refusing the file name %q in the backup", f.Path)
|
||||||
|
}
|
||||||
|
dst := filepath.Join(keysDir, f.Path)
|
||||||
|
if err := mkdir(filepath.Dir(dst)); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
tmp := dst + ".restore-tmp"
|
||||||
|
if err := os.WriteFile(tmp, f.Data, 0o600); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
if err := os.Chown(tmp, uid, gid); err != nil {
|
||||||
|
os.Remove(tmp)
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
if err := os.Chmod(tmp, f.Mode); err != nil {
|
||||||
|
os.Remove(tmp)
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
if err := os.Rename(tmp, dst); err != nil {
|
||||||
|
os.Remove(tmp)
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
func listBackups(dir string) error {
|
func listBackups(dir string) error {
|
||||||
files, err := backup.List(dir)
|
files, err := backup.List(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -290,6 +440,9 @@ func describe(w io.Writer, in *backup.Info, made time.Time) {
|
|||||||
fmt.Fprintf(w, " made\t%s (%s ago)\n", made.Local().Format("2006-01-02 15:04:05"), fmtDuration(time.Since(made)))
|
fmt.Fprintf(w, " made\t%s (%s ago)\n", made.Local().Format("2006-01-02 15:04:05"), fmtDuration(time.Since(made)))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, " contents\t%s, %s, %s (schema %d)\n", plural(in.Zones, "zone"), plural(in.Records, "record"), plural(in.Users, "user"), in.Schema)
|
fmt.Fprintf(w, " contents\t%s, %s, %s (schema %d)\n", plural(in.Zones, "zone"), plural(in.Records, "record"), plural(in.Users, "user"), in.Schema)
|
||||||
|
if in.SignedZones > 0 {
|
||||||
|
fmt.Fprintf(w, " signed zones\t%d\n", in.SignedZones)
|
||||||
|
}
|
||||||
if in.LastChange != nil {
|
if in.LastChange != nil {
|
||||||
fmt.Fprintf(w, " last change\t%s\n", in.LastChange.Local().Format("2006-01-02 15:04:05"))
|
fmt.Fprintf(w, " last change\t%s\n", in.LastChange.Local().Format("2006-01-02 15:04:05"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import (
|
|||||||
"jarl/internal/config"
|
"jarl/internal/config"
|
||||||
"jarl/internal/engine"
|
"jarl/internal/engine"
|
||||||
"jarl/internal/model"
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/porkbun"
|
||||||
"jarl/internal/render"
|
"jarl/internal/render"
|
||||||
"jarl/internal/server"
|
"jarl/internal/server"
|
||||||
"jarl/internal/stats"
|
"jarl/internal/stats"
|
||||||
@@ -291,12 +292,20 @@ func serveCmd() *cobra.Command {
|
|||||||
// database closes, however serving ends.
|
// database closes, however serving ends.
|
||||||
defer func() { cancel(); <-collectorDone }()
|
defer func() { cancel(); <-collectorDone }()
|
||||||
}
|
}
|
||||||
|
var pb *porkbun.Client
|
||||||
|
if a.cfg.Porkbun.Enabled() {
|
||||||
|
pb = &porkbun.Client{BaseURL: a.cfg.Porkbun.APIURL, APIKey: a.cfg.Porkbun.APIKey, Secret: a.cfg.Porkbun.SecretAPIKey}
|
||||||
|
if fi, err := os.Stat(configPath); err == nil && fi.Mode().Perm()&0o004 != 0 {
|
||||||
|
a.log.Warn("the configuration file holds the Porkbun API key and everyone can read it; make it readable only by root and jarld (chown root:jarl, chmod 640)", "file", configPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
srv := server.New(server.Config{
|
srv := server.New(server.Config{
|
||||||
Listen: a.cfg.Listen, TLSCertFile: a.cfg.TLS.CertFile, TLSKeyFile: a.cfg.TLS.KeyFile,
|
Listen: a.cfg.Listen, TLSCertFile: a.cfg.TLS.CertFile, TLSKeyFile: a.cfg.TLS.KeyFile,
|
||||||
TrustedProxies: a.cfg.Proxies(), SessionLifetime: time.Duration(a.cfg.Session.Lifetime),
|
TrustedProxies: a.cfg.Proxies(), SessionLifetime: time.Duration(a.cfg.Session.Lifetime),
|
||||||
SessionIdle: time.Duration(a.cfg.Session.IdleTimeout), CookieSecure: a.cfg.Session.CookieSecure,
|
SessionIdle: time.Duration(a.cfg.Session.IdleTimeout), CookieSecure: a.cfg.Session.CookieSecure,
|
||||||
Version: version.Version, Stats: collector, Socket: a.cfg.Socket,
|
Version: version.Version, Stats: collector, Socket: a.cfg.Socket,
|
||||||
BackupDir: a.cfg.Backup.Dir, BackupWarnAfter: time.Duration(a.cfg.Backup.WarnAfter),
|
BackupDir: a.cfg.Backup.Dir, BackupWarnAfter: time.Duration(a.cfg.Backup.WarnAfter),
|
||||||
|
Porkbun: pb, PorkbunAllows: a.cfg.Porkbun.Allows,
|
||||||
HTTPReq: server.HTTPReq{
|
HTTPReq: server.HTTPReq{
|
||||||
Enabled: a.cfg.ACME.HTTPReq.Enabled,
|
Enabled: a.cfg.ACME.HTTPReq.Enabled,
|
||||||
AllowPlainHTTP: !a.cfg.ACME.HTTPReq.RequireHTTPS,
|
AllowPlainHTTP: !a.cfg.ACME.HTTPReq.RequireHTTPS,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# Jarl: one database backup, run daily by jarl-backup.timer.
|
# Jarl: one database backup (with the DNSSEC keys), run daily by
|
||||||
|
# jarl-backup.timer.
|
||||||
# Installed as /etc/systemd/system/jarl-backup.service (see
|
# Installed as /etc/systemd/system/jarl-backup.service (see
|
||||||
# docs/operations.md#backups). What to keep, and where, is in the backup:
|
# docs/operations.md#backups). What to keep, and where, is in the backup:
|
||||||
# section of /etc/jarl/jarl.yaml; when it runs is in jarl-backup.timer.
|
# section of /etc/jarl/jarl.yaml; when it runs is in jarl-backup.timer.
|
||||||
@@ -28,8 +29,12 @@ PrivateTmp=yes
|
|||||||
PrivateDevices=yes
|
PrivateDevices=yes
|
||||||
PrivateNetwork=yes
|
PrivateNetwork=yes
|
||||||
NoNewPrivileges=yes
|
NoNewPrivileges=yes
|
||||||
CapabilityBoundingSet=
|
# Read access to every file, and nothing else: named's DNSSEC private keys
|
||||||
AmbientCapabilities=
|
# (under /var/lib/bind/jarl/dnssec-keys) are readable only by named's user,
|
||||||
|
# and the backup includes them. Everything outside the paths above stays
|
||||||
|
# read-only (ProtectSystem=strict).
|
||||||
|
CapabilityBoundingSet=CAP_DAC_READ_SEARCH
|
||||||
|
AmbientCapabilities=CAP_DAC_READ_SEARCH
|
||||||
ProtectKernelTunables=yes
|
ProtectKernelTunables=yes
|
||||||
ProtectKernelModules=yes
|
ProtectKernelModules=yes
|
||||||
ProtectKernelLogs=yes
|
ProtectKernelLogs=yes
|
||||||
|
|||||||
+99
@@ -144,6 +144,14 @@ may be the name.
|
|||||||
| GET | `/zones/{zone}/file` | the generated zone file (text/plain) |
|
| GET | `/zones/{zone}/file` | the generated zone file (text/plain) |
|
||||||
| GET | `/zones/{zone}/serials` | asks the zone's other name servers for their serial (below) |
|
| GET | `/zones/{zone}/serials` | asks the zone's other name servers for their serial (below) |
|
||||||
| GET | `/zones/{zone}/delegation` | checks the parent zone's delegation of a primary zone (below); `?resolver=IP` |
|
| GET | `/zones/{zone}/delegation` | checks the parent zone's delegation of a primary zone (below); `?resolver=IP` |
|
||||||
|
| GET | `/zones/{zone}/dnssec` | the zone's DNSSEC keys, DS record and phase ([DNSSEC](#dnssec)) |
|
||||||
|
| POST | `/zones/{zone}/dnssec/check-ds` | asks the parent for the zone's DS records and tells named; `?resolver=IP` |
|
||||||
|
| POST | `/zones/{zone}/dnssec/wipe` | `{"force": false, "dry_run": false}`: signing off at once, keys deleted (administrators) |
|
||||||
|
| GET | `/zones/{zone}/registrar` | name servers, glue and DS records at the registrar ([Registrar](#registrar-porkbun)) |
|
||||||
|
| POST | `/zones/{zone}/registrar/glue` | create or update glue records |
|
||||||
|
| PUT | `/zones/{zone}/registrar/ns` | set the domain's name servers |
|
||||||
|
| POST | `/zones/{zone}/registrar/ds` | publish the zone's DS record |
|
||||||
|
| DELETE | `/zones/{zone}/registrar/ds/{keytag}` | remove a DS record |
|
||||||
| POST | `/zones/{zone}/import` | `{"text": "<zone file>", "mode": "merge"\|"replace", "use_soa": false, "dry_run": false}` |
|
| POST | `/zones/{zone}/import` | `{"text": "<zone file>", "mode": "merge"\|"replace", "use_soa": false, "dry_run": false}` |
|
||||||
|
|
||||||
ZoneInput:
|
ZoneInput:
|
||||||
@@ -159,6 +167,7 @@ ZoneInput:
|
|||||||
"refresh": 3600, "retry": 900, "expire": 1209600, "minimum": 300},
|
"refresh": 3600, "retry": 900, "expire": 1209600, "minimum": 300},
|
||||||
"default_ttl": 3600,
|
"default_ttl": 3600,
|
||||||
"serial_policy": "date", // date, increment, unixtime
|
"serial_policy": "date", // date, increment, unixtime
|
||||||
|
"dnssec_policy": "default", // primary zones: "" (off), "default", a custom policy, "insecure" (turning off)
|
||||||
"comment": "",
|
"comment": "",
|
||||||
// create only:
|
// create only:
|
||||||
"nameservers": ["ns1.adbraun.lol."], // default: settings
|
"nameservers": ["ns1.adbraun.lol."], // default: settings
|
||||||
@@ -197,6 +206,96 @@ when called ([operations.md](operations.md#checking-name-servers-and-the-delegat
|
|||||||
(`name`, `parent`, `jarl`, `match`), `servers` (as above, for the delegated
|
(`name`, `parent`, `jarl`, `match`), `servers` (as above, for the delegated
|
||||||
name servers) and `findings`: `{"level": "ok"|"info"|"warning"|"error",
|
name servers) and `findings`: `{"level": "ok"|"info"|"warning"|"error",
|
||||||
"message": "..."}`. A zone that isn't delegated gets one `info` finding.
|
"message": "..."}`. A zone that isn't delegated gets one `info` finding.
|
||||||
|
`parent_ds` lists the zone's DS records at the parent, and the findings
|
||||||
|
compare them with the zone's keys (a DS that matches no key, or a DS for a
|
||||||
|
zone that isn't signed, is an `error`).
|
||||||
|
|
||||||
|
Zones in responses also carry `registrar` (`"porkbun"`) when Jarl can
|
||||||
|
manage the domain at a registrar.
|
||||||
|
|
||||||
|
#### DNSSEC
|
||||||
|
|
||||||
|
Signing is the zone's `dnssec_policy` field, changed with `PATCH
|
||||||
|
/zones/{zone}` like any other field, so it goes through validation,
|
||||||
|
changesets and history. Jarl refuses unsafe steps there: `""` straight from
|
||||||
|
a signed policy (use `"insecure"` first), `""` before named has finished
|
||||||
|
removing the signatures, deleting a signed zone, or moving it to another
|
||||||
|
view ([dnssec.md](dnssec.md#what-jarl-refuses-and-why)).
|
||||||
|
|
||||||
|
`GET /zones/{zone}/dnssec`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"zone": "adbraun.lol.", "view": "external", "type": "primary",
|
||||||
|
"policy": "default",
|
||||||
|
"key_dir": "/var/lib/bind/jarl/dnssec-keys/view-3",
|
||||||
|
"keys": [{
|
||||||
|
"tag": 51126, "algorithm": 13, "algorithm_name": "ECDSAP256SHA256", "role": "CSK",
|
||||||
|
"dnskey": "adbraun.lol.\t3600\tIN\tDNSKEY\t257 3 13 ...",
|
||||||
|
"ds": {"key_tag": 51126, "algorithm": 13, "digest_type": 2, "digest": "FFBE...", "record": "adbraun.lol.\t3600\tIN\tDS\t51126 13 2 FFBE..."},
|
||||||
|
"goal": "omnipresent", "dnskey_state": "rumoured", "ds_state": "hidden",
|
||||||
|
"zone_rrsig_state": "rumoured", "key_rrsig_state": "rumoured",
|
||||||
|
"created": "...", "published": "...", "active": "...", "publish_cds": "...",
|
||||||
|
"files": ["Kadbraun.lol.+013+51126.key", "Kadbraun.lol.+013+51126.private", "Kadbraun.lol.+013+51126.state"]
|
||||||
|
}],
|
||||||
|
"phase": {
|
||||||
|
"code": "signing", "summary": "named is signing the zone. ...", "next": "Wait until ...",
|
||||||
|
"ds_ready_at": "...", "can_publish_ds": false, "can_finish": false
|
||||||
|
},
|
||||||
|
"named": {"secure": true, "inline_signing": true, "serial": 2026100802, "signed_serial": 2026100804, "next_key_event": "..."},
|
||||||
|
"policies": ["default"],
|
||||||
|
"parent_zone": "", // set when the parent zone is a primary zone in Jarl
|
||||||
|
"registrar": "porkbun" // when the DS can be published through Jarl
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`phase.code` is one of `off`, `leftover_keys`, `starting`, `signing`,
|
||||||
|
`ready`, `ds_pending`, `secure`, `removing_ds`, `ds_expiring`,
|
||||||
|
`removing_keys`, `unsigned` ([dnssec.md](dnssec.md#phases)).
|
||||||
|
|
||||||
|
`POST /dnssec/check-ds` (zones write) returns `parent` (the parent's
|
||||||
|
servers with their `ds`, the union `ds`, `delegated`, `reached`,
|
||||||
|
`consistent`, or `error`), `marked` (what named was told, `rndc dnssec
|
||||||
|
-checkds`), `notes` and the updated `status`.
|
||||||
|
|
||||||
|
`POST /dnssec/wipe` (administrators) asks the parent first and answers
|
||||||
|
`409` while it has a DS record for the zone, or while named still counts a
|
||||||
|
removed one as cached; when the parent can't be asked, it needs `"force":
|
||||||
|
true`. It returns `removed` (the files deleted) and `changeset_id`.
|
||||||
|
|
||||||
|
#### Registrar (Porkbun)
|
||||||
|
|
||||||
|
Administrators only, and only with a Porkbun key in jarl.yaml
|
||||||
|
([dnssec.md](dnssec.md#porkbun)). `GET /zones/{zone}/registrar`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"registrar": "porkbun", "domain": "adbraun.lol",
|
||||||
|
"ns": ["curitiba.ns.porkbun.com", "fortaleza.ns.porkbun.com"], "jarl_ns": ["ns1.adbraun.lol", "ns2.adbraun.lol"],
|
||||||
|
"ns_match": false,
|
||||||
|
"glue": [{"host": "ns1.adbraun.lol", "registry": [], "jarl": ["203.0.113.1", "2001:db8::1"],
|
||||||
|
"needed": true, "in_use": false, "action": "create"}],
|
||||||
|
"ds": [{"key_tag": 51126, "algorithm": 13, "digest_type": 2, "digest": "FFBE...", "matches": true}],
|
||||||
|
"findings": [{"level": "warning", "message": "..."}],
|
||||||
|
"error": "" // e.g. "Porkbun: ... (API_ACCESS_DISABLED)"; the rest is then empty
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The changes take `{"force": false, "dry_run": false}` (`PUT /ns` also
|
||||||
|
`"ns": [...]`, default the zone's NS records; `POST /ds` also `"key_tag"`)
|
||||||
|
and answer:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"done": ["create glue for ns1.adbraun.lol: 203.0.113.1, 2001:db8::1"], "dry_run": false,
|
||||||
|
"checks": [{"level": "ok"|"info"|"warning"|"error", "message": "..."}], "warnings": []}
|
||||||
|
```
|
||||||
|
|
||||||
|
Each change runs its checks first: the name servers answer for the zone,
|
||||||
|
glue matches, the DS points at a key the zone has, and the domain is
|
||||||
|
delegated to servers that serve the signed zone before a DS is published. An
|
||||||
|
`error` check refuses the change with `409` unless `force` is set; a dry run
|
||||||
|
returns the checks without changing anything. Errors from Porkbun are `502
|
||||||
|
registrar_error`.
|
||||||
|
|
||||||
### Records
|
### Records
|
||||||
|
|
||||||
|
|||||||
+32
-1
@@ -150,7 +150,7 @@ to stderr with `-o json` or `-o yaml`, so stdout holds just the documents.
|
|||||||
|------|---------|
|
|------|---------|
|
||||||
| 0 | Success |
|
| 0 | Success |
|
||||||
| 1 | Other error (bad arguments, connection failure, ...) |
|
| 1 | Other error (bad arguments, connection failure, ...) |
|
||||||
| 2 | A check found problems (`zone serials`, `zone delegation`); its report was printed |
|
| 2 | A check found problems (`zone serials`, `zone delegation`, `zone dnssec check-ds`, `zone registrar status`), or a step can't be taken yet (`zone dnssec disable` before turning off has finished); the report was printed |
|
||||||
| 3 | Not authenticated, or not allowed (token lacks the permission) |
|
| 3 | Not authenticated, or not allowed (token lacks the permission) |
|
||||||
| 4 | Not found |
|
| 4 | Not found |
|
||||||
| 5 | Conflict: concurrent change, object in use, drift |
|
| 5 | Conflict: concurrent change, object in use, drift |
|
||||||
@@ -211,6 +211,37 @@ zone's delegation and glue against the zone, and calls a zone that isn't
|
|||||||
delegated (an internal-only zone) a note, not a problem. Both only run when
|
delegated (an internal-only zone) a note, not a problem. Both only run when
|
||||||
you run them; see [operations.md](operations.md#checking-name-servers-and-the-delegation).
|
you run them; see [operations.md](operations.md#checking-name-servers-and-the-delegation).
|
||||||
|
|
||||||
|
### DNSSEC and the registrar
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jarl zone dnssec status adbraun.lol --view external # keys, DS record, what's next
|
||||||
|
jarl zone dnssec enable adbraun.lol --view external [--policy NAME]
|
||||||
|
jarl zone dnssec check-ds adbraun.lol --view external # has the parent got the DS? tells named
|
||||||
|
jarl zone dnssec disable adbraun.lol --view external # step 1: insecure; run again to finish
|
||||||
|
jarl zone dnssec wipe adbraun.lol --view external [--force] # off at once, keys deleted
|
||||||
|
|
||||||
|
jarl zone registrar status adbraun.lol --view external # Porkbun: NS, glue, DS vs the zone
|
||||||
|
jarl zone registrar sync-glue adbraun.lol --view external [--dry-run]
|
||||||
|
jarl zone registrar set-ns adbraun.lol --view external [NS...] [--dry-run]
|
||||||
|
jarl zone registrar publish-ds adbraun.lol --view external [--key TAG]
|
||||||
|
jarl zone registrar remove-ds adbraun.lol 51126 --view external
|
||||||
|
```
|
||||||
|
|
||||||
|
[dnssec.md](dnssec.md) explains the steps. `enable` is safe at any time:
|
||||||
|
validation only starts once the zone's DS record is at the parent, and
|
||||||
|
`status` says when to publish it. `disable` never makes a zone unsigned
|
||||||
|
while the parent may still have its DS: its first run switches to BIND's
|
||||||
|
insecure policy, and it finishes (exit 0) only when named is done (exit 2
|
||||||
|
before). `wipe` switches off at once and deletes the keys, and refuses
|
||||||
|
while the parent zone has a DS record for the zone; `--force` wipes when the
|
||||||
|
parent can't be checked.
|
||||||
|
|
||||||
|
The `registrar` commands need a Porkbun API key in jarl.yaml and an
|
||||||
|
administrator. Each change checks first that it won't break the domain and
|
||||||
|
is refused otherwise: `--dry-run` shows the checks, `--force` skips them.
|
||||||
|
(Here `--force` means that; elsewhere it overwrites files changed outside
|
||||||
|
Jarl.)
|
||||||
|
|
||||||
## Records
|
## Records
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
+2
-4
@@ -40,8 +40,8 @@ renders the complete configuration from the database:
|
|||||||
`jarld adopt` turns `/etc/bind/named.conf` into a single
|
`jarld adopt` turns `/etc/bind/named.conf` into a single
|
||||||
`include "/etc/bind/jarl/named.conf";`, so named loads only what Jarl
|
`include "/etc/bind/jarl/named.conf";`, so named loads only what Jarl
|
||||||
generates. Zone files go under `/var/lib/bind` because Debian's AppArmor
|
generates. Zone files go under `/var/lib/bind` because Debian's AppArmor
|
||||||
profile lets named write there. That keeps journals and future DNSSEC
|
profile lets named write there: its journals, the signed copies of zones
|
||||||
signing working.
|
it signs, and their keys (under `dnssec-keys/`, see [dnssec.md](dnssec.md)).
|
||||||
|
|
||||||
Because files are always regenerated, anything you edit by hand is
|
Because files are always regenerated, anything you edit by hand is
|
||||||
overwritten. Jarl records a checksum of every file it writes and reports
|
overwritten. Jarl records a checksum of every file it writes and reports
|
||||||
@@ -290,8 +290,6 @@ journal through jarld's log.
|
|||||||
* **Dynamic updates** (`allow-update`, `update-policy`): named would write
|
* **Dynamic updates** (`allow-update`, `update-policy`): named would write
|
||||||
to zone files that Jarl regenerates, so the validator rejects them on Jarl
|
to zone files that Jarl regenerates, so the validator rejects them on Jarl
|
||||||
zones. Use the API (for example `jarl acme`) instead of nsupdate.
|
zones. Use the API (for example `jarl acme`) instead of nsupdate.
|
||||||
* **DNSSEC signing**: not managed yet. The zone directory is
|
|
||||||
named-writable, so `dnssec-policy` can be added later.
|
|
||||||
* **Several servers from one jarld**: each jarld manages the named on its
|
* **Several servers from one jarld**: each jarld manages the named on its
|
||||||
own host. A second server runs its own jarld with secondary zones, which
|
own host. A second server runs its own jarld with secondary zones, which
|
||||||
copy the primary's zones by normal AXFR/IXFR (see "A secondary server" in
|
copy the primary's zones by normal AXFR/IXFR (see "A secondary server" in
|
||||||
|
|||||||
+24
-3
@@ -39,8 +39,8 @@ Durations accept Go syntax (`90s`, `15m`, `12h`) and days (`30d`).
|
|||||||
### Backups
|
### Backups
|
||||||
|
|
||||||
`jarld backup` without a file name, which the `jarl-backup.timer` systemd
|
`jarld backup` without a file name, which the `jarl-backup.timer` systemd
|
||||||
timer runs daily, writes `jarl-<UTC time>.db` into `backup.dir` and then
|
timer runs daily, writes `jarl-<UTC time>.db` into `backup.dir` (with the
|
||||||
deletes old backups there. It reads these settings from this file each
|
DNSSEC keys of signed zones inside it) and then deletes old backups there. It reads these settings from this file each
|
||||||
time it runs; when it runs is the timer's (`systemctl edit
|
time it runs; when it runs is the timer's (`systemctl edit
|
||||||
jarl-backup.timer`). See [operations.md](operations.md#backups), also for
|
jarl-backup.timer`). See [operations.md](operations.md#backups), also for
|
||||||
restoring.
|
restoring.
|
||||||
@@ -91,9 +91,10 @@ jarld restarts.
|
|||||||
|-----|---------|---------|
|
|-----|---------|---------|
|
||||||
| `bind.main_config` | `/etc/bind/named.conf` | The file named loads. `jarld import` reads it, and `jarld adopt` replaces it with an include of Jarl's configuration. |
|
| `bind.main_config` | `/etc/bind/named.conf` | The file named loads. `jarld import` reads it, and `jarld adopt` replaces it with an include of Jarl's configuration. |
|
||||||
| `bind.config_dir` | `/etc/bind/jarl` | Where Jarl writes `named.conf` and `keys.conf`. Must be readable by named. |
|
| `bind.config_dir` | `/etc/bind/jarl` | Where Jarl writes `named.conf` and `keys.conf`. Must be readable by named. |
|
||||||
| `bind.zone_dir` | `/var/lib/bind/jarl` | Primary zone files (`<view>/<zone>.zone`). named may write journals here. |
|
| `bind.zone_dir` | `/var/lib/bind/jarl` | Primary zone files (`<view>/<zone>.zone`). named may write journals, signed copies of zones and, under `dnssec-keys/`, DNSSEC keys here. |
|
||||||
| `bind.cache_dir` | `/var/cache/bind/jarl` | Where named stores secondary, stub and mirror zones. |
|
| `bind.cache_dir` | `/var/cache/bind/jarl` | Where named stores secondary, stub and mirror zones. |
|
||||||
| `bind.file_group` | `bind` | Group given to generated files and directories so named can read them. Empty leaves the group alone. |
|
| `bind.file_group` | `bind` | Group given to generated files and directories so named can read them. Empty leaves the group alone. |
|
||||||
|
| `bind.named_user` | `bind` | The user named runs as. `jarld restore` gives it the DNSSEC keys it puts back. |
|
||||||
| `bind.named_checkconf` | `/usr/bin/named-checkconf` | Used to check every candidate configuration (`-z` also loads the zones). |
|
| `bind.named_checkconf` | `/usr/bin/named-checkconf` | Used to check every candidate configuration (`-z` also loads the zones). |
|
||||||
| `bind.named_checkzone` | `/usr/bin/named-checkzone` | Used to check zone files. |
|
| `bind.named_checkzone` | `/usr/bin/named-checkzone` | Used to check zone files. |
|
||||||
| `bind.rndc` | `/usr/sbin/rndc` | Used to reconfigure and reload named and to read zone serials. |
|
| `bind.rndc` | `/usr/sbin/rndc` | Used to reconfigure and reload named and to read zone serials. |
|
||||||
@@ -111,6 +112,26 @@ there (`ReadWritePaths`). If you change them, update both
|
|||||||
ReadWritePaths=/srv/bind/jarl /srv/bind/zones
|
ReadWritePaths=/srv/bind/jarl /srv/bind/zones
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Porkbun (registrar)
|
||||||
|
|
||||||
|
With an API key, Jarl can show and set a domain's name servers, glue
|
||||||
|
records and DNSSEC DS records at Porkbun, after checking that the change
|
||||||
|
won't break the domain ([dnssec.md](dnssec.md#porkbun)). Without a key
|
||||||
|
(the default) nothing about Porkbun shows up.
|
||||||
|
|
||||||
|
| Key | Default | Meaning |
|
||||||
|
|-----|---------|---------|
|
||||||
|
| `porkbun.api_key` | `""` | The API key (`pk1_...`). Set both or neither. |
|
||||||
|
| `porkbun.secret_api_key` | `""` | Its secret (`sk1_...`). |
|
||||||
|
| `porkbun.domains` | `[]` | Only these domains (default: every primary zone the key can reach). |
|
||||||
|
|
||||||
|
The key can move your domain anywhere, so it is only ever read from this
|
||||||
|
file: it isn't stored in the database or backups, and there is no API to
|
||||||
|
set it. Keep the file readable only by root and jarld (`chown root:jarl
|
||||||
|
jarl.yaml; chmod 640 jarl.yaml`, as the Debian package installs it); jarld
|
||||||
|
warns at start when everyone can read it. At porkbun.com, switch on "API
|
||||||
|
Access" for the domain, and limit the key to the domain if you can.
|
||||||
|
|
||||||
## Example: management network with TLS
|
## Example: management network with TLS
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
+8
-3
@@ -24,8 +24,10 @@ internal/
|
|||||||
web/static/ the web UI: plain ES modules, no build step, embedded with go:embed
|
web/static/ the web UI: plain ES modules, no build step, embedded with go:embed
|
||||||
api/, client/ JSON types and the Go client shared by server and CLI
|
api/, client/ JSON types and the Go client shared by server and CLI
|
||||||
acme/ ACME DNS-01 challenge records, shared by jarl acme and the httpreq endpoint
|
acme/ ACME DNS-01 challenge records, shared by jarl acme and the httpreq endpoint
|
||||||
backup/ database backups: write (VACUUM INTO) and check, list, prune by the time in the name
|
backup/ database backups: write (VACUUM INTO, plus the DNSSEC key files) and check, list, prune by the time in the name
|
||||||
nscheck/ DNS queries to other name servers: zone serials and the parent's delegation
|
nscheck/ DNS queries to other name servers: zone serials, the parent's delegation and DS records
|
||||||
|
dnssec/ reads named's DNSSEC key and state files; DS records; the signing phases (docs/dnssec.md)
|
||||||
|
porkbun/ Porkbun API client (name servers, glue, DS records) and an in-memory fake for tests
|
||||||
config/ jarld's YAML configuration
|
config/ jarld's YAML configuration
|
||||||
deploy/ systemd units (jarld, the daily backup service and timer), sysusers.d and tmpfiles.d files
|
deploy/ systemd units (jarld, the daily backup service and timer), sysusers.d and tmpfiles.d files
|
||||||
deploy/debian/ the Debian package's control template and postinst/prerm/postrm
|
deploy/debian/ the Debian package's control template and postinst/prerm/postrm
|
||||||
@@ -110,7 +112,10 @@ checker tests work with the installed `bind9-utils` too.
|
|||||||
`scripts/e2e.sh` builds a legacy BIND setup, starts named, runs
|
`scripts/e2e.sh` builds a legacy BIND setup, starts named, runs
|
||||||
`jarld init`, `import`, `adopt` and `serve`, then drives every CLI command
|
`jarld init`, `import`, `adopt` and `serve`, then drives every CLI command
|
||||||
(records, batches, changesets, views, ACLs, TSIG, options, users, tokens,
|
(records, batches, changesets, views, ACLs, TSIG, options, users, tokens,
|
||||||
ACME hooks, audit) and checks the answers with `dig`. `KEEP=1` leaves named
|
ACME hooks, DNSSEC signing, backup and restore with keys, audit) and checks
|
||||||
|
the answers with `dig`. The Porkbun code is tested against
|
||||||
|
`porkbun.Fake`, an in-memory stand-in for its API; nothing calls the real
|
||||||
|
one. `KEEP=1` leaves named
|
||||||
and jarld running afterwards. The output says where; set `JARL_CLI_CONFIG`
|
and jarld running afterwards. The output says where; set `JARL_CLI_CONFIG`
|
||||||
to that directory's `cli.yaml` to keep using the CLI against it.
|
to that directory's `cli.yaml` to keep using the CLI against it.
|
||||||
|
|
||||||
|
|||||||
+334
@@ -0,0 +1,334 @@
|
|||||||
|
# DNSSEC signing
|
||||||
|
|
||||||
|
DNSSEC lets resolvers that validate (Cloudflare 1.1.1.1, Google 8.8.8.8,
|
||||||
|
Quad9, many ISPs) detect forged answers for your domain. Jarl signs zones
|
||||||
|
with BIND's own key and signing policy (`dnssec-policy`), and guides you
|
||||||
|
through the steps that involve the parent zone, where getting the order
|
||||||
|
wrong takes a domain offline.
|
||||||
|
|
||||||
|
- [Should you sign?](#should-you-sign)
|
||||||
|
- [How it works](#how-it-works)
|
||||||
|
- [Turning signing on](#turning-signing-on)
|
||||||
|
- [Putting your own name servers on the internet](#putting-your-own-name-servers-on-the-internet)
|
||||||
|
- [Porkbun](#porkbun)
|
||||||
|
- [Turning signing off](#turning-signing-off)
|
||||||
|
- [Wipe: a clean slate](#wipe-a-clean-slate)
|
||||||
|
- [Keys, backups and moving servers](#keys-backups-and-moving-servers)
|
||||||
|
- [What Jarl refuses, and why](#what-jarl-refuses-and-why)
|
||||||
|
- [Phases](#phases)
|
||||||
|
- [Custom policies](#custom-policies)
|
||||||
|
- [Adopting a signed zone](#adopting-a-signed-zone)
|
||||||
|
|
||||||
|
## Should you sign?
|
||||||
|
|
||||||
|
Sign a zone that the internet sees through a delegation from its parent:
|
||||||
|
your registered domain (`adbraun.lol`), as served to the outside world.
|
||||||
|
Validation only happens once the parent zone (`lol`) publishes a DS
|
||||||
|
record for the zone's key, which you add at your registrar.
|
||||||
|
|
||||||
|
Signing an internal-only zone (one no registrar delegates, or a split-DNS
|
||||||
|
view only your own network reaches) adds nothing. There is no parent to
|
||||||
|
publish a DS, and BIND doesn't validate the zones it serves itself.
|
||||||
|
|
||||||
|
**Split DNS.** In Jarl a zone belongs to a view, so you sign the external
|
||||||
|
view's `adbraun.lol` and leave the internal view's copy unsigned. That is
|
||||||
|
the usual setup, with one catch. Once the DS is at the parent, the world
|
||||||
|
expects `adbraun.lol` to be signed. A device on your network that validates
|
||||||
|
DNSSEC *itself* and gets the internal, unsigned copy rejects it. Examples
|
||||||
|
are a Pi-hole or Unbound with DNSSEC on, systemd-resolved with
|
||||||
|
`DNSSEC=yes`, and some routers. Devices that just ask this server are fine.
|
||||||
|
If you run such a validator, sign the internal copy too and publish both
|
||||||
|
DS records.
|
||||||
|
|
||||||
|
**What it costs.** It is one more way for the domain to break: if the DS at
|
||||||
|
the parent stops matching the zone's keys (keys lost, wiped, or a server
|
||||||
|
moved without them), every validating resolver rejects the whole domain.
|
||||||
|
Most of Jarl's DNSSEC features exist to stop that from happening.
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
named signs the zone itself, with *inline signing*:
|
||||||
|
|
||||||
|
- Jarl writes the zone file as before (`/var/lib/bind/jarl/<view>/<zone>.zone`).
|
||||||
|
named keeps a signed copy next to it (`.signed`, `.signed.jnl`), signs
|
||||||
|
every change Jarl makes, and re-signs before signatures expire.
|
||||||
|
- The keys live in Jarl's key directory,
|
||||||
|
`/var/lib/bind/jarl/dnssec-keys/<view>/`. The subdirectory is named after
|
||||||
|
the view's ID, so renaming a view doesn't move the keys. Each key is
|
||||||
|
three files, `K<zone>.+013+<tag>.key`, `.private` (readable only by
|
||||||
|
named's user) and `.state`. Zones of the same name in two views have
|
||||||
|
separate directories, because named requires that.
|
||||||
|
- With BIND's `default` policy there is one key, a CSK (combined signing
|
||||||
|
key) using ECDSA P-256 (algorithm 13). It is never replaced, so the DS
|
||||||
|
record at the registrar never has to change.
|
||||||
|
- The signed zone has its own serial, usually a little ahead of Jarl's.
|
||||||
|
Jarl's reload check compares the serial of the file it wrote. The serials
|
||||||
|
check (`jarl zone serials`) compares the signed serial, which is what
|
||||||
|
secondaries serve.
|
||||||
|
- Secondaries transfer the signed zone and need nothing else.
|
||||||
|
- The server's clock must be right (NTP): signatures are valid for a fixed
|
||||||
|
time window.
|
||||||
|
|
||||||
|
## Turning signing on
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jarl zone dnssec enable adbraun.lol --view external
|
||||||
|
jarl zone dnssec status adbraun.lol --view external
|
||||||
|
```
|
||||||
|
|
||||||
|
or, in the web UI, the zone's **DNSSEC** tab → *Turn signing on*. This is
|
||||||
|
safe at any time. Resolvers keep treating the zone as unsigned until its
|
||||||
|
DS record is at the parent.
|
||||||
|
|
||||||
|
`status` shows the key, the DS record, and when it is safe to publish:
|
||||||
|
|
||||||
|
```
|
||||||
|
Status: named is signing the zone. Resolvers still treat it as unsigned, ...
|
||||||
|
Next: Wait until Fri 9 Oct 21:13 UTC before adding the DS at the parent: ...
|
||||||
|
|
||||||
|
KEY ROLE ALGORITHM GOAL DNSKEY DS AT PARENT CREATED
|
||||||
|
51126 CSK ECDSAP256SHA256 omnipresent rumoured hidden 2026-10-08 21:08
|
||||||
|
|
||||||
|
DS record for the parent zone (at your registrar):
|
||||||
|
(not yet: wait until Fri, 09 Oct 2026 21:13:51 UTC)
|
||||||
|
adbraun.lol. 3600 IN DS 51126 13 2 FFBECE3D...
|
||||||
|
key tag 51126, algorithm 13 (ECDSAP256SHA256), digest type 2 (SHA-256), digest FFBECE3D...
|
||||||
|
```
|
||||||
|
|
||||||
|
named first publishes the key for long enough that every resolver's cache
|
||||||
|
has caught up: about a day with the default policy. Adding the DS earlier
|
||||||
|
can make validating resolvers reject cached answers. Then:
|
||||||
|
|
||||||
|
1. **Make sure the domain is delegated to servers that serve the signed
|
||||||
|
zone.** Your own servers, or secondaries that transfer from them.
|
||||||
|
Publishing a DS while the registrar still points at other name servers
|
||||||
|
(Porkbun's own, say) breaks the domain. `jarl zone delegation ZONE`
|
||||||
|
shows where the parent points.
|
||||||
|
2. **Publish the DS record at the registrar**, by hand (the DNSSEC tab has
|
||||||
|
copy buttons for the whole record and for its four fields), or with
|
||||||
|
Jarl's [Porkbun](#porkbun) support, which checks step 1 first.
|
||||||
|
3. **Tell named.** Once the parent zone has the DS (minutes to hours after
|
||||||
|
the registrar accepts it), run the DS check:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jarl zone dnssec check-ds adbraun.lol --view external
|
||||||
|
```
|
||||||
|
|
||||||
|
It asks every server of the parent zone for the zone's DS records, and
|
||||||
|
tells named (`rndc dnssec -checkds`) when all of them have it. named
|
||||||
|
waits for the parent's DS TTL before it counts the DS as in place.
|
||||||
|
4. **Check.** `jarl zone delegation ZONE` now also compares the parent's
|
||||||
|
DS with the zone's keys. A DS that matches no key is an error.
|
||||||
|
[DNSViz](https://dnsviz.net/) gives an independent picture.
|
||||||
|
|
||||||
|
If the parent zone is itself a primary zone in Jarl (`home.adbraun.lol`
|
||||||
|
inside `adbraun.lol`), the DNSSEC tab says so: add the DS as a record in
|
||||||
|
that zone.
|
||||||
|
|
||||||
|
## Putting your own name servers on the internet
|
||||||
|
|
||||||
|
To serve your domain from your own server, the parent zone must delegate
|
||||||
|
it to your server's *name* (NS records can't hold addresses). If that name
|
||||||
|
is inside the domain itself (`ns1.adbraun.lol` for `adbraun.lol`),
|
||||||
|
resolvers couldn't look it up without already reaching your server. **Glue
|
||||||
|
records** solve this: the registry publishes `ns1.adbraun.lol`'s address
|
||||||
|
together with the delegation. Each name server inside the domain needs its
|
||||||
|
own glue record, with all of its addresses (IPv4 and IPv6).
|
||||||
|
|
||||||
|
The order matters:
|
||||||
|
|
||||||
|
1. In the zone (external view): NS records for your name servers, and A/AAAA
|
||||||
|
records for the ones inside the domain.
|
||||||
|
2. At the registrar: a glue record for each of those (Porkbun calls them
|
||||||
|
"glue records", others "host records" or "child name servers").
|
||||||
|
3. Check that every name server answers for the zone from the internet.
|
||||||
|
4. At the registrar: set the domain's name servers.
|
||||||
|
5. `jarl zone delegation ZONE` until it is all green. Resolvers may use the
|
||||||
|
old name servers for a day or two after the change, so keep those
|
||||||
|
serving the zone until then.
|
||||||
|
|
||||||
|
Jarl's [Porkbun](#porkbun) support does steps 2 to 4 with checks.
|
||||||
|
|
||||||
|
Before you go public:
|
||||||
|
|
||||||
|
- **Two name servers.** Registries and RFC 1034 expect at least two, on
|
||||||
|
different networks: with one server at home, a power or internet outage
|
||||||
|
takes the domain off the internet. A free secondary service (Hurricane
|
||||||
|
Electric's dns.he.net, for example) or a small VPS transfers the zone
|
||||||
|
from Jarl, signed zone included. A *hidden primary* goes one step
|
||||||
|
further: your server feeds the secondaries but isn't in the NS records,
|
||||||
|
so your home address isn't advertised.
|
||||||
|
- **A dynamic home address** means the glue must follow it.
|
||||||
|
- **Inbound port 53** (UDP and TCP) must reach the server: some ISPs block
|
||||||
|
it, and CGNAT makes it impossible.
|
||||||
|
|
||||||
|
## Porkbun
|
||||||
|
|
||||||
|
With a Porkbun API key, Jarl manages a domain's name servers, glue records
|
||||||
|
and DS records at Porkbun, and checks each change before making it.
|
||||||
|
|
||||||
|
**Setting it up**
|
||||||
|
|
||||||
|
1. At porkbun.com, *Account → API Access*: create a key. If you can,
|
||||||
|
limit it to the domain and the permissions it needs (domains, read),
|
||||||
|
and to your server's address.
|
||||||
|
2. On the domain's page, switch **API Access** on (Porkbun refuses API
|
||||||
|
calls for a domain until you do).
|
||||||
|
3. Put the key in `/etc/jarl/jarl.yaml` and restart jarld:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
porkbun:
|
||||||
|
api_key: pk1_...
|
||||||
|
secret_api_key: sk1_...
|
||||||
|
domains: [adbraun.lol] # optional: only these
|
||||||
|
```
|
||||||
|
|
||||||
|
The key can move your domain anywhere, so it lives only in that file:
|
||||||
|
never in Jarl's database or its backups, and there is no API or CLI command
|
||||||
|
to upload it. Keep the file readable by root and jarld only (`chown
|
||||||
|
root:jarl`, `chmod 640`, as the package installs it); jarld warns at start
|
||||||
|
when everyone can read it. Only administrators can use the registrar
|
||||||
|
features.
|
||||||
|
|
||||||
|
**Using it**: the zone's **Registrar** tab, or `jarl zone registrar`:
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| `status ZONE` | Name servers, glue and DS records at Porkbun next to the zone's, with what doesn't match. |
|
||||||
|
| `sync-glue ZONE` | Gives every name server inside the domain a glue record with the zone's A and AAAA records for it. Changing the glue of a name server the domain already uses sends resolvers to the new addresses, so Jarl checks first that they answer for the zone. |
|
||||||
|
| `set-ns ZONE [NS...]` | Sets the domain's name servers (default: the zone's NS records). Checked first: each answers for the zone with the current serial, the ones inside the domain have matching glue, and DS records at Porkbun match the zone's keys (otherwise the domain goes dark for validating resolvers). |
|
||||||
|
| `publish-ds ZONE` | Publishes the zone's DS record. Refused until named says the zone is ready, and unless the domain is delegated to the zone's name servers and they serve the signed zone. |
|
||||||
|
| `remove-ds ZONE KEYTAG` | Removes a DS record (the step when turning signing off; also the fix for a DS that matches no key). |
|
||||||
|
|
||||||
|
Every change can be tried first with `--dry-run`, which shows the checks.
|
||||||
|
Errors refuse the change; `--force` (in the web UI, a checkbox) overrides
|
||||||
|
them, for example when this server can't reach its own public address to
|
||||||
|
check it.
|
||||||
|
|
||||||
|
## Turning signing off
|
||||||
|
|
||||||
|
Never switch a signed zone straight to unsigned while its DS might still
|
||||||
|
be at the parent: validating resolvers would reject the whole domain until
|
||||||
|
the DS is gone *and* its TTL has passed (often a day). Jarl refuses that
|
||||||
|
step and goes through BIND's `insecure` policy instead:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jarl zone dnssec disable adbraun.lol --view external
|
||||||
|
```
|
||||||
|
|
||||||
|
1. The zone switches to the `insecure` policy. named keeps it signed and
|
||||||
|
publishes a CDS "delete" record. Nothing breaks.
|
||||||
|
2. Remove the DS record at your registrar (`jarl zone registrar remove-ds`
|
||||||
|
with Porkbun). Once the parent zone no longer has it, run `jarl zone
|
||||||
|
dnssec check-ds` so named knows.
|
||||||
|
3. named waits until resolvers have forgotten the DS (the parent's DS TTL
|
||||||
|
plus a margin, about a day), then removes the keys and signatures.
|
||||||
|
`status` shows the progress.
|
||||||
|
4. Run `jarl zone dnssec disable` again (or *Finish turning off* in the web
|
||||||
|
UI) when `status` says so: DNSSEC is then off for the zone.
|
||||||
|
|
||||||
|
If the DS never reached the parent, named skips the wait and you can
|
||||||
|
finish at once. The old keys stay in the key directory (named keeps them
|
||||||
|
retired; signing again makes a new key) until you wipe them.
|
||||||
|
|
||||||
|
## Wipe: a clean slate
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jarl zone dnssec wipe adbraun.lol --view external
|
||||||
|
```
|
||||||
|
|
||||||
|
or *Wipe (clean slate)* on the DNSSEC tab. It switches signing off at once,
|
||||||
|
without the insecure policy, and deletes the zone's keys and named's signed
|
||||||
|
copy, so signing again starts from scratch. It also cleans up a zone that
|
||||||
|
is off but still has old keys.
|
||||||
|
|
||||||
|
That is only safe when the parent zone has no DS record for the zone, so
|
||||||
|
Jarl asks the parent's servers first and **refuses while they have one**.
|
||||||
|
It also refuses while named still counts a recently removed DS as cached.
|
||||||
|
When the parent can't be asked (no internet access, or a zone that isn't on
|
||||||
|
the internet), `--force` wipes anyway. Wiping needs an administrator, and
|
||||||
|
the web UI asks you to type the zone's name.
|
||||||
|
|
||||||
|
Deleting a zone that is signed is refused: turn signing off first.
|
||||||
|
|
||||||
|
## Keys, backups and moving servers
|
||||||
|
|
||||||
|
The zone's keys exist only in the key directory: Jarl's database doesn't
|
||||||
|
hold them. Losing them while the parent has a DS for them breaks the
|
||||||
|
domain.
|
||||||
|
|
||||||
|
- **Backups.** Every backup (`jarld backup`, and the daily
|
||||||
|
`jarl-backup.timer`) stores the key directory's files inside the backup
|
||||||
|
file, private keys included. Keep `/var/backups/jarl` private (it is
|
||||||
|
`0700`). named's private keys are readable only by named's user, so
|
||||||
|
`jarl-backup.service` runs with the one capability it needs to read them
|
||||||
|
(`CAP_DAC_READ_SEARCH`); a manual backup must run as root. `--without-keys`
|
||||||
|
backs up only the database.
|
||||||
|
- **Restoring.** `jarld restore` puts the keys back, owned by named's user
|
||||||
|
(`bind.named_user`), which needs root. Key files that exist but aren't in
|
||||||
|
the backup are left alone.
|
||||||
|
- **Serials after a restore.** A restored database may have older zone
|
||||||
|
serials than named has. named won't load a signed zone's file unless its
|
||||||
|
serial went up, and secondaries ignore a serial that went down. Jarl
|
||||||
|
checks this whenever it writes a zone file, and raises the serial above
|
||||||
|
named's when needed (it shows in the result, and in the audit log).
|
||||||
|
- **Moving to a new server.** Restore the backup *before* named loads
|
||||||
|
Jarl's configuration there. Otherwise named finds no keys and makes new
|
||||||
|
ones, which the parent's DS doesn't match.
|
||||||
|
|
||||||
|
## What Jarl refuses, and why
|
||||||
|
|
||||||
|
| Change | Why |
|
||||||
|
|---|---|
|
||||||
|
| Switching a signed zone straight to unsigned | The parent may still have the DS: use `disable` (insecure first), or `wipe` when the parent has none. |
|
||||||
|
| Finishing `disable` before named is done | Resolvers may still have the DS cached. |
|
||||||
|
| Deleting a signed zone | Turn signing off first. |
|
||||||
|
| Moving a signed zone to another view | It would get new keys (another key directory) that the DS doesn't match. |
|
||||||
|
| A TTL above the policy's `max-zone-ttl` (a day by default) | named refuses to load such a signed zone and keeps serving the old one. |
|
||||||
|
| `dnssec-policy` as a zone, view or server option | Jarl sets it per zone, so it can guard the steps. Top-level `dnssec-policy NAME { ... }` statements (custom policies) are fine. |
|
||||||
|
| A custom policy with an empty `keys { }` list | It crashes named 9.20 when the configuration loads (named-checkconf accepts it). Use the built-in `insecure` policy. |
|
||||||
|
| `inline-signing no` on a signed zone | Jarl rewrites zone files; named must keep its signatures in a separate copy. |
|
||||||
|
| Signing a secondary zone | A secondary gets its signatures from its primary. |
|
||||||
|
|
||||||
|
## Phases
|
||||||
|
|
||||||
|
`status`, the DNSSEC tab and the API report a phase:
|
||||||
|
|
||||||
|
| Phase | Meaning | Next |
|
||||||
|
|---|---|---|
|
||||||
|
| `off` | Not signed. | |
|
||||||
|
| `leftover_keys` | Not signed, but old keys are in the key directory. | Wipe them, or sign again. |
|
||||||
|
| `starting` | Signing is on; named hasn't made the key yet. | Wait a moment. |
|
||||||
|
| `signing` | Signed, but caches may not have the key yet. | Wait until the time shown, then publish the DS. |
|
||||||
|
| `ready` | Safe to add the DS at the parent. | Publish it, then run the DS check. |
|
||||||
|
| `ds_pending` | named knows the DS is at the parent and waits for its TTL. | |
|
||||||
|
| `secure` | Signed, and the parent's DS points at the key. | |
|
||||||
|
| `removing_ds` | Turning off; the DS must go from the parent first. | Remove it, then run the DS check. |
|
||||||
|
| `ds_expiring` | The DS is gone; caches may still have it. | Wait. |
|
||||||
|
| `removing_keys` | named removes the keys and signatures. | Finish when you like (it's safe now). |
|
||||||
|
| `unsigned` | Turning off has finished. | Switch DNSSEC off for the zone. |
|
||||||
|
|
||||||
|
The key states come from named (`rndc dnssec -status ZONE` shows the same):
|
||||||
|
*rumoured* means published, but caches may not have it yet; *omnipresent*
|
||||||
|
means everyone has it; *unretentive* means removed, but caches may still
|
||||||
|
have it; *hidden* means gone.
|
||||||
|
|
||||||
|
## Custom policies
|
||||||
|
|
||||||
|
`default` suits most domains. For anything else (scheduled key rollovers,
|
||||||
|
NSEC3, other algorithms), define a policy as a top-level statement
|
||||||
|
(`jarl option set dnssec-policy 'NAME { ... }' --toplevel`, or *Server
|
||||||
|
options* in the web UI) and enable it with `jarl zone dnssec enable ZONE
|
||||||
|
--policy NAME`. With a policy that rolls the key-signing key,
|
||||||
|
the DS at the parent must change at every rollover: `status` and the DS
|
||||||
|
check tell you when, and named waits for the DS check before it retires
|
||||||
|
the old key.
|
||||||
|
|
||||||
|
## Adopting a signed zone
|
||||||
|
|
||||||
|
When `jarld import` finds a zone that named already signs, it imports its
|
||||||
|
policy and warns. Before `jarld adopt`, copy the zone's key files
|
||||||
|
(`K<zone>.+*`) from its old key directory into the one Jarl uses (`jarl
|
||||||
|
zone dnssec status ZONE` shows it), owned by named's user. Otherwise named
|
||||||
|
makes new keys, and if the parent has a DS for the old ones, the zone stops
|
||||||
|
validating.
|
||||||
+2
-2
@@ -167,7 +167,7 @@ This installs:
|
|||||||
| `/usr/local/bin/jarld`, `/usr/local/bin/jarl` | daemon and CLI |
|
| `/usr/local/bin/jarld`, `/usr/local/bin/jarl` | daemon and CLI |
|
||||||
| `/usr/local/share/bash-completion/completions/jarl`, `.../jarld` | bash completion (loaded automatically by the `bash-completion` package) |
|
| `/usr/local/share/bash-completion/completions/jarl`, `.../jarld` | bash completion (loaded automatically by the `bash-completion` package) |
|
||||||
| `/etc/systemd/system/jarl.service` | systemd unit (`Type=notify`, sandboxed) |
|
| `/etc/systemd/system/jarl.service` | systemd unit (`Type=notify`, sandboxed) |
|
||||||
| `/etc/systemd/system/jarl-backup.service`, `jarl-backup.timer` | the daily database backup ([operations.md](operations.md#backups)) |
|
| `/etc/systemd/system/jarl-backup.service`, `jarl-backup.timer` | the daily database backup, DNSSEC keys included ([operations.md](operations.md#backups)) |
|
||||||
| `/usr/lib/sysusers.d/jarl.conf` | creates the `jarl` system user and adds it to group `bind` |
|
| `/usr/lib/sysusers.d/jarl.conf` | creates the `jarl` system user and adds it to group `bind` |
|
||||||
| `/usr/lib/tmpfiles.d/jarl.conf` | creates `/etc/jarl`, `/var/lib/jarl`, `/etc/bind/jarl`, `/var/lib/bind/jarl`, `/var/cache/bind/jarl`, `/var/backups/jarl` |
|
| `/usr/lib/tmpfiles.d/jarl.conf` | creates `/etc/jarl`, `/var/lib/jarl`, `/etc/bind/jarl`, `/var/lib/bind/jarl`, `/var/cache/bind/jarl`, `/var/backups/jarl` |
|
||||||
| `/etc/jarl/jarl.yaml` | example configuration (only if none exists) |
|
| `/etc/jarl/jarl.yaml` | example configuration (only if none exists) |
|
||||||
@@ -390,7 +390,7 @@ a backup (it is safe while jarld runs); `jarld restore` puts it back if
|
|||||||
needed:
|
needed:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo -u jarl jarld backup
|
sudo jarld backup
|
||||||
```
|
```
|
||||||
|
|
||||||
## Uninstalling
|
## Uninstalling
|
||||||
|
|||||||
+37
-18
@@ -6,7 +6,8 @@
|
|||||||
|------|-----|
|
|------|-----|
|
||||||
| Is everything healthy? | `jarl status`, or the web UI dashboard: named reachable, adoption, drift, open changesets, configuration problems, the newest backup, tokens about to expire |
|
| Is everything healthy? | `jarl status`, or the web UI dashboard: named reachable, adoption, drift, open changesets, configuration problems, the newest backup, tokens about to expire |
|
||||||
| Are the secondaries up to date? | `jarl zone serials ZONE`, or the zone's Name servers tab ([below](#checking-name-servers-and-the-delegation)) |
|
| Are the secondaries up to date? | `jarl zone serials ZONE`, or the zone's Name servers tab ([below](#checking-name-servers-and-the-delegation)) |
|
||||||
| Back up / restore | Daily by `jarl-backup.timer`; by hand `sudo -u jarl jarld backup`; restore with `jarld restore` ([below](#backups)) |
|
| Back up / restore | Daily by `jarl-backup.timer`; by hand `sudo jarld backup`; restore with `jarld restore` ([below](#backups)) |
|
||||||
|
| DNSSEC | `jarl zone dnssec status ZONE`, or the zone's DNSSEC tab ([dnssec.md](dnssec.md)) |
|
||||||
| What changed and who did it? | `jarl history`, `jarl changeset show ID` (with diff), `jarl audit` |
|
| What changed and who did it? | `jarl history`, `jarl changeset show ID` (with diff), `jarl audit` |
|
||||||
| Undo a change | `jarl changeset revert ID`, review it, then `jarl changeset apply NEW_ID` (or History → Revert in the UI) |
|
| Undo a change | `jarl changeset revert ID`, review it, then `jarl changeset apply NEW_ID` (or History → Revert in the UI) |
|
||||||
| Check the configuration | `jarl check`: full validation plus `named-checkconf -z` |
|
| Check the configuration | `jarl check`: full validation plus `named-checkconf -z` |
|
||||||
@@ -23,8 +24,10 @@ loaded. jarld is only needed to make changes.
|
|||||||
|
|
||||||
Everything Jarl knows is in its database (`/var/lib/jarl/jarl.db`): zones,
|
Everything Jarl knows is in its database (`/var/lib/jarl/jarl.db`): zones,
|
||||||
records, views, ACLs, TSIG keys, options, users, tokens, history and the
|
records, views, ACLs, TSIG keys, options, users, tokens, history and the
|
||||||
audit log. named's files are generated from it, so the database is the one
|
audit log. named's files are generated from it. The one exception is the
|
||||||
thing to back up.
|
DNSSEC keys of signed zones, which named keeps in Jarl's key directory
|
||||||
|
(`/var/lib/bind/jarl/dnssec-keys`): every backup stores those too, inside the
|
||||||
|
backup file ([dnssec.md](dnssec.md#keys-backups-and-moving-servers)).
|
||||||
|
|
||||||
### The daily backup
|
### The daily backup
|
||||||
|
|
||||||
@@ -41,17 +44,19 @@ Each run:
|
|||||||
1. writes a consistent copy of the database with SQLite's `VACUUM INTO`
|
1. writes a consistent copy of the database with SQLite's `VACUUM INTO`
|
||||||
(safe while jarld runs and changes things) to a temporary file in the
|
(safe while jarld runs and changes things) to a temporary file in the
|
||||||
backup directory;
|
backup directory;
|
||||||
2. checks the copy with SQLite's `integrity_check`, and only then gives it
|
2. stores the DNSSEC keys in it (every file of the key directory, private
|
||||||
|
keys included);
|
||||||
|
3. checks the copy with SQLite's `integrity_check`, and only then gives it
|
||||||
its name, `jarl-<UTC time>.db`, e.g. `jarl-20261008T031512Z.db`. A file
|
its name, `jarl-<UTC time>.db`, e.g. `jarl-20261008T031512Z.db`. A file
|
||||||
with that name is always a complete, intact backup;
|
with that name is always a complete, intact backup;
|
||||||
3. deletes backups older than `retention`, but always keeps the newest
|
4. deletes backups older than `retention`, but always keeps the newest
|
||||||
`keep_at_least`, however old they are. If backups stop for a while (the
|
`keep_at_least`, however old they are. If backups stop for a while (the
|
||||||
machine was off, the disk was full), the old ones aren't all deleted by
|
machine was off, the disk was full), the old ones aren't all deleted by
|
||||||
the next run. Ages come from the time in the name, not the file's
|
the next run. Ages come from the time in the name, not the file's
|
||||||
modification time, which copying the directory would change. Only files
|
modification time, which copying the directory would change. Only files
|
||||||
named `jarl-<time>.db` (and `stats-<time>.db`) are ever deleted, so
|
named `jarl-<time>.db` (and `stats-<time>.db`) are ever deleted, so
|
||||||
anything else you put in the directory is safe;
|
anything else you put in the directory is safe;
|
||||||
4. records the result in the database, so the dashboard and `jarl status`
|
5. records the result in the database, so the dashboard and `jarl status`
|
||||||
show when the newest backup was made, and whether the last attempt
|
show when the newest backup was made, and whether the last attempt
|
||||||
failed.
|
failed.
|
||||||
|
|
||||||
@@ -87,7 +92,9 @@ systemctl edit jarl-backup.timer
|
|||||||
|
|
||||||
The backup service runs as the `jarl` user in a sandbox that may only
|
The backup service runs as the `jarl` user in a sandbox that may only
|
||||||
write to `/var/lib/jarl` and `/var/backups/jarl` (created by
|
write to `/var/lib/jarl` and `/var/backups/jarl` (created by
|
||||||
`tmpfiles.d/jarl.conf`, mode 0700). To keep backups elsewhere, set
|
`tmpfiles.d/jarl.conf`, mode 0700). It has one capability,
|
||||||
|
`CAP_DAC_READ_SEARCH`, to read named's DNSSEC private keys, which only
|
||||||
|
named's user may read. To keep backups elsewhere, set
|
||||||
`backup.dir`, create the directory (owned by `jarl`, mode 0700) and allow
|
`backup.dir`, create the directory (owned by `jarl`, mode 0700) and allow
|
||||||
it:
|
it:
|
||||||
|
|
||||||
@@ -104,18 +111,23 @@ well.
|
|||||||
### By hand
|
### By hand
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo -u jarl jarld backup # into backup.dir, as the timer does
|
sudo jarld backup # into backup.dir, as the timer does
|
||||||
sudo -u jarl jarld backup /root/before-upgrade.db # one copy, never deleted automatically
|
sudo jarld backup /root/before-upgrade.db # one copy, never deleted automatically
|
||||||
sudo jarld restore # list the backups in backup.dir
|
sudo jarld restore # list the backups in backup.dir
|
||||||
|
sudo systemctl start jarl-backup # or exactly what the timer runs
|
||||||
```
|
```
|
||||||
|
|
||||||
Query statistics live in a separate database (`/var/lib/jarl/stats.db`).
|
Query statistics live in a separate database (`/var/lib/jarl/stats.db`).
|
||||||
DNS doesn't need it, so it is backed up only with `backup.stats: true`, as
|
DNS doesn't need it, so it is backed up only with `backup.stats: true`, as
|
||||||
`stats-<UTC time>.db`.
|
`stats-<UTC time>.db`.
|
||||||
|
|
||||||
|
Run it as root (files it creates are given to `jarl`): named's DNSSEC
|
||||||
|
private keys are readable only by named's user. As another user it fails
|
||||||
|
when there are keys; `--without-keys` backs up only the database.
|
||||||
|
|
||||||
The database holds password and token *hashes*, and TSIG secrets in the
|
The database holds password and token *hashes*, and TSIG secrets in the
|
||||||
clear. Backups are written with mode 0600 into a 0700 directory; keep any
|
clear, and backups hold the DNSSEC private keys too. Backups are written
|
||||||
copies just as private.
|
with mode 0600 into a 0700 directory; keep any copies just as private.
|
||||||
|
|
||||||
### Restoring
|
### Restoring
|
||||||
|
|
||||||
@@ -138,7 +150,11 @@ changing anything (`--yes` skips the question). Then it:
|
|||||||
`jarl.db.before-restore-<UTC time>` (with its `-wal` and `-shm` files),
|
`jarl.db.before-restore-<UTC time>` (with its `-wal` and `-shm` files),
|
||||||
so a restore can be undone the same way;
|
so a restore can be undone the same way;
|
||||||
* copies the backup in place, upgrades it to the current schema if it is
|
* copies the backup in place, upgrades it to the current schema if it is
|
||||||
older, and records the restore in its audit log.
|
older, and records the restore in its audit log;
|
||||||
|
* puts the DNSSEC keys stored in the backup back into the key directory,
|
||||||
|
owned by named's user (`bind.named_user`) with the modes they had. Key
|
||||||
|
files that are there but not in the backup are left alone.
|
||||||
|
`--without-keys` skips this; without it, a backup with keys needs root.
|
||||||
|
|
||||||
Then start jarld and bring named in line with the restored database:
|
Then start jarld and bring named in line with the restored database:
|
||||||
|
|
||||||
@@ -152,11 +168,14 @@ jarl resync --force # write everything and reload named
|
|||||||
Things to know:
|
Things to know:
|
||||||
|
|
||||||
* **Zone serials.** An older backup can carry lower zone serials than named
|
* **Zone serials.** An older backup can carry lower zone serials than named
|
||||||
last served. Your own named doesn't mind, but secondaries and caches
|
last served. Secondaries ignore a serial that went backwards, and named
|
||||||
ignore a serial that went backwards, so they keep the newer data. If you
|
refuses one for a signed zone. Jarl handles it: whenever it writes a zone
|
||||||
have secondaries, raise the serials after a restore:
|
file whose serial isn't above the one named has loaded, it raises the
|
||||||
`jarl zone update ZONE --serial <higher than before>`, then check with
|
serial past named's (the resync result and the audit log show it). Check
|
||||||
`jarl zone serials ZONE`.
|
the secondaries afterwards with `jarl zone serials ZONE`.
|
||||||
|
* **DNSSEC keys** must be back before named loads a signed zone, or named
|
||||||
|
makes new keys that the parent's DS record doesn't match. On a new
|
||||||
|
machine, restore before adopting.
|
||||||
* **Tokens and passwords** go back to what they were when the backup was
|
* **Tokens and passwords** go back to what they were when the backup was
|
||||||
made: tokens created since are gone, and revoked ones work again. Rotate
|
made: tokens created since are gone, and revoked ones work again. Rotate
|
||||||
or revoke as needed.
|
or revoke as needed.
|
||||||
|
|||||||
+4
-3
@@ -27,8 +27,9 @@ certbot, CI jobs and backups.
|
|||||||
## Grants
|
## Grants
|
||||||
|
|
||||||
A user's permissions are a list of grants. Administrators (`admin: true`)
|
A user's permissions are a list of grants. Administrators (`admin: true`)
|
||||||
may do everything, and only they can manage users, see everyone's tokens
|
may do everything, and only they can manage users, see everyone's tokens,
|
||||||
and run `resync`.
|
run `resync`, wipe a zone's DNSSEC keys, and use the registrar (Porkbun,
|
||||||
|
whose key can move the domain).
|
||||||
|
|
||||||
A grant is written as:
|
A grant is written as:
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ RESOURCE:ACCESS [zones=PATTERNS] [views=PATTERNS] [names=PATTERNS] [types=TYPES]
|
|||||||
|
|
||||||
| Resource | Covers |
|
| Resource | Covers |
|
||||||
|----------|--------|
|
|----------|--------|
|
||||||
| `zones` | zone definitions (create, delete, SOA, TTL, view) and zone options |
|
| `zones` | zone definitions (create, delete, SOA, TTL, view, DNSSEC signing and the DS check) and zone options |
|
||||||
| `records` | records in primary zones |
|
| `records` | records in primary zones |
|
||||||
| `views` | views and view options |
|
| `views` | views and view options |
|
||||||
| `acls` | ACLs |
|
| `acls` | ACLs |
|
||||||
|
|||||||
+22
-1
@@ -74,11 +74,32 @@ showing them.
|
|||||||
| `option_unknown`, `option_scope_invalid` | error | The option must exist in BIND 9.20 and be allowed where it is set (server, view, zone of this type, top level) |
|
| `option_unknown`, `option_scope_invalid` | error | The option must exist in BIND 9.20 and be allowed where it is set (server, view, zone of this type, top level) |
|
||||||
| `option_syntax`, `option_value_invalid` | error | The value must parse (balanced braces, strings, the grammar's value type: yes/no, enums, numbers, durations, sizes, address match lists) |
|
| `option_syntax`, `option_value_invalid` | error | The value must parse (balanced braces, strings, the grammar's value type: yes/no, enums, numbers, durations, sizes, address match lists) |
|
||||||
| `option_duplicate` | error | Options that may appear once, appear once |
|
| `option_duplicate` | error | Options that may appear once, appear once |
|
||||||
| `option_managed` | error | Statements Jarl manages itself can't be raw options: `zone`, `view`, `acl`, `key`, `options`, a zone's `type`/`file`/`in-view`, a view's `match-*` |
|
| `option_managed` | error | Statements Jarl manages itself can't be raw options: `zone`, `view`, `acl`, `key`, `options`, a zone's `type`/`file`/`in-view`/`key-directory`, a view's `match-*`, and `dnssec-policy` in zones, views and server options (set per zone instead; top-level `dnssec-policy NAME { }` definitions are options) |
|
||||||
| `option_deprecated`, `option_obsolete`, `option_unavailable` | warning | Flags from the BIND 9.20 reference |
|
| `option_deprecated`, `option_obsolete`, `option_unavailable` | warning | Flags from the BIND 9.20 reference |
|
||||||
| `option_experimental` | info | |
|
| `option_experimental` | info | |
|
||||||
| `settings_invalid` | error | Defaults for new zones are valid |
|
| `settings_invalid` | error | Defaults for new zones are valid |
|
||||||
|
|
||||||
|
## DNSSEC
|
||||||
|
|
||||||
|
These rules come from [dnssec.md](dnssec.md#what-jarl-refuses-and-why).
|
||||||
|
Those that compare the change with the current state are checked when it is
|
||||||
|
applied.
|
||||||
|
|
||||||
|
| Code | Severity | Rule |
|
||||||
|
|------|----------|------|
|
||||||
|
| `dnssec_zone_type` | error | Only primary zones are signed by Jarl |
|
||||||
|
| `dnssec_policy_unknown` | error | The zone's policy must be `default`, `insecure` or a top-level `dnssec-policy` statement |
|
||||||
|
| `dnssec_policy_no_keys` | error | A custom policy with an empty `keys { }` list (named 9.20 crashes loading it) |
|
||||||
|
| `dnssec_ttl_too_long` | error | TTLs (and the default TTL) of a signed zone must be at most the policy's `max-zone-ttl` (a day for the built-in policies); named refuses to load the zone otherwise |
|
||||||
|
| `dnssec_inline_signing` | error | No `inline-signing no` on a signed zone |
|
||||||
|
| `dnssec_off_unsafe` | error | A signed zone can't go straight to unsigned: use the `insecure` policy first (or wipe, when the parent has no DS) |
|
||||||
|
| `dnssec_off_too_early`, `dnssec_off_unknown` | error | Switching off after `insecure` waits until named is done removing the signatures |
|
||||||
|
| `dnssec_delete_signed` | error | A signed zone can't be deleted; turn signing off first |
|
||||||
|
| `dnssec_keys_moved` | error | A signed zone can't move to another view (its keys would change) |
|
||||||
|
| `dnssec_policy_change` | warning | Changing the policy may replace the keys, and with them the DS at the parent |
|
||||||
|
| `dnssec_old_keys` | info | Signing a zone whose key directory still has old keys |
|
||||||
|
| `serial_not_higher` | error | An explicit serial on a signed zone must be above the one named has loaded (automatic serials are raised by themselves) |
|
||||||
|
|
||||||
## Security lints
|
## Security lints
|
||||||
|
|
||||||
| Code | Severity | What it catches |
|
| Code | Severity | What it catches |
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"jarl/internal/dnssec"
|
||||||
"jarl/internal/model"
|
"jarl/internal/model"
|
||||||
"jarl/internal/nscheck"
|
"jarl/internal/nscheck"
|
||||||
|
"jarl/internal/porkbun"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is the API path prefix.
|
// Version is the API path prefix.
|
||||||
@@ -21,6 +23,9 @@ type Zone struct {
|
|||||||
Records int `json:"record_count"`
|
Records int `json:"record_count"`
|
||||||
ZoneFile string `json:"zone_file,omitempty"` // the file named loads
|
ZoneFile string `json:"zone_file,omitempty"` // the file named loads
|
||||||
RName string `json:"rname_email,omitempty"`
|
RName string `json:"rname_email,omitempty"`
|
||||||
|
// Registrar names the registrar Jarl can manage the domain at
|
||||||
|
// ("porkbun"), when one is configured for it.
|
||||||
|
Registrar string `json:"registrar,omitempty"`
|
||||||
// Pending is set when listing with a changeset: add, change or delete.
|
// Pending is set when listing with a changeset: add, change or delete.
|
||||||
Pending string `json:"pending,omitempty"`
|
Pending string `json:"pending,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -267,3 +272,105 @@ type DelegationResponse struct {
|
|||||||
Notes []string `json:"notes"`
|
Notes []string `json:"notes"`
|
||||||
CheckedAt time.Time `json:"checked_at"`
|
CheckedAt time.Time `json:"checked_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DNSSECResponse is GET /zones/{zone}/dnssec.
|
||||||
|
type DNSSECResponse struct {
|
||||||
|
Zone string `json:"zone"`
|
||||||
|
View string `json:"view,omitempty"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
*dnssec.Status
|
||||||
|
// ParentZone is set when the parent zone is a primary zone in Jarl
|
||||||
|
// (in the same view): the DS record then goes there, as a record.
|
||||||
|
ParentZone string `json:"parent_zone,omitempty"`
|
||||||
|
// Registrar names the registrar Jarl can publish the DS at
|
||||||
|
// ("porkbun"), when one is configured in jarl.yaml.
|
||||||
|
Registrar string `json:"registrar,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckDSResponse is POST /zones/{zone}/dnssec/check-ds: what the parent
|
||||||
|
// zone has, and what named was told.
|
||||||
|
type CheckDSResponse struct {
|
||||||
|
Parent *nscheck.ParentDSReport `json:"parent"`
|
||||||
|
Marked []string `json:"marked"`
|
||||||
|
Notes []string `json:"notes"`
|
||||||
|
Status *dnssec.Status `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DNSSECWipe is POST /zones/{zone}/dnssec/wipe.
|
||||||
|
type DNSSECWipe struct {
|
||||||
|
// Force wipes although the parent zone's DS records couldn't be
|
||||||
|
// checked, or named still counts a removed DS as cached.
|
||||||
|
Force bool `json:"force,omitempty"`
|
||||||
|
DryRun bool `json:"dry_run,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DNSSECWipeResponse is the result of a wipe.
|
||||||
|
type DNSSECWipeResponse struct {
|
||||||
|
Removed []string `json:"removed"`
|
||||||
|
DryRun bool `json:"dry_run,omitempty"`
|
||||||
|
ChangesetID int64 `json:"changeset_id,omitempty"`
|
||||||
|
Parent *nscheck.ParentDSReport `json:"parent,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegistrarResponse is GET /zones/{zone}/registrar: the domain's
|
||||||
|
// delegation at the registrar, next to what the zone says.
|
||||||
|
type RegistrarResponse struct {
|
||||||
|
Registrar string `json:"registrar"` // "porkbun"
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
// NS are the name servers at the registry, JarlNS those in the
|
||||||
|
// zone's NS records (both without trailing dots).
|
||||||
|
NS []string `json:"ns"`
|
||||||
|
JarlNS []string `json:"jarl_ns"`
|
||||||
|
NSMatch bool `json:"ns_match"`
|
||||||
|
// Glue covers every glue record at the registry and every name server
|
||||||
|
// inside the zone that needs one.
|
||||||
|
Glue []GlueStatus `json:"glue"`
|
||||||
|
// DS are the DS records at the registry.
|
||||||
|
DS []RegistrarDS `json:"ds"`
|
||||||
|
Findings []nscheck.Finding `json:"findings"`
|
||||||
|
// Error is set when the registrar couldn't be asked; the rest is
|
||||||
|
// then empty.
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlueStatus compares a glue record at the registry with the zone.
|
||||||
|
type GlueStatus struct {
|
||||||
|
Host string `json:"host"`
|
||||||
|
Registry []string `json:"registry"` // addresses at the registry (none: no glue record)
|
||||||
|
Jarl []string `json:"jarl"` // the zone's A and AAAA records for the host
|
||||||
|
// Needed: a name server in the zone's NS records that is inside the
|
||||||
|
// domain, so resolvers need its glue. InUse: in the registry's NS.
|
||||||
|
Needed bool `json:"needed"`
|
||||||
|
InUse bool `json:"in_use"`
|
||||||
|
// Action is what syncing the glue does: "create", "update" or "".
|
||||||
|
Action string `json:"action,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegistrarDS is a DS record at the registry.
|
||||||
|
type RegistrarDS struct {
|
||||||
|
porkbun.DS
|
||||||
|
// Matches: it points at a key named publishes for the zone.
|
||||||
|
Matches bool `json:"matches"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegistrarChange asks for a change at the registrar.
|
||||||
|
type RegistrarChange struct {
|
||||||
|
// NS (set-ns) are the name servers to set (default: the zone's NS
|
||||||
|
// records).
|
||||||
|
NS []string `json:"ns,omitempty"`
|
||||||
|
// KeyTag (publish DS) picks the key (default: every key that needs
|
||||||
|
// one).
|
||||||
|
KeyTag uint16 `json:"key_tag,omitempty"`
|
||||||
|
// Force skips the checks that the change won't break the domain.
|
||||||
|
Force bool `json:"force,omitempty"`
|
||||||
|
DryRun bool `json:"dry_run,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegistrarChangeResponse is the result of a change at the registrar.
|
||||||
|
type RegistrarChangeResponse struct {
|
||||||
|
// Done lists what was changed (or would be, in a dry run).
|
||||||
|
Done []string `json:"done"`
|
||||||
|
DryRun bool `json:"dry_run,omitempty"`
|
||||||
|
Checks []nscheck.Finding `json:"checks"`
|
||||||
|
Warnings []string `json:"warnings"`
|
||||||
|
}
|
||||||
+144
-3
@@ -59,9 +59,11 @@ func parse(name string) (kind string, t time.Time, ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write makes a consistent copy of the live SQLite database src as
|
// Write makes a consistent copy of the live SQLite database src as
|
||||||
// dir/Name(kind, now), and checks the copy before giving it its final
|
// dir/Name(kind, now), stores the files under filesDir in it (the DNSSEC
|
||||||
// name: a file with a backup's name is always a complete, intact backup.
|
// keys; "" for none, see AddFiles), and checks the copy before giving it
|
||||||
func Write(ctx context.Context, src, dir, kind string, now time.Time) (*File, error) {
|
// its final name: a file with a backup's name is always a complete,
|
||||||
|
// intact backup.
|
||||||
|
func Write(ctx context.Context, src, dir, kind string, now time.Time, filesDir string) (*File, error) {
|
||||||
if _, err := os.Stat(src); err != nil {
|
if _, err := os.Stat(src); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -78,6 +80,12 @@ func Write(ctx context.Context, src, dir, kind string, now time.Time) (*File, er
|
|||||||
os.Remove(tmp)
|
os.Remove(tmp)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if filesDir != "" {
|
||||||
|
if _, err := AddFiles(ctx, tmp, filesDir); err != nil {
|
||||||
|
os.Remove(tmp)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := Verify(ctx, tmp); err != nil {
|
if err := Verify(ctx, tmp); err != nil {
|
||||||
os.Remove(tmp)
|
os.Remove(tmp)
|
||||||
return nil, fmt.Errorf("the new backup failed its check: %w", err)
|
return nil, fmt.Errorf("the new backup failed its check: %w", err)
|
||||||
@@ -144,6 +152,130 @@ func openCopy(path string) (*sql.DB, error) {
|
|||||||
return sql.Open("sqlite", "file:"+escape(path)+"?mode=ro&immutable=1")
|
return sql.Open("sqlite", "file:"+escape(path)+"?mode=ro&immutable=1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FilesTable holds the files a backup stores next to the database. It
|
||||||
|
// exists only in backups: 'jarld restore' writes the files back and drops
|
||||||
|
// the table.
|
||||||
|
const FilesTable = "backup_files"
|
||||||
|
|
||||||
|
// StoredFile is a file stored in a backup.
|
||||||
|
type StoredFile struct {
|
||||||
|
// Path is relative to the directory the files came from (Root).
|
||||||
|
Path string
|
||||||
|
Mode os.FileMode
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddFiles stores every regular file under root in the backup database
|
||||||
|
// at path (the DNSSEC keys named keeps under Jarl's key directory,
|
||||||
|
// private keys included). A missing root stores nothing. Files that can't
|
||||||
|
// be read are an error: named's private keys are readable only by named's
|
||||||
|
// user, so the backup must run as root or with CAP_DAC_READ_SEARCH (as
|
||||||
|
// jarl-backup.service does).
|
||||||
|
func AddFiles(ctx context.Context, path, root string) (int, error) {
|
||||||
|
var files []StoredFile
|
||||||
|
err := filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) && p == root {
|
||||||
|
return filepath.SkipAll
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !d.Type().IsRegular() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
b, err := os.ReadFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fi, err := d.Info()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rel, _ := filepath.Rel(root, p)
|
||||||
|
files = append(files, StoredFile{Path: rel, Mode: fi.Mode().Perm(), Data: b})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
if os.IsPermission(err) {
|
||||||
|
return 0, fmt.Errorf("reading the DNSSEC keys: %w (named's private keys are readable only by its own user: back up as root, or through jarl-backup.service)", err)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("reading the DNSSEC keys: %w", err)
|
||||||
|
}
|
||||||
|
db, err := sql.Open("sqlite", "file:"+escape(path)+"?mode=rw")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
tx, err := db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer tx.Rollback()
|
||||||
|
if _, err := tx.ExecContext(ctx, `CREATE TABLE `+FilesTable+` (root TEXT NOT NULL, path TEXT NOT NULL, mode INTEGER NOT NULL, data BLOB NOT NULL, PRIMARY KEY (root, path))`); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
for _, f := range files {
|
||||||
|
if _, err := tx.ExecContext(ctx, `INSERT INTO `+FilesTable+` (root, path, mode, data) VALUES (?, ?, ?, ?)`, root, f.Path, int(f.Mode), f.Data); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(files), tx.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Files returns the files stored in a backup and the directory they came
|
||||||
|
// from ("" and none for a backup without files).
|
||||||
|
func Files(ctx context.Context, path string) (string, []StoredFile, error) {
|
||||||
|
db, err := openCopy(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
if !hasTable(ctx, db, FilesTable) {
|
||||||
|
return "", nil, nil
|
||||||
|
}
|
||||||
|
rows, err := db.QueryContext(ctx, `SELECT root, path, mode, data FROM `+FilesTable+` ORDER BY path`)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var root string
|
||||||
|
var out []StoredFile
|
||||||
|
for rows.Next() {
|
||||||
|
var f StoredFile
|
||||||
|
var mode int
|
||||||
|
if err := rows.Scan(&root, &f.Path, &mode, &f.Data); err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
f.Mode = os.FileMode(mode).Perm()
|
||||||
|
out = append(out, f)
|
||||||
|
}
|
||||||
|
return root, out, rows.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasTable(ctx context.Context, db *sql.DB, name string) bool {
|
||||||
|
var n int
|
||||||
|
db.QueryRowContext(ctx, `SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = ?`, name).Scan(&n)
|
||||||
|
return n > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// DropFiles removes the stored files from a database restored from a
|
||||||
|
// backup, and vacuums it so the private keys don't linger in free pages.
|
||||||
|
func DropFiles(ctx context.Context, path string) error {
|
||||||
|
db, err := sql.Open("sqlite", "file:"+escape(path)+"?mode=rw")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
if !hasTable(ctx, db, FilesTable) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, err := db.ExecContext(ctx, `DROP TABLE `+FilesTable); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = db.ExecContext(ctx, `VACUUM`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Info describes the contents of a configuration database (KindJarl).
|
// Info describes the contents of a configuration database (KindJarl).
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Schema int `json:"schema"`
|
Schema int `json:"schema"`
|
||||||
@@ -151,6 +283,10 @@ type Info struct {
|
|||||||
Records int `json:"records"`
|
Records int `json:"records"`
|
||||||
Users int `json:"users"`
|
Users int `json:"users"`
|
||||||
LastChange *time.Time `json:"last_change,omitempty"`
|
LastChange *time.Time `json:"last_change,omitempty"`
|
||||||
|
// KeyFiles is the number of DNSSEC key files stored in a backup, and
|
||||||
|
// SignedZones how many zones were signed.
|
||||||
|
KeyFiles int `json:"key_files"`
|
||||||
|
SignedZones int `json:"signed_zones"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspect reads a configuration database's schema version and size. It
|
// Inspect reads a configuration database's schema version and size. It
|
||||||
@@ -168,6 +304,11 @@ func Inspect(ctx context.Context, path string) (*Info, error) {
|
|||||||
db.QueryRowContext(ctx, `SELECT count(*) FROM zones`).Scan(&in.Zones)
|
db.QueryRowContext(ctx, `SELECT count(*) FROM zones`).Scan(&in.Zones)
|
||||||
db.QueryRowContext(ctx, `SELECT count(*) FROM records`).Scan(&in.Records)
|
db.QueryRowContext(ctx, `SELECT count(*) FROM records`).Scan(&in.Records)
|
||||||
db.QueryRowContext(ctx, `SELECT count(*) FROM users`).Scan(&in.Users)
|
db.QueryRowContext(ctx, `SELECT count(*) FROM users`).Scan(&in.Users)
|
||||||
|
if hasTable(ctx, db, FilesTable) {
|
||||||
|
db.QueryRowContext(ctx, `SELECT count(*) FROM `+FilesTable).Scan(&in.KeyFiles)
|
||||||
|
}
|
||||||
|
// dnssec_policy exists from schema 3 on.
|
||||||
|
db.QueryRowContext(ctx, `SELECT count(*) FROM zones WHERE dnssec_policy != ''`).Scan(&in.SignedZones)
|
||||||
var last sql.NullString
|
var last sql.NullString
|
||||||
db.QueryRowContext(ctx, `SELECT max(applied_at) FROM changesets`).Scan(&last)
|
db.QueryRowContext(ctx, `SELECT max(applied_at) FROM changesets`).Scan(&last)
|
||||||
if t, err := time.Parse(time.RFC3339Nano, last.String); err == nil {
|
if t, err := time.Parse(time.RFC3339Nano, last.String); err == nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ func TestWriteVerifyInspect(t *testing.T) {
|
|||||||
src := newDB(t)
|
src := newDB(t)
|
||||||
dir := filepath.Join(t.TempDir(), "backups")
|
dir := filepath.Join(t.TempDir(), "backups")
|
||||||
now := time.Date(2026, 10, 8, 3, 15, 12, 0, time.UTC)
|
now := time.Date(2026, 10, 8, 3, 15, 12, 0, time.UTC)
|
||||||
f, err := Write(ctx, src, dir, KindJarl, now)
|
f, err := Write(ctx, src, dir, KindJarl, now, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ func TestWriteVerifyInspect(t *testing.T) {
|
|||||||
t.Errorf("inspect: %+v %v", in, err)
|
t.Errorf("inspect: %+v %v", in, err)
|
||||||
}
|
}
|
||||||
// The same second again is refused rather than overwritten.
|
// The same second again is refused rather than overwritten.
|
||||||
if _, err := Write(ctx, src, dir, KindJarl, now); err == nil {
|
if _, err := Write(ctx, src, dir, KindJarl, now, ""); err == nil {
|
||||||
t.Error("overwrote a backup")
|
t.Error("overwrote a backup")
|
||||||
}
|
}
|
||||||
// No temporary files are left.
|
// No temporary files are left.
|
||||||
@@ -54,7 +55,7 @@ func TestWriteVerifyInspect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// A missing database is an error, and isn't created.
|
// A missing database is an error, and isn't created.
|
||||||
missing := filepath.Join(t.TempDir(), "nope.db")
|
missing := filepath.Join(t.TempDir(), "nope.db")
|
||||||
if _, err := Write(ctx, missing, dir, KindJarl, now.Add(time.Second)); err == nil {
|
if _, err := Write(ctx, missing, dir, KindJarl, now.Add(time.Second), ""); err == nil {
|
||||||
t.Error("backed up a missing database")
|
t.Error("backed up a missing database")
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(missing); err == nil {
|
if _, err := os.Stat(missing); err == nil {
|
||||||
@@ -149,3 +150,52 @@ func TestPruneTempFiles(t *testing.T) {
|
|||||||
t.Error("a running backup's temporary file was deleted")
|
t.Error("a running backup's temporary file was deleted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeyFiles(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
src := newDB(t)
|
||||||
|
keys := t.TempDir()
|
||||||
|
os.MkdirAll(filepath.Join(keys, "view-3"), 0o755)
|
||||||
|
os.WriteFile(filepath.Join(keys, "view-3", "Kexample.com.+013+12345.key"), []byte("public"), 0o644)
|
||||||
|
os.WriteFile(filepath.Join(keys, "view-3", "Kexample.com.+013+12345.private"), []byte("private-key-material-xyz"), 0o600)
|
||||||
|
dir := t.TempDir()
|
||||||
|
f, err := Write(ctx, src, dir, KindJarl, time.Now(), keys)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
root, files, err := Files(ctx, f.Path)
|
||||||
|
if err != nil || root != keys || len(files) != 2 {
|
||||||
|
t.Fatalf("files: %q %+v %v", root, files, err)
|
||||||
|
}
|
||||||
|
if files[1].Path != "view-3/Kexample.com.+013+12345.private" || string(files[1].Data) != "private-key-material-xyz" || files[1].Mode != 0o600 {
|
||||||
|
t.Errorf("private key: %+v", files[1])
|
||||||
|
}
|
||||||
|
if in, err := Inspect(ctx, f.Path); err != nil || in.KeyFiles != 2 {
|
||||||
|
t.Errorf("inspect: %+v %v", in, err)
|
||||||
|
}
|
||||||
|
// A restored database loses the table again.
|
||||||
|
restored := filepath.Join(t.TempDir(), "jarl.db")
|
||||||
|
b, _ := os.ReadFile(f.Path)
|
||||||
|
os.WriteFile(restored, b, 0o600)
|
||||||
|
if err := DropFiles(ctx, restored); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, files, _ := Files(ctx, restored); len(files) != 0 {
|
||||||
|
t.Error("files left after DropFiles")
|
||||||
|
}
|
||||||
|
if b, _ := os.ReadFile(restored); strings.Contains(string(b), "private-key-material-xyz") {
|
||||||
|
t.Error("the private key is still in the file")
|
||||||
|
}
|
||||||
|
// No key directory: nothing stored. An unreadable key: an error.
|
||||||
|
if f, err := Write(ctx, src, dir, KindJarl, time.Now().Add(time.Second), filepath.Join(keys, "missing")); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if _, files, _ := Files(ctx, f.Path); len(files) != 0 {
|
||||||
|
t.Errorf("files from a missing directory: %v", files)
|
||||||
|
}
|
||||||
|
if os.Geteuid() != 0 {
|
||||||
|
os.Chmod(filepath.Join(keys, "view-3", "Kexample.com.+013+12345.private"), 0)
|
||||||
|
if _, err := Write(ctx, src, dir, KindJarl, time.Now().Add(2*time.Second), keys); err == nil || !strings.Contains(err.Error(), "back up as root") {
|
||||||
|
t.Errorf("unreadable key: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-10
@@ -223,6 +223,18 @@ func (t *Tools) ReloadZone(ctx context.Context, zone, view string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckDS tells named that the parent zone has published (or withdrawn)
|
||||||
|
// the DS record for key tag of a zone it signs (rndc dnssec -checkds).
|
||||||
|
func (t *Tools) CheckDS(ctx context.Context, zone, view string, tag uint16, alg uint8, published bool) (string, error) {
|
||||||
|
which := "withdrawn"
|
||||||
|
if published {
|
||||||
|
which = "published"
|
||||||
|
}
|
||||||
|
z := zoneArgs("", zone, view)[1:]
|
||||||
|
args := append([]string{"dnssec", "-checkds", "-key", strconv.Itoa(int(tag)), "-alg", strconv.Itoa(int(alg)), which}, z...)
|
||||||
|
return t.RNDCRun(ctx, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func zoneArgs(cmd, zone, view string) []string {
|
func zoneArgs(cmd, zone, view string) []string {
|
||||||
z := strings.TrimSuffix(zone, ".")
|
z := strings.TrimSuffix(zone, ".")
|
||||||
if z == "" {
|
if z == "" {
|
||||||
@@ -236,16 +248,32 @@ func zoneArgs(cmd, zone, view string) []string {
|
|||||||
|
|
||||||
// ZoneStatus is the result of rndc zonestatus.
|
// ZoneStatus is the result of rndc zonestatus.
|
||||||
type ZoneStatus struct {
|
type ZoneStatus struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Files string `json:"files"`
|
Files string `json:"files"`
|
||||||
Serial uint32 `json:"serial"`
|
// Serial is the serial of the zone file named loaded. For a zone
|
||||||
HasSerial bool `json:"-"`
|
// named signs (inline signing) that is the unsigned zone Jarl wrote;
|
||||||
Nodes int `json:"nodes"`
|
// the signed zone that named serves has its own serial, SignedSerial.
|
||||||
LastLoaded string `json:"last_loaded"`
|
Serial uint32 `json:"serial"`
|
||||||
Secure bool `json:"secure"`
|
HasSerial bool `json:"-"`
|
||||||
Dynamic bool `json:"dynamic"`
|
SignedSerial uint32 `json:"signed_serial,omitempty"`
|
||||||
Raw string `json:"raw"`
|
HasSignedSerial bool `json:"-"`
|
||||||
|
Nodes int `json:"nodes"`
|
||||||
|
LastLoaded string `json:"last_loaded"`
|
||||||
|
Secure bool `json:"secure"`
|
||||||
|
InlineSigning bool `json:"inline_signing"`
|
||||||
|
NextKeyEvent string `json:"next_key_event,omitempty"`
|
||||||
|
Dynamic bool `json:"dynamic"`
|
||||||
|
Raw string `json:"raw"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServedSerial is the serial named answers queries with: the signed
|
||||||
|
// zone's for a zone it signs, otherwise the loaded one.
|
||||||
|
func (zs *ZoneStatus) ServedSerial() (uint32, bool) {
|
||||||
|
if zs.HasSignedSerial {
|
||||||
|
return zs.SignedSerial, true
|
||||||
|
}
|
||||||
|
return zs.Serial, zs.HasSerial
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZoneStatus returns named's view of a zone.
|
// ZoneStatus returns named's view of a zone.
|
||||||
@@ -277,6 +305,14 @@ func ParseZoneStatus(out string) *ZoneStatus {
|
|||||||
if n, err := strconv.ParseUint(v, 10, 32); err == nil {
|
if n, err := strconv.ParseUint(v, 10, 32); err == nil {
|
||||||
zs.Serial, zs.HasSerial = uint32(n), true
|
zs.Serial, zs.HasSerial = uint32(n), true
|
||||||
}
|
}
|
||||||
|
case "signed serial":
|
||||||
|
if n, err := strconv.ParseUint(v, 10, 32); err == nil {
|
||||||
|
zs.SignedSerial, zs.HasSignedSerial = uint32(n), true
|
||||||
|
}
|
||||||
|
case "inline signing":
|
||||||
|
zs.InlineSigning = v == "yes"
|
||||||
|
case "next key event":
|
||||||
|
zs.NextKeyEvent = v
|
||||||
case "nodes":
|
case "nodes":
|
||||||
zs.Nodes, _ = strconv.Atoi(v)
|
zs.Nodes, _ = strconv.Atoi(v)
|
||||||
case "last loaded":
|
case "last loaded":
|
||||||
|
|||||||
@@ -17,3 +17,33 @@ zone example.com/IN/internal: loaded serial 1
|
|||||||
t.Errorf("exit 1: %+v", bad)
|
t.Errorf("exit 1: %+v", bad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseZoneStatusSigned(t *testing.T) {
|
||||||
|
// rndc zonestatus of a zone named signs with dnssec-policy (BIND 9.20).
|
||||||
|
zs := ParseZoneStatus(`name: example.test
|
||||||
|
type: primary
|
||||||
|
files: /var/lib/bind/jarl/_default/example.test.zone
|
||||||
|
serial: 2026100802
|
||||||
|
signed serial: 2026100804
|
||||||
|
nodes: 4
|
||||||
|
last loaded: Thu, 08 Oct 2026 19:03:31 GMT
|
||||||
|
secure: yes
|
||||||
|
inline signing: yes
|
||||||
|
key maintenance: automatic
|
||||||
|
next key event: Thu, 08 Oct 2026 21:08:31 GMT
|
||||||
|
next resign node: new.example.test/A
|
||||||
|
next resign time: Sat, 17 Oct 2026 07:32:59 GMT
|
||||||
|
dynamic: no
|
||||||
|
reconfigurable via modzone: no
|
||||||
|
`)
|
||||||
|
if zs.Serial != 2026100802 || zs.SignedSerial != 2026100804 || !zs.Secure || !zs.InlineSigning || zs.NextKeyEvent != "Thu, 08 Oct 2026 21:08:31 GMT" {
|
||||||
|
t.Errorf("%+v", zs)
|
||||||
|
}
|
||||||
|
if s, ok := zs.ServedSerial(); !ok || s != 2026100804 {
|
||||||
|
t.Errorf("served serial %d %v", s, ok)
|
||||||
|
}
|
||||||
|
plain := ParseZoneStatus("name: example.com\nserial: 7\nsecure: no\n")
|
||||||
|
if s, ok := plain.ServedSerial(); !ok || s != 7 || plain.HasSignedSerial {
|
||||||
|
t.Errorf("unsigned: %+v", plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,13 +102,25 @@ var managed = map[string]map[string]string{
|
|||||||
"match-recursive-only": "the view's match-recursive-only field",
|
"match-recursive-only": "the view's match-recursive-only field",
|
||||||
"key": "TSIG keys (define keys at the top level)",
|
"key": "TSIG keys (define keys at the top level)",
|
||||||
"zone": "zones",
|
"zone": "zones",
|
||||||
|
"dnssec-policy": dnssecManaged,
|
||||||
|
},
|
||||||
|
ScopeOptions: {
|
||||||
|
"dnssec-policy": dnssecManaged,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dnssecManaged: Jarl turns signing on and off per zone, so that it can
|
||||||
|
// guard the steps (a zone mustn't go unsigned while the parent zone still
|
||||||
|
// has a DS record for it). dnssec-policy statements that define custom
|
||||||
|
// policies (at the top level) are still options.
|
||||||
|
const dnssecManaged = "each zone's DNSSEC setting (jarl zone dnssec enable ZONE; see docs/dnssec.md)"
|
||||||
|
|
||||||
var zoneManaged = map[string]string{
|
var zoneManaged = map[string]string{
|
||||||
"type": "the zone's type field",
|
"type": "the zone's type field",
|
||||||
"file": "the zone's file (generated by Jarl)",
|
"file": "the zone's file (generated by Jarl)",
|
||||||
"in-view": "the zone's in-view field",
|
"in-view": "the zone's in-view field",
|
||||||
|
"dnssec-policy": dnssecManaged,
|
||||||
|
"key-directory": "Jarl (signed zones keep their keys in Jarl's key directory, which its backups include)",
|
||||||
}
|
}
|
||||||
|
|
||||||
// synonyms are older spellings that named 9.20 still accepts.
|
// synonyms are older spellings that named 9.20 still accepts.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -34,6 +35,62 @@ type Config struct {
|
|||||||
Backup Backup `yaml:"backup"`
|
Backup Backup `yaml:"backup"`
|
||||||
Stats Stats `yaml:"stats"`
|
Stats Stats `yaml:"stats"`
|
||||||
ACME ACME `yaml:"acme"`
|
ACME ACME `yaml:"acme"`
|
||||||
|
Porkbun Porkbun `yaml:"porkbun"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Porkbun lets Jarl manage domains' name servers, glue records and DNSSEC
|
||||||
|
// DS records at the registrar Porkbun (docs/dnssec.md#porkbun). The key
|
||||||
|
// lives only here, in a file root and jarld can read, and never in the
|
||||||
|
// database (so not in backups either).
|
||||||
|
type Porkbun struct {
|
||||||
|
APIKey string `yaml:"api_key"`
|
||||||
|
SecretAPIKey string `yaml:"secret_api_key"`
|
||||||
|
// Domains limits which domains Jarl may manage at Porkbun (default:
|
||||||
|
// every Jarl zone the key can reach).
|
||||||
|
Domains []string `yaml:"domains"`
|
||||||
|
// APIURL is the API's base URL (for tests).
|
||||||
|
APIURL string `yaml:"api_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enabled reports whether a Porkbun key is configured.
|
||||||
|
func (p *Porkbun) Enabled() bool { return p.APIKey != "" }
|
||||||
|
|
||||||
|
// Allows reports whether Jarl may manage domain (no trailing dot) at
|
||||||
|
// Porkbun.
|
||||||
|
func (p *Porkbun) Allows(domain string) bool {
|
||||||
|
if !p.Enabled() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(p.Domains) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, d := range p.Domains {
|
||||||
|
if strings.EqualFold(strings.TrimSuffix(d, "."), domain) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Porkbun) check() error {
|
||||||
|
if (p.APIKey == "") != (p.SecretAPIKey == "") {
|
||||||
|
return fmt.Errorf("set both api_key and secret_api_key (or neither)")
|
||||||
|
}
|
||||||
|
if p.APIURL != "" {
|
||||||
|
u, err := url.Parse(p.APIURL)
|
||||||
|
if err != nil || (u.Scheme != "https" && !(u.Scheme == "http" && isLoopbackHost(u.Hostname()))) {
|
||||||
|
return fmt.Errorf("api_url must be an https:// URL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isLoopbackHost(h string) bool {
|
||||||
|
if h == "localhost" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
a, err := netip.ParseAddr(h)
|
||||||
|
return err == nil && a.IsLoopback()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backup configures 'jarld backup' run without a file name, which is what
|
// Backup configures 'jarld backup' run without a file name, which is what
|
||||||
@@ -94,11 +151,14 @@ type Session struct {
|
|||||||
|
|
||||||
// BIND says where BIND's files and tools are.
|
// BIND says where BIND's files and tools are.
|
||||||
type BIND struct {
|
type BIND struct {
|
||||||
MainConfig string `yaml:"main_config"`
|
MainConfig string `yaml:"main_config"`
|
||||||
ConfigDir string `yaml:"config_dir"`
|
ConfigDir string `yaml:"config_dir"`
|
||||||
ZoneDir string `yaml:"zone_dir"`
|
ZoneDir string `yaml:"zone_dir"`
|
||||||
CacheDir string `yaml:"cache_dir"`
|
CacheDir string `yaml:"cache_dir"`
|
||||||
FileGroup string `yaml:"file_group"`
|
FileGroup string `yaml:"file_group"`
|
||||||
|
// NamedUser is the user named runs as. 'jarld restore' gives it the
|
||||||
|
// DNSSEC keys it puts back.
|
||||||
|
NamedUser string `yaml:"named_user"`
|
||||||
NamedCheckConf string `yaml:"named_checkconf"`
|
NamedCheckConf string `yaml:"named_checkconf"`
|
||||||
NamedCheckZone string `yaml:"named_checkzone"`
|
NamedCheckZone string `yaml:"named_checkzone"`
|
||||||
RNDC string `yaml:"rndc"`
|
RNDC string `yaml:"rndc"`
|
||||||
@@ -200,6 +260,7 @@ func Default() *Config {
|
|||||||
ZoneDir: "/var/lib/bind/jarl",
|
ZoneDir: "/var/lib/bind/jarl",
|
||||||
CacheDir: "/var/cache/bind/jarl",
|
CacheDir: "/var/cache/bind/jarl",
|
||||||
FileGroup: "bind",
|
FileGroup: "bind",
|
||||||
|
NamedUser: "bind",
|
||||||
NamedCheckConf: "/usr/bin/named-checkconf",
|
NamedCheckConf: "/usr/bin/named-checkconf",
|
||||||
NamedCheckZone: "/usr/bin/named-checkzone",
|
NamedCheckZone: "/usr/bin/named-checkzone",
|
||||||
RNDC: "/usr/sbin/rndc",
|
RNDC: "/usr/sbin/rndc",
|
||||||
@@ -273,6 +334,9 @@ func (c *Config) check() error {
|
|||||||
if err := c.Backup.check(); err != nil {
|
if err := c.Backup.check(); err != nil {
|
||||||
return fmt.Errorf("backup: %w", err)
|
return fmt.Errorf("backup: %w", err)
|
||||||
}
|
}
|
||||||
|
if err := c.Porkbun.check(); err != nil {
|
||||||
|
return fmt.Errorf("porkbun: %w", err)
|
||||||
|
}
|
||||||
switch c.Log.Format {
|
switch c.Log.Format {
|
||||||
case "text", "json":
|
case "text", "json":
|
||||||
default:
|
default:
|
||||||
@@ -415,6 +479,8 @@ bind:
|
|||||||
cache_dir: /var/cache/bind/jarl
|
cache_dir: /var/cache/bind/jarl
|
||||||
# Group of generated files; named must be able to read them.
|
# Group of generated files; named must be able to read them.
|
||||||
file_group: bind
|
file_group: bind
|
||||||
|
# The user named runs as ('jarld restore' gives it the DNSSEC keys back).
|
||||||
|
named_user: bind
|
||||||
named_checkconf: /usr/bin/named-checkconf
|
named_checkconf: /usr/bin/named-checkconf
|
||||||
named_checkzone: /usr/bin/named-checkzone
|
named_checkzone: /usr/bin/named-checkzone
|
||||||
rndc: /usr/sbin/rndc
|
rndc: /usr/sbin/rndc
|
||||||
@@ -434,7 +500,9 @@ audit:
|
|||||||
# 'systemctl edit jarl-backup.timer'. Each run writes
|
# 'systemctl edit jarl-backup.timer'. Each run writes
|
||||||
# DIR/jarl-<UTC time>.db, checks it, then deletes backups older than
|
# DIR/jarl-<UTC time>.db, checks it, then deletes backups older than
|
||||||
# 'retention', always keeping the newest 'keep_at_least'. Only files named
|
# 'retention', always keeping the newest 'keep_at_least'. Only files named
|
||||||
# like that are ever deleted. Restore with 'jarld restore'.
|
# like that are ever deleted. Each backup also holds the DNSSEC keys of
|
||||||
|
# signed zones (private keys included), so keep the directory private.
|
||||||
|
# Restore with 'jarld restore'.
|
||||||
backup:
|
backup:
|
||||||
dir: /var/backups/jarl # the timer's sandbox may write only here (see the docs to move it)
|
dir: /var/backups/jarl # the timer's sandbox may write only here (see the docs to move it)
|
||||||
retention: 30d # 0 keeps every backup
|
retention: 30d # 0 keeps every backup
|
||||||
@@ -478,4 +546,17 @@ acme:
|
|||||||
# this server. Leave false if a reverse proxy runs on this server but
|
# this server. Leave false if a reverse proxy runs on this server but
|
||||||
# isn't in trusted_proxies: its requests would look local.
|
# isn't in trusted_proxies: its requests would look local.
|
||||||
allow_loopback_http: false
|
allow_loopback_http: false
|
||||||
|
|
||||||
|
# The registrar Porkbun (docs/dnssec.md#porkbun): with an API key, Jarl can
|
||||||
|
# show and set a domain's name servers, glue records and DNSSEC DS records
|
||||||
|
# there, after checking that the change won't break the domain. Off without
|
||||||
|
# a key. Create the key at porkbun.com (Account -> API Access), switch on
|
||||||
|
# "API Access" for the domain, and limit the key to that domain if you can.
|
||||||
|
# The key can move your domain elsewhere: it lives only in this file (keep
|
||||||
|
# it readable by root and jarld only: chown root:jarl, chmod 640), never in
|
||||||
|
# Jarl's database or backups.
|
||||||
|
porkbun:
|
||||||
|
api_key: "" # pk1_...
|
||||||
|
secret_api_key: "" # sk1_...
|
||||||
|
domains: [] # only these domains (default: any Jarl zone the key reaches)
|
||||||
`
|
`
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
// Package dnssec reads the DNSSEC keys named keeps for the zones it signs
|
||||||
|
// (dnssec-policy with inline signing) and works out where a zone is in the
|
||||||
|
// steps of turning signing on or off.
|
||||||
|
//
|
||||||
|
// named writes three files per key into the zone's key-directory:
|
||||||
|
// K<zone>.+<alg>+<tag>.key (the public DNSKEY, world-readable),
|
||||||
|
// .private (the private key, readable only by named's user) and .state
|
||||||
|
// (the key's timing and state, see the dnssec-keymgr states in the BIND
|
||||||
|
// ARM). Jarl only reads the .key and .state files.
|
||||||
|
package dnssec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Key states, as named writes them in .state files.
|
||||||
|
const (
|
||||||
|
Hidden = "hidden" // not in the zone (or the parent)
|
||||||
|
Rumoured = "rumoured" // published, but caches may not have it yet
|
||||||
|
Omnipresent = "omnipresent" // published long enough that everyone has it
|
||||||
|
Unretentive = "unretentive" // removed, but caches may still have it
|
||||||
|
)
|
||||||
|
|
||||||
|
// Status describes how a zone is signed.
|
||||||
|
type Status struct {
|
||||||
|
Policy string `json:"policy"`
|
||||||
|
// KeyDir is the zone's key-directory.
|
||||||
|
KeyDir string `json:"key_dir"`
|
||||||
|
Keys []*Key `json:"keys"`
|
||||||
|
Phase Phase `json:"phase"`
|
||||||
|
Named *NamedSigning `json:"named,omitempty"`
|
||||||
|
// NamedError says why named couldn't be asked.
|
||||||
|
NamedError string `json:"named_error,omitempty"`
|
||||||
|
// KeyError says why the key directory couldn't be read.
|
||||||
|
KeyError string `json:"key_error,omitempty"`
|
||||||
|
// Policies are the policies the zone could use: default and the
|
||||||
|
// custom dnssec-policy statements.
|
||||||
|
Policies []string `json:"policies"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NamedSigning is what named reports about a zone it signs.
|
||||||
|
type NamedSigning struct {
|
||||||
|
Secure bool `json:"secure"`
|
||||||
|
InlineSigning bool `json:"inline_signing"`
|
||||||
|
Serial uint32 `json:"serial"`
|
||||||
|
SignedSerial uint32 `json:"signed_serial,omitempty"`
|
||||||
|
NextKeyEvent string `json:"next_key_event,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DS is a DS record for a key: what the parent zone publishes to vouch
|
||||||
|
// for it.
|
||||||
|
type DS struct {
|
||||||
|
KeyTag uint16 `json:"key_tag"`
|
||||||
|
Algorithm uint8 `json:"algorithm"`
|
||||||
|
DigestType uint8 `json:"digest_type"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
// Record is the DS record in zone file format.
|
||||||
|
Record string `json:"record"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key is one DNSSEC key of a zone.
|
||||||
|
type Key struct {
|
||||||
|
Tag uint16 `json:"tag"`
|
||||||
|
Algorithm uint8 `json:"algorithm"`
|
||||||
|
AlgorithmName string `json:"algorithm_name"`
|
||||||
|
// Role is CSK (signs everything: BIND's default policy), KSK (signs
|
||||||
|
// the DNSKEY set; the parent's DS points at it) or ZSK.
|
||||||
|
Role string `json:"role"`
|
||||||
|
// DNSKEY is the public key record, and DS its DS record (KSK and CSK
|
||||||
|
// only).
|
||||||
|
DNSKEY string `json:"dnskey,omitempty"`
|
||||||
|
DS *DS `json:"ds,omitempty"`
|
||||||
|
// States from the .state file.
|
||||||
|
Goal string `json:"goal,omitempty"`
|
||||||
|
DNSKEYState string `json:"dnskey_state,omitempty"`
|
||||||
|
DSState string `json:"ds_state,omitempty"`
|
||||||
|
ZoneRRSIG string `json:"zone_rrsig_state,omitempty"`
|
||||||
|
KeyRRSIG string `json:"key_rrsig_state,omitempty"`
|
||||||
|
// Times from the .state file.
|
||||||
|
Created *time.Time `json:"created,omitempty"`
|
||||||
|
Published *time.Time `json:"published,omitempty"`
|
||||||
|
Active *time.Time `json:"active,omitempty"`
|
||||||
|
Retired *time.Time `json:"retired,omitempty"`
|
||||||
|
Removed *time.Time `json:"removed,omitempty"`
|
||||||
|
// PublishCDS is when named publishes CDS/CDNSKEY records: from then on
|
||||||
|
// the DS can safely be added at the parent.
|
||||||
|
PublishCDS *time.Time `json:"publish_cds,omitempty"`
|
||||||
|
// DSPublished and DSRemoved are when named was told (or saw) that the
|
||||||
|
// parent added or removed the DS.
|
||||||
|
DSPublished *time.Time `json:"ds_published,omitempty"`
|
||||||
|
DSRemoved *time.Time `json:"ds_removed,omitempty"`
|
||||||
|
// Files are the key's file names in the key directory.
|
||||||
|
Files []string `json:"files"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SigningKey reports whether the parent's DS should point at the key.
|
||||||
|
func (k *Key) SigningKey() bool { return k.Role == "CSK" || k.Role == "KSK" }
|
||||||
|
|
||||||
|
// Gone reports whether named has finished removing the key: every state
|
||||||
|
// is hidden.
|
||||||
|
func (k *Key) Gone() bool {
|
||||||
|
for _, s := range []string{k.Goal, k.DNSKEYState, k.DSState, k.ZoneRRSIG, k.KeyRRSIG} {
|
||||||
|
if s != "" && s != Hidden {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilePrefix is how named's key files for zone (a name with the trailing
|
||||||
|
// dot) begin.
|
||||||
|
func FilePrefix(zone string) string { return "K" + strings.ToLower(zone) + "+" }
|
||||||
|
|
||||||
|
// Files lists the names of zone's key files in dir (every .key, .private
|
||||||
|
// and .state file, and any other file named with the zone's key prefix).
|
||||||
|
// A missing directory has none.
|
||||||
|
func Files(dir, zone string) ([]string, error) {
|
||||||
|
ents, err := os.ReadDir(dir)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
prefix := FilePrefix(zone)
|
||||||
|
var out []string
|
||||||
|
for _, e := range ents {
|
||||||
|
if !e.IsDir() && strings.HasPrefix(strings.ToLower(e.Name()), strings.ToLower(prefix)) {
|
||||||
|
out = append(out, e.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keys reads zone's keys from dir, ordered with the signing keys first.
|
||||||
|
func Keys(dir, zone string) ([]*Key, error) {
|
||||||
|
files, err := Files(dir, zone)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
byBase := map[string]*Key{}
|
||||||
|
var order []string
|
||||||
|
for _, f := range files {
|
||||||
|
ext := filepath.Ext(f)
|
||||||
|
base := strings.TrimSuffix(f, ext)
|
||||||
|
k := byBase[base]
|
||||||
|
if k == nil {
|
||||||
|
k = &Key{}
|
||||||
|
byBase[base] = k
|
||||||
|
order = append(order, base)
|
||||||
|
}
|
||||||
|
k.Files = append(k.Files, f)
|
||||||
|
switch ext {
|
||||||
|
case ".key":
|
||||||
|
if err := k.readPublic(filepath.Join(dir, f)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
case ".state":
|
||||||
|
if err := k.readState(filepath.Join(dir, f)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var out []*Key
|
||||||
|
for _, b := range order {
|
||||||
|
k := byBase[b]
|
||||||
|
if k.DNSKEY == "" && k.Goal == "" {
|
||||||
|
continue // only a .private file: nothing to show
|
||||||
|
}
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
sort.SliceStable(out, func(i, j int) bool {
|
||||||
|
if out[i].SigningKey() != out[j].SigningKey() {
|
||||||
|
return out[i].SigningKey()
|
||||||
|
}
|
||||||
|
return out[i].Tag < out[j].Tag
|
||||||
|
})
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Key) readPublic(path string) error {
|
||||||
|
b, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
zp := dns.NewZoneParser(strings.NewReader(string(b)), "", path)
|
||||||
|
for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
|
||||||
|
key, isKey := rr.(*dns.DNSKEY)
|
||||||
|
if !isKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
k.Tag = key.KeyTag()
|
||||||
|
k.Algorithm = key.Algorithm
|
||||||
|
k.AlgorithmName = dns.AlgorithmToString[key.Algorithm]
|
||||||
|
k.DNSKEY = key.String()
|
||||||
|
if k.Role == "" {
|
||||||
|
switch {
|
||||||
|
case key.Flags&dns.SEP != 0:
|
||||||
|
k.Role = "KSK"
|
||||||
|
default:
|
||||||
|
k.Role = "ZSK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if key.Flags&dns.SEP != 0 {
|
||||||
|
if ds := key.ToDS(dns.SHA256); ds != nil {
|
||||||
|
k.DS = &DS{KeyTag: ds.KeyTag, Algorithm: ds.Algorithm, DigestType: ds.DigestType, Digest: strings.ToUpper(ds.Digest), Record: ds.String()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := zp.Err(); err != nil {
|
||||||
|
return fmt.Errorf("%s: %w", path, err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s: no DNSKEY record", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *Key) readState(path string) error {
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
var ksk, zsk bool
|
||||||
|
sc := bufio.NewScanner(f)
|
||||||
|
for sc.Scan() {
|
||||||
|
line := sc.Text()
|
||||||
|
if strings.HasPrefix(line, ";") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name, v, ok := strings.Cut(line, ":")
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v = strings.TrimSpace(v)
|
||||||
|
t := func() *time.Time {
|
||||||
|
// 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
f := strings.Fields(v)
|
||||||
|
if len(f) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ts, err := time.Parse("20060102150405", f[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ts
|
||||||
|
}
|
||||||
|
switch name {
|
||||||
|
case "Algorithm":
|
||||||
|
if n, err := strconv.Atoi(v); err == nil && k.Algorithm == 0 {
|
||||||
|
k.Algorithm = uint8(n)
|
||||||
|
k.AlgorithmName = dns.AlgorithmToString[uint8(n)]
|
||||||
|
}
|
||||||
|
case "KSK":
|
||||||
|
ksk = v == "yes"
|
||||||
|
case "ZSK":
|
||||||
|
zsk = v == "yes"
|
||||||
|
case "Generated":
|
||||||
|
k.Created = t()
|
||||||
|
case "Published":
|
||||||
|
k.Published = t()
|
||||||
|
case "Active":
|
||||||
|
k.Active = t()
|
||||||
|
case "Retired":
|
||||||
|
k.Retired = t()
|
||||||
|
case "Removed":
|
||||||
|
k.Removed = t()
|
||||||
|
case "PublishCDS":
|
||||||
|
k.PublishCDS = t()
|
||||||
|
case "DSPublish":
|
||||||
|
k.DSPublished = t()
|
||||||
|
case "DSRemoved":
|
||||||
|
k.DSRemoved = t()
|
||||||
|
case "GoalState":
|
||||||
|
k.Goal = v
|
||||||
|
case "DNSKEYState":
|
||||||
|
k.DNSKEYState = v
|
||||||
|
case "DSState":
|
||||||
|
k.DSState = v
|
||||||
|
case "ZRRSIGState":
|
||||||
|
k.ZoneRRSIG = v
|
||||||
|
case "KRRSIGState":
|
||||||
|
k.KeyRRSIG = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case ksk && zsk:
|
||||||
|
k.Role = "CSK"
|
||||||
|
case ksk:
|
||||||
|
k.Role = "KSK"
|
||||||
|
case zsk:
|
||||||
|
k.Role = "ZSK"
|
||||||
|
}
|
||||||
|
return sc.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZoneFileSuffixes are the files named keeps next to a zone file: the
|
||||||
|
// journal of the zone Jarl wrote (.jnl, and .jbk while it rewrites it) and,
|
||||||
|
// for a signed zone, the signed copy and its journal.
|
||||||
|
var ZoneFileSuffixes = []string{".jnl", ".jbk", ".signed", ".signed.jnl", ".signed.jbk"}
|
||||||
|
|
||||||
|
// DerivedFiles returns the files named made next to zoneFile that exist.
|
||||||
|
func DerivedFiles(zoneFile string) []string {
|
||||||
|
var out []string
|
||||||
|
for _, s := range ZoneFileSuffixes {
|
||||||
|
if _, err := os.Lstat(zoneFile + s); err == nil {
|
||||||
|
out = append(out, zoneFile+s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package dnssec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// testdata holds key files written by named 9.20 with dnssec-policy:
|
||||||
|
// example.test just signed (default policy), fast.test turned insecure
|
||||||
|
// after its DS was removed, fast2.test turned insecure before any DS.
|
||||||
|
|
||||||
|
func TestKeys(t *testing.T) {
|
||||||
|
keys, err := Keys("testdata", "example.test.")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(keys) != 1 {
|
||||||
|
t.Fatalf("%d keys", len(keys))
|
||||||
|
}
|
||||||
|
k := keys[0]
|
||||||
|
if k.Tag != 22642 || k.Role != "CSK" || k.Algorithm != 13 || k.AlgorithmName != "ECDSAP256SHA256" || len(k.Files) != 3 {
|
||||||
|
t.Errorf("key: %+v", k)
|
||||||
|
}
|
||||||
|
if k.DS == nil || k.DS.KeyTag != 22642 || k.DS.DigestType != 2 || len(k.DS.Digest) != 64 || !strings.HasPrefix(k.DS.Record, "example.test.\t3600\tIN\tDS\t22642 13 2 ") {
|
||||||
|
t.Errorf("DS: %+v", k.DS)
|
||||||
|
}
|
||||||
|
if k.DNSKEYState != Rumoured || k.Goal != Omnipresent || k.PublishCDS == nil || k.PublishCDS.Format("2006-01-02 15:04") != "2026-10-09 19:08" {
|
||||||
|
t.Errorf("state: %+v", k)
|
||||||
|
}
|
||||||
|
// "fast.test." mustn't pick up fast2.test's keys, nor "test." anyone's.
|
||||||
|
if keys, _ := Keys("testdata", "fast.test."); len(keys) != 1 || keys[0].Tag != 642 {
|
||||||
|
t.Errorf("fast.test: %+v", keys)
|
||||||
|
}
|
||||||
|
if files, _ := Files("testdata", "test."); len(files) != 0 {
|
||||||
|
t.Errorf("test.: %v", files)
|
||||||
|
}
|
||||||
|
if files, _ := Files("no-such-dir", "test."); files != nil {
|
||||||
|
t.Errorf("missing dir: %v", files)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssess(t *testing.T) {
|
||||||
|
load := func(zone string) []*Key {
|
||||||
|
keys, err := Keys("testdata", zone)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
check := func(name string, p Phase, code string) {
|
||||||
|
t.Helper()
|
||||||
|
if p.Code != code {
|
||||||
|
t.Errorf("%s: %s (%s), want %s", name, p.Code, p.Summary, code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
check("unsigned", Assess("", nil), PhaseOff)
|
||||||
|
check("left over", Assess("", load("example.test.")), PhaseLeftover)
|
||||||
|
check("no keys yet", Assess("default", nil), PhaseStarting)
|
||||||
|
p := Assess("default", load("example.test."))
|
||||||
|
check("new", p, PhaseSigning)
|
||||||
|
if p.CanPublishDS || p.DSReadyAt == nil {
|
||||||
|
t.Errorf("new: %+v", p)
|
||||||
|
}
|
||||||
|
check("DS removed", Assess("insecure", load("fast.test.")), PhaseDSExpiring)
|
||||||
|
if Assess("insecure", load("fast.test.")).CanFinish {
|
||||||
|
t.Error("DNSSEC mustn't be switched off while resolvers may still have the DS cached")
|
||||||
|
}
|
||||||
|
p = Assess("insecure", load("fast2.test."))
|
||||||
|
check("no DS ever", p, PhaseRemovingKeys)
|
||||||
|
if !p.CanFinish {
|
||||||
|
t.Error("no DS: switching off is safe")
|
||||||
|
}
|
||||||
|
check("insecure, no keys", Assess("insecure", nil), PhaseUnsigned)
|
||||||
|
|
||||||
|
// The rest of the life cycle, from edited state files.
|
||||||
|
edit := func(zone string, repl ...string) []*Key {
|
||||||
|
dir := t.TempDir()
|
||||||
|
files, _ := Files("testdata", zone)
|
||||||
|
for _, f := range files {
|
||||||
|
b, _ := os.ReadFile(filepath.Join("testdata", f))
|
||||||
|
s := strings.NewReplacer(repl...).Replace(string(b))
|
||||||
|
os.WriteFile(filepath.Join(dir, f), []byte(s), 0o644)
|
||||||
|
}
|
||||||
|
keys, err := Keys(dir, zone)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
ready := edit("example.test.", "DNSKEYState: rumoured", "DNSKEYState: omnipresent", "KRRSIGState: rumoured", "KRRSIGState: omnipresent", "DSState: hidden", "DSState: rumoured")
|
||||||
|
p = Assess("default", ready)
|
||||||
|
check("ready", p, PhaseReady)
|
||||||
|
if !p.CanPublishDS || len(p.NeedsDS) != 1 || p.NeedsDS[0] != 22642 {
|
||||||
|
t.Errorf("ready: %+v", p)
|
||||||
|
}
|
||||||
|
check("DS added", Assess("default", edit("example.test.", "DNSKEYState: rumoured", "DNSKEYState: omnipresent", "KRRSIGState: rumoured", "KRRSIGState: omnipresent", "DSChange:", "DSPublish: 20261010000000\nDSChange:")), PhaseDSPending)
|
||||||
|
check("secure", Assess("default", edit("example.test.", "DNSKEYState: rumoured", "DNSKEYState: omnipresent", "KRRSIGState: rumoured", "KRRSIGState: omnipresent", "DSState: hidden", "DSState: omnipresent")), PhaseSecure)
|
||||||
|
p = Assess("insecure", edit("fast.test.", "DSRemoved:", "XDSRemoved:"))
|
||||||
|
check("turning off with the DS still there", p, PhaseRemovingDS)
|
||||||
|
if p.CanFinish {
|
||||||
|
t.Error("the DS is still at the parent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDerivedFiles(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
zf := filepath.Join(dir, "example.com.zone")
|
||||||
|
for _, f := range []string{zf, zf + ".jnl", zf + ".signed", zf + ".signed.jnl", zf + ".other"} {
|
||||||
|
os.WriteFile(f, nil, 0o644)
|
||||||
|
}
|
||||||
|
got := DerivedFiles(zf)
|
||||||
|
if len(got) != 3 {
|
||||||
|
t.Errorf("%v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package dnssec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Phases of a zone, from unsigned to signed and back. Turning signing on:
|
||||||
|
// off -> starting -> signing -> ready (add the DS at the parent) ->
|
||||||
|
// ds_pending -> secure. Turning it off: secure -> removing_ds (remove the
|
||||||
|
// DS at the parent) -> ds_expiring -> removing_keys -> unsigned -> off.
|
||||||
|
const (
|
||||||
|
PhaseOff = "off" // not signed, no keys
|
||||||
|
PhaseLeftover = "leftover_keys" // not signed, but old keys are still in the key directory
|
||||||
|
PhaseStarting = "starting" // signing is on in Jarl; named hasn't made keys yet
|
||||||
|
PhaseSigning = "signing" // keys made, zone signed; not yet safe to add the DS
|
||||||
|
PhaseReady = "ready" // safe to add the DS at the parent
|
||||||
|
PhaseDSPending = "ds_pending" // the DS is at the parent; named waits for its TTL
|
||||||
|
PhaseSecure = "secure" // signed, and the parent's DS is in place
|
||||||
|
PhaseRemovingDS = "removing_ds" // turning off: the DS must go from the parent first
|
||||||
|
PhaseDSExpiring = "ds_expiring" // the DS is gone; named waits until caches forget it
|
||||||
|
PhaseRemovingKeys = "removing_keys" // named removes the keys and signatures
|
||||||
|
PhaseUnsigned = "unsigned" // turning off has finished; switch DNSSEC off
|
||||||
|
)
|
||||||
|
|
||||||
|
// Phase says where a zone is and what comes next.
|
||||||
|
type Phase struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
Summary string `json:"summary"`
|
||||||
|
Next string `json:"next,omitempty"`
|
||||||
|
// DSReadyAt is when the DS can safely be added at the parent (phase
|
||||||
|
// signing).
|
||||||
|
DSReadyAt *time.Time `json:"ds_ready_at,omitempty"`
|
||||||
|
// CanPublishDS: the zone is ready for (or already has) a DS at the
|
||||||
|
// parent.
|
||||||
|
CanPublishDS bool `json:"can_publish_ds"`
|
||||||
|
// CanFinish: the zone is being turned off and the parent has no DS
|
||||||
|
// any more (as far as named knows), so DNSSEC can be switched off.
|
||||||
|
CanFinish bool `json:"can_finish"`
|
||||||
|
// NeedsDS lists the signing keys whose DS should be at the parent,
|
||||||
|
// and StaleDS those whose DS should be removed from it.
|
||||||
|
NeedsDS []uint16 `json:"needs_ds,omitempty"`
|
||||||
|
StaleDS []uint16 `json:"stale_ds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assess works out the phase of a zone signed with policy ("" when Jarl
|
||||||
|
// doesn't sign it, "insecure" while signing is being removed) that has
|
||||||
|
// keys.
|
||||||
|
func Assess(policy string, keys []*Key) Phase {
|
||||||
|
var live []*Key // signing keys named keeps (or is introducing)
|
||||||
|
for _, k := range keys {
|
||||||
|
if k.SigningKey() && k.Goal == Omnipresent {
|
||||||
|
live = append(live, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case policy == "":
|
||||||
|
if len(keys) == 0 {
|
||||||
|
return Phase{Code: PhaseOff, Summary: "DNSSEC is off."}
|
||||||
|
}
|
||||||
|
return Phase{Code: PhaseLeftover, Summary: "DNSSEC is off, but keys from when the zone was signed are still in its key directory.",
|
||||||
|
Next: "Wipe them (jarl zone dnssec wipe) once you're sure the parent zone has no DS record for them, or turn signing on again to reuse them."}
|
||||||
|
case policy == "insecure":
|
||||||
|
return assessOff(keys)
|
||||||
|
}
|
||||||
|
if len(live) == 0 {
|
||||||
|
return Phase{Code: PhaseStarting, Summary: "Signing is on; named hasn't created the zone's keys yet.",
|
||||||
|
Next: "Wait a moment: named makes the keys when it loads the configuration."}
|
||||||
|
}
|
||||||
|
p := Phase{}
|
||||||
|
var notReady []*Key
|
||||||
|
for _, k := range live {
|
||||||
|
if k.DNSKEYState != Omnipresent || k.KeyRRSIG != Omnipresent {
|
||||||
|
notReady = append(notReady, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, k := range keys {
|
||||||
|
if k.SigningKey() && k.Goal == Hidden && k.DSState != Hidden && k.DSRemoved == nil {
|
||||||
|
p.StaleDS = append(p.StaleDS, k.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(notReady) > 0 {
|
||||||
|
p.Code = PhaseSigning
|
||||||
|
p.Summary = "named is signing the zone. Resolvers still treat it as unsigned, because the parent zone has no DS record for it."
|
||||||
|
for _, k := range notReady {
|
||||||
|
if k.PublishCDS != nil && (p.DSReadyAt == nil || k.PublishCDS.After(*p.DSReadyAt)) {
|
||||||
|
t := *k.PublishCDS
|
||||||
|
p.DSReadyAt = &t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p.DSReadyAt != nil {
|
||||||
|
p.Next = fmt.Sprintf("Wait until %s before adding the DS at the parent: until then some resolvers may still have unsigned answers cached, and would reject them once the DS appears.", p.DSReadyAt.UTC().Format("Mon 2 Jan 15:04 MST"))
|
||||||
|
} else {
|
||||||
|
p.Next = "Wait until named has published the keys long enough for caches to pick them up before adding the DS."
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
p.CanPublishDS = true
|
||||||
|
var pending, secure int
|
||||||
|
for _, k := range live {
|
||||||
|
switch {
|
||||||
|
case k.DSState == Omnipresent:
|
||||||
|
secure++
|
||||||
|
case k.DSPublished != nil:
|
||||||
|
pending++
|
||||||
|
default:
|
||||||
|
p.NeedsDS = append(p.NeedsDS, k.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case len(p.NeedsDS) > 0:
|
||||||
|
p.Code = PhaseReady
|
||||||
|
p.Summary = "The zone is signed and ready: add the DS record at the parent zone (your registrar) to turn validation on."
|
||||||
|
p.Next = "Add the DS record (" + tags(p.NeedsDS) + ") at your registrar, then run the DS check so named knows it's there."
|
||||||
|
case pending > 0:
|
||||||
|
p.Code = PhaseDSPending
|
||||||
|
p.Summary = "The parent zone has the DS record. named waits for the parent's TTL before it treats it as in place."
|
||||||
|
default:
|
||||||
|
p.Code = PhaseSecure
|
||||||
|
p.Summary = "The zone is signed and the parent zone's DS record points at its key: validating resolvers check its answers."
|
||||||
|
}
|
||||||
|
if len(p.StaleDS) > 0 && p.Next == "" {
|
||||||
|
p.Next = "Remove the DS record of the retired key " + tags(p.StaleDS) + " at your registrar, then run the DS check."
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func assessOff(keys []*Key) Phase {
|
||||||
|
var dsUp, dsGoing, keysLeft bool
|
||||||
|
for _, k := range keys {
|
||||||
|
if !k.SigningKey() {
|
||||||
|
if !k.Gone() {
|
||||||
|
keysLeft = true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case k.DSState == Hidden || k.DSState == "":
|
||||||
|
case k.DSRemoved != nil:
|
||||||
|
dsGoing = true
|
||||||
|
default:
|
||||||
|
dsUp = true
|
||||||
|
}
|
||||||
|
if !k.Gone() {
|
||||||
|
keysLeft = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case dsUp:
|
||||||
|
return Phase{Code: PhaseRemovingDS, Summary: "Turning DNSSEC off: named keeps the zone signed until the parent zone's DS record is gone.",
|
||||||
|
Next: "Remove the DS record at your registrar, then run the DS check so named knows. Don't switch DNSSEC off before that: the zone would fail to validate."}
|
||||||
|
case dsGoing:
|
||||||
|
return Phase{Code: PhaseDSExpiring, Summary: "Turning DNSSEC off: the parent's DS record is gone; named keeps signing until resolvers' cached copies of it expire (the parent's DS TTL, often a day).",
|
||||||
|
Next: "Wait: switching DNSSEC off now would make the zone fail to validate for resolvers that still have the DS cached."}
|
||||||
|
case keysLeft:
|
||||||
|
return Phase{Code: PhaseRemovingKeys, Summary: "Turning DNSSEC off: the parent has no DS any more, and named is removing the keys and signatures.",
|
||||||
|
Next: "Wait until named has finished, then switch DNSSEC off.", CanFinish: true}
|
||||||
|
}
|
||||||
|
return Phase{Code: PhaseUnsigned, Summary: "Turning DNSSEC off has finished: the zone is no longer signed.",
|
||||||
|
Next: "Switch DNSSEC off for the zone to finish (jarl zone dnssec disable), and wipe the old keys if you like.", CanFinish: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tags(ts []uint16) string {
|
||||||
|
var s []string
|
||||||
|
for _, t := range ts {
|
||||||
|
s = append(s, fmt.Sprintf("key %d", t))
|
||||||
|
}
|
||||||
|
return strings.Join(s, ", ")
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
; This is a key-signing key, keyid 22642, for example.test.
|
||||||
|
; Created: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
; Publish: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
; Activate: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
; SyncPublish: 20261009190831 (Fri Oct 9 19:08:31 2026)
|
||||||
|
example.test. 3600 IN DNSKEY 257 3 13 fiSDgJJGHyAp36ZNGOeb45gn+O1pF3hCbTUPHeJ3ztIuisGoywmo7Be3 +vUPyC6e9BmTCIRIeElB4f2o9HoPXg==
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Private-key-format: v1.3 (test data, not a real key)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
; This is the state of key 22642, for example.test.
|
||||||
|
Algorithm: 13
|
||||||
|
Length: 256
|
||||||
|
Lifetime: 0
|
||||||
|
KSK: yes
|
||||||
|
ZSK: yes
|
||||||
|
Generated: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
Published: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
Active: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
PublishCDS: 20261009190831 (Fri Oct 9 19:08:31 2026)
|
||||||
|
DNSKEYChange: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
ZRRSIGChange: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
KRRSIGChange: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
DSChange: 20261008190331 (Thu Oct 8 19:03:31 2026)
|
||||||
|
DNSKEYState: rumoured
|
||||||
|
ZRRSIGState: rumoured
|
||||||
|
KRRSIGState: rumoured
|
||||||
|
DSState: hidden
|
||||||
|
GoalState: omnipresent
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
; This is a key-signing key, keyid 642, for fast.test.
|
||||||
|
; Created: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
; Publish: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
; Activate: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
; Inactive: 20261008203319 (Thu Oct 8 20:33:19 2026)
|
||||||
|
; Delete: 20261024213819 (Sat Oct 24 21:38:19 2026)
|
||||||
|
; SyncPublish: 20261008203234 (Thu Oct 8 20:32:34 2026)
|
||||||
|
fast.test. 3600 IN DNSKEY 257 3 13 D6O3u6ZWXwKPu/Y4acS2eRm1zKQ8LaN8zhvkr6KNWP+fEPgko6yLib94 J5KcUXpFcG6Y/jdxKM8FgeASRDq/ow==
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Private-key-format: v1.3 (test data, not a real key)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
; This is the state of key 642, for fast.test.
|
||||||
|
Algorithm: 13
|
||||||
|
Length: 256
|
||||||
|
Lifetime: 0
|
||||||
|
KSK: yes
|
||||||
|
ZSK: yes
|
||||||
|
Generated: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
Published: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
Active: 20261008203220 (Thu Oct 8 20:32:20 2026)
|
||||||
|
Retired: 20261008203319 (Thu Oct 8 20:33:19 2026)
|
||||||
|
Removed: 20261024213819 (Sat Oct 24 21:38:19 2026)
|
||||||
|
DSPublish: 20261008203249 (Thu Oct 8 20:32:49 2026)
|
||||||
|
DSRemoved: 20261008203329 (Thu Oct 8 20:33:29 2026)
|
||||||
|
PublishCDS: 20261008203234 (Thu Oct 8 20:32:34 2026)
|
||||||
|
DNSKEYChange: 20261008203234 (Thu Oct 8 20:32:34 2026)
|
||||||
|
ZRRSIGChange: 20261008203232 (Thu Oct 8 20:32:32 2026)
|
||||||
|
KRRSIGChange: 20261008203234 (Thu Oct 8 20:32:34 2026)
|
||||||
|
DSChange: 20261008203319 (Thu Oct 8 20:33:19 2026)
|
||||||
|
DNSKEYState: omnipresent
|
||||||
|
ZRRSIGState: omnipresent
|
||||||
|
KRRSIGState: omnipresent
|
||||||
|
DSState: unretentive
|
||||||
|
GoalState: hidden
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
; This is a key-signing key, keyid 28643, for fast2.test.
|
||||||
|
; Created: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
; Publish: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
; Activate: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
; Inactive: 20261008203344 (Thu Oct 8 20:33:44 2026)
|
||||||
|
; Delete: 20261024213844 (Sat Oct 24 21:38:44 2026)
|
||||||
|
; SyncPublish: 20261008203354 (Thu Oct 8 20:33:54 2026)
|
||||||
|
fast2.test. 3600 IN DNSKEY 257 3 13 6WkqPp3kxXxMJtC9clsF4zTnZGPXaFRikSdMLG1eFExa4d0Uo+PtMbqo KHR/Qe601tO7yZoY8itie0aZzPaMiA==
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Private-key-format: v1.3 (test data, not a real key)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
; This is the state of key 28643, for fast2.test.
|
||||||
|
Algorithm: 13
|
||||||
|
Length: 256
|
||||||
|
Lifetime: 0
|
||||||
|
KSK: yes
|
||||||
|
ZSK: yes
|
||||||
|
Generated: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
Published: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
Active: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
Retired: 20261008203344 (Thu Oct 8 20:33:44 2026)
|
||||||
|
Removed: 20261024213844 (Sat Oct 24 21:38:44 2026)
|
||||||
|
PublishCDS: 20261008203354 (Thu Oct 8 20:33:54 2026)
|
||||||
|
DNSKEYChange: 20261008203344 (Thu Oct 8 20:33:44 2026)
|
||||||
|
ZRRSIGChange: 20261008203344 (Thu Oct 8 20:33:44 2026)
|
||||||
|
KRRSIGChange: 20261008203344 (Thu Oct 8 20:33:44 2026)
|
||||||
|
DSChange: 20261008203340 (Thu Oct 8 20:33:40 2026)
|
||||||
|
DNSKEYState: unretentive
|
||||||
|
ZRRSIGState: unretentive
|
||||||
|
KRRSIGState: unretentive
|
||||||
|
DSState: hidden
|
||||||
|
GoalState: hidden
|
||||||
@@ -60,7 +60,7 @@ func DiffOps(from, to *model.State) []model.Op {
|
|||||||
n := to.Zones[k]
|
n := to.Zones[k]
|
||||||
s := n.SOA
|
s := n.SOA
|
||||||
in := ZoneInput{Name: &n.Name, ViewID: &n.ViewID, Type: &n.Type, InView: &n.InView, File: &n.File,
|
in := ZoneInput{Name: &n.Name, ViewID: &n.ViewID, Type: &n.Type, InView: &n.InView, File: &n.File,
|
||||||
DefaultTTL: &n.DefaultTTL, SerialPolicy: &n.SerialPolicy, Comment: &n.Comment}
|
DefaultTTL: &n.DefaultTTL, SerialPolicy: &n.SerialPolicy, DNSSECPolicy: &n.DNSSECPolicy, Comment: &n.Comment}
|
||||||
if n.Type == model.ZonePrimary {
|
if n.Type == model.ZonePrimary {
|
||||||
in.SOA = &SOAInput{MName: &s.MName, RName: &s.RName, Serial: &s.Serial, Refresh: &s.Refresh, Retry: &s.Retry, Expire: &s.Expire, Minimum: &s.Minimum}
|
in.SOA = &SOAInput{MName: &s.MName, RName: &s.RName, Serial: &s.Serial, Refresh: &s.Refresh, Retry: &s.Retry, Expire: &s.Expire, Minimum: &s.Minimum}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
package engine
|
||||||
|
|
||||||
|
// DNSSEC signing (docs/dnssec.md). named signs zones itself (dnssec-policy
|
||||||
|
// with inline signing) and keeps their keys in a key directory Jarl
|
||||||
|
// chooses (render.KeyDir). Jarl's part is to keep the steps in order: a
|
||||||
|
// zone must never become unsigned while the parent zone may still have a
|
||||||
|
// DS record for it, or validating resolvers reject the whole domain.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"jarl/internal/auth"
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/render"
|
||||||
|
"jarl/internal/validate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DNSSEC returns the signing status of zone z.
|
||||||
|
func (e *Engine) DNSSEC(ctx context.Context, st *model.State, z *model.Zone) *dnssec.Status {
|
||||||
|
s := &dnssec.Status{Policy: z.DNSSECPolicy, KeyDir: render.KeyDir(st, z, e.cfg.Paths), Keys: []*dnssec.Key{}, Policies: []string{model.DNSSECDefault}}
|
||||||
|
for name := range validate.Policies(st) {
|
||||||
|
s.Policies = append(s.Policies, name)
|
||||||
|
}
|
||||||
|
sort.Strings(s.Policies[1:])
|
||||||
|
keys, err := dnssec.Keys(s.KeyDir, z.Name)
|
||||||
|
if err != nil {
|
||||||
|
s.KeyError = err.Error()
|
||||||
|
} else if keys != nil {
|
||||||
|
s.Keys = keys
|
||||||
|
}
|
||||||
|
s.Phase = dnssec.Assess(z.DNSSECPolicy, s.Keys)
|
||||||
|
if z.Type == model.ZonePrimary && !e.cfg.NoReload && e.tools != nil {
|
||||||
|
zs, err := e.tools.ZoneStatus(ctx, z.Name, e.namedView(st, z))
|
||||||
|
if err != nil {
|
||||||
|
s.NamedError = err.Error()
|
||||||
|
} else {
|
||||||
|
s.Named = &dnssec.NamedSigning{Secure: zs.Secure, InlineSigning: zs.InlineSigning, Serial: zs.Serial, SignedSerial: zs.SignedSerial, NextKeyEvent: zs.NextKeyEvent}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// dnssecChanges checks the DNSSEC side of going from base to work: the
|
||||||
|
// steps that would make a signed zone fail to validate, or give it new
|
||||||
|
// keys its parent's DS doesn't match.
|
||||||
|
func (e *Engine) dnssecChanges(base, work *model.State, opts ApplyOptions) []validate.Problem {
|
||||||
|
var out []validate.Problem
|
||||||
|
problem := func(sev validate.Severity, st *model.State, z *model.Zone, code, format string, args ...any) {
|
||||||
|
out = append(out, validate.Problem{Severity: sev, Code: code, Message: fmt.Sprintf(format, args...), ObjectType: "zone", ObjectID: z.ID, Zone: z.Name, View: st.ViewName(z)})
|
||||||
|
}
|
||||||
|
for _, old := range base.SortedZones() {
|
||||||
|
if !old.Signed() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
z := work.Zones[old.ID]
|
||||||
|
if z == nil {
|
||||||
|
problem(validate.Error, base, old, "dnssec_delete_signed", "the zone is signed: turn DNSSEC off before deleting it (jarl zone dnssec disable, and remove the DS record at your registrar), or the domain fails to validate while the parent still points at its keys")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
continue // reported by validate (dnssec_zone_type)
|
||||||
|
}
|
||||||
|
if render.KeyDir(base, old, e.cfg.Paths) != render.KeyDir(work, z, e.cfg.Paths) {
|
||||||
|
problem(validate.Error, work, z, "dnssec_keys_moved", "the zone is signed, and moving it to another view would make named sign it with new keys that the parent's DS record doesn't match; turn DNSSEC off first, or create the zone anew in the other view")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case z.DNSSECPolicy == "" && opts.wipeZone == z.ID:
|
||||||
|
// WipeDNSSEC: the caller checked that the parent has no DS.
|
||||||
|
case z.DNSSECPolicy == "" && old.DNSSECPolicy != model.DNSSECInsecure:
|
||||||
|
problem(validate.Error, work, z, "dnssec_off_unsafe", "switching DNSSEC off at once makes named serve the zone unsigned immediately, and if the parent zone has a DS record for it, validating resolvers then reject the whole domain. Turn it off in steps: 'jarl zone dnssec disable' (the insecure policy) keeps the zone signed while you remove the DS at your registrar, and Jarl says when it's safe to finish. If the zone never had a DS at its parent, wipe it instead ('jarl zone dnssec wipe')")
|
||||||
|
case z.DNSSECPolicy == "":
|
||||||
|
keys, err := dnssec.Keys(render.KeyDir(base, old, e.cfg.Paths), old.Name)
|
||||||
|
if err != nil {
|
||||||
|
problem(validate.Error, work, z, "dnssec_off_unknown", "can't tell whether turning DNSSEC off has finished, because the zone's keys can't be read: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ph := dnssec.Assess(model.DNSSECInsecure, keys); !ph.CanFinish {
|
||||||
|
problem(validate.Error, work, z, "dnssec_off_too_early", "turning DNSSEC off hasn't finished yet: %s %s", ph.Summary, ph.Next)
|
||||||
|
}
|
||||||
|
case z.DNSSECPolicy != old.DNSSECPolicy && z.DNSSECPolicy != model.DNSSECInsecure && old.DNSSECPolicy != model.DNSSECInsecure:
|
||||||
|
problem(validate.Warning, work, z, "dnssec_policy_change", "changing the zone's DNSSEC policy from %s to %s can make named replace its keys; when its key-signing key changes, the DS record at the parent must change too (Jarl shows when)", old.DNSSECPolicy, z.DNSSECPolicy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, z := range work.SortedZones() {
|
||||||
|
if !z.Signed() || z.DNSSECPolicy == model.DNSSECInsecure {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if old := base.Zones[z.ID]; old != nil && old.Signed() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if files, _ := dnssec.Files(render.KeyDir(work, z, e.cfg.Paths), z.Name); len(files) > 0 {
|
||||||
|
problem(validate.Info, work, z, "dnssec_old_keys", "the zone's key directory still has keys from when it was signed before; named only reuses keys it hasn't retired, and makes new ones otherwise (wipe the old ones first for a clean start)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// removeDerived deletes what named kept for zones that are gone after a
|
||||||
|
// change: the journals and signed copies next to their files and, for a
|
||||||
|
// deleted zone, keys left over from when it was signed (a signed zone
|
||||||
|
// can't be deleted). Failures are only logged.
|
||||||
|
func (e *Engine) removeDerived(pl *plan) {
|
||||||
|
for _, path := range pl.removed {
|
||||||
|
for _, f := range dnssec.DerivedFiles(path) {
|
||||||
|
if err := os.Remove(f); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
e.log.Warn("removing a file named kept for a deleted zone failed", "file", f, "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for id, old := range pl.base.Zones {
|
||||||
|
if old.Type != model.ZonePrimary || pl.work.Zones[id] != nil || pl.work.FindZone(old.Name, old.ViewID) != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dir := render.KeyDir(pl.base, old, e.cfg.Paths)
|
||||||
|
files, _ := dnssec.Files(dir, old.Name)
|
||||||
|
for _, f := range files {
|
||||||
|
if err := os.Remove(filepath.Join(dir, f)); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
e.log.Warn("removing a deleted zone's old DNSSEC key failed", "file", f, "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WipeResult is the outcome of WipeDNSSEC.
|
||||||
|
type WipeResult struct {
|
||||||
|
Result *Result `json:"result,omitempty"` // the change that switched signing off, if one was needed
|
||||||
|
Removed []string `json:"removed"`
|
||||||
|
DryRun bool `json:"dry_run,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WipeDNSSEC switches signing off for a zone at once, skipping the
|
||||||
|
// insecure policy, and deletes its keys and named's signed copy of it, so
|
||||||
|
// that signing it again starts from scratch. The caller must make sure the
|
||||||
|
// parent zone has no DS record for the zone: otherwise the domain stops
|
||||||
|
// validating.
|
||||||
|
func (e *Engine) WipeDNSSEC(ctx context.Context, zoneID int64, p *auth.Principal, via string, opts ApplyOptions) (*WipeResult, error) {
|
||||||
|
st, err := e.store.LoadState(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
z := st.Zones[zoneID]
|
||||||
|
if z == nil {
|
||||||
|
return nil, errf(KindNotFound, "zone %d not found", zoneID)
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
return nil, errf(KindBadRequest, "only primary zones are signed by Jarl")
|
||||||
|
}
|
||||||
|
if !p.Can(zoneAction(st, z, true)) {
|
||||||
|
return nil, errf(KindForbidden, "permission denied: this needs write access to zone %s", zoneDesc(st, z))
|
||||||
|
}
|
||||||
|
out := &WipeResult{Removed: []string{}, DryRun: opts.DryRun}
|
||||||
|
dir := render.KeyDir(st, z, e.cfg.Paths)
|
||||||
|
keyFiles, err := dnssec.Files(dir, z.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("reading the key directory: %w", err)
|
||||||
|
}
|
||||||
|
zoneFile := render.ZoneFilePath(st, z, e.cfg.Paths)
|
||||||
|
var signed []string
|
||||||
|
for _, f := range dnssec.DerivedFiles(zoneFile) {
|
||||||
|
if strings.Contains(filepath.Base(f), ".signed") {
|
||||||
|
signed = append(signed, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if z.DNSSECPolicy == "" && len(keyFiles) == 0 && len(signed) == 0 {
|
||||||
|
return nil, errf(KindConflict, "zone %s isn't signed and has no keys or signed files left: there is nothing to wipe", zoneDesc(st, z))
|
||||||
|
}
|
||||||
|
if z.DNSSECPolicy != "" {
|
||||||
|
opts.wipeZone = z.ID
|
||||||
|
res, err := e.Submit(ctx, []Request{NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("")})}, p, via, "wipe DNSSEC from zone "+zoneDesc(st, z), opts)
|
||||||
|
out.Result = res
|
||||||
|
if err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range keyFiles {
|
||||||
|
out.Removed = append(out.Removed, filepath.Join(dir, f))
|
||||||
|
}
|
||||||
|
out.Removed = append(out.Removed, signed...)
|
||||||
|
if opts.DryRun {
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
e.mu.Lock()
|
||||||
|
defer e.mu.Unlock()
|
||||||
|
var failed []string
|
||||||
|
for _, f := range out.Removed {
|
||||||
|
if err := os.Remove(f); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
failed = append(failed, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg := fmt.Sprintf("%d files removed", len(out.Removed))
|
||||||
|
if len(failed) > 0 {
|
||||||
|
e.audit(ctx, p, "dnssec.wipe", "zone", z.ID, zoneDesc(st, z), 0, "failure", strings.Join(failed, "; "), nil)
|
||||||
|
return out, fmt.Errorf("signing is off, but removing files failed: %s", strings.Join(failed, "; "))
|
||||||
|
}
|
||||||
|
e.audit(ctx, p, "dnssec.wipe", "zone", z.ID, zoneDesc(st, z), 0, "success", msg, nil)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkDS tells named that the parent zone now has (published) or no
|
||||||
|
// longer has (withdrawn) the DS record of each key, as a DS check found.
|
||||||
|
// named moves to the next step of signing or unsigning the zone once it
|
||||||
|
// knows, and (unless it can query the parent itself) waits until told.
|
||||||
|
func (e *Engine) MarkDS(ctx context.Context, st *model.State, z *model.Zone, p *auth.Principal, published, withdrawn []*dnssec.Key) ([]string, error) {
|
||||||
|
if e.cfg.NoReload || e.tools == nil {
|
||||||
|
return nil, errf(KindConflict, "jarld doesn't control named here (bind.no_reload)")
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
run := func(k *dnssec.Key, pub bool) error {
|
||||||
|
msg, err := e.tools.CheckDS(ctx, z.Name, e.namedView(st, z), k.Tag, k.Algorithm, pub)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out = append(out, fmt.Sprintf("key %d: %s", k.Tag, strings.TrimSpace(msg)))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, k := range published {
|
||||||
|
if err := run(k, true); err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, k := range withdrawn {
|
||||||
|
if err := run(k, false); err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(out) > 0 {
|
||||||
|
e.audit(ctx, p, "dnssec.checkds", "zone", z.ID, zoneDesc(st, z), 0, "success", strings.Join(out, "; "), nil)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
package engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/render"
|
||||||
|
"jarl/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// waitPhase polls the zone's DNSSEC status until ok accepts it.
|
||||||
|
func (n *namedEnv) waitPhase(z *model.Zone, what string, ok func(*dnssec.Status) bool) *dnssec.Status {
|
||||||
|
n.t.Helper()
|
||||||
|
deadline := time.Now().Add(15 * time.Second)
|
||||||
|
for {
|
||||||
|
st := n.state()
|
||||||
|
s := n.e.DNSSEC(n.ctx, st, st.Zones[z.ID])
|
||||||
|
if ok(s) {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
n.t.Fatalf("waiting for %s: %+v (phase %+v)", what, s, s.Phase)
|
||||||
|
}
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDNSSECWithRealNamed(t *testing.T) {
|
||||||
|
n := newNamedEnv(t)
|
||||||
|
z := n.state().ZonesNamed("example.test")[0]
|
||||||
|
zoneFile := filepath.Join(n.dir, "zones/_default/example.test.zone")
|
||||||
|
|
||||||
|
// Switching signing on for an existing zone: named makes a key and
|
||||||
|
// signs the zone (inline signing, keeping Jarl's file as it is).
|
||||||
|
n.submit(n.admin, NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("default")}))
|
||||||
|
conf, _ := os.ReadFile(n.e.cfg.Paths.MainConfig())
|
||||||
|
if !strings.Contains(string(conf), `dnssec-policy "default";`) || !strings.Contains(string(conf), `key-directory "`+filepath.Join(n.dir, "zones/dnssec-keys/_default")+`";`) {
|
||||||
|
t.Errorf("named.conf:\n%s", conf)
|
||||||
|
}
|
||||||
|
s := n.waitPhase(z, "signing", func(s *dnssec.Status) bool { return len(s.Keys) == 1 && s.Named != nil && s.Named.Secure })
|
||||||
|
k := s.Keys[0]
|
||||||
|
if s.Phase.Code != dnssec.PhaseSigning || k.Role != "CSK" || k.Algorithm != 13 || k.DS == nil || s.Phase.DSReadyAt == nil {
|
||||||
|
t.Errorf("status: %+v, key %+v", s.Phase, k)
|
||||||
|
}
|
||||||
|
if got := n.dig("example.test", "DNSKEY"); !strings.HasPrefix(got, "257 3 13 ") {
|
||||||
|
t.Errorf("DNSKEY = %q", got)
|
||||||
|
}
|
||||||
|
// Changes still load (Jarl's serial is the unsigned zone's), and the
|
||||||
|
// serial check sees the signed zone's serial.
|
||||||
|
r := findRec(n.state(), "www.example.test.", "A")
|
||||||
|
n.submit(n.admin, NewRequest(OpRecordUpdate, r.ID, RecordInput{Data: model.Ptr("192.0.2.12")}))
|
||||||
|
if got := n.dig("www.example.test", "A"); got != "192.0.2.12" {
|
||||||
|
t.Errorf("www = %q", got)
|
||||||
|
}
|
||||||
|
cur := n.state()
|
||||||
|
served, ok, err := n.e.LoadedSerial(n.ctx, cur, cur.Zones[z.ID])
|
||||||
|
if !ok || err != nil || !serialGreater(served, cur.Zones[z.ID].SOA.Serial) {
|
||||||
|
t.Errorf("served serial %d (%v %v), Jarl's %d", served, ok, err, cur.Zones[z.ID].SOA.Serial)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unsafe steps are refused.
|
||||||
|
if e := n.submitErr(n.admin, NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("")})); !strings.Contains(e.Message, "switching DNSSEC off at once") {
|
||||||
|
t.Errorf("switching off directly: %v", e)
|
||||||
|
}
|
||||||
|
if e := n.submitErr(n.admin, NewRequest(OpZoneDelete, z.ID, nil)); !strings.Contains(e.Message, "turn DNSSEC off before deleting") {
|
||||||
|
t.Errorf("deleting: %v", e)
|
||||||
|
}
|
||||||
|
r = findRec(n.state(), "www.example.test.", "A")
|
||||||
|
if e := n.submitErr(n.admin, NewRequest(OpRecordUpdate, r.ID, RecordInput{TTL: model.Some(uint32(172800))})); !strings.Contains(e.Message, "max-zone-ttl") {
|
||||||
|
t.Errorf("long TTL: %v", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A restore of an older database: Jarl's serial is now below named's,
|
||||||
|
// which named refuses for a signed zone. Resync raises it.
|
||||||
|
before := n.state()
|
||||||
|
older := before.Clone()
|
||||||
|
older.Zones[z.ID].SOA.Serial -= 5
|
||||||
|
findRec(older, "www.example.test.", "A").Data = "192.0.2.10"
|
||||||
|
if err := n.st.InTx(n.ctx, func(tx *store.Tx) error { return tx.SaveState(before, older) }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
res, err := n.e.Resync(n.ctx, n.admin, ApplyOptions{Force: true})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("resync: %v", err)
|
||||||
|
}
|
||||||
|
if len(res.Serials) != 1 || !serialGreater(res.Serials[0].New, before.Zones[z.ID].SOA.Serial) {
|
||||||
|
t.Errorf("serials: %+v (named had %d)", res.Serials, before.Zones[z.ID].SOA.Serial)
|
||||||
|
}
|
||||||
|
if got := n.dig("www.example.test", "A"); got != "192.0.2.10" {
|
||||||
|
t.Errorf("www after restore = %q", got)
|
||||||
|
}
|
||||||
|
if n.state().Zones[z.ID].SOA.Serial != res.Serials[0].New {
|
||||||
|
t.Error("raised serial not saved")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turning off: insecure first. The DS was never at the parent, so
|
||||||
|
// named removes the keys at once and finishing is allowed.
|
||||||
|
n.submit(n.admin, NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("insecure")}))
|
||||||
|
n.waitPhase(z, "removal", func(s *dnssec.Status) bool { return s.Phase.CanFinish })
|
||||||
|
n.submit(n.admin, NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("")}))
|
||||||
|
if got := n.dig("example.test", "DNSKEY"); got != "" {
|
||||||
|
t.Errorf("DNSKEY after switching off = %q", got)
|
||||||
|
}
|
||||||
|
s = n.waitPhase(z, "leftover keys", func(s *dnssec.Status) bool { return true })
|
||||||
|
if s.Phase.Code != dnssec.PhaseLeftover {
|
||||||
|
t.Errorf("after switching off: %+v", s.Phase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signing again makes a new key (the old one stays retired); a wipe
|
||||||
|
// switches off at once and deletes keys and signed files.
|
||||||
|
n.submit(n.admin, NewRequest(OpZoneUpdate, z.ID, ZoneInput{DNSSECPolicy: model.Ptr("default")}))
|
||||||
|
s = n.waitPhase(z, "signing again", func(s *dnssec.Status) bool { return len(s.Keys) == 2 && s.Named != nil && s.Named.Secure })
|
||||||
|
if s.Phase.Code != dnssec.PhaseSigning || s.Keys[0].Tag == k.Tag && s.Keys[0].Goal == dnssec.Omnipresent {
|
||||||
|
t.Errorf("signing again: %+v %+v", s.Phase, s.Keys[0])
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(zoneFile + ".signed"); err != nil {
|
||||||
|
t.Errorf("signed copy: %v", err)
|
||||||
|
}
|
||||||
|
w, err := n.e.WipeDNSSEC(n.ctx, z.ID, n.admin, "test", ApplyOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("wipe: %v", err)
|
||||||
|
}
|
||||||
|
if len(w.Removed) < 4 || w.Result == nil || !w.Result.Applied {
|
||||||
|
t.Errorf("wipe: %+v", w)
|
||||||
|
}
|
||||||
|
if files, _ := dnssec.Files(render.KeyDir(n.state(), z, n.e.cfg.Paths), z.Name); len(files) != 0 {
|
||||||
|
t.Errorf("keys left: %v", files)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(zoneFile + ".signed"); !os.IsNotExist(err) {
|
||||||
|
t.Errorf("signed copy left: %v", err)
|
||||||
|
}
|
||||||
|
if got := n.dig("www.example.test", "A"); got != "192.0.2.10" {
|
||||||
|
t.Errorf("www after wipe = %q", got)
|
||||||
|
}
|
||||||
|
if _, err := n.e.WipeDNSSEC(n.ctx, z.ID, n.admin, "test", ApplyOptions{}); err == nil {
|
||||||
|
t.Error("a second wipe found something")
|
||||||
|
}
|
||||||
|
// Deleting the zone also removes named's journal.
|
||||||
|
n.submit(n.admin, NewRequest(OpZoneDelete, z.ID, nil))
|
||||||
|
if left, _ := filepath.Glob(zoneFile + "*"); len(left) != 0 {
|
||||||
|
t.Errorf("left after deleting the zone: %v", left)
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
-11
@@ -122,6 +122,8 @@ type ApplyOptions struct {
|
|||||||
Force bool
|
Force bool
|
||||||
// NoReload writes the files without reloading named.
|
// NoReload writes the files without reloading named.
|
||||||
NoReload bool
|
NoReload bool
|
||||||
|
// wipeZone lets WipeDNSSEC switch signing off for this zone at once.
|
||||||
|
wipeZone int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) replay(base *model.State, ops []model.Op, p *auth.Principal) (*model.State, []string, error) {
|
func (e *Engine) replay(base *model.State, ops []model.Op, p *auth.Principal) (*model.State, []string, error) {
|
||||||
@@ -397,11 +399,11 @@ func (pl *plan) files() []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) makePlan(ctx context.Context, base, work *model.State, user string) (*plan, error) {
|
func (e *Engine) makePlan(ctx context.Context, base, work *model.State, user string, opts ApplyOptions) (*plan, error) {
|
||||||
pl := &plan{base: base, work: work, verify: map[int64]uint32{}}
|
pl := &plan{base: base, work: work, verify: map[int64]uint32{}}
|
||||||
before := e.validate(base)
|
before := e.validate(base)
|
||||||
after := e.validate(work)
|
after := e.validate(work)
|
||||||
pl.introduced = validate.Introduced(before, after)
|
pl.introduced = append(validate.Introduced(before, after), e.dnssecChanges(base, work, opts)...)
|
||||||
introducedKeys := map[string]bool{}
|
introducedKeys := map[string]bool{}
|
||||||
for _, p := range pl.introduced {
|
for _, p := range pl.introduced {
|
||||||
introducedKeys[p.Key()] = true
|
introducedKeys[p.Key()] = true
|
||||||
@@ -415,6 +417,12 @@ func (e *Engine) makePlan(ctx context.Context, base, work *model.State, user str
|
|||||||
return pl, nil
|
return pl, nil
|
||||||
}
|
}
|
||||||
pl.serials = bumpSerials(base, work, e.Now(), user)
|
pl.serials = bumpSerials(base, work, e.Now(), user)
|
||||||
|
guarded, problems := e.guardSerials(ctx, base, work, pl.serials, user)
|
||||||
|
pl.serials = append(pl.serials, guarded...)
|
||||||
|
if validate.HasErrors(problems) {
|
||||||
|
pl.introduced = append(pl.introduced, problems...)
|
||||||
|
return pl, nil
|
||||||
|
}
|
||||||
pl.out = render.Render(work, e.cfg.Paths, e.cfg.Extras)
|
pl.out = render.Render(work, e.cfg.Paths, e.cfg.Extras)
|
||||||
deployed, err := e.store.DeployedFiles(ctx)
|
deployed, err := e.store.DeployedFiles(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -498,6 +506,11 @@ func (e *Engine) stagingCheck(ctx context.Context, pl *plan) error {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
sp := render.Paths{ConfigDir: filepath.Join(dir, "config"), ZoneDir: filepath.Join(dir, "zones"), CacheDir: filepath.Join(dir, "cache")}
|
sp := render.Paths{ConfigDir: filepath.Join(dir, "config"), ZoneDir: filepath.Join(dir, "zones"), CacheDir: filepath.Join(dir, "cache")}
|
||||||
sout := render.Render(pl.work, sp, e.cfg.Extras)
|
sout := render.Render(pl.work, sp, e.cfg.Extras)
|
||||||
|
for _, d := range sout.Dirs {
|
||||||
|
if err := os.MkdirAll(d, 0o750); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, f := range sout.Files {
|
for _, f := range sout.Files {
|
||||||
if err := os.MkdirAll(filepath.Dir(f.Path), 0o750); err != nil {
|
if err := os.MkdirAll(filepath.Dir(f.Path), 0o750); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -635,7 +648,7 @@ func (e *Engine) Preview(ctx context.Context, csID int64, p *auth.Principal) (*R
|
|||||||
res.Error = ee
|
res.Error = ee
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
pl, err := e.makePlan(ctx, base, work, p.Name())
|
pl, err := e.makePlan(ctx, base, work, p.Name(), ApplyOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -714,7 +727,7 @@ func (e *Engine) applyOps(ctx context.Context, cs *model.Changeset, reqs []Reque
|
|||||||
cs.Description += fmt.Sprintf(" (+%d more)", len(cs.Ops)-1)
|
cs.Description += fmt.Sprintf(" (+%d more)", len(cs.Ops)-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pl, err := e.makePlan(ctx, base, work, p.Name())
|
pl, err := e.makePlan(ctx, base, work, p.Name(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -782,6 +795,7 @@ func (e *Engine) applyOps(ctx context.Context, cs *model.Changeset, reqs []Reque
|
|||||||
}
|
}
|
||||||
res.ChangesetID = cs.ID
|
res.ChangesetID = cs.ID
|
||||||
res.Applied = true
|
res.Applied = true
|
||||||
|
e.removeDerived(pl)
|
||||||
e.log.Info("changeset applied", "changeset", cs.ID, "user", p.Name(), "ops", len(cs.Ops), "files", len(res.Files), "description", cs.Description)
|
e.log.Info("changeset applied", "changeset", cs.ID, "user", p.Name(), "ops", len(cs.Ops), "files", len(res.Files), "description", cs.Description)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@@ -956,15 +970,16 @@ func (e *Engine) Resync(ctx context.Context, p *auth.Principal, opts ApplyOption
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
work := base.Clone()
|
work := base.Clone()
|
||||||
pl, err := e.makePlan(ctx, base, work, p.Name())
|
pl, err := e.makePlan(ctx, base, work, p.Name(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res := pl.result()
|
res := pl.result()
|
||||||
res.DryRun = opts.DryRun
|
res.DryRun = opts.DryRun
|
||||||
if validate.HasErrors(pl.existing) {
|
if validate.HasErrors(pl.existing) || validate.HasErrors(pl.introduced) {
|
||||||
// Resync deploys the stored state as is; it must be valid.
|
// Resync deploys the stored state as is; it must be valid.
|
||||||
return res, &Error{Kind: KindValidation, Message: "the stored configuration has errors: " + describeErrors(pl.existing), Problems: validate.Errors(pl.existing)}
|
ps := append(append([]validate.Problem{}, pl.existing...), pl.introduced...)
|
||||||
|
return res, &Error{Kind: KindValidation, Message: "the stored configuration has errors: " + describeErrors(ps), Problems: validate.Errors(ps)}
|
||||||
}
|
}
|
||||||
if pl.check != nil && !pl.check.OK {
|
if pl.check != nil && !pl.check.OK {
|
||||||
return res, &Error{Kind: KindValidation, Message: "named-checkconf rejected the configuration: " + firstCheckError(pl.checkMsgs), Check: pl.checkMsgs}
|
return res, &Error{Kind: KindValidation, Message: "named-checkconf rejected the configuration: " + firstCheckError(pl.checkMsgs), Check: pl.checkMsgs}
|
||||||
@@ -998,15 +1013,26 @@ func (e *Engine) Resync(ctx context.Context, p *auth.Principal, opts ApplyOption
|
|||||||
}
|
}
|
||||||
deployed := deployedList(pl.out, 0, e.Now())
|
deployed := deployedList(pl.out, 0, e.Now())
|
||||||
err = e.store.InTx(ctx, func(tx *store.Tx) error {
|
err = e.store.InTx(ctx, func(tx *store.Tx) error {
|
||||||
|
// Serials raised above named's (guardSerials) are kept.
|
||||||
|
if len(pl.serials) > 0 {
|
||||||
|
if err := tx.SaveState(base, work); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := tx.SetDeployedFiles(deployed); err != nil {
|
if err := tx.SetDeployedFiles(deployed); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return tx.AddAudit(e.auditEvent(p, "system.resync", "", 0, "", 0, "success", fmt.Sprintf("%d files written", len(res.Files)), nil))
|
var details json.RawMessage
|
||||||
|
if len(pl.serials) > 0 {
|
||||||
|
details, _ = json.Marshal(map[string]any{"serials": pl.serials})
|
||||||
|
}
|
||||||
|
return tx.AddAudit(e.auditEvent(p, "system.resync", "", 0, "", 0, "success", fmt.Sprintf("%d files written", len(res.Files)), details))
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res.Applied = true
|
res.Applied = true
|
||||||
|
e.removeDerived(pl)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1058,7 +1084,7 @@ func (e *Engine) CheckCurrent(ctx context.Context) (*Result, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pl, err := e.makePlan(ctx, base, base.Clone(), "")
|
pl, err := e.makePlan(ctx, base, base.Clone(), "", ApplyOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1192,7 +1218,9 @@ func (e *Engine) WorkingState(ctx context.Context, csID int64, p *auth.Principal
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadedSerial returns the serial named serves for zone z, from rndc
|
// LoadedSerial returns the serial named serves for zone z, from rndc
|
||||||
// zonestatus. ok is false when named isn't asked (no_reload) or doesn't
|
// zonestatus: for a zone named signs, the signed zone's serial (which
|
||||||
|
// secondaries and the rest of the world see), not that of the zone file
|
||||||
|
// Jarl wrote. ok is false when named isn't asked (no_reload) or doesn't
|
||||||
// report a serial (the zone isn't loaded yet).
|
// report a serial (the zone isn't loaded yet).
|
||||||
func (e *Engine) LoadedSerial(ctx context.Context, st *model.State, z *model.Zone) (serial uint32, ok bool, err error) {
|
func (e *Engine) LoadedSerial(ctx context.Context, st *model.State, z *model.Zone) (serial uint32, ok bool, err error) {
|
||||||
if e.cfg.NoReload || e.tools == nil {
|
if e.cfg.NoReload || e.tools == nil {
|
||||||
@@ -1202,5 +1230,6 @@ func (e *Engine) LoadedSerial(ctx context.Context, st *model.State, z *model.Zon
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, err
|
return 0, false, err
|
||||||
}
|
}
|
||||||
return zs.Serial, zs.HasSerial, nil
|
serial, ok = zs.ServedSerial()
|
||||||
|
return serial, ok, nil
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,11 @@ type ZoneInput struct {
|
|||||||
SOA *SOAInput `json:"soa,omitempty"`
|
SOA *SOAInput `json:"soa,omitempty"`
|
||||||
DefaultTTL *uint32 `json:"default_ttl,omitempty"`
|
DefaultTTL *uint32 `json:"default_ttl,omitempty"`
|
||||||
SerialPolicy *string `json:"serial_policy,omitempty"`
|
SerialPolicy *string `json:"serial_policy,omitempty"`
|
||||||
Comment *string `json:"comment,omitempty"`
|
// DNSSECPolicy turns signing on ("default" or a custom policy's
|
||||||
|
// name), starts turning it off ("insecure") or, once that has
|
||||||
|
// finished, off ("").
|
||||||
|
DNSSECPolicy *string `json:"dnssec_policy,omitempty"`
|
||||||
|
Comment *string `json:"comment,omitempty"`
|
||||||
|
|
||||||
// Create only: name servers for the apex NS records (default: the
|
// Create only: name servers for the apex NS records (default: the
|
||||||
// configured default name servers), additional records, and a zone to
|
// configured default name servers), additional records, and a zone to
|
||||||
|
|||||||
@@ -230,6 +230,16 @@ func setZoneFields(st *model.State, z *model.Zone, in *ZoneInput, creating bool)
|
|||||||
if in.SerialPolicy != nil {
|
if in.SerialPolicy != nil {
|
||||||
z.SerialPolicy = strings.ToLower(strings.TrimSpace(*in.SerialPolicy))
|
z.SerialPolicy = strings.ToLower(strings.TrimSpace(*in.SerialPolicy))
|
||||||
}
|
}
|
||||||
|
if in.DNSSECPolicy != nil {
|
||||||
|
p := strings.Trim(strings.TrimSpace(*in.DNSSECPolicy), `"`)
|
||||||
|
switch strings.ToLower(p) {
|
||||||
|
case "none", "off":
|
||||||
|
p = ""
|
||||||
|
case model.DNSSECDefault, model.DNSSECInsecure:
|
||||||
|
p = strings.ToLower(p)
|
||||||
|
}
|
||||||
|
z.DNSSECPolicy = p
|
||||||
|
}
|
||||||
if in.Comment != nil {
|
if in.Comment != nil {
|
||||||
z.Comment = *in.Comment
|
z.Comment = *in.Comment
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"jarl/internal/model"
|
"jarl/internal/model"
|
||||||
"jarl/internal/render"
|
"jarl/internal/render"
|
||||||
|
"jarl/internal/validate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// serialGreater reports whether a > b in RFC 1982 serial number
|
// serialGreater reports whether a > b in RFC 1982 serial number
|
||||||
@@ -73,3 +76,59 @@ func bumpSerials(base, work *model.State, now time.Time, user string) []SerialCh
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// guardSerials makes sure every zone whose file is about to change gets
|
||||||
|
// a serial above the one named has loaded. Normally Jarl's serial is
|
||||||
|
// already higher, but not after restoring an older database or when the
|
||||||
|
// files on disk were replaced: named refuses to load a signed zone's file
|
||||||
|
// unless its serial went up (and keeps serving the old data), and
|
||||||
|
// secondaries ignore a zone whose serial went down. Zones are bumped past
|
||||||
|
// named's serial unless the user set the serial explicitly; an explicit
|
||||||
|
// serial that a signed zone can't take is an error. named is only asked
|
||||||
|
// when it controls the zone (not with no_reload).
|
||||||
|
func (e *Engine) guardSerials(ctx context.Context, base, work *model.State, bumped []SerialChange, user string) ([]SerialChange, []validate.Problem) {
|
||||||
|
if e.cfg.NoReload || e.tools == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
auto := map[int64]bool{}
|
||||||
|
for _, c := range bumped {
|
||||||
|
auto[c.ZoneID] = true
|
||||||
|
}
|
||||||
|
var out []SerialChange
|
||||||
|
var problems []validate.Problem
|
||||||
|
for _, z := range work.SortedZones() {
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
old := base.Zones[z.ID]
|
||||||
|
if old == nil || old.Type != model.ZonePrimary || old.ViewID != z.ViewID {
|
||||||
|
continue // new to named: nothing loaded to compare with
|
||||||
|
}
|
||||||
|
path := render.ZoneFilePath(work, z, e.cfg.Paths)
|
||||||
|
if cur, ok, _ := readFile(path); ok && string(cur) == render.ZoneFile(work, z) {
|
||||||
|
continue // named keeps what it has
|
||||||
|
}
|
||||||
|
zs, err := e.tools.ZoneStatus(ctx, z.Name, e.namedView(work, z))
|
||||||
|
if err != nil || !zs.HasSerial || serialGreater(z.SOA.Serial, zs.Serial) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
explicit := z.SOA.Serial != old.SOA.Serial && !auto[z.ID]
|
||||||
|
if explicit {
|
||||||
|
if z.Signed() {
|
||||||
|
problems = append(problems, validate.Problem{Severity: validate.Error, Code: "serial_not_higher", ObjectType: "zone", ObjectID: z.ID, Zone: z.Name, View: work.ViewName(z),
|
||||||
|
Message: fmt.Sprintf("named only loads a signed zone's file when its serial goes up, and it has serial %d loaded; set a higher serial (or leave it to Jarl)", zs.Serial)})
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
policy := z.SerialPolicy
|
||||||
|
if policy == "" {
|
||||||
|
policy = work.Settings.SerialPolicy
|
||||||
|
}
|
||||||
|
next := NextSerial(zs.Serial, policy, e.Now())
|
||||||
|
out = append(out, SerialChange{ZoneID: z.ID, Zone: z.Name, View: work.ViewName(z), Old: z.SOA.Serial, New: next})
|
||||||
|
e.log.Info("raising a zone's serial above the one named has loaded", "zone", z.Name, "view", work.ViewName(z), "jarl", z.SOA.Serial, "named", zs.Serial, "new", next)
|
||||||
|
z.SOA.Serial = next
|
||||||
|
z.Touch(user, e.Now())
|
||||||
|
}
|
||||||
|
return out, problems
|
||||||
|
}
|
||||||
@@ -61,6 +61,9 @@ type importer struct {
|
|||||||
dir string // the directory option, for relative zone file names
|
dir string // the directory option, for relative zone file names
|
||||||
seen map[string]bool
|
seen map[string]bool
|
||||||
ctrl map[string]bool // key names used by controls
|
ctrl map[string]bool // key names used by controls
|
||||||
|
// policies are dnssec-policy statements of the options block (key
|
||||||
|
// "options") and of views ("view:ID"), which Jarl sets per zone.
|
||||||
|
policies map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *importer) warn(format string, args ...any) {
|
func (im *importer) warn(format string, args ...any) {
|
||||||
@@ -90,7 +93,7 @@ func (im *importer) meta() model.Meta {
|
|||||||
|
|
||||||
// Import reads the configuration starting at mainPath.
|
// Import reads the configuration starting at mainPath.
|
||||||
func Import(ctx context.Context, mainPath string, opts Options) (*model.State, *Report, error) {
|
func Import(ctx context.Context, mainPath string, opts Options) (*model.State, *Report, error) {
|
||||||
im := &importer{ctx: ctx, opts: opts, st: model.NewState(), rep: &Report{}, seen: map[string]bool{}, ctrl: map[string]bool{}}
|
im := &importer{ctx: ctx, opts: opts, st: model.NewState(), rep: &Report{}, seen: map[string]bool{}, ctrl: map[string]bool{}, policies: map[string]string{}}
|
||||||
stmts, err := im.readFile(mainPath)
|
stmts, err := im.readFile(mainPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -116,6 +119,7 @@ func Import(ctx context.Context, mainPath string, opts Options) (*model.State, *
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
im.dnssecZones()
|
||||||
im.rep.Counts = map[string]int{"views": len(im.st.Views), "zones": len(im.st.Zones), "records": len(im.st.Records), "acls": len(im.st.ACLs), "tsig_keys": len(im.st.Keys), "options": len(im.st.Options)}
|
im.rep.Counts = map[string]int{"views": len(im.st.Views), "zones": len(im.st.Zones), "records": len(im.st.Records), "acls": len(im.st.ACLs), "tsig_keys": len(im.st.Keys), "options": len(im.st.Options)}
|
||||||
sort.Slice(im.rep.Zones, func(i, j int) bool {
|
sort.Slice(im.rep.Zones, func(i, j int) bool {
|
||||||
a, b := im.rep.Zones[i], im.rep.Zones[j]
|
a, b := im.rep.Zones[i], im.rep.Zones[j]
|
||||||
@@ -246,6 +250,20 @@ func (im *importer) keepInclude(path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (im *importer) addOption(scope string, scopeID int64, name, value, comment string) {
|
func (im *importer) addOption(scope string, scopeID int64, name, value, comment string) {
|
||||||
|
switch {
|
||||||
|
case name == "dnssec-policy" && scope == model.ScopeOptions:
|
||||||
|
im.policies["options"] = value
|
||||||
|
return
|
||||||
|
case name == "dnssec-policy" && scope == model.ScopeView:
|
||||||
|
im.policies[fmt.Sprintf("view:%d", scopeID)] = value
|
||||||
|
return
|
||||||
|
case name == "dnssec-policy" && scope == model.ScopeZone:
|
||||||
|
im.policies[fmt.Sprintf("zone:%d", scopeID)] = value
|
||||||
|
return
|
||||||
|
case name == "key-directory" && scope == model.ScopeZone:
|
||||||
|
// Jarl chooses signed zones' key directories (see dnssecKeys).
|
||||||
|
return
|
||||||
|
}
|
||||||
id, err := im.id()
|
id, err := im.id()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -259,6 +277,45 @@ func (im *importer) addOption(scope string, scopeID int64, name, value, comment
|
|||||||
im.st.Options[id] = &model.Option{ID: id, Scope: scope, ScopeID: scopeID, Name: name, Value: value, Position: pos, Comment: comment, Meta: im.meta()}
|
im.st.Options[id] = &model.Option{ID: id, Scope: scope, ScopeID: scopeID, Name: name, Value: value, Position: pos, Comment: comment, Meta: im.meta()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policyName turns a dnssec-policy value into a zone's DNSSECPolicy.
|
||||||
|
func policyName(v string) string {
|
||||||
|
v = strings.Trim(strings.TrimSpace(v), `"`)
|
||||||
|
switch l := strings.ToLower(v); l {
|
||||||
|
case "none":
|
||||||
|
return ""
|
||||||
|
case model.DNSSECDefault, model.DNSSECInsecure:
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// dnssecZones gives primary zones the dnssec-policy they inherit from
|
||||||
|
// their view or the options block (Jarl sets it per zone), and warns
|
||||||
|
// about signed zones' keys: Jarl keeps them in its own key directory, and
|
||||||
|
// unless the existing keys are moved there, named makes new ones that the
|
||||||
|
// parent's DS record doesn't match.
|
||||||
|
func (im *importer) dnssecZones() {
|
||||||
|
for _, z := range im.st.SortedZones() {
|
||||||
|
v, ok := im.policies[fmt.Sprintf("zone:%d", z.ID)]
|
||||||
|
if !ok {
|
||||||
|
v, ok = im.policies[fmt.Sprintf("view:%d", z.ViewID)]
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
v = im.policies["options"]
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
if p := policyName(v); p != "" {
|
||||||
|
im.warn("zone %s: named signs this %s zone (dnssec-policy %s); Jarl only signs primary zones, so the setting was dropped", dnsname.Display(z.Name), z.Type, p)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
z.DNSSECPolicy = policyName(v)
|
||||||
|
if z.DNSSECPolicy != "" {
|
||||||
|
im.warn("zone %s is signed (dnssec-policy %s). Before 'jarld adopt', copy its key files (K%s+*) into the key directory Jarl uses for it ('jarl zone dnssec status %s' shows it), owned by named's user; otherwise named makes new keys, and if the parent zone has a DS record for the old ones, the zone stops validating (docs/dnssec.md#adopting-a-signed-zone)", dnsname.Display(z.Name), z.DNSSECPolicy, z.Name, dnsname.Display(z.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func restText(s *namedconf.Stmt) string {
|
func restText(s *namedconf.Stmt) string {
|
||||||
return namedconf.Compact(s.Items[1:])
|
return namedconf.Compact(s.Items[1:])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,3 +165,43 @@ func TestImportAllowUpdateWarning(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportSignedZones(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
zone := "$TTL 300\n@ IN SOA ns1 h 1 2 3 4 5\n@ IN NS ns1\nns1 IN A 192.0.2.1\n"
|
||||||
|
for _, n := range []string{"a", "b", "c"} {
|
||||||
|
os.WriteFile(filepath.Join(dir, n+".db"), []byte(strings.ReplaceAll(zone, "ns1", "ns1."+n+".test.")), 0o644)
|
||||||
|
}
|
||||||
|
conf := `options { directory "` + dir + `"; dnssec-policy default; key-directory "/var/cache/bind/keys"; };
|
||||||
|
view "external" {
|
||||||
|
zone "a.test" { type primary; file "a.db"; key-directory "/elsewhere"; };
|
||||||
|
zone "b.test" { type primary; file "b.db"; dnssec-policy none; };
|
||||||
|
};
|
||||||
|
view "internal" {
|
||||||
|
dnssec-policy "none";
|
||||||
|
zone "c.test" { type primary; file "c.db"; };
|
||||||
|
};`
|
||||||
|
os.WriteFile(filepath.Join(dir, "named.conf"), []byte(conf), 0o644)
|
||||||
|
st, rep, err := Import(context.Background(), filepath.Join(dir, "named.conf"), Options{Alloc: seqAlloc()})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
policy := map[string]string{}
|
||||||
|
for _, z := range st.Zones {
|
||||||
|
policy[z.Name] = z.DNSSECPolicy
|
||||||
|
}
|
||||||
|
if policy["a.test."] != "default" || policy["b.test."] != "" || policy["c.test."] != "" {
|
||||||
|
t.Errorf("policies: %v", policy)
|
||||||
|
}
|
||||||
|
for _, o := range st.Options {
|
||||||
|
if o.Name == "dnssec-policy" || o.Scope == model.ScopeZone && o.Name == "key-directory" {
|
||||||
|
t.Errorf("option kept: %+v", o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !strings.Contains(strings.Join(rep.Warnings, "\n"), "zone a.test is signed (dnssec-policy default). Before 'jarld adopt', copy its key files (Ka.test.+*)") {
|
||||||
|
t.Errorf("warnings: %v", rep.Warnings)
|
||||||
|
}
|
||||||
|
if ps := validate.Errors(validate.State(st, validate.Options{})); len(ps) != 0 {
|
||||||
|
t.Errorf("imported state has errors: %v", ps)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,13 +118,28 @@ type Zone struct {
|
|||||||
SOA SOA `json:"soa"`
|
SOA SOA `json:"soa"`
|
||||||
DefaultTTL uint32 `json:"default_ttl"`
|
DefaultTTL uint32 `json:"default_ttl"`
|
||||||
SerialPolicy string `json:"serial_policy,omitempty"`
|
SerialPolicy string `json:"serial_policy,omitempty"`
|
||||||
|
// DNSSECPolicy is the dnssec-policy named signs the zone with (primary
|
||||||
|
// zones only): "" for an unsigned zone, "default" (BIND's built-in
|
||||||
|
// policy), the name of a dnssec-policy statement, or "insecure" while
|
||||||
|
// signing is being removed safely (docs/dnssec.md).
|
||||||
|
DNSSECPolicy string `json:"dnssec_policy,omitempty"`
|
||||||
Comment string `json:"comment"`
|
Comment string `json:"comment"`
|
||||||
Meta
|
Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DNSSEC policies with a special meaning.
|
||||||
|
const (
|
||||||
|
DNSSECDefault = "default" // BIND's built-in policy
|
||||||
|
DNSSECInsecure = "insecure" // BIND's built-in policy for removing signing
|
||||||
|
)
|
||||||
|
|
||||||
// HasRecords reports whether Jarl manages the zone's records.
|
// HasRecords reports whether Jarl manages the zone's records.
|
||||||
func (z *Zone) HasRecords() bool { return z.Type == ZonePrimary }
|
func (z *Zone) HasRecords() bool { return z.Type == ZonePrimary }
|
||||||
|
|
||||||
|
// Signed reports whether named signs the zone (or is still removing its
|
||||||
|
// signatures, under the insecure policy).
|
||||||
|
func (z *Zone) Signed() bool { return z.Type == ZonePrimary && z.DNSSECPolicy != "" }
|
||||||
|
|
||||||
// Record is a resource record in a primary zone.
|
// Record is a resource record in a primary zone.
|
||||||
type Record struct {
|
type Record struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
|||||||
+256
-46
@@ -9,6 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
|
"jarl/internal/dnssec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Finding is one conclusion of a delegation check. Level is "ok",
|
// Finding is one conclusion of a delegation check. Level is "ok",
|
||||||
@@ -28,8 +30,73 @@ type ParentAnswer struct {
|
|||||||
NS []string `json:"ns,omitempty"`
|
NS []string `json:"ns,omitempty"`
|
||||||
// Glue is the addresses the parent hands out for in-zone name
|
// Glue is the addresses the parent hands out for in-zone name
|
||||||
// servers.
|
// servers.
|
||||||
Glue map[string][]string `json:"glue,omitempty"`
|
Glue map[string][]string `json:"glue,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
// DS is the zone's DS records at this server ("" in DSError when it
|
||||||
|
// couldn't be asked).
|
||||||
|
DS []dnssec.DS `json:"ds,omitempty"`
|
||||||
|
DSError string `json:"ds_error,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signing is how Jarl signs a zone, for comparing with the parent's DS
|
||||||
|
// records.
|
||||||
|
type Signing struct {
|
||||||
|
// Policy is the zone's dnssec-policy ("" when unsigned, "insecure"
|
||||||
|
// while signing is being removed).
|
||||||
|
Policy string
|
||||||
|
// DS are the DS records of the zone's key-signing keys that named
|
||||||
|
// still publishes.
|
||||||
|
DS []dnssec.DS
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParentDSReport is what the parent zone's servers say about the zone's
|
||||||
|
// DS records.
|
||||||
|
type ParentDSReport struct {
|
||||||
|
Zone string `json:"zone"`
|
||||||
|
Parent string `json:"parent,omitempty"`
|
||||||
|
Resolver string `json:"resolver,omitempty"`
|
||||||
|
// Delegated: at least one parent server delegates the zone. Reached
|
||||||
|
// is how many answered.
|
||||||
|
Delegated bool `json:"delegated"`
|
||||||
|
Reached int `json:"reached"`
|
||||||
|
Servers []ParentAnswer `json:"parent_servers"`
|
||||||
|
// DS is every DS record any parent server has.
|
||||||
|
DS []dnssec.DS `json:"ds"`
|
||||||
|
// Consistent: every server that answered has the same DS records.
|
||||||
|
Consistent bool `json:"consistent"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllHaveDS reports whether every parent server that answered has a DS
|
||||||
|
// record for key tag (with digest, unless "").
|
||||||
|
func (r *ParentDSReport) AllHaveDS(tag uint16, digest string) bool {
|
||||||
|
n := 0
|
||||||
|
for _, a := range r.Servers {
|
||||||
|
if a.Status != "delegated" || a.DSError != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n++
|
||||||
|
found := false
|
||||||
|
for _, d := range a.DS {
|
||||||
|
if d.KeyTag == tag && (digest == "" || strings.EqualFold(d.Digest, digest)) {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDS reports whether a parent server has a DS record for key tag.
|
||||||
|
func (r *ParentDSReport) HasDS(tag uint16, digest string) bool {
|
||||||
|
for _, d := range r.DS {
|
||||||
|
if d.KeyTag == tag && (digest == "" || strings.EqualFold(d.Digest, digest)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlueCheck compares the parent's glue for an in-zone name server with
|
// GlueCheck compares the parent's glue for an in-zone name server with
|
||||||
@@ -52,6 +119,8 @@ type DelegationReport struct {
|
|||||||
JarlNS []string `json:"jarl_ns"`
|
JarlNS []string `json:"jarl_ns"`
|
||||||
Parents []ParentAnswer `json:"parent_servers"`
|
Parents []ParentAnswer `json:"parent_servers"`
|
||||||
Glue []GlueCheck `json:"glue"`
|
Glue []GlueCheck `json:"glue"`
|
||||||
|
// ParentDS are the zone's DS records at the parent (DNSSEC).
|
||||||
|
ParentDS []dnssec.DS `json:"parent_ds"`
|
||||||
// Servers are the delegated name servers' SOA answers, as resolvers
|
// Servers are the delegated name servers' SOA answers, as resolvers
|
||||||
// on the internet would reach them.
|
// on the internet would reach them.
|
||||||
Servers []Result `json:"servers"`
|
Servers []Result `json:"servers"`
|
||||||
@@ -60,12 +129,14 @@ type DelegationReport struct {
|
|||||||
|
|
||||||
// Delegation checks how the parent zone delegates zone: it finds the
|
// Delegation checks how the parent zone delegates zone: it finds the
|
||||||
// parent through the resolver, asks each of the parent's servers for the
|
// parent through the resolver, asks each of the parent's servers for the
|
||||||
// zone's NS records and glue, compares those with jarlNS and jarlAddrs
|
// zone's NS records, glue and DS records, compares those with jarlNS and
|
||||||
// (Jarl's NS records and its addresses for in-zone name servers), and
|
// jarlAddrs (Jarl's NS records and its addresses for in-zone name
|
||||||
// asks every delegated server for the zone's serial (compared with ref).
|
// servers) and with sig (how Jarl signs the zone; nil skips the DNSSEC
|
||||||
func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string, jarlAddrs map[string][]string, ref *uint32) *DelegationReport {
|
// part), and asks every delegated server for the zone's serial (compared
|
||||||
|
// with ref).
|
||||||
|
func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string, jarlAddrs map[string][]string, ref *uint32, sig *Signing) *DelegationReport {
|
||||||
zone = dns.CanonicalName(zone)
|
zone = dns.CanonicalName(zone)
|
||||||
rep := &DelegationReport{Zone: zone, JarlNS: canonAll(jarlNS), ParentNS: []string{}, Parents: []ParentAnswer{}, Glue: []GlueCheck{}, Servers: []Result{}, Findings: []Finding{}}
|
rep := &DelegationReport{Zone: zone, JarlNS: canonAll(jarlNS), ParentNS: []string{}, Parents: []ParentAnswer{}, Glue: []GlueCheck{}, ParentDS: []dnssec.DS{}, Servers: []Result{}, Findings: []Finding{}}
|
||||||
sort.Strings(rep.JarlNS)
|
sort.Strings(rep.JarlNS)
|
||||||
add := func(level, format string, args ...any) {
|
add := func(level, format string, args ...any) {
|
||||||
for i, a := range args {
|
for i, a := range args {
|
||||||
@@ -78,42 +149,17 @@ func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string,
|
|||||||
}
|
}
|
||||||
rep.Findings = append(rep.Findings, Finding{level, fmt.Sprintf(format, args...)})
|
rep.Findings = append(rep.Findings, Finding{level, fmt.Sprintf(format, args...)})
|
||||||
}
|
}
|
||||||
res, err := c.resolver()
|
pr := c.ParentDS(ctx, zone)
|
||||||
if err != nil {
|
rep.Resolver, rep.Parent, rep.Parents = pr.Resolver, pr.Parent, pr.Servers
|
||||||
add("error", "No resolver to find the parent zone with: %v", err)
|
if pr.Error != "" {
|
||||||
|
level := "error"
|
||||||
|
if zone == "." {
|
||||||
|
level = "info"
|
||||||
|
}
|
||||||
|
rep.Findings = append(rep.Findings, Finding{level, pr.Error})
|
||||||
return rep
|
return rep
|
||||||
}
|
}
|
||||||
rep.Resolver = res
|
parent, answers := pr.Parent, pr.Servers
|
||||||
if zone == "." {
|
|
||||||
add("info", "The root zone has no parent to delegate it.")
|
|
||||||
return rep
|
|
||||||
}
|
|
||||||
|
|
||||||
// The parent zone: the zone that holds the name just above ours.
|
|
||||||
parent, err := c.enclosingZone(ctx, res, parentName(zone))
|
|
||||||
if err != nil {
|
|
||||||
add("error", "Couldn't find the parent zone of %s through %s: %v", zone, res, err)
|
|
||||||
return rep
|
|
||||||
}
|
|
||||||
rep.Parent = parent
|
|
||||||
pns, err := c.nsNames(ctx, res, parent)
|
|
||||||
if err != nil || len(pns) == 0 {
|
|
||||||
add("error", "Couldn't find the name servers of the parent zone %s through %s: %v", parent, res, errOr(err, "none listed"))
|
|
||||||
return rep
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask every parent server, in parallel.
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
answers := make([]ParentAnswer, len(pns))
|
|
||||||
for i, name := range pns {
|
|
||||||
wg.Add(1)
|
|
||||||
go func(i int, name string) {
|
|
||||||
defer wg.Done()
|
|
||||||
answers[i] = c.askParent(ctx, zone, name)
|
|
||||||
}(i, name)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
rep.Parents = answers
|
|
||||||
|
|
||||||
parentNS := map[string]bool{}
|
parentNS := map[string]bool{}
|
||||||
glue := map[string]map[string]bool{}
|
glue := map[string]map[string]bool{}
|
||||||
@@ -141,10 +187,6 @@ func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string,
|
|||||||
notDelegated++
|
notDelegated++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if reached == 0 {
|
|
||||||
add("error", "None of the parent zone's servers (%s) answered; this server may not be able to reach them.", pns)
|
|
||||||
return rep
|
|
||||||
}
|
|
||||||
if delegated == 0 {
|
if delegated == 0 {
|
||||||
rep.Delegated = false
|
rep.Delegated = false
|
||||||
where := "the parent zone " + show(parent)
|
where := "the parent zone " + show(parent)
|
||||||
@@ -154,6 +196,7 @@ func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string,
|
|||||||
add("info", "%s isn't delegated from %s, so the internet can't see it. That's expected for a zone used only on your own network. To publish it, register the domain and give your registrar these name servers: %s.", zone, where, rep.JarlNS)
|
add("info", "%s isn't delegated from %s, so the internet can't see it. That's expected for a zone used only on your own network. To publish it, register the domain and give your registrar these name servers: %s.", zone, where, rep.JarlNS)
|
||||||
return rep
|
return rep
|
||||||
}
|
}
|
||||||
|
rep.ParentDS = pr.DS
|
||||||
rep.Delegated = true
|
rep.Delegated = true
|
||||||
if notDelegated > 0 {
|
if notDelegated > 0 {
|
||||||
add("warning", "%d of the parent's %d servers don't know the delegation yet (a recent change at the registrar can take a while to reach them all).", notDelegated, reached)
|
add("warning", "%d of the parent's %d servers don't know the delegation yet (a recent change at the registrar can take a while to reach them all).", notDelegated, reached)
|
||||||
@@ -207,6 +250,12 @@ func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sig != nil {
|
||||||
|
for _, f := range dsFindings(zone, pr, sig) {
|
||||||
|
rep.Findings = append(rep.Findings, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Every delegated server, reached the way resolvers reach it: by its
|
// Every delegated server, reached the way resolvers reach it: by its
|
||||||
// glue, or by looking its name up.
|
// glue, or by looking its name up.
|
||||||
var targets []Target
|
var targets []Target
|
||||||
@@ -262,7 +311,151 @@ func (c *Checker) Delegation(ctx context.Context, zone string, jarlNS []string,
|
|||||||
return rep
|
return rep
|
||||||
}
|
}
|
||||||
|
|
||||||
// askParent asks one of the parent's servers (by name) for zone's NS.
|
// ParentDS finds the parent of zone through the resolver and asks each of
|
||||||
|
// its servers for the zone's delegation and DS records.
|
||||||
|
func (c *Checker) ParentDS(ctx context.Context, zone string) *ParentDSReport {
|
||||||
|
zone = dns.CanonicalName(zone)
|
||||||
|
rep := &ParentDSReport{Zone: zone, Servers: []ParentAnswer{}, DS: []dnssec.DS{}}
|
||||||
|
res, err := c.resolver()
|
||||||
|
if err != nil {
|
||||||
|
rep.Error = "No resolver to find the parent zone with: " + err.Error()
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
rep.Resolver = res
|
||||||
|
if zone == "." {
|
||||||
|
rep.Error = "The root zone has no parent to delegate it."
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
// The parent zone: the zone that holds the name just above ours.
|
||||||
|
parent, err := c.enclosingZone(ctx, res, parentName(zone))
|
||||||
|
if err != nil {
|
||||||
|
rep.Error = fmt.Sprintf("Couldn't find the parent zone of %s through %s: %v", show(zone), res, err)
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
rep.Parent = parent
|
||||||
|
pns, err := c.nsNames(ctx, res, parent)
|
||||||
|
if err != nil || len(pns) == 0 {
|
||||||
|
rep.Error = fmt.Sprintf("Couldn't find the name servers of the parent zone %s through %s: %v", show(parent), res, errOr(err, "none listed"))
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
// Ask every parent server, in parallel.
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
answers := make([]ParentAnswer, len(pns))
|
||||||
|
for i, name := range pns {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int, name string) {
|
||||||
|
defer wg.Done()
|
||||||
|
answers[i] = c.askParent(ctx, zone, name)
|
||||||
|
}(i, name)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
rep.Servers = answers
|
||||||
|
all := map[string]dnssec.DS{}
|
||||||
|
sets := map[string]bool{}
|
||||||
|
for _, a := range answers {
|
||||||
|
if a.Status != "delegated" && a.Status != "not_delegated" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rep.Reached++
|
||||||
|
if a.Status == "delegated" {
|
||||||
|
rep.Delegated = true
|
||||||
|
}
|
||||||
|
if a.DSError != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var set []string
|
||||||
|
for _, d := range a.DS {
|
||||||
|
k := dsKey(d)
|
||||||
|
all[k] = d
|
||||||
|
set = append(set, k)
|
||||||
|
}
|
||||||
|
sort.Strings(set)
|
||||||
|
sets[strings.Join(set, " ")] = true
|
||||||
|
}
|
||||||
|
if rep.Reached == 0 {
|
||||||
|
names := make([]string, len(pns))
|
||||||
|
for i, n := range pns {
|
||||||
|
names[i] = show(n)
|
||||||
|
}
|
||||||
|
rep.Error = fmt.Sprintf("None of the parent zone's servers (%s) answered; this server may not be able to reach them.", strings.Join(names, ", "))
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
for _, k := range keys(boolSet(all)) {
|
||||||
|
rep.DS = append(rep.DS, all[k])
|
||||||
|
}
|
||||||
|
rep.Consistent = len(sets) <= 1
|
||||||
|
return rep
|
||||||
|
}
|
||||||
|
|
||||||
|
func dsKey(d dnssec.DS) string {
|
||||||
|
return fmt.Sprintf("%05d %d %d %s", d.KeyTag, d.Algorithm, d.DigestType, strings.ToUpper(d.Digest))
|
||||||
|
}
|
||||||
|
|
||||||
|
func boolSet(m map[string]dnssec.DS) map[string]bool {
|
||||||
|
out := map[string]bool{}
|
||||||
|
for k := range m {
|
||||||
|
out[k] = true
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// dsFindings compares the parent's DS records with how Jarl signs the
|
||||||
|
// zone.
|
||||||
|
func dsFindings(zone string, pr *ParentDSReport, sig *Signing) []Finding {
|
||||||
|
var out []Finding
|
||||||
|
add := func(level, format string, args ...any) {
|
||||||
|
out = append(out, Finding{level, fmt.Sprintf(format, args...)})
|
||||||
|
}
|
||||||
|
z := show(zone)
|
||||||
|
var tags []string
|
||||||
|
for _, d := range pr.DS {
|
||||||
|
tags = append(tags, fmt.Sprint(d.KeyTag))
|
||||||
|
}
|
||||||
|
if !pr.Consistent {
|
||||||
|
add("warning", "The parent's servers have different DS records for %s (a change at the registrar may still be on its way to them all).", z)
|
||||||
|
}
|
||||||
|
matches := func(d dnssec.DS) bool {
|
||||||
|
for _, k := range sig.DS {
|
||||||
|
if k.KeyTag == d.KeyTag && k.Algorithm == d.Algorithm && k.DigestType == d.DigestType && strings.EqualFold(k.Digest, d.Digest) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var good, stale []string
|
||||||
|
for _, d := range pr.DS {
|
||||||
|
if matches(d) {
|
||||||
|
good = append(good, fmt.Sprint(d.KeyTag))
|
||||||
|
} else {
|
||||||
|
stale = append(stale, fmt.Sprint(d.KeyTag))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case len(pr.DS) == 0 && sig.Policy == "":
|
||||||
|
// Unsigned and no DS: nothing to say about DNSSEC.
|
||||||
|
case len(pr.DS) == 0 && sig.Policy == "insecure":
|
||||||
|
add("ok", "The parent has no DS record for %s any more, so turning DNSSEC off can go ahead.", z)
|
||||||
|
case len(pr.DS) == 0:
|
||||||
|
add("info", "%s is signed, but the parent has no DS record for it, so resolvers treat it as unsigned. Add the DS record at your registrar when the zone's DNSSEC page says it's ready.", z)
|
||||||
|
case sig.Policy == "":
|
||||||
|
add("error", "The parent has a DS record for %s (key %s), but the zone isn't signed: validating resolvers reject all of its answers. Remove the DS record at your registrar now.", z, strings.Join(tags, ", "))
|
||||||
|
case len(good) == 0:
|
||||||
|
add("error", "The parent's DS record for %s (key %s) matches none of the zone's keys: validating resolvers reject all of its answers. Replace it at your registrar with the zone's DS record.", z, strings.Join(tags, ", "))
|
||||||
|
default:
|
||||||
|
if sig.Policy == "insecure" {
|
||||||
|
add("warning", "The parent still has the DS record for %s (key %s). DNSSEC is being turned off: remove it at your registrar, then run the DS check.", z, strings.Join(good, ", "))
|
||||||
|
} else {
|
||||||
|
add("ok", "The parent's DS record matches the zone's key %s: validating resolvers check its answers.", strings.Join(good, ", "))
|
||||||
|
}
|
||||||
|
if len(stale) > 0 {
|
||||||
|
add("warning", "The parent also has a DS record for key %s, which the zone no longer has. Remove it at your registrar.", strings.Join(stale, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// askParent asks one of the parent's servers (by name) for zone's NS and
|
||||||
|
// DS records.
|
||||||
func (c *Checker) askParent(ctx context.Context, zone, server string) ParentAnswer {
|
func (c *Checker) askParent(ctx context.Context, zone, server string) ParentAnswer {
|
||||||
pa := ParentAnswer{Name: server}
|
pa := ParentAnswer{Name: server}
|
||||||
addrs, err := c.lookup(ctx, server)
|
addrs, err := c.lookup(ctx, server)
|
||||||
@@ -331,6 +524,23 @@ func (c *Checker) askParent(ctx context.Context, zone, server string) ParentAnsw
|
|||||||
for n := range pa.Glue {
|
for n := range pa.Glue {
|
||||||
pa.Glue[n] = canonAddrs(pa.Glue[n])
|
pa.Glue[n] = canonAddrs(pa.Glue[n])
|
||||||
}
|
}
|
||||||
|
// The parent itself answers DS queries for the zone.
|
||||||
|
m = new(dns.Msg)
|
||||||
|
m.SetQuestion(zone, dns.TypeDS)
|
||||||
|
m.RecursionDesired = false
|
||||||
|
resp, _, err = c.exchange(ctx, m, pa.Address, nil)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
pa.DSError = err.Error()
|
||||||
|
case resp.Rcode != dns.RcodeSuccess:
|
||||||
|
pa.DSError = "answered " + dns.RcodeToString[resp.Rcode]
|
||||||
|
default:
|
||||||
|
for _, rr := range resp.Answer {
|
||||||
|
if d, ok := rr.(*dns.DS); ok && dns.CanonicalName(d.Hdr.Name) == zone {
|
||||||
|
pa.DS = append(pa.DS, dnssec.DS{KeyTag: d.KeyTag, Algorithm: d.Algorithm, DigestType: d.DigestType, Digest: strings.ToUpper(d.Digest), Record: d.String()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return pa
|
return pa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
|
"jarl/internal/dnssec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fake is a DNS server on one loopback address that answers with fn.
|
// fake is a DNS server on one loopback address that answers with fn.
|
||||||
@@ -187,7 +189,7 @@ func TestDelegationMismatch(t *testing.T) {
|
|||||||
ref := uint32(7)
|
ref := uint32(7)
|
||||||
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.",
|
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.",
|
||||||
[]string{"ns1.adbraun.lol.", "ns2.adbraun.lol."},
|
[]string{"ns1.adbraun.lol.", "ns2.adbraun.lol."},
|
||||||
map[string][]string{"ns1.adbraun.lol.": {"127.0.0.99"}, "ns2.adbraun.lol.": {"127.0.0.14"}}, &ref)
|
map[string][]string{"ns1.adbraun.lol.": {"127.0.0.99"}, "ns2.adbraun.lol.": {"127.0.0.14"}}, &ref, nil)
|
||||||
if rep.Parent != "lol." || !rep.Delegated {
|
if rep.Parent != "lol." || !rep.Delegated {
|
||||||
t.Fatalf("report: %+v", rep)
|
t.Fatalf("report: %+v", rep)
|
||||||
}
|
}
|
||||||
@@ -218,7 +220,7 @@ func TestDelegationGood(t *testing.T) {
|
|||||||
return m
|
return m
|
||||||
})
|
})
|
||||||
ref := uint32(7)
|
ref := uint32(7)
|
||||||
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, map[string][]string{"ns1.adbraun.lol.": {"127.0.0.12"}}, &ref)
|
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, map[string][]string{"ns1.adbraun.lol.": {"127.0.0.12"}}, &ref, nil)
|
||||||
l := levels(rep)
|
l := levels(rep)
|
||||||
if len(l["error"])+len(l["warning"])+len(l["info"]) != 0 || len(l["ok"]) != 2 {
|
if len(l["error"])+len(l["warning"])+len(l["info"]) != 0 || len(l["ok"]) != 2 {
|
||||||
t.Errorf("findings: %v", l)
|
t.Errorf("findings: %v", l)
|
||||||
@@ -234,7 +236,7 @@ func TestNotDelegated(t *testing.T) {
|
|||||||
m.Ns = []dns.RR{rr("lol. 300 IN SOA ns.nic.lol. hostmaster.lol. 1 3600 900 1209600 300")}
|
m.Ns = []dns.RR{rr("lol. 300 IN SOA ns.nic.lol. hostmaster.lol. 1 3600 900 1209600 300")}
|
||||||
return m
|
return m
|
||||||
})
|
})
|
||||||
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, nil, nil)
|
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, nil, nil, nil)
|
||||||
l := levels(rep)
|
l := levels(rep)
|
||||||
if rep.Delegated || len(l["info"]) != 1 || len(l["warning"])+len(l["error"]) != 0 {
|
if rep.Delegated || len(l["info"]) != 1 || len(l["warning"])+len(l["error"]) != 0 {
|
||||||
t.Errorf("findings: %v", l)
|
t.Errorf("findings: %v", l)
|
||||||
@@ -243,3 +245,65 @@ func TestNotDelegated(t *testing.T) {
|
|||||||
t.Errorf("note: %s", l["info"][0])
|
t.Errorf("note: %s", l["info"][0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDelegationDS(t *testing.T) {
|
||||||
|
const dsData = "22642 13 2 0B7A2F5E1C8E2F6A0B7A2F5E1C8E2F6A0B7A2F5E1C8E2F6A0B7A2F5E1C8E2F6A"
|
||||||
|
parent := func(withDS bool) fake {
|
||||||
|
return func(q dns.Question) *dns.Msg {
|
||||||
|
m := new(dns.Msg)
|
||||||
|
switch {
|
||||||
|
case q.Qtype == dns.TypeNS && q.Name == "adbraun.lol.":
|
||||||
|
m.Ns = []dns.RR{rr("adbraun.lol. 3600 IN NS ns1.adbraun.lol.")}
|
||||||
|
m.Extra = []dns.RR{rr("ns1.adbraun.lol. 3600 IN A 127.0.0.12")}
|
||||||
|
case q.Qtype == dns.TypeDS && q.Name == "adbraun.lol.":
|
||||||
|
m.Authoritative = true
|
||||||
|
if withDS {
|
||||||
|
m.Answer = []dns.RR{rr("adbraun.lol. 3600 IN DS " + dsData)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ours := dnssec.DS{KeyTag: 22642, Algorithm: 13, DigestType: 2, Digest: strings.Fields(dsData)[3]}
|
||||||
|
other := ours
|
||||||
|
other.KeyTag, other.Digest = 1111, strings.Repeat("AB", 32)
|
||||||
|
ref := uint32(7)
|
||||||
|
for _, c := range []struct {
|
||||||
|
name string
|
||||||
|
withDS bool
|
||||||
|
sig Signing
|
||||||
|
level string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"secure", true, Signing{Policy: "default", DS: []dnssec.DS{ours}}, "ok", "matches the zone's key 22642"},
|
||||||
|
{"wrong key", true, Signing{Policy: "default", DS: []dnssec.DS{other}}, "error", "matches none of the zone's keys"},
|
||||||
|
{"unsigned", true, Signing{}, "error", "but the zone isn't signed"},
|
||||||
|
{"turning off", true, Signing{Policy: "insecure", DS: []dnssec.DS{ours}}, "warning", "remove it at your registrar"},
|
||||||
|
{"no DS yet", false, Signing{Policy: "default", DS: []dnssec.DS{ours}}, "info", "the parent has no DS record for it"},
|
||||||
|
{"DS gone", false, Signing{Policy: "insecure"}, "ok", "turning DNSSEC off can go ahead"},
|
||||||
|
} {
|
||||||
|
port, res := internet(t, parent(c.withDS))
|
||||||
|
sig := c.sig
|
||||||
|
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, map[string][]string{"ns1.adbraun.lol.": {"127.0.0.12"}}, &ref, &sig)
|
||||||
|
found := false
|
||||||
|
for _, f := range rep.Findings {
|
||||||
|
if f.Level == c.level && strings.Contains(f.Message, c.want) {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Errorf("%s: no %s finding %q in %+v", c.name, c.level, c.want, rep.Findings)
|
||||||
|
}
|
||||||
|
if c.withDS && (len(rep.ParentDS) != 1 || rep.ParentDS[0].KeyTag != 22642) {
|
||||||
|
t.Errorf("%s: parent DS %+v", c.name, rep.ParentDS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Unsigned and no DS: nothing about DNSSEC.
|
||||||
|
port, res := internet(t, parent(false))
|
||||||
|
rep := checker(port, res).Delegation(context.Background(), "adbraun.lol.", []string{"ns1.adbraun.lol."}, map[string][]string{"ns1.adbraun.lol.": {"127.0.0.12"}}, &ref, &Signing{})
|
||||||
|
for _, f := range rep.Findings {
|
||||||
|
if strings.Contains(f.Message, "DS") {
|
||||||
|
t.Errorf("unsigned zone: %+v", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package porkbun
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fake is an in-memory stand-in for the Porkbun API, for tests: it knows
|
||||||
|
// one account's domains and checks the key like Porkbun does.
|
||||||
|
type Fake struct {
|
||||||
|
APIKey, Secret string
|
||||||
|
mu sync.Mutex
|
||||||
|
Domains map[string]*FakeDomain
|
||||||
|
// Calls lists the paths called, in order.
|
||||||
|
Calls []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// FakeDomain is a domain in a Fake.
|
||||||
|
type FakeDomain struct {
|
||||||
|
NS []string
|
||||||
|
Glue map[string][]string // host -> addresses
|
||||||
|
DS map[uint16]DS
|
||||||
|
APIAccess bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFake returns a Fake with the given domains (API access on, Porkbun's
|
||||||
|
// own name servers, no glue or DS).
|
||||||
|
func NewFake(key, secret string, domains ...string) *Fake {
|
||||||
|
f := &Fake{APIKey: key, Secret: secret, Domains: map[string]*FakeDomain{}}
|
||||||
|
for _, d := range domains {
|
||||||
|
f.Domains[d] = &FakeDomain{NS: []string{"curitiba.ns.porkbun.com", "fortaleza.ns.porkbun.com"}, Glue: map[string][]string{}, DS: map[uint16]DS{}, APIAccess: true}
|
||||||
|
}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Fake) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
f.mu.Lock()
|
||||||
|
defer f.mu.Unlock()
|
||||||
|
reply := func(status int, v map[string]any) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(status)
|
||||||
|
json.NewEncoder(w).Encode(v)
|
||||||
|
}
|
||||||
|
fail := func(status int, code, msg string) {
|
||||||
|
reply(status, map[string]any{"status": "ERROR", "code": code, "message": msg})
|
||||||
|
}
|
||||||
|
var body map[string]any
|
||||||
|
json.NewDecoder(r.Body).Decode(&body)
|
||||||
|
path := strings.TrimPrefix(r.URL.Path, "/api/json/v3")
|
||||||
|
f.Calls = append(f.Calls, path)
|
||||||
|
if body["apikey"] != f.APIKey || body["secretapikey"] != f.Secret {
|
||||||
|
fail(http.StatusForbidden, "INVALID_API_KEYS_001", "Invalid API key.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if path == "/ping" {
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "yourIp": "192.0.2.1", "credentialsValid": true, "account": "tester", "scopes": []string{"full"}})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parts := strings.Split(strings.Trim(path, "/"), "/")
|
||||||
|
if len(parts) < 3 {
|
||||||
|
fail(404, "NOT_FOUND", "Unknown endpoint.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
op, domain := parts[0]+"/"+parts[1], parts[2]
|
||||||
|
d := f.Domains[domain]
|
||||||
|
if d == nil {
|
||||||
|
fail(400, "DOMAIN_NOT_FOUND", "Domain not found in this account.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !d.APIAccess {
|
||||||
|
fail(403, "API_ACCESS_DISABLED", "The domain is not opted in to API access.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
host := ""
|
||||||
|
if len(parts) > 3 {
|
||||||
|
host = parts[3] + "." + domain
|
||||||
|
}
|
||||||
|
ips := func() []string {
|
||||||
|
var out []string
|
||||||
|
if l, ok := body["ips"].([]any); ok {
|
||||||
|
for _, v := range l {
|
||||||
|
out = append(out, v.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
switch op {
|
||||||
|
case "domain/getNs":
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "ns": d.NS})
|
||||||
|
case "domain/updateNs":
|
||||||
|
var ns []string
|
||||||
|
for _, v := range body["ns"].([]any) {
|
||||||
|
n := v.(string)
|
||||||
|
if strings.HasSuffix(n, "."+domain) && d.Glue[n] == nil {
|
||||||
|
fail(400, "INVALID_NAMESERVER", "Host "+n+" doesn't exist at the registry.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ns = append(ns, n)
|
||||||
|
}
|
||||||
|
d.NS = ns
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS"})
|
||||||
|
case "domain/getGlue":
|
||||||
|
hosts := []any{}
|
||||||
|
for h, a := range d.Glue {
|
||||||
|
v4, v6 := []string{}, []string{}
|
||||||
|
for _, ip := range a {
|
||||||
|
if strings.Contains(ip, ":") {
|
||||||
|
v6 = append(v6, ip)
|
||||||
|
} else {
|
||||||
|
v4 = append(v4, ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hosts = append(hosts, []any{h, map[string]any{"v4": v4, "v6": v6}})
|
||||||
|
}
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "hosts": hosts})
|
||||||
|
case "domain/createGlue":
|
||||||
|
if d.Glue[host] != nil {
|
||||||
|
fail(400, "GLUE_EXISTS", "Host already exists.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.Glue[host] = ips()
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS"})
|
||||||
|
case "domain/updateGlue":
|
||||||
|
if d.Glue[host] == nil {
|
||||||
|
fail(400, "GLUE_NOT_FOUND", "Host not found.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.Glue[host] = ips()
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS"})
|
||||||
|
case "domain/deleteGlue":
|
||||||
|
for _, n := range d.NS {
|
||||||
|
if n == host {
|
||||||
|
fail(400, "GLUE_IN_USE", "Host is in use as a name server.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(d.Glue, host)
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS"})
|
||||||
|
case "dns/getDnssecRecords":
|
||||||
|
if len(d.DS) == 0 {
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "records": []any{}})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recs := map[string]any{}
|
||||||
|
for tag, ds := range d.DS {
|
||||||
|
recs[strconv.Itoa(int(tag))] = map[string]any{"keyTag": strconv.Itoa(int(tag)), "alg": strconv.Itoa(int(ds.Algorithm)), "digestType": strconv.Itoa(int(ds.DigestType)), "digest": strings.ToLower(ds.Digest)}
|
||||||
|
}
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "records": recs})
|
||||||
|
case "dns/createDnssecRecord":
|
||||||
|
num := func(k string) int { n, _ := strconv.Atoi(body[k].(string)); return n }
|
||||||
|
tag := uint16(num("keyTag"))
|
||||||
|
d.DS[tag] = DS{KeyTag: tag, Algorithm: uint8(num("alg")), DigestType: uint8(num("digestType")), Digest: strings.ToUpper(body["digest"].(string))}
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS"})
|
||||||
|
case "dns/deleteDnssecRecord":
|
||||||
|
tag, _ := strconv.Atoi(parts[3])
|
||||||
|
delete(d.DS, uint16(tag))
|
||||||
|
reply(200, map[string]any{"status": "SUCCESS", "message": "Deleted."})
|
||||||
|
default:
|
||||||
|
fail(404, "NOT_FOUND", "Unknown endpoint.")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
// Package porkbun is a small client for the parts of Porkbun's API v3
|
||||||
|
// (https://porkbun.com/api/json/v3/documentation) that Jarl uses to manage
|
||||||
|
// a domain's delegation: its name servers, glue records (host objects at
|
||||||
|
// the registry) and DNSSEC DS records.
|
||||||
|
//
|
||||||
|
// Every call is a POST with the API key and secret in the JSON body. API
|
||||||
|
// access must be switched on for each domain in Porkbun's web interface,
|
||||||
|
// and a key can be limited to some domains, permissions and source
|
||||||
|
// addresses there.
|
||||||
|
package porkbun
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultURL is the API's base URL.
|
||||||
|
const DefaultURL = "https://api.porkbun.com/api/json/v3"
|
||||||
|
|
||||||
|
// Client calls the Porkbun API.
|
||||||
|
type Client struct {
|
||||||
|
BaseURL string
|
||||||
|
APIKey string
|
||||||
|
Secret string
|
||||||
|
HTTP *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error is an error the API returned.
|
||||||
|
type Error struct {
|
||||||
|
Status int // HTTP status
|
||||||
|
Code string // e.g. API_ACCESS_DISABLED
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Error) Error() string {
|
||||||
|
msg := "Porkbun: " + e.Message
|
||||||
|
if e.Code != "" {
|
||||||
|
msg += " (" + e.Code + ")"
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Glue is a glue record (a host object at the registry).
|
||||||
|
type Glue struct {
|
||||||
|
Host string `json:"host"` // full host name, without a trailing dot
|
||||||
|
V4 []string `json:"v4"`
|
||||||
|
V6 []string `json:"v6"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Addresses returns all of the glue's addresses.
|
||||||
|
func (g Glue) Addresses() []string { return append(append([]string{}, g.V4...), g.V6...) }
|
||||||
|
|
||||||
|
// DS is a DS record at the registry.
|
||||||
|
type DS struct {
|
||||||
|
KeyTag uint16 `json:"key_tag"`
|
||||||
|
Algorithm uint8 `json:"algorithm"`
|
||||||
|
DigestType uint8 `json:"digest_type"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type response struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Warnings []string `json:"warnings"`
|
||||||
|
NS []string `json:"ns"`
|
||||||
|
Hosts json.RawMessage `json:"hosts"`
|
||||||
|
Records json.RawMessage `json:"records"`
|
||||||
|
YourIP string `json:"yourIp"`
|
||||||
|
Valid bool `json:"credentialsValid"`
|
||||||
|
Account string `json:"account"`
|
||||||
|
Scopes []string `json:"scopes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) call(ctx context.Context, path string, body map[string]any) (*response, error) {
|
||||||
|
if body == nil {
|
||||||
|
body = map[string]any{}
|
||||||
|
}
|
||||||
|
body["apikey"], body["secretapikey"] = c.APIKey, c.Secret
|
||||||
|
b, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := c.BaseURL
|
||||||
|
if base == "" {
|
||||||
|
base = DefaultURL
|
||||||
|
}
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, strings.TrimSuffix(base, "/")+path, bytes.NewReader(b))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "jarl")
|
||||||
|
hc := c.HTTP
|
||||||
|
if hc == nil {
|
||||||
|
hc = &http.Client{Timeout: 30 * time.Second}
|
||||||
|
}
|
||||||
|
resp, err := hc.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Porkbun: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
raw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Porkbun: %w", err)
|
||||||
|
}
|
||||||
|
var r response
|
||||||
|
if err := json.Unmarshal(raw, &r); err != nil {
|
||||||
|
return nil, &Error{Status: resp.StatusCode, Message: fmt.Sprintf("unexpected answer (HTTP %d)", resp.StatusCode)}
|
||||||
|
}
|
||||||
|
if r.Status != "SUCCESS" {
|
||||||
|
msg := r.Message
|
||||||
|
if msg == "" {
|
||||||
|
msg = fmt.Sprintf("request failed (HTTP %d)", resp.StatusCode)
|
||||||
|
}
|
||||||
|
return &r, &Error{Status: resp.StatusCode, Code: r.Code, Message: msg}
|
||||||
|
}
|
||||||
|
return &r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func domainPath(op, domain string, rest ...string) string {
|
||||||
|
p := op + "/" + url.PathEscape(strings.ToLower(strings.TrimSuffix(domain, ".")))
|
||||||
|
for _, r := range rest {
|
||||||
|
p += "/" + url.PathEscape(r)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ping checks the credentials and returns the account name and the key's
|
||||||
|
// permission scopes.
|
||||||
|
func (c *Client) Ping(ctx context.Context) (account string, scopes []string, err error) {
|
||||||
|
r, err := c.call(ctx, "/ping", nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
if !r.Valid {
|
||||||
|
return "", nil, &Error{Code: "INVALID_API_KEYS_001", Message: "the API key wasn't accepted"}
|
||||||
|
}
|
||||||
|
return r.Account, r.Scopes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NS returns the domain's name servers at the registry (lowercase,
|
||||||
|
// without trailing dots, sorted).
|
||||||
|
func (c *Client) NS(ctx context.Context, domain string) ([]string, error) {
|
||||||
|
r, err := c.call(ctx, domainPath("/domain/getNs", domain), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := []string{}
|
||||||
|
for _, n := range r.NS {
|
||||||
|
out = append(out, normName(n))
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNS replaces the domain's name servers at the registry.
|
||||||
|
func (c *Client) SetNS(ctx context.Context, domain string, ns []string) error {
|
||||||
|
list := make([]string, len(ns))
|
||||||
|
for i, n := range ns {
|
||||||
|
list[i] = normName(n)
|
||||||
|
}
|
||||||
|
_, err := c.call(ctx, domainPath("/domain/updateNs", domain), map[string]any{"ns": list})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Glue returns the domain's glue records.
|
||||||
|
func (c *Client) Glue(ctx context.Context, domain string) ([]Glue, error) {
|
||||||
|
r, err := c.call(ctx, domainPath("/domain/getGlue", domain), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := []Glue{}
|
||||||
|
if len(r.Hosts) == 0 || string(r.Hosts) == "null" {
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
var tuples [][]json.RawMessage
|
||||||
|
if err := json.Unmarshal(r.Hosts, &tuples); err != nil {
|
||||||
|
return nil, fmt.Errorf("Porkbun: unexpected glue records: %w", err)
|
||||||
|
}
|
||||||
|
for _, t := range tuples {
|
||||||
|
if len(t) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var g Glue
|
||||||
|
var ips struct{ V4, V6 []string }
|
||||||
|
if json.Unmarshal(t[0], &g.Host) != nil || json.Unmarshal(t[1], &ips) != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
g.Host, g.V4, g.V6 = normName(g.Host), nonNil(ips.V4), nonNil(ips.V6)
|
||||||
|
out = append(out, g)
|
||||||
|
}
|
||||||
|
sort.Slice(out, func(i, j int) bool { return out[i].Host < out[j].Host })
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGlue creates the glue record for host (a name inside domain) or, when
|
||||||
|
// exists, replaces its addresses.
|
||||||
|
func (c *Client) SetGlue(ctx context.Context, domain, host string, ips []string, exists bool) error {
|
||||||
|
sub, err := subdomain(domain, host)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
op := "/domain/createGlue"
|
||||||
|
if exists {
|
||||||
|
op = "/domain/updateGlue"
|
||||||
|
}
|
||||||
|
_, err = c.call(ctx, domainPath(op, domain, sub), map[string]any{"ips": ips})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGlue deletes the glue record for host. The registry refuses while
|
||||||
|
// the domain (or another one) uses it as a name server.
|
||||||
|
func (c *Client) DeleteGlue(ctx context.Context, domain, host string) error {
|
||||||
|
sub, err := subdomain(domain, host)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = c.call(ctx, domainPath("/domain/deleteGlue", domain, sub), nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DS returns the domain's DS records at the registry.
|
||||||
|
func (c *Client) DS(ctx context.Context, domain string) ([]DS, error) {
|
||||||
|
r, err := c.call(ctx, domainPath("/dns/getDnssecRecords", domain), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := []DS{}
|
||||||
|
type rec struct {
|
||||||
|
KeyTag json.Number `json:"keyTag"`
|
||||||
|
Alg json.Number `json:"alg"`
|
||||||
|
DigestType json.Number `json:"digestType"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
}
|
||||||
|
var recs []rec
|
||||||
|
// An object keyed by key tag; an empty one may come as [].
|
||||||
|
var byTag map[string]rec
|
||||||
|
if err := json.Unmarshal(r.Records, &byTag); err == nil {
|
||||||
|
for _, v := range byTag {
|
||||||
|
recs = append(recs, v)
|
||||||
|
}
|
||||||
|
} else if err := json.Unmarshal(r.Records, &recs); err != nil && len(r.Records) > 0 && string(r.Records) != "null" {
|
||||||
|
return nil, fmt.Errorf("Porkbun: unexpected DNSSEC records: %w", err)
|
||||||
|
}
|
||||||
|
for _, v := range recs {
|
||||||
|
tag, _ := strconv.ParseUint(v.KeyTag.String(), 10, 16)
|
||||||
|
alg, _ := strconv.ParseUint(v.Alg.String(), 10, 8)
|
||||||
|
dt, _ := strconv.ParseUint(v.DigestType.String(), 10, 8)
|
||||||
|
out = append(out, DS{KeyTag: uint16(tag), Algorithm: uint8(alg), DigestType: uint8(dt), Digest: strings.ToUpper(v.Digest)})
|
||||||
|
}
|
||||||
|
sort.Slice(out, func(i, j int) bool { return out[i].KeyTag < out[j].KeyTag })
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDS adds a DS record at the registry. Warnings (a value the registry is
|
||||||
|
// retiring) come back with a nil error.
|
||||||
|
func (c *Client) AddDS(ctx context.Context, domain string, ds DS) ([]string, error) {
|
||||||
|
r, err := c.call(ctx, domainPath("/dns/createDnssecRecord", domain), map[string]any{
|
||||||
|
"keyTag": strconv.Itoa(int(ds.KeyTag)), "alg": strconv.Itoa(int(ds.Algorithm)),
|
||||||
|
"digestType": strconv.Itoa(int(ds.DigestType)), "digest": ds.Digest,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return r.Warnings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDS deletes the DS record with key tag at the registry. Porkbun
|
||||||
|
// warns that most registries delete every record with the same key data.
|
||||||
|
func (c *Client) DeleteDS(ctx context.Context, domain string, keyTag uint16) error {
|
||||||
|
_, err := c.call(ctx, domainPath("/dns/deleteDnssecRecord", domain, strconv.Itoa(int(keyTag))), nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// subdomain returns host's label(s) below domain ("ns1" for
|
||||||
|
// ns1.example.com in example.com).
|
||||||
|
func subdomain(domain, host string) (string, error) {
|
||||||
|
d, h := normName(domain), normName(host)
|
||||||
|
sub, ok := strings.CutSuffix(h, "."+d)
|
||||||
|
if !ok || sub == "" {
|
||||||
|
return "", fmt.Errorf("%s isn't inside %s, so it can't have a glue record there", h, d)
|
||||||
|
}
|
||||||
|
return sub, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normName(n string) string { return strings.ToLower(strings.TrimSuffix(strings.TrimSpace(n), ".")) }
|
||||||
|
|
||||||
|
func nonNil(s []string) []string {
|
||||||
|
if s == nil {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package porkbun
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestClient(t *testing.T) {
|
||||||
|
f := NewFake("pk1_x", "sk1_y", "adbraun.lol")
|
||||||
|
ts := httptest.NewServer(f)
|
||||||
|
defer ts.Close()
|
||||||
|
c := &Client{BaseURL: ts.URL + "/api/json/v3", APIKey: "pk1_x", Secret: "sk1_y"}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
if acct, _, err := c.Ping(ctx); err != nil || acct != "tester" {
|
||||||
|
t.Fatalf("ping: %q %v", acct, err)
|
||||||
|
}
|
||||||
|
ns, err := c.NS(ctx, "adbraun.lol.")
|
||||||
|
if err != nil || strings.Join(ns, " ") != "curitiba.ns.porkbun.com fortaleza.ns.porkbun.com" {
|
||||||
|
t.Errorf("NS: %v %v", ns, err)
|
||||||
|
}
|
||||||
|
// Two glue records, one with IPv4 and IPv6.
|
||||||
|
if err := c.SetGlue(ctx, "adbraun.lol", "ns1.adbraun.lol.", []string{"203.0.113.1", "2001:db8::1"}, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := c.SetGlue(ctx, "adbraun.lol", "ns2.adbraun.lol", []string{"203.0.113.2"}, false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := c.SetGlue(ctx, "adbraun.lol", "ns2.adbraun.lol", []string{"203.0.113.3"}, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := c.SetGlue(ctx, "adbraun.lol", "ns.elsewhere.net", nil, false); err == nil {
|
||||||
|
t.Error("glue outside the domain accepted")
|
||||||
|
}
|
||||||
|
glue, err := c.Glue(ctx, "adbraun.lol")
|
||||||
|
if err != nil || len(glue) != 2 || glue[0].Host != "ns1.adbraun.lol" || strings.Join(glue[0].Addresses(), " ") != "203.0.113.1 2001:db8::1" || glue[1].V4[0] != "203.0.113.3" {
|
||||||
|
t.Errorf("glue: %+v %v", glue, err)
|
||||||
|
}
|
||||||
|
if err := c.SetNS(ctx, "adbraun.lol", []string{"ns1.adbraun.lol.", "ns2.adbraun.lol"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := c.DeleteGlue(ctx, "adbraun.lol", "ns2.adbraun.lol"); err == nil {
|
||||||
|
t.Error("deleted glue in use")
|
||||||
|
}
|
||||||
|
// DS records: empty comes as [], others keyed by tag.
|
||||||
|
if ds, err := c.DS(ctx, "adbraun.lol"); err != nil || len(ds) != 0 {
|
||||||
|
t.Errorf("no DS: %v %v", ds, err)
|
||||||
|
}
|
||||||
|
if _, err := c.AddDS(ctx, "adbraun.lol", DS{KeyTag: 22642, Algorithm: 13, DigestType: 2, Digest: "ABCDEF"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ds, err := c.DS(ctx, "adbraun.lol"); err != nil || len(ds) != 1 || ds[0].KeyTag != 22642 || ds[0].Algorithm != 13 || ds[0].Digest != "ABCDEF" {
|
||||||
|
t.Errorf("DS: %+v %v", ds, err)
|
||||||
|
}
|
||||||
|
if err := c.DeleteDS(ctx, "adbraun.lol", 22642); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Errors carry Porkbun's code.
|
||||||
|
f.Domains["adbraun.lol"].APIAccess = false
|
||||||
|
_, err = c.NS(ctx, "adbraun.lol")
|
||||||
|
var pe *Error
|
||||||
|
if !errors.As(err, &pe) || pe.Code != "API_ACCESS_DISABLED" {
|
||||||
|
t.Errorf("error: %v", err)
|
||||||
|
}
|
||||||
|
bad := &Client{BaseURL: c.BaseURL, APIKey: "pk1_x", Secret: "wrong"}
|
||||||
|
if _, _, err := bad.Ping(ctx); err == nil || !strings.Contains(err.Error(), "INVALID_API_KEYS") {
|
||||||
|
t.Errorf("bad key: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,7 +62,8 @@ type Span struct {
|
|||||||
// Output is the result of rendering.
|
// Output is the result of rendering.
|
||||||
type Output struct {
|
type Output struct {
|
||||||
Files []*File
|
Files []*File
|
||||||
// Dirs are directories named needs to exist (for secondary zone files).
|
// Dirs are directories named must be able to write to (secondary zone
|
||||||
|
// files, DNSSEC key directories).
|
||||||
Dirs []string
|
Dirs []string
|
||||||
// Spans maps file paths to source spans.
|
// Spans maps file paths to source spans.
|
||||||
Spans map[string][]Span
|
Spans map[string][]Span
|
||||||
@@ -103,6 +104,22 @@ func ViewDir(viewName string) string {
|
|||||||
return dnsname.FileSafe(dnsname.Fqdn(strings.ToLower(viewName)))
|
return dnsname.FileSafe(dnsname.Fqdn(strings.ToLower(viewName)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KeysDir is the directory under which named keeps the DNSSEC keys of the
|
||||||
|
// zones Jarl signs, one subdirectory per view.
|
||||||
|
func (p Paths) KeysDir() string { return filepath.Join(p.ZoneDir, "dnssec-keys") }
|
||||||
|
|
||||||
|
// KeyDir returns the key-directory of zone z: one per view, because named
|
||||||
|
// refuses one directory for zones of the same name in two views. It is
|
||||||
|
// named after the view's ID, which unlike its name never changes: a new
|
||||||
|
// directory would make named create new keys, which the parent's DS
|
||||||
|
// record wouldn't match.
|
||||||
|
func KeyDir(s *model.State, z *model.Zone, p Paths) string {
|
||||||
|
if z.ViewID == 0 {
|
||||||
|
return filepath.Join(p.KeysDir(), "_default")
|
||||||
|
}
|
||||||
|
return filepath.Join(p.KeysDir(), fmt.Sprintf("view-%d", z.ViewID))
|
||||||
|
}
|
||||||
|
|
||||||
// ZoneFilePath returns the file named loads for zone z, or "" for zone
|
// ZoneFilePath returns the file named loads for zone z, or "" for zone
|
||||||
// types without files.
|
// types without files.
|
||||||
func ZoneFilePath(s *model.State, z *model.Zone, p Paths) string {
|
func ZoneFilePath(s *model.State, z *model.Zone, p Paths) string {
|
||||||
@@ -387,6 +404,14 @@ func renderZone(w *confWriter, s *model.State, z *model.Zone, p Paths, out *Outp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if z.Signed() {
|
||||||
|
// named signs the zone itself (inline signing): it keeps the
|
||||||
|
// signed copy next to Jarl's file (.signed) and its keys in dir.
|
||||||
|
dir := KeyDir(s, z, p)
|
||||||
|
w.write(fmt.Sprintf("%s\tdnssec-policy %s;\n", tabs, namedconf.QuoteString(z.DNSSECPolicy)))
|
||||||
|
w.write(fmt.Sprintf("%s\tkey-directory %s;\n", tabs, namedconf.QuoteString(dir)))
|
||||||
|
out.Dirs = appendUnique(out.Dirs, dir)
|
||||||
|
}
|
||||||
for _, o := range s.ScopedOptions(model.ScopeZone, z.ID) {
|
for _, o := range s.ScopedOptions(model.ScopeZone, z.ID) {
|
||||||
w.begin("option", o.ID, label+" option "+o.Name)
|
w.begin("option", o.ID, label+" option "+o.Name)
|
||||||
w.write(optionText(o, indent+1))
|
w.write(optionText(o, indent+1))
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/nscheck"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDNSSECEndpoints(t *testing.T) {
|
||||||
|
e := newAPIEnv(t)
|
||||||
|
// Nothing answers DNS here, so the parent can't be checked.
|
||||||
|
e.srv.nsChecker = &nscheck.Checker{Timeout: 200 * time.Millisecond, Resolver: "127.0.0.1:1"}
|
||||||
|
e.do("POST", "/zones", e.token, map[string]any{"name": "example.com", "records": []map[string]any{{"name": "ns1", "type": "A", "data": "192.0.2.1"}}}, 201)
|
||||||
|
e.do("GET", "/zones/example.com/dnssec?view=", e.token, nil, 200)
|
||||||
|
|
||||||
|
e.do("PATCH", "/zones/example.com", e.token, map[string]any{"dnssec_policy": "default"}, 200)
|
||||||
|
got := e.do("GET", "/zones/example.com/dnssec", e.token, nil, 200)
|
||||||
|
if got["policy"] != "default" || got["phase"].(map[string]any)["code"] != dnssec.PhaseStarting || !strings.HasSuffix(got["key_dir"].(string), "zones/dnssec-keys/_default") {
|
||||||
|
t.Errorf("status: %v", got)
|
||||||
|
}
|
||||||
|
// Switching off at once is refused; insecure is the way.
|
||||||
|
out := e.do("PATCH", "/zones/example.com", e.token, map[string]any{"dnssec_policy": "off"}, 422)
|
||||||
|
if !strings.Contains(out["error"].(map[string]any)["message"].(string), "switching DNSSEC off at once") {
|
||||||
|
t.Errorf("switching off: %v", out)
|
||||||
|
}
|
||||||
|
cd := e.do("POST", "/zones/example.com/dnssec/check-ds", e.token, nil, 200)
|
||||||
|
if cd["parent"].(map[string]any)["error"] == "" || len(cd["marked"].([]any)) != 0 {
|
||||||
|
t.Errorf("check-ds without a resolver: %v", cd)
|
||||||
|
}
|
||||||
|
// Wipe: refused while the parent can't be checked, unless forced.
|
||||||
|
out = e.do("POST", "/zones/example.com/dnssec/wipe", e.token, nil, 409)
|
||||||
|
if !strings.Contains(out["error"].(map[string]any)["message"].(string), "wipe with force") {
|
||||||
|
t.Errorf("wipe: %v", out)
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/example.com/dnssec/wipe", e.token, map[string]any{"force": true, "dry_run": true}, 200)
|
||||||
|
if e.do("GET", "/zones/example.com", e.token, nil, 200)["dnssec_policy"] != "default" {
|
||||||
|
t.Error("a dry run changed the zone")
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/example.com/dnssec/wipe", e.token, map[string]any{"force": true}, 200)
|
||||||
|
if p, ok := e.do("GET", "/zones/example.com", e.token, nil, 200)["dnssec_policy"]; ok && p != "" {
|
||||||
|
t.Errorf("after wipe: %v", p)
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/example.com/dnssec/wipe", e.token, map[string]any{"force": true}, 409) // nothing left
|
||||||
|
|
||||||
|
// Secondary zones aren't signed by Jarl.
|
||||||
|
e.do("POST", "/zones", e.token, map[string]any{"name": "copy.example", "type": "secondary", "options": []map[string]any{{"name": "primaries", "value": "{ 192.0.2.1; }"}}}, 201)
|
||||||
|
e.do("GET", "/zones/copy.example/dnssec", e.token, nil, 400)
|
||||||
|
e.do("PATCH", "/zones/copy.example", e.token, map[string]any{"dnssec_policy": "default"}, 422)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDSChanges(t *testing.T) {
|
||||||
|
ds := dnssec.DS{KeyTag: 1, Algorithm: 13, DigestType: 2, Digest: "AA"}
|
||||||
|
key := func(goal, dsState string) *dnssec.Key {
|
||||||
|
d := ds
|
||||||
|
return &dnssec.Key{Tag: 1, Role: "CSK", DS: &d, Goal: goal, DSState: dsState}
|
||||||
|
}
|
||||||
|
with := &nscheck.ParentDSReport{Servers: []nscheck.ParentAnswer{{Status: "delegated", DS: []dnssec.DS{ds}}, {Status: "delegated", DS: []dnssec.DS{ds}}}, DS: []dnssec.DS{ds}, Consistent: true}
|
||||||
|
half := &nscheck.ParentDSReport{Servers: []nscheck.ParentAnswer{{Status: "delegated", DS: []dnssec.DS{ds}}, {Status: "delegated"}}, DS: []dnssec.DS{ds}}
|
||||||
|
without := &nscheck.ParentDSReport{Servers: []nscheck.ParentAnswer{{Status: "delegated"}}, Consistent: true}
|
||||||
|
signed := &model.Zone{DNSSECPolicy: "default"}
|
||||||
|
off := &model.Zone{DNSSECPolicy: "insecure"}
|
||||||
|
|
||||||
|
if p, w := dsChanges(signed, []*dnssec.Key{key("omnipresent", "rumoured")}, with); len(p) != 1 || len(w) != 0 {
|
||||||
|
t.Errorf("DS added: %v %v", p, w)
|
||||||
|
}
|
||||||
|
if p, _ := dsChanges(signed, []*dnssec.Key{key("omnipresent", "rumoured")}, half); len(p) != 0 {
|
||||||
|
t.Error("published while not every parent server has it")
|
||||||
|
}
|
||||||
|
if p, w := dsChanges(signed, []*dnssec.Key{key("omnipresent", "rumoured")}, without); len(p)+len(w) != 0 {
|
||||||
|
t.Error("a signed zone without a DS yet is just waiting")
|
||||||
|
}
|
||||||
|
if p, w := dsChanges(off, []*dnssec.Key{key("hidden", "unretentive")}, without); len(p) != 0 || len(w) != 1 {
|
||||||
|
t.Errorf("DS removed: %v %v", p, w)
|
||||||
|
}
|
||||||
|
if _, w := dsChanges(off, []*dnssec.Key{key("hidden", "unretentive")}, half); len(w) != 0 {
|
||||||
|
t.Error("withdrawn while a parent server still has it")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
// DNSSEC signing (docs/dnssec.md): GET /zones/{zone}/dnssec,
|
||||||
|
// POST /zones/{zone}/dnssec/check-ds and POST /zones/{zone}/dnssec/wipe.
|
||||||
|
// Signing itself is switched with the zone's dnssec_policy field
|
||||||
|
// (PATCH /zones/{zone}), which goes through a changeset like any change.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/netip"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"jarl/internal/api"
|
||||||
|
"jarl/internal/auth"
|
||||||
|
"jarl/internal/dnsname"
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
"jarl/internal/engine"
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/nscheck"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) zoneDNSSEC(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
st, err := s.state(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
z, err := s.zoneByPath(r, st, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
return badRequest("only primary zones are signed by Jarl (this is a %s zone)", z.Type)
|
||||||
|
}
|
||||||
|
resp := api.DNSSECResponse{Zone: z.Name, View: st.ViewName(z), Type: z.Type, Status: s.eng.DNSSEC(r.Context(), st, z), Registrar: s.registrarFor(z)}
|
||||||
|
if pz := parentInJarl(st, z); pz != nil {
|
||||||
|
resp.ParentZone = pz.Name
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, resp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// parentInJarl returns the primary zone in z's view that z is delegated
|
||||||
|
// from, if Jarl has it.
|
||||||
|
func parentInJarl(st *model.State, z *model.Zone) *model.Zone {
|
||||||
|
var best *model.Zone
|
||||||
|
for _, o := range st.ZonesInView(z.ViewID) {
|
||||||
|
if o.ID == z.ID || o.Type != model.ZonePrimary || o.Name == z.Name || !dnsname.IsSubdomain(z.Name, o.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if best == nil || len(o.Name) > len(best.Name) {
|
||||||
|
best = o
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best
|
||||||
|
}
|
||||||
|
|
||||||
|
// dsChecker returns the checker for parent DS lookups, with ?resolver=IP.
|
||||||
|
func (s *Server) dsChecker(r *http.Request) (*nscheck.Checker, error) {
|
||||||
|
c := s.checker()
|
||||||
|
if v := r.URL.Query().Get("resolver"); v != "" {
|
||||||
|
a, err := netip.ParseAddr(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, badRequest("resolver must be an IP address, e.g. 1.1.1.1 or 9.9.9.9")
|
||||||
|
}
|
||||||
|
c.Resolver = net.JoinHostPort(a.String(), "53")
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) zoneCheckDS(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
st, err := s.state(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
z, err := s.zoneByPath(r, st, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := require(p, auth.Action{Resource: auth.ResZones, Write: true, Zone: z.Name, View: st.ViewName(z)}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
return badRequest("only primary zones are signed by Jarl (this is a %s zone)", z.Type)
|
||||||
|
}
|
||||||
|
c, err := s.dsChecker(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
resp := api.CheckDSResponse{Parent: c.ParentDS(ctx, z.Name), Marked: []string{}, Notes: []string{}}
|
||||||
|
status := s.eng.DNSSEC(ctx, st, z)
|
||||||
|
if resp.Parent.Error == "" {
|
||||||
|
pub, wd := dsChanges(z, status.Keys, resp.Parent)
|
||||||
|
if len(pub)+len(wd) > 0 {
|
||||||
|
marked, err := s.eng.MarkDS(ctx, st, z, p, pub, wd)
|
||||||
|
resp.Marked = append(resp.Marked, marked...)
|
||||||
|
if err != nil {
|
||||||
|
resp.Notes = append(resp.Notes, "telling named failed: "+err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !resp.Parent.Consistent {
|
||||||
|
resp.Notes = append(resp.Notes, "The parent's servers don't all have the same DS records yet; named is only told once they agree. Check again in a while.")
|
||||||
|
}
|
||||||
|
if len(resp.Marked) == 0 {
|
||||||
|
resp.Notes = append(resp.Notes, "Nothing new: named already knows what the parent has.")
|
||||||
|
}
|
||||||
|
status = s.eng.DNSSEC(ctx, st, z)
|
||||||
|
} else {
|
||||||
|
resp.Notes = append(resp.Notes, "The parent zone couldn't be checked, so named wasn't told anything.")
|
||||||
|
}
|
||||||
|
resp.Status = status
|
||||||
|
writeJSON(w, http.StatusOK, resp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dsChanges works out what named should be told after a DS check: keys
|
||||||
|
// whose DS every parent server now has (published), and keys whose DS no
|
||||||
|
// parent server has any more, when they're on their way out (withdrawn).
|
||||||
|
// A signed zone without a DS yet is simply waiting for one: nothing is
|
||||||
|
// withdrawn for it.
|
||||||
|
func dsChanges(z *model.Zone, keys []*dnssec.Key, pr *nscheck.ParentDSReport) (published, withdrawn []*dnssec.Key) {
|
||||||
|
for _, k := range keys {
|
||||||
|
if !k.SigningKey() || k.DS == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
leaving := z.DNSSECPolicy == model.DNSSECInsecure || k.Goal == dnssec.Hidden
|
||||||
|
switch {
|
||||||
|
case !leaving && k.DSState != dnssec.Omnipresent && k.DSPublished == nil && pr.AllHaveDS(k.Tag, k.DS.Digest):
|
||||||
|
published = append(published, k)
|
||||||
|
case leaving && k.DSState != dnssec.Hidden && k.DSRemoved == nil && !pr.HasDS(k.Tag, k.DS.Digest):
|
||||||
|
withdrawn = append(withdrawn, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return published, withdrawn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) zoneDNSSECWipe(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
if err := requireAdmin(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
st, err := s.state(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
z, err := s.zoneByPath(r, st, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var in api.DNSSECWipe
|
||||||
|
if err := decodeOptional(r, &in); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if queryBool(r, "dry_run") {
|
||||||
|
in.DryRun = true
|
||||||
|
}
|
||||||
|
c, err := s.dsChecker(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
// The one thing that must not happen: the zone goes unsigned while
|
||||||
|
// resolvers can still get a DS record for it.
|
||||||
|
pr := c.ParentDS(ctx, z.Name)
|
||||||
|
if len(pr.DS) > 0 {
|
||||||
|
var tags []string
|
||||||
|
for _, d := range pr.DS {
|
||||||
|
tags = append(tags, fmt.Sprint(d.KeyTag))
|
||||||
|
}
|
||||||
|
return conflict("the parent zone %s still has a DS record for %s (key %s): wiping now would make validating resolvers reject the whole domain. Remove the DS at your registrar first and wait for its TTL to pass (or turn DNSSEC off step by step: jarl zone dnssec disable)", dnsname.Display(pr.Parent), dnsname.Display(z.Name), strings.Join(tags, ", "))
|
||||||
|
}
|
||||||
|
if pr.Error != "" && !in.Force {
|
||||||
|
return conflict("couldn't check that the parent zone has no DS record for %s: %s. If the zone isn't on the internet (or you're sure its parent has no DS for it), wipe with force", dnsname.Display(z.Name), pr.Error)
|
||||||
|
}
|
||||||
|
if !in.Force {
|
||||||
|
for _, k := range s.eng.DNSSEC(ctx, st, z).Keys {
|
||||||
|
if k.SigningKey() && k.DSPublished != nil && k.DSState != dnssec.Hidden {
|
||||||
|
return conflict("the parent's DS record for key %d is gone, but resolvers may still have it cached (named counts until its TTL has passed); wait until 'jarl zone dnssec status' no longer shows it, or wipe with force", k.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res, err := s.eng.WipeDNSSEC(r.Context(), z.ID, p, via(r, p), engine.ApplyOptions{DryRun: in.DryRun})
|
||||||
|
if err != nil {
|
||||||
|
if res != nil && res.Result != nil {
|
||||||
|
s.writeErr(w, r, err, res.Result)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out := api.DNSSECWipeResponse{Removed: res.Removed, DryRun: res.DryRun}
|
||||||
|
if pr.Error == "" {
|
||||||
|
out.Parent = pr
|
||||||
|
}
|
||||||
|
if res.Result != nil {
|
||||||
|
out.ChangesetID = res.Result.ChangesetID
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, out)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"jarl/internal/api"
|
"jarl/internal/api"
|
||||||
"jarl/internal/auth"
|
"jarl/internal/auth"
|
||||||
"jarl/internal/dnsname"
|
"jarl/internal/dnsname"
|
||||||
|
"jarl/internal/dnssec"
|
||||||
"jarl/internal/model"
|
"jarl/internal/model"
|
||||||
"jarl/internal/namedconf"
|
"jarl/internal/namedconf"
|
||||||
"jarl/internal/nscheck"
|
"jarl/internal/nscheck"
|
||||||
@@ -61,6 +62,11 @@ func (s *Server) zoneSerials(w http.ResponseWriter, r *http.Request, p *auth.Pri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Notes = append(resp.Notes, "named on this server didn't report the zone's serial: "+err.Error())
|
resp.Notes = append(resp.Notes, "named on this server didn't report the zone's serial: "+err.Error())
|
||||||
}
|
}
|
||||||
|
if z.Signed() && resp.SerialSource == "jarl" {
|
||||||
|
// named gives the signed zone its own serial, ahead of Jarl's.
|
||||||
|
resp.Notes = append(resp.Notes, "The zone is signed and named wasn't asked: other servers serve the signed zone's serial, which named sets and which is usually ahead of Jarl's.")
|
||||||
|
resp.Serial = nil
|
||||||
|
}
|
||||||
if len(targets) == 0 {
|
if len(targets) == 0 {
|
||||||
if z.Type == model.ZonePrimary {
|
if z.Type == model.ZonePrimary {
|
||||||
resp.Notes = append(resp.Notes, "The zone has no NS records or also-notify targets to check.")
|
resp.Notes = append(resp.Notes, "The zone has no NS records or also-notify targets to check.")
|
||||||
@@ -116,7 +122,7 @@ func (s *Server) zoneDelegation(w http.ResponseWriter, r *http.Request, p *auth.
|
|||||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ref, _, _ := s.localSerial(ctx, st, z)
|
ref, _, _ := s.localSerial(ctx, st, z)
|
||||||
resp := api.DelegationResponse{DelegationReport: c.Delegation(ctx, z.Name, ns, addrs, ref), View: st.ViewName(z), Notes: []string{}, CheckedAt: time.Now()}
|
resp := api.DelegationResponse{DelegationReport: c.Delegation(ctx, z.Name, ns, addrs, ref, s.signing(ctx, st, z)), View: st.ViewName(z), Notes: []string{}, CheckedAt: time.Now()}
|
||||||
if resp.View != "" {
|
if resp.View != "" {
|
||||||
resp.Notes = append(resp.Notes, fmt.Sprintf("Compared with the zone in view %s. Resolvers on the internet get the view that matches their address; make sure that's this one.", resp.View))
|
resp.Notes = append(resp.Notes, fmt.Sprintf("Compared with the zone in view %s. Resolvers on the internet get the view that matches their address; make sure that's this one.", resp.View))
|
||||||
}
|
}
|
||||||
@@ -124,6 +130,18 @@ func (s *Server) zoneDelegation(w http.ResponseWriter, r *http.Request, p *auth.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// signing describes how Jarl signs z, for comparing with the parent's DS
|
||||||
|
// records: the DS of every key-signing key named still publishes.
|
||||||
|
func (s *Server) signing(ctx context.Context, st *model.State, z *model.Zone) *nscheck.Signing {
|
||||||
|
sig := &nscheck.Signing{Policy: z.DNSSECPolicy}
|
||||||
|
for _, k := range s.eng.DNSSEC(ctx, st, z).Keys {
|
||||||
|
if k.DS != nil && k.DNSKEYState != dnssec.Hidden {
|
||||||
|
sig.DS = append(sig.DS, *k.DS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sig
|
||||||
|
}
|
||||||
|
|
||||||
// localSerial is the serial this server serves for z: named's, or for a
|
// localSerial is the serial this server serves for z: named's, or for a
|
||||||
// primary zone Jarl's when named isn't asked.
|
// primary zone Jarl's when named isn't asked.
|
||||||
func (s *Server) localSerial(ctx context.Context, st *model.State, z *model.Zone) (*uint32, string, error) {
|
func (s *Server) localSerial(ctx context.Context, st *model.State, z *model.Zone) (*uint32, string, error) {
|
||||||
|
|||||||
@@ -0,0 +1,587 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
// The registrar (docs/dnssec.md#porkbun): a domain's name servers, glue
|
||||||
|
// records and DNSSEC DS records at Porkbun, next to what the zone in Jarl
|
||||||
|
// says.
|
||||||
|
//
|
||||||
|
// GET /zones/{zone}/registrar
|
||||||
|
// POST /zones/{zone}/registrar/glue create or update glue records
|
||||||
|
// POST /zones/{zone}/registrar/ds publish the zone's DS record
|
||||||
|
// DELETE /zones/{zone}/registrar/ds/{keytag} remove a DS record
|
||||||
|
// PUT /zones/{zone}/registrar/ns set the domain's name servers
|
||||||
|
//
|
||||||
|
// All of them need an administrator: the API key can move the domain
|
||||||
|
// anywhere. Every change first checks that it won't break the domain
|
||||||
|
// (errors refuse it unless forced), and a dry run returns those checks
|
||||||
|
// without changing anything.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/netip"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"jarl/internal/api"
|
||||||
|
"jarl/internal/auth"
|
||||||
|
"jarl/internal/dnsname"
|
||||||
|
"jarl/internal/dnssec"
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/nscheck"
|
||||||
|
"jarl/internal/porkbun"
|
||||||
|
)
|
||||||
|
|
||||||
|
// registrarFor names the registrar Jarl can manage z's delegation at:
|
||||||
|
// "porkbun" when a key is configured and allows the zone's name.
|
||||||
|
func (s *Server) registrarFor(z *model.Zone) string {
|
||||||
|
if s.cfg.Porkbun == nil || z.Type != model.ZonePrimary {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if s.cfg.PorkbunAllows != nil && !s.cfg.PorkbunAllows(dnsname.Display(z.Name)) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "porkbun"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarZone(r *http.Request, p *auth.Principal) (*model.State, *model.Zone, string, error) {
|
||||||
|
if err := requireAdmin(p); err != nil {
|
||||||
|
return nil, nil, "", err
|
||||||
|
}
|
||||||
|
st, err := s.state(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, "", err
|
||||||
|
}
|
||||||
|
z, err := s.zoneByPath(r, st, p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, "", err
|
||||||
|
}
|
||||||
|
if s.registrarFor(z) == "" {
|
||||||
|
if s.cfg.Porkbun == nil {
|
||||||
|
return nil, nil, "", badRequest("no registrar is configured: add a Porkbun API key to jarl.yaml (porkbun:, see docs/dnssec.md#porkbun)")
|
||||||
|
}
|
||||||
|
return nil, nil, "", badRequest("Jarl may not manage %s at Porkbun (only primary zones listed in porkbun.domains in jarl.yaml)", dnsname.Display(z.Name))
|
||||||
|
}
|
||||||
|
return st, z, dnsname.Display(z.Name), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lowerNoDot(n string) string { return strings.ToLower(strings.TrimSuffix(n, ".")) }
|
||||||
|
|
||||||
|
// zoneNS returns the zone's apex NS records, as lowercase names without
|
||||||
|
// trailing dots.
|
||||||
|
func zoneNS(st *model.State, z *model.Zone) []string {
|
||||||
|
var out []string
|
||||||
|
for _, rec := range st.ZoneRecords(z.ID) {
|
||||||
|
if rec.Type == "NS" && rec.Name == z.Name {
|
||||||
|
out = append(out, lowerNoDot(rec.Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func sameSet(a, b []string) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
x := append([]string{}, a...)
|
||||||
|
y := append([]string{}, b...)
|
||||||
|
sort.Strings(x)
|
||||||
|
sort.Strings(y)
|
||||||
|
return strings.Join(x, " ") == strings.Join(y, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// registrarState asks the registrar about the domain and compares that
|
||||||
|
// with the zone.
|
||||||
|
func (s *Server) registrarState(ctx context.Context, st *model.State, z *model.Zone, domain string, sig *dnssec.Status) *api.RegistrarResponse {
|
||||||
|
resp := &api.RegistrarResponse{Registrar: "porkbun", Domain: domain, NS: []string{}, JarlNS: zoneNS(st, z), Glue: []api.GlueStatus{}, DS: []api.RegistrarDS{}, Findings: []nscheck.Finding{}}
|
||||||
|
if resp.JarlNS == nil {
|
||||||
|
resp.JarlNS = []string{}
|
||||||
|
}
|
||||||
|
pb := s.cfg.Porkbun
|
||||||
|
ns, err := pb.NS(ctx, domain)
|
||||||
|
if err != nil {
|
||||||
|
resp.Error = err.Error()
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
glue, err := pb.Glue(ctx, domain)
|
||||||
|
if err != nil {
|
||||||
|
resp.Error = err.Error()
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
ds, err := pb.DS(ctx, domain)
|
||||||
|
if err != nil {
|
||||||
|
resp.Error = err.Error()
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
resp.NS = ns
|
||||||
|
resp.NSMatch = sameSet(ns, resp.JarlNS)
|
||||||
|
add := func(level, format string, args ...any) {
|
||||||
|
resp.Findings = append(resp.Findings, nscheck.Finding{Level: level, Message: fmt.Sprintf(format, args...)})
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case resp.NSMatch:
|
||||||
|
add("ok", "Porkbun delegates %s to the zone's name servers: %s.", domain, strings.Join(ns, ", "))
|
||||||
|
case len(resp.JarlNS) == 0:
|
||||||
|
add("warning", "The zone has no NS records.")
|
||||||
|
default:
|
||||||
|
add("warning", "Porkbun delegates %s to %s, but the zone's NS records are %s.", domain, strings.Join(ns, ", "), strings.Join(resp.JarlNS, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Glue: every host at the registry, and every name server inside the
|
||||||
|
// domain (which resolvers can only find through its glue).
|
||||||
|
byHost := map[string]*api.GlueStatus{}
|
||||||
|
var order []string
|
||||||
|
get := func(host string) *api.GlueStatus {
|
||||||
|
if g := byHost[host]; g != nil {
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
g := &api.GlueStatus{Host: host, Registry: []string{}, Jarl: []string{}}
|
||||||
|
byHost[host] = g
|
||||||
|
order = append(order, host)
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
for _, g := range glue {
|
||||||
|
get(g.Host).Registry = canonAddrs(g.Addresses())
|
||||||
|
}
|
||||||
|
for _, n := range resp.JarlNS {
|
||||||
|
if n == domain || !dnsname.IsSubdomain(dnsname.Fqdn(n), z.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
g := get(n)
|
||||||
|
g.Needed = true
|
||||||
|
g.Jarl = canonAddrs(jarlAddresses(st, z.ViewID, dnsname.Fqdn(n)))
|
||||||
|
switch {
|
||||||
|
case len(g.Registry) == 0:
|
||||||
|
g.Action = "create"
|
||||||
|
case !sameSet(g.Registry, g.Jarl) && len(g.Jarl) > 0:
|
||||||
|
g.Action = "update"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(order)
|
||||||
|
for _, h := range order {
|
||||||
|
g := byHost[h]
|
||||||
|
for _, n := range ns {
|
||||||
|
if n == h {
|
||||||
|
g.InUse = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.Glue = append(resp.Glue, *g)
|
||||||
|
switch {
|
||||||
|
case g.Needed && len(g.Jarl) == 0:
|
||||||
|
add("error", "%s is one of the zone's name servers, inside the domain, but the zone has no A or AAAA record for it; add one, then sync the glue.", h)
|
||||||
|
case g.Action == "create":
|
||||||
|
add("warning", "%s has no glue record at Porkbun, so resolvers can't find it once the domain is delegated to it. Sync the glue (%s).", h, strings.Join(g.Jarl, ", "))
|
||||||
|
case g.Action == "update":
|
||||||
|
add("warning", "The glue for %s at Porkbun is %s, but the zone says %s. Sync the glue.", h, strings.Join(g.Registry, ", "), strings.Join(g.Jarl, ", "))
|
||||||
|
case g.Needed:
|
||||||
|
add("ok", "The glue for %s matches the zone (%s).", h, strings.Join(g.Jarl, ", "))
|
||||||
|
case !g.InUse:
|
||||||
|
add("info", "Porkbun has a glue record for %s (%s), which the zone's NS records don't use.", h, strings.Join(g.Registry, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DS records.
|
||||||
|
live := publishedDS(sig)
|
||||||
|
var good, stale []string
|
||||||
|
for _, d := range ds {
|
||||||
|
rd := api.RegistrarDS{DS: d}
|
||||||
|
for _, k := range live {
|
||||||
|
if k.KeyTag == d.KeyTag && k.Algorithm == d.Algorithm && k.DigestType == d.DigestType && strings.EqualFold(k.Digest, d.Digest) {
|
||||||
|
rd.Matches = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.DS = append(resp.DS, rd)
|
||||||
|
if rd.Matches {
|
||||||
|
good = append(good, strconv.Itoa(int(d.KeyTag)))
|
||||||
|
} else {
|
||||||
|
stale = append(stale, strconv.Itoa(int(d.KeyTag)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signed := sig != nil && sig.Policy != "" && sig.Policy != model.DNSSECInsecure
|
||||||
|
switch {
|
||||||
|
case len(ds) == 0 && signed && sig.Phase.CanPublishDS:
|
||||||
|
add("info", "The zone is signed and ready: publish its DS record at Porkbun to turn validation on.")
|
||||||
|
case len(ds) == 0 && signed:
|
||||||
|
add("info", "The zone is signed; its DS record can be published once named says it's ready (DNSSEC tab).")
|
||||||
|
case len(ds) > 0 && (sig == nil || sig.Policy == ""):
|
||||||
|
add("error", "Porkbun has a DS record for %s (key %s), but the zone isn't signed: validating resolvers reject the domain. Remove the DS record.", domain, strings.Join(stale, ", "))
|
||||||
|
case len(ds) > 0 && len(good) == 0:
|
||||||
|
add("error", "Porkbun's DS record (key %s) matches none of the zone's keys: validating resolvers reject the domain. Replace it with the zone's DS record.", strings.Join(stale, ", "))
|
||||||
|
case len(ds) > 0 && sig.Policy == model.DNSSECInsecure:
|
||||||
|
add("warning", "DNSSEC is being turned off: remove the DS record (key %s) at Porkbun, then run the DS check.", strings.Join(good, ", "))
|
||||||
|
case len(good) > 0:
|
||||||
|
add("ok", "Porkbun's DS record matches the zone's key %s.", strings.Join(good, ", "))
|
||||||
|
if len(stale) > 0 {
|
||||||
|
add("warning", "Porkbun also has a DS record for key %s, which the zone doesn't have any more; remove it.", strings.Join(stale, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
// publishedDS returns the DS records of the key-signing keys named
|
||||||
|
// publishes for the zone.
|
||||||
|
func publishedDS(sig *dnssec.Status) []dnssec.DS {
|
||||||
|
if sig == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var out []dnssec.DS
|
||||||
|
for _, k := range sig.Keys {
|
||||||
|
if k.DS != nil && k.DNSKEYState != dnssec.Hidden {
|
||||||
|
out = append(out, *k.DS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func canonAddrs(addrs []string) []string {
|
||||||
|
out := []string{}
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for _, a := range addrs {
|
||||||
|
if v, err := netip.ParseAddr(a); err == nil && !seen[v.String()] {
|
||||||
|
seen[v.String()] = true
|
||||||
|
out = append(out, v.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) zoneRegistrar(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
st, z, domain, err := s.registrarZone(r, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(r.Context(), 45*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
writeJSON(w, http.StatusOK, s.registrarState(ctx, st, z, domain, s.eng.DNSSEC(ctx, st, z)))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// changeCtx holds what a registrar change needs.
|
||||||
|
type changeCtx struct {
|
||||||
|
st *model.State
|
||||||
|
z *model.Zone
|
||||||
|
domain string
|
||||||
|
in api.RegistrarChange
|
||||||
|
sig *dnssec.Status
|
||||||
|
cur *api.RegistrarResponse
|
||||||
|
out api.RegistrarChangeResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *changeCtx) check(level, format string, args ...any) {
|
||||||
|
c.out.Checks = append(c.out.Checks, nscheck.Finding{Level: level, Message: fmt.Sprintf(format, args...)})
|
||||||
|
}
|
||||||
|
|
||||||
|
// blocked returns the error that refuses the change when a check failed
|
||||||
|
// (unless forced).
|
||||||
|
func (c *changeCtx) blocked() error {
|
||||||
|
if c.in.Force || c.in.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var errs []string
|
||||||
|
for _, f := range c.out.Checks {
|
||||||
|
if f.Level == "error" {
|
||||||
|
errs = append(errs, f.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(errs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return conflict("not changed, because it could break the domain: %s (force overrides this check)", strings.Join(errs, " "))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarChange(w http.ResponseWriter, r *http.Request, p *auth.Principal, body bool, run func(ctx context.Context, c *changeCtx) error) error {
|
||||||
|
st, z, domain, err := s.registrarZone(r, p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c := &changeCtx{st: st, z: z, domain: domain, out: api.RegistrarChangeResponse{Done: []string{}, Checks: []nscheck.Finding{}, Warnings: []string{}}}
|
||||||
|
if body {
|
||||||
|
if err := decodeOptional(r, &c.in); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if queryBool(r, "dry_run") {
|
||||||
|
c.in.DryRun = true
|
||||||
|
}
|
||||||
|
if queryBool(r, "force") {
|
||||||
|
c.in.Force = true
|
||||||
|
}
|
||||||
|
c.out.DryRun = c.in.DryRun
|
||||||
|
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
c.sig = s.eng.DNSSEC(ctx, st, z)
|
||||||
|
c.cur = s.registrarState(ctx, st, z, domain, c.sig)
|
||||||
|
if c.cur.Error != "" {
|
||||||
|
return &httpError{http.StatusBadGateway, "registrar_error", c.cur.Error}
|
||||||
|
}
|
||||||
|
if err := run(ctx, c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, c.out)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) audit(ctx context.Context, p *auth.Principal, c *changeCtx, action, msg string) {
|
||||||
|
s.eng.Audit(ctx, p, action, "zone", c.z.ID, dnsname.Display(c.z.Name), "success", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// serving checks that the name servers answer authoritatively for the
|
||||||
|
// zone with the serial this server serves (for a signed zone, the signed
|
||||||
|
// serial: so they serve the signed zone).
|
||||||
|
func (s *Server) serving(ctx context.Context, c *changeCtx, targets []nscheck.Target, why string) {
|
||||||
|
ref, _, _ := s.localSerial(ctx, c.st, c.z)
|
||||||
|
for _, res := range s.checker().Serials(ctx, c.z.Name, ref, targets) {
|
||||||
|
where := dnsname.Display(res.Name)
|
||||||
|
if res.Address != "" {
|
||||||
|
where += " (" + res.Address + ")"
|
||||||
|
}
|
||||||
|
switch res.Status {
|
||||||
|
case "self", "in_sync":
|
||||||
|
case "answered":
|
||||||
|
c.check("warning", "%s answers for the zone, but its serial couldn't be compared with this server's.", where)
|
||||||
|
case "behind", "ahead":
|
||||||
|
c.check("error", "%s serves serial %d, not this server's %d; %s.", where, *res.Serial, *ref, why)
|
||||||
|
default:
|
||||||
|
msg := res.Status
|
||||||
|
if res.Error != "" {
|
||||||
|
msg += ": " + res.Error
|
||||||
|
}
|
||||||
|
c.check("error", "%s doesn't serve the zone (%s); %s.", where, msg, why)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// targetsFor returns check targets for name servers: in-domain ones at
|
||||||
|
// the given addresses, others looked up.
|
||||||
|
func targetsFor(names []string, addrs map[string][]string) []nscheck.Target {
|
||||||
|
var out []nscheck.Target
|
||||||
|
for _, n := range names {
|
||||||
|
out = append(out, nscheck.Target{Name: dnsname.Fqdn(n), Addresses: addrs[n], Source: "name server"})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarSyncGlue(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
return s.registrarChange(w, r, p, true, func(ctx context.Context, c *changeCtx) error {
|
||||||
|
var todo []api.GlueStatus
|
||||||
|
for _, g := range c.cur.Glue {
|
||||||
|
if !g.Needed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(g.Jarl) == 0 {
|
||||||
|
c.check("error", "%s has no A or AAAA record in the zone, so there is no address to give its glue.", g.Host)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if g.Action == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
todo = append(todo, g)
|
||||||
|
if g.Action == "update" && g.InUse {
|
||||||
|
// Resolvers go to the new addresses at once.
|
||||||
|
s.serving(ctx, c, []nscheck.Target{{Name: dnsname.Fqdn(g.Host), Addresses: g.Jarl, Source: "glue"}}, "the domain is delegated to "+g.Host+", so resolvers would go there")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(todo) == 0 && len(c.out.Checks) == 0 {
|
||||||
|
c.check("ok", "The glue records at Porkbun already match the zone.")
|
||||||
|
}
|
||||||
|
if err := c.blocked(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, g := range todo {
|
||||||
|
what := fmt.Sprintf("%s glue for %s: %s", map[string]string{"create": "create", "update": "update"}[g.Action], g.Host, strings.Join(g.Jarl, ", "))
|
||||||
|
if !c.in.DryRun {
|
||||||
|
if err := s.cfg.Porkbun.SetGlue(ctx, c.domain, g.Host, g.Jarl, g.Action == "update"); err != nil {
|
||||||
|
return &httpError{http.StatusBadGateway, "registrar_error", fmt.Sprintf("%v (done before that: %s)", err, strings.Join(c.out.Done, "; "))}
|
||||||
|
}
|
||||||
|
s.audit(ctx, p, c, "registrar.glue", what)
|
||||||
|
}
|
||||||
|
c.out.Done = append(c.out.Done, what)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarPublishDS(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
return s.registrarChange(w, r, p, true, func(ctx context.Context, c *changeCtx) error {
|
||||||
|
sig := c.sig
|
||||||
|
if sig.Policy == "" || sig.Policy == model.DNSSECInsecure {
|
||||||
|
return conflict("the zone isn't signed (or DNSSEC is being turned off), so it has no DS record to publish")
|
||||||
|
}
|
||||||
|
var keys []*dnssec.Key
|
||||||
|
for _, k := range sig.Keys {
|
||||||
|
if k.DS != nil && k.Goal == dnssec.Omnipresent && (c.in.KeyTag == 0 || k.Tag == c.in.KeyTag) {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(keys) == 0 {
|
||||||
|
return conflict("no key to publish a DS record for (named hasn't made the zone's key yet, or there is no key %d)", c.in.KeyTag)
|
||||||
|
}
|
||||||
|
if !sig.Phase.CanPublishDS {
|
||||||
|
c.check("error", "Not yet: %s", sig.Phase.Next)
|
||||||
|
}
|
||||||
|
// The DS turns validation on: whatever the domain is delegated
|
||||||
|
// to must serve this signed zone.
|
||||||
|
if !c.cur.NSMatch {
|
||||||
|
c.check("error", "Porkbun delegates the domain to %s, not to the zone's name servers (%s): validating resolvers would reject the answers of servers that don't serve this signed zone. Set the name servers first.", strings.Join(c.cur.NS, ", "), strings.Join(c.cur.JarlNS, ", "))
|
||||||
|
} else {
|
||||||
|
glue := map[string][]string{}
|
||||||
|
for _, g := range c.cur.Glue {
|
||||||
|
glue[g.Host] = g.Registry
|
||||||
|
}
|
||||||
|
s.serving(ctx, c, targetsFor(c.cur.NS, glue), "validating resolvers would reject its answers once the DS is published")
|
||||||
|
}
|
||||||
|
if err := c.blocked(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, k := range keys {
|
||||||
|
already := false
|
||||||
|
for _, d := range c.cur.DS {
|
||||||
|
if d.Matches && d.KeyTag == k.Tag {
|
||||||
|
already = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if already {
|
||||||
|
c.out.Warnings = append(c.out.Warnings, fmt.Sprintf("Porkbun already has the DS record for key %d.", k.Tag))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
what := fmt.Sprintf("publish the DS record for key %d (algorithm %d, digest type %d)", k.Tag, k.DS.Algorithm, k.DS.DigestType)
|
||||||
|
if !c.in.DryRun {
|
||||||
|
warns, err := s.cfg.Porkbun.AddDS(ctx, c.domain, porkbun.DS{KeyTag: k.DS.KeyTag, Algorithm: k.DS.Algorithm, DigestType: k.DS.DigestType, Digest: k.DS.Digest})
|
||||||
|
if err != nil {
|
||||||
|
return &httpError{http.StatusBadGateway, "registrar_error", err.Error()}
|
||||||
|
}
|
||||||
|
c.out.Warnings = append(c.out.Warnings, warns...)
|
||||||
|
s.audit(ctx, p, c, "registrar.ds.add", what)
|
||||||
|
}
|
||||||
|
c.out.Done = append(c.out.Done, what)
|
||||||
|
}
|
||||||
|
if len(c.out.Done) > 0 && !c.in.DryRun {
|
||||||
|
c.out.Warnings = append(c.out.Warnings, "The registry publishes it in the parent zone within minutes to hours; then run the DS check (jarl zone dnssec check-ds) so named knows.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarRemoveDS(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
tag, err := strconv.ParseUint(r.PathValue("keytag"), 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return badRequest("invalid key tag %q", r.PathValue("keytag"))
|
||||||
|
}
|
||||||
|
return s.registrarChange(w, r, p, false, func(ctx context.Context, c *changeCtx) error {
|
||||||
|
var found *api.RegistrarDS
|
||||||
|
for i := range c.cur.DS {
|
||||||
|
if c.cur.DS[i].KeyTag == uint16(tag) {
|
||||||
|
found = &c.cur.DS[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found == nil {
|
||||||
|
return notFound("Porkbun has no DS record for key %d", tag)
|
||||||
|
}
|
||||||
|
if found.Matches && c.sig.Policy != "" && c.sig.Policy != model.DNSSECInsecure {
|
||||||
|
c.check("warning", "This DS record points at the zone's key: without it, resolvers stop validating the domain (the zone stays signed). To turn DNSSEC off, start with 'Turn signing off' so named removes its signatures safely afterwards.")
|
||||||
|
}
|
||||||
|
c.check("info", "Porkbun notes that most registries delete every DS record with the same key data.")
|
||||||
|
what := fmt.Sprintf("remove the DS record for key %d", tag)
|
||||||
|
if !c.in.DryRun {
|
||||||
|
if err := s.cfg.Porkbun.DeleteDS(ctx, c.domain, uint16(tag)); err != nil {
|
||||||
|
return &httpError{http.StatusBadGateway, "registrar_error", err.Error()}
|
||||||
|
}
|
||||||
|
s.audit(ctx, p, c, "registrar.ds.delete", what)
|
||||||
|
c.out.Warnings = append(c.out.Warnings, "Resolvers may keep the DS cached for its TTL (often a day). If DNSSEC is being turned off, run the DS check once the parent zone no longer has it.")
|
||||||
|
}
|
||||||
|
c.out.Done = append(c.out.Done, what)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) registrarSetNS(w http.ResponseWriter, r *http.Request, p *auth.Principal) error {
|
||||||
|
return s.registrarChange(w, r, p, true, func(ctx context.Context, c *changeCtx) error {
|
||||||
|
target := c.cur.JarlNS
|
||||||
|
if len(c.in.NS) > 0 {
|
||||||
|
target = nil
|
||||||
|
for _, n := range c.in.NS {
|
||||||
|
n = lowerNoDot(n)
|
||||||
|
if !dnsname.IsHostname(dnsname.Fqdn(n), false) {
|
||||||
|
return badRequest("%q isn't a host name", n)
|
||||||
|
}
|
||||||
|
target = append(target, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(target) == 0 {
|
||||||
|
return badRequest("no name servers to set: the zone has no NS records")
|
||||||
|
}
|
||||||
|
if sameSet(target, c.cur.NS) {
|
||||||
|
c.check("ok", "Porkbun already delegates the domain to %s.", strings.Join(target, ", "))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(target) < 2 {
|
||||||
|
c.check("warning", "Only one name server: when it can't be reached, the domain can't be resolved at all. Registries and RFC 1034 expect at least two (a secondary on another network).")
|
||||||
|
}
|
||||||
|
if !sameSet(target, c.cur.JarlNS) {
|
||||||
|
c.check("warning", "These aren't the zone's NS records (%s); resolvers prefer the zone's own list once they reach it.", strings.Join(c.cur.JarlNS, ", "))
|
||||||
|
}
|
||||||
|
// In-domain servers need glue at the registry.
|
||||||
|
addrs := map[string][]string{}
|
||||||
|
for _, n := range target {
|
||||||
|
if !dnsname.IsSubdomain(dnsname.Fqdn(n), c.z.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var g *api.GlueStatus
|
||||||
|
for i := range c.cur.Glue {
|
||||||
|
if c.cur.Glue[i].Host == n {
|
||||||
|
g = &c.cur.Glue[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case g == nil || len(g.Registry) == 0:
|
||||||
|
c.check("error", "%s is inside the domain but has no glue record at Porkbun, so resolvers couldn't find it. Sync the glue first.", n)
|
||||||
|
case len(g.Jarl) > 0 && !sameSet(g.Registry, g.Jarl):
|
||||||
|
c.check("error", "The glue for %s at Porkbun (%s) differs from the zone (%s). Sync the glue first.", n, strings.Join(g.Registry, ", "), strings.Join(g.Jarl, ", "))
|
||||||
|
default:
|
||||||
|
addrs[n] = g.Registry
|
||||||
|
}
|
||||||
|
if addrs[n] == nil {
|
||||||
|
// Check the addresses the glue will have.
|
||||||
|
addrs[n] = canonAddrs(jarlAddresses(c.st, c.z.ViewID, dnsname.Fqdn(n)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Every new server must serve the zone...
|
||||||
|
s.serving(ctx, c, targetsFor(target, addrs), "resolvers would be sent there")
|
||||||
|
// ...and match the DS records at the registry, or the domain goes
|
||||||
|
// dark for validating resolvers.
|
||||||
|
if len(c.cur.DS) > 0 {
|
||||||
|
matches := false
|
||||||
|
for _, d := range c.cur.DS {
|
||||||
|
matches = matches || d.Matches
|
||||||
|
}
|
||||||
|
if !matches {
|
||||||
|
c.check("error", "Porkbun has DS records for the domain (key %s), and the zone's keys don't match them: validating resolvers would reject every answer from the new name servers. Remove the DS records first (or publish the zone's own).", dsTags(c.cur.DS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := c.blocked(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
what := "set the name servers to " + strings.Join(target, ", ")
|
||||||
|
if !c.in.DryRun {
|
||||||
|
if err := s.cfg.Porkbun.SetNS(ctx, c.domain, target); err != nil {
|
||||||
|
return &httpError{http.StatusBadGateway, "registrar_error", err.Error()}
|
||||||
|
}
|
||||||
|
s.audit(ctx, p, c, "registrar.ns", what+" (was "+strings.Join(c.cur.NS, ", ")+")")
|
||||||
|
c.out.Warnings = append(c.out.Warnings, "Resolvers may keep using the old name servers for the parent's NS TTL (often a day or two); keep them serving the zone until then.")
|
||||||
|
}
|
||||||
|
c.out.Done = append(c.out.Done, what)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func dsTags(ds []api.RegistrarDS) string {
|
||||||
|
var s []string
|
||||||
|
for _, d := range ds {
|
||||||
|
s = append(s, strconv.Itoa(int(d.KeyTag)))
|
||||||
|
}
|
||||||
|
return strings.Join(s, ", ")
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ func (s *Server) presentZone(st *model.State, z *model.Zone, counts map[int64]in
|
|||||||
if z.Type == model.ZonePrimary {
|
if z.Type == model.ZonePrimary {
|
||||||
out.RName = dnsname.EmailFromMailbox(z.SOA.RName)
|
out.RName = dnsname.EmailFromMailbox(z.SOA.RName)
|
||||||
}
|
}
|
||||||
|
out.Registrar = s.registrarFor(z)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/netip"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
|
"jarl/internal/nscheck"
|
||||||
|
"jarl/internal/porkbun"
|
||||||
|
)
|
||||||
|
|
||||||
|
// soaServers answers SOA queries for zone with serial on each address
|
||||||
|
// (all on one port, which it returns).
|
||||||
|
func soaServers(t *testing.T, zone string, serial uint32, addrs ...string) string {
|
||||||
|
t.Helper()
|
||||||
|
port := "0"
|
||||||
|
for _, a := range addrs {
|
||||||
|
pc, err := net.ListenPacket("udp", net.JoinHostPort(a, port))
|
||||||
|
if err != nil {
|
||||||
|
t.Skipf("can't listen on %s: %v", a, err)
|
||||||
|
}
|
||||||
|
_, port, _ = net.SplitHostPort(pc.LocalAddr().String())
|
||||||
|
srv := &dns.Server{PacketConn: pc, Handler: dns.HandlerFunc(func(w dns.ResponseWriter, req *dns.Msg) {
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetReply(req)
|
||||||
|
m.Authoritative = true
|
||||||
|
if req.Question[0].Qtype == dns.TypeSOA {
|
||||||
|
rr, _ := dns.NewRR(zone + " 300 IN SOA ns1." + zone + " h." + zone + " " + strconv.FormatUint(uint64(serial), 10) + " 3600 900 1209600 300")
|
||||||
|
m.Answer = []dns.RR{rr}
|
||||||
|
}
|
||||||
|
w.WriteMsg(m)
|
||||||
|
})}
|
||||||
|
go srv.ActivateAndServe()
|
||||||
|
t.Cleanup(func() { srv.Shutdown() })
|
||||||
|
}
|
||||||
|
return port
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistrar(t *testing.T) {
|
||||||
|
fake := porkbun.NewFake("pk1_a", "sk1_b", "adbraun.lol")
|
||||||
|
pts := httptest.NewServer(fake)
|
||||||
|
t.Cleanup(pts.Close)
|
||||||
|
e := newAPIEnvConfig(t, Config{Version: "test", Porkbun: &porkbun.Client{BaseURL: pts.URL + "/api/json/v3", APIKey: "pk1_a", Secret: "sk1_b"},
|
||||||
|
PorkbunAllows: func(d string) bool { return d == "adbraun.lol" }})
|
||||||
|
e.do("POST", "/zones", e.token, map[string]any{
|
||||||
|
"name": "adbraun.lol", "nameservers": []string{"ns1.adbraun.lol.", "ns2.adbraun.lol."},
|
||||||
|
"records": []map[string]any{
|
||||||
|
{"name": "ns1", "type": "A", "data": "127.0.0.41"}, {"name": "ns1", "type": "AAAA", "data": "::1"},
|
||||||
|
{"name": "ns2", "type": "A", "data": "127.0.0.42"},
|
||||||
|
},
|
||||||
|
}, 201)
|
||||||
|
e.do("POST", "/zones", e.token, map[string]any{"name": "other.lol"}, 201)
|
||||||
|
e.do("GET", "/zones/other.lol/registrar", e.token, nil, 400)
|
||||||
|
|
||||||
|
st := e.do("GET", "/zones/adbraun.lol/registrar", e.token, nil, 200)
|
||||||
|
if st["ns_match"] != false || len(st["glue"].([]any)) != 2 {
|
||||||
|
t.Fatalf("status: %v", st)
|
||||||
|
}
|
||||||
|
for _, g := range st["glue"].([]any) {
|
||||||
|
if g.(map[string]any)["action"] != "create" {
|
||||||
|
t.Errorf("glue: %v", g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Glue: a dry run changes nothing; then both hosts, IPv4 and IPv6.
|
||||||
|
out := e.do("POST", "/zones/adbraun.lol/registrar/glue", e.token, map[string]any{"dry_run": true}, 200)
|
||||||
|
if len(out["done"].([]any)) != 2 || len(fake.Domains["adbraun.lol"].Glue) != 0 {
|
||||||
|
t.Errorf("dry run: %v", out)
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/adbraun.lol/registrar/glue", e.token, nil, 200)
|
||||||
|
g := fake.Domains["adbraun.lol"].Glue
|
||||||
|
sort.Strings(g["ns1.adbraun.lol"])
|
||||||
|
if strings.Join(g["ns1.adbraun.lol"], " ") != "127.0.0.41 ::1" || strings.Join(g["ns2.adbraun.lol"], " ") != "127.0.0.42" {
|
||||||
|
t.Errorf("glue at Porkbun: %v", g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NS: refused while the servers don't answer...
|
||||||
|
e.srv.nsChecker = &nscheck.Checker{Timeout: 200 * time.Millisecond, Port: "1", IsLocal: func(netip.Addr) bool { return false }}
|
||||||
|
out = e.do("PUT", "/zones/adbraun.lol/registrar/ns", e.token, nil, 409)
|
||||||
|
if !strings.Contains(out["error"].(map[string]any)["message"].(string), "doesn't serve the zone") {
|
||||||
|
t.Errorf("set-ns without servers: %v", out)
|
||||||
|
}
|
||||||
|
chk := e.do("PUT", "/zones/adbraun.lol/registrar/ns", e.token, map[string]any{"dry_run": true}, 200)
|
||||||
|
if len(chk["checks"].([]any)) == 0 {
|
||||||
|
t.Errorf("dry run checks: %v", chk)
|
||||||
|
}
|
||||||
|
// ...and allowed once they serve the zone.
|
||||||
|
serial := uint32(e.do("GET", "/zones/adbraun.lol", e.token, nil, 200)["soa"].(map[string]any)["serial"].(float64))
|
||||||
|
port := soaServers(t, "adbraun.lol.", serial, "127.0.0.41", "127.0.0.42", "::1")
|
||||||
|
e.srv.nsChecker.Port = port
|
||||||
|
e.do("PUT", "/zones/adbraun.lol/registrar/ns", e.token, nil, 200)
|
||||||
|
if ns := fake.Domains["adbraun.lol"].NS; strings.Join(ns, " ") != "ns1.adbraun.lol ns2.adbraun.lol" {
|
||||||
|
t.Errorf("NS at Porkbun: %v", ns)
|
||||||
|
}
|
||||||
|
if st = e.do("GET", "/zones/adbraun.lol/registrar", e.token, nil, 200); st["ns_match"] != true {
|
||||||
|
t.Errorf("after set-ns: %v", st)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A DS record for an unsigned zone: reported, removable; and setting
|
||||||
|
// NS while a foreign DS is there is refused.
|
||||||
|
fake.Domains["adbraun.lol"].DS[4242] = porkbun.DS{KeyTag: 4242, Algorithm: 13, DigestType: 2, Digest: "AB"}
|
||||||
|
st = e.do("GET", "/zones/adbraun.lol/registrar", e.token, nil, 200)
|
||||||
|
found := false
|
||||||
|
for _, f := range st["findings"].([]any) {
|
||||||
|
if f.(map[string]any)["level"] == "error" && strings.Contains(f.(map[string]any)["message"].(string), "isn't signed") {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Errorf("DS on an unsigned zone not reported: %v", st["findings"])
|
||||||
|
}
|
||||||
|
out = e.do("PUT", "/zones/adbraun.lol/registrar/ns", e.token, map[string]any{"ns": []string{"ns1.adbraun.lol"}}, 409)
|
||||||
|
if !strings.Contains(out["error"].(map[string]any)["message"].(string), "DS records") {
|
||||||
|
t.Errorf("set-ns with a foreign DS: %v", out)
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/adbraun.lol/registrar/ds", e.token, nil, 409) // not signed
|
||||||
|
e.do("DELETE", "/zones/adbraun.lol/registrar/ds/4242", e.token, nil, 200)
|
||||||
|
if len(fake.Domains["adbraun.lol"].DS) != 0 {
|
||||||
|
t.Error("DS not removed")
|
||||||
|
}
|
||||||
|
e.do("DELETE", "/zones/adbraun.lol/registrar/ds/4242", e.token, nil, 404)
|
||||||
|
|
||||||
|
// A signed zone whose key named has published long enough: its DS
|
||||||
|
// goes to Porkbun.
|
||||||
|
e.do("PATCH", "/zones/adbraun.lol", e.token, map[string]any{"dnssec_policy": "default"}, 200)
|
||||||
|
e.do("POST", "/zones/adbraun.lol/registrar/ds", e.token, nil, 409) // no key yet
|
||||||
|
tag := writeKey(t, filepath.Join(e.srv.eng.Config().Paths.KeysDir(), "_default"), "adbraun.lol.")
|
||||||
|
e.do("POST", "/zones/adbraun.lol/registrar/ds", e.token, nil, 200)
|
||||||
|
if d, ok := fake.Domains["adbraun.lol"].DS[tag]; !ok || d.Algorithm != 13 || d.DigestType != 2 || len(d.Digest) != 64 {
|
||||||
|
t.Errorf("DS at Porkbun: %+v", fake.Domains["adbraun.lol"].DS)
|
||||||
|
}
|
||||||
|
st = e.do("GET", "/zones/adbraun.lol/registrar", e.token, nil, 200)
|
||||||
|
if !st["ds"].([]any)[0].(map[string]any)["matches"].(bool) {
|
||||||
|
t.Errorf("DS doesn't match: %v", st["ds"])
|
||||||
|
}
|
||||||
|
out = e.do("POST", "/zones/adbraun.lol/registrar/ds", e.token, nil, 200)
|
||||||
|
if len(out["done"].([]any)) != 0 {
|
||||||
|
t.Errorf("published twice: %v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registrar errors are passed on.
|
||||||
|
fake.Domains["adbraun.lol"].APIAccess = false
|
||||||
|
if st = e.do("GET", "/zones/adbraun.lol/registrar", e.token, nil, 200); !strings.Contains(st["error"].(string), "API_ACCESS_DISABLED") {
|
||||||
|
t.Errorf("error: %v", st)
|
||||||
|
}
|
||||||
|
e.do("POST", "/zones/adbraun.lol/registrar/glue", e.token, nil, 502)
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeKey writes the .key and .state files named would have for a key
|
||||||
|
// of zone that is ready for its DS record, and returns its tag.
|
||||||
|
func writeKey(t *testing.T, dir, zone string) uint16 {
|
||||||
|
t.Helper()
|
||||||
|
k := &dns.DNSKEY{Hdr: dns.RR_Header{Name: zone, Rrtype: dns.TypeDNSKEY, Class: dns.ClassINET, Ttl: 3600}, Flags: 257, Protocol: 3, Algorithm: dns.ECDSAP256SHA256}
|
||||||
|
if _, err := k.Generate(256); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
base := filepath.Join(dir, fmt.Sprintf("K%s+013+%05d", zone, k.KeyTag()))
|
||||||
|
os.MkdirAll(dir, 0o755)
|
||||||
|
os.WriteFile(base+".key", []byte(k.String()+"\n"), 0o644)
|
||||||
|
os.WriteFile(base+".state", []byte("Algorithm: 13\nKSK: yes\nZSK: yes\nGoalState: omnipresent\nDNSKEYState: omnipresent\nKRRSIGState: omnipresent\nZRRSIGState: omnipresent\nDSState: rumoured\n"), 0o644)
|
||||||
|
return k.KeyTag()
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -156,6 +157,21 @@ func readBody(r *http.Request) (json.RawMessage, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decodeOptional reads a JSON body into v like decodeJSON, but an empty
|
||||||
|
// body leaves v as it is.
|
||||||
|
func decodeOptional(r *http.Request, v any) error {
|
||||||
|
b, err := readBody(r)
|
||||||
|
if err != nil || b == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(b))
|
||||||
|
dec.DisallowUnknownFields()
|
||||||
|
if err := dec.Decode(v); err != nil {
|
||||||
|
return badRequest("invalid JSON: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func pathID(r *http.Request, name string) (int64, error) {
|
func pathID(r *http.Request, name string) (int64, error) {
|
||||||
v := r.PathValue(name)
|
v := r.PathValue(name)
|
||||||
id, err := strconv.ParseInt(v, 10, 64)
|
id, err := strconv.ParseInt(v, 10, 64)
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ func (s *Server) routes() {
|
|||||||
m.HandleFunc("DELETE "+p+"/zones/{zone}", s.authed(s.deleteZone))
|
m.HandleFunc("DELETE "+p+"/zones/{zone}", s.authed(s.deleteZone))
|
||||||
m.HandleFunc("GET "+p+"/zones/{zone}/serials", s.authed(s.zoneSerials))
|
m.HandleFunc("GET "+p+"/zones/{zone}/serials", s.authed(s.zoneSerials))
|
||||||
m.HandleFunc("GET "+p+"/zones/{zone}/delegation", s.authed(s.zoneDelegation))
|
m.HandleFunc("GET "+p+"/zones/{zone}/delegation", s.authed(s.zoneDelegation))
|
||||||
|
m.HandleFunc("GET "+p+"/zones/{zone}/dnssec", s.authed(s.zoneDNSSEC))
|
||||||
|
m.HandleFunc("POST "+p+"/zones/{zone}/dnssec/check-ds", s.authed(s.zoneCheckDS))
|
||||||
|
m.HandleFunc("POST "+p+"/zones/{zone}/dnssec/wipe", s.authed(s.zoneDNSSECWipe))
|
||||||
|
m.HandleFunc("GET "+p+"/zones/{zone}/registrar", s.authed(s.zoneRegistrar))
|
||||||
|
m.HandleFunc("POST "+p+"/zones/{zone}/registrar/glue", s.authed(s.registrarSyncGlue))
|
||||||
|
m.HandleFunc("POST "+p+"/zones/{zone}/registrar/ds", s.authed(s.registrarPublishDS))
|
||||||
|
m.HandleFunc("DELETE "+p+"/zones/{zone}/registrar/ds/{keytag}", s.authed(s.registrarRemoveDS))
|
||||||
|
m.HandleFunc("PUT "+p+"/zones/{zone}/registrar/ns", s.authed(s.registrarSetNS))
|
||||||
m.HandleFunc("GET "+p+"/zones/{zone}/file", s.authed(s.zoneFile))
|
m.HandleFunc("GET "+p+"/zones/{zone}/file", s.authed(s.zoneFile))
|
||||||
m.HandleFunc("POST "+p+"/zones/{zone}/import", s.authed(s.importZoneFile))
|
m.HandleFunc("POST "+p+"/zones/{zone}/import", s.authed(s.importZoneFile))
|
||||||
m.HandleFunc("GET "+p+"/zones/{zone}/records", s.authed(s.listRecords))
|
m.HandleFunc("GET "+p+"/zones/{zone}/records", s.authed(s.listRecords))
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"jarl/internal/auth"
|
"jarl/internal/auth"
|
||||||
"jarl/internal/engine"
|
"jarl/internal/engine"
|
||||||
"jarl/internal/nscheck"
|
"jarl/internal/nscheck"
|
||||||
|
"jarl/internal/porkbun"
|
||||||
"jarl/internal/stats"
|
"jarl/internal/stats"
|
||||||
"jarl/internal/store"
|
"jarl/internal/store"
|
||||||
)
|
)
|
||||||
@@ -47,6 +48,10 @@ type Config struct {
|
|||||||
// reports on (backup.dir and backup.warn_after).
|
// reports on (backup.dir and backup.warn_after).
|
||||||
BackupDir string
|
BackupDir string
|
||||||
BackupWarnAfter time.Duration
|
BackupWarnAfter time.Duration
|
||||||
|
// Porkbun manages domains' delegation at the registrar Porkbun (nil
|
||||||
|
// without an API key); PorkbunAllows says which domains it may touch.
|
||||||
|
Porkbun *porkbun.Client
|
||||||
|
PorkbunAllows func(domain string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server is the HTTP server.
|
// Server is the HTTP server.
|
||||||
|
|||||||
@@ -92,14 +92,14 @@ func loadState(ctx context.Context, e execer) (*model.State, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err = e.QueryContext(ctx, `SELECT id, name, view_id, type, in_view, file, soa_mname, soa_rname, soa_serial, soa_refresh, soa_retry, soa_expire, soa_minimum, default_ttl, serial_policy, comment, version, created_at, updated_at, created_by, updated_by FROM zones`)
|
rows, err = e.QueryContext(ctx, `SELECT id, name, view_id, type, in_view, file, soa_mname, soa_rname, soa_serial, soa_refresh, soa_retry, soa_expire, soa_minimum, default_ttl, serial_policy, dnssec_policy, comment, version, created_at, updated_at, created_by, updated_by FROM zones`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
z := &model.Zone{}
|
z := &model.Zone{}
|
||||||
var ca, ua string
|
var ca, ua string
|
||||||
if err := rows.Scan(&z.ID, &z.Name, &z.ViewID, &z.Type, &z.InView, &z.File, &z.SOA.MName, &z.SOA.RName, &z.SOA.Serial, &z.SOA.Refresh, &z.SOA.Retry, &z.SOA.Expire, &z.SOA.Minimum, &z.DefaultTTL, &z.SerialPolicy, &z.Comment, &z.Version, &ca, &ua, &z.CreatedBy, &z.UpdatedBy); err != nil {
|
if err := rows.Scan(&z.ID, &z.Name, &z.ViewID, &z.Type, &z.InView, &z.File, &z.SOA.MName, &z.SOA.RName, &z.SOA.Serial, &z.SOA.Refresh, &z.SOA.Retry, &z.SOA.Expire, &z.SOA.Minimum, &z.DefaultTTL, &z.SerialPolicy, &z.DNSSECPolicy, &z.Comment, &z.Version, &ca, &ua, &z.CreatedBy, &z.UpdatedBy); err != nil {
|
||||||
rows.Close()
|
rows.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -209,8 +209,8 @@ func saveState(ctx context.Context, e execer, old, new *model.State) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := diffMap(old.Zones, new.Zones, func(z *model.Zone) error {
|
if err := diffMap(old.Zones, new.Zones, func(z *model.Zone) error {
|
||||||
_, err := e.ExecContext(ctx, `INSERT OR REPLACE INTO zones (id, name, view_id, type, in_view, file, soa_mname, soa_rname, soa_serial, soa_refresh, soa_retry, soa_expire, soa_minimum, default_ttl, serial_policy, comment, version, created_at, updated_at, created_by, updated_by) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
_, err := e.ExecContext(ctx, `INSERT OR REPLACE INTO zones (id, name, view_id, type, in_view, file, soa_mname, soa_rname, soa_serial, soa_refresh, soa_retry, soa_expire, soa_minimum, default_ttl, serial_policy, dnssec_policy, comment, version, created_at, updated_at, created_by, updated_by) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||||
z.ID, z.Name, z.ViewID, z.Type, z.InView, z.File, z.SOA.MName, z.SOA.RName, z.SOA.Serial, z.SOA.Refresh, z.SOA.Retry, z.SOA.Expire, z.SOA.Minimum, z.DefaultTTL, z.SerialPolicy, z.Comment, z.Version, ts(z.CreatedAt), ts(z.UpdatedAt), z.CreatedBy, z.UpdatedBy)
|
z.ID, z.Name, z.ViewID, z.Type, z.InView, z.File, z.SOA.MName, z.SOA.RName, z.SOA.Serial, z.SOA.Refresh, z.SOA.Retry, z.SOA.Expire, z.SOA.Minimum, z.DefaultTTL, z.SerialPolicy, z.DNSSECPolicy, z.Comment, z.Version, ts(z.CreatedAt), ts(z.UpdatedAt), z.CreatedBy, z.UpdatedBy)
|
||||||
return err
|
return err
|
||||||
}, func(id int64) error { return del(ctx, e, "zones", id) }); err != nil {
|
}, func(id int64) error { return del(ctx, e, "zones", id) }); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -238,6 +238,10 @@ CREATE TABLE deployed_files (
|
|||||||
ALTER TABLE tokens ADD COLUMN rotated_at TEXT;
|
ALTER TABLE tokens ADD COLUMN rotated_at TEXT;
|
||||||
ALTER TABLE tokens ADD COLUMN prev_secret_hash TEXT NOT NULL DEFAULT '';
|
ALTER TABLE tokens ADD COLUMN prev_secret_hash TEXT NOT NULL DEFAULT '';
|
||||||
ALTER TABLE tokens ADD COLUMN prev_expires_at TEXT;
|
ALTER TABLE tokens ADD COLUMN prev_expires_at TEXT;
|
||||||
|
`,
|
||||||
|
// 3: DNSSEC signing (the zone's dnssec-policy).
|
||||||
|
`
|
||||||
|
ALTER TABLE zones ADD COLUMN dnssec_policy TEXT NOT NULL DEFAULT '';
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package validate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"jarl/internal/model"
|
||||||
|
"jarl/internal/namedconf"
|
||||||
|
)
|
||||||
|
|
||||||
|
// defaultMaxZoneTTL is max-zone-ttl of BIND's built-in policies (and of
|
||||||
|
// custom ones that don't set it): named refuses to load a signed zone
|
||||||
|
// with a longer TTL.
|
||||||
|
const defaultMaxZoneTTL = 86400
|
||||||
|
|
||||||
|
// Policies returns the custom dnssec-policy statements defined at the top
|
||||||
|
// level, by name.
|
||||||
|
func Policies(s *model.State) map[string]*namedconf.Stmt {
|
||||||
|
out := map[string]*namedconf.Stmt{}
|
||||||
|
for _, o := range s.ScopedOptions(model.ScopeTopLevel, 0) {
|
||||||
|
if strings.ToLower(o.Name) != "dnssec-policy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stmt, err := namedconf.ParseOptionValue(o.Name, o.Value)
|
||||||
|
if err != nil || stmt.Arg(0) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out[stmt.Arg(0)] = stmt
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checker) checkDNSSEC() {
|
||||||
|
policies := Policies(c.s)
|
||||||
|
// A custom policy without keys crashes named 9.20 when it loads the
|
||||||
|
// configuration (an assertion in kaspconf.c), although named-checkconf
|
||||||
|
// accepts it. BIND's built-in "insecure" policy is the way to go
|
||||||
|
// unsigned.
|
||||||
|
for _, o := range c.s.ScopedOptions(model.ScopeTopLevel, 0) {
|
||||||
|
if strings.ToLower(o.Name) != "dnssec-policy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stmt, err := namedconf.ParseOptionValue(o.Name, o.Value)
|
||||||
|
if err != nil {
|
||||||
|
continue // reported by checkOptions
|
||||||
|
}
|
||||||
|
if b := stmt.FirstBlock(); b != nil {
|
||||||
|
if keys := namedconf.FindOne(b.Stmts, "keys"); keys != nil {
|
||||||
|
if kb := keys.FirstBlock(); kb != nil && len(kb.Stmts) == 0 {
|
||||||
|
c.errf("dnssec_policy_no_keys", "option", o.ID, "dnssec-policy %s has an empty keys list, which makes named 9.20 crash when it loads the configuration; to remove signing from a zone, use BIND's built-in insecure policy (jarl zone dnssec disable)", stmt.Arg(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, z := range c.s.SortedZones() {
|
||||||
|
if z.DNSSECPolicy == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if z.Type != model.ZonePrimary {
|
||||||
|
c.zoneProblem(z, Error, "dnssec_zone_type", "only primary zones can be signed by Jarl; a %s zone gets its signatures from its primary", z.Type)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
maxTTL := uint32(defaultMaxZoneTTL)
|
||||||
|
switch z.DNSSECPolicy {
|
||||||
|
case model.DNSSECDefault, model.DNSSECInsecure:
|
||||||
|
default:
|
||||||
|
stmt := policies[z.DNSSECPolicy]
|
||||||
|
if stmt == nil {
|
||||||
|
c.zoneProblem(z, Error, "dnssec_policy_unknown", "dnssec-policy %q doesn't exist: use default (BIND's built-in policy), or define it as a top-level dnssec-policy statement", z.DNSSECPolicy)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if b := stmt.FirstBlock(); b != nil {
|
||||||
|
if m := namedconf.FindOne(b.Stmts, "max-zone-ttl"); m != nil {
|
||||||
|
if v, ok := parseDuration(m.Arg(0)); ok && v > 0 {
|
||||||
|
maxTTL = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if o := c.s.FindOption(model.ScopeZone, z.ID, "inline-signing"); o != nil && isNo(o.Value) {
|
||||||
|
c.zoneProblem(z, Error, "dnssec_inline_signing", "a signed zone needs inline signing: named keeps its signatures in a separate copy of the zone, because Jarl rewrites the zone file (remove the inline-signing option)")
|
||||||
|
}
|
||||||
|
// named refuses to load a signed zone with a TTL above the
|
||||||
|
// policy's max-zone-ttl, and keeps serving the old version.
|
||||||
|
if z.DefaultTTL > maxTTL {
|
||||||
|
c.zoneProblem(z, Error, "dnssec_ttl_too_long", "the default TTL (%d) is longer than the DNSSEC policy's max-zone-ttl (%d), so named would refuse to load the signed zone; lower it to %d or less", z.DefaultTTL, maxTTL, maxTTL)
|
||||||
|
}
|
||||||
|
for _, r := range c.zoneRecords[z.ID] {
|
||||||
|
if r.TTL != nil && *r.TTL > maxTTL {
|
||||||
|
p := c.zoneProblem(z, Error, "dnssec_ttl_too_long", "%s %s has TTL %d, longer than the DNSSEC policy's max-zone-ttl (%d), so named would refuse to load the signed zone; lower it to %d or less", strings.TrimSuffix(r.Name, "."), r.Type, *r.TTL, maxTTL, maxTTL)
|
||||||
|
p.ObjectType, p.ObjectID, p.Name = "record", r.ID, r.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNo(v string) bool {
|
||||||
|
switch strings.ToLower(strings.Trim(strings.TrimSpace(v), `";`)) {
|
||||||
|
case "no", "false", "0":
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
isoDuration = regexp.MustCompile(`^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$`)
|
||||||
|
ttlDuration = regexp.MustCompile(`^(?:\d+[wdhms])+$`)
|
||||||
|
ttlPart = regexp.MustCompile(`(\d+)([wdhms])`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// parseDuration parses a BIND duration: ISO 8601 (P1D, PT12H), seconds, or
|
||||||
|
// TTL style (1d, 12h30m).
|
||||||
|
func parseDuration(s string) (uint32, bool) {
|
||||||
|
s = strings.ToUpper(strings.TrimSpace(s))
|
||||||
|
if n, err := strconv.ParseUint(s, 10, 32); err == nil {
|
||||||
|
return uint32(n), true
|
||||||
|
}
|
||||||
|
if m := isoDuration.FindStringSubmatch(s); m != nil && s != "P" && s != "PT" {
|
||||||
|
units := []uint64{31536000, 2592000, 604800, 86400, 3600, 60, 1}
|
||||||
|
var total uint64
|
||||||
|
for i, u := range units {
|
||||||
|
if m[i+1] != "" {
|
||||||
|
n, _ := strconv.ParseUint(m[i+1], 10, 32)
|
||||||
|
total += n * u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uint32(min(total, 1<<32-1)), true
|
||||||
|
}
|
||||||
|
l := strings.ToLower(s)
|
||||||
|
if ttlDuration.MatchString(l) {
|
||||||
|
units := map[string]uint64{"w": 604800, "d": 86400, "h": 3600, "m": 60, "s": 1}
|
||||||
|
var total uint64
|
||||||
|
for _, m := range ttlPart.FindAllStringSubmatch(l, -1) {
|
||||||
|
n, _ := strconv.ParseUint(m[1], 10, 32)
|
||||||
|
total += n * units[m[2]]
|
||||||
|
}
|
||||||
|
return uint32(min(total, 1<<32-1)), true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package validate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"jarl/internal/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDNSSEC(t *testing.T) {
|
||||||
|
b := newBuilder()
|
||||||
|
ok := b.primary("signed.example", nil)
|
||||||
|
ok.DNSSECPolicy = model.DNSSECDefault
|
||||||
|
ps := State(b.s, Options{})
|
||||||
|
if len(codes(ps, Error)) != 0 {
|
||||||
|
t.Fatalf("a signed zone: %v", ps)
|
||||||
|
}
|
||||||
|
|
||||||
|
sec := b.zone("copy.example", nil, model.ZoneSecondary)
|
||||||
|
b.opt(model.ScopeZone, sec.ID, "primaries", "{ 192.0.2.1; }")
|
||||||
|
sec.DNSSECPolicy = model.DNSSECDefault
|
||||||
|
unknown := b.primary("custom.example", nil)
|
||||||
|
unknown.DNSSECPolicy = "fast"
|
||||||
|
long := b.primary("long.example", nil)
|
||||||
|
long.DNSSECPolicy = model.DNSSECInsecure
|
||||||
|
r := b.rec(long, "www", "A", "192.0.2.80")
|
||||||
|
r.TTL = model.Ptr(uint32(172800))
|
||||||
|
b.opt(model.ScopeZone, ok.ID, "inline-signing", "no")
|
||||||
|
ps = State(b.s, Options{})
|
||||||
|
for _, c := range []string{"dnssec_zone_type", "dnssec_policy_unknown", "dnssec_ttl_too_long", "dnssec_inline_signing"} {
|
||||||
|
if !hasCode(ps, c) {
|
||||||
|
t.Errorf("missing %s in %v", c, ps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A custom policy: its max-zone-ttl applies; an empty keys list would
|
||||||
|
// crash named.
|
||||||
|
b2 := newBuilder()
|
||||||
|
z := b2.primary("custom.example", nil)
|
||||||
|
z.DNSSECPolicy = "fast"
|
||||||
|
z.DefaultTTL = 600
|
||||||
|
b2.opt(model.ScopeTopLevel, 0, "dnssec-policy", `fast { keys { csk lifetime unlimited algorithm 13; }; max-zone-ttl PT5M; }`)
|
||||||
|
b2.opt(model.ScopeTopLevel, 0, "dnssec-policy", `"off" { keys { }; }`)
|
||||||
|
ps = State(b2.s, Options{})
|
||||||
|
if !hasCode(ps, "dnssec_ttl_too_long") || !hasCode(ps, "dnssec_policy_no_keys") || hasCode(ps, "dnssec_policy_unknown") {
|
||||||
|
t.Errorf("custom policy: %v", ps)
|
||||||
|
}
|
||||||
|
|
||||||
|
// dnssec-policy is set per zone in Jarl, not as an option.
|
||||||
|
b3 := newBuilder()
|
||||||
|
z = b3.primary("example.com", nil)
|
||||||
|
b3.opt(model.ScopeZone, z.ID, "dnssec-policy", "default")
|
||||||
|
b3.opt(model.ScopeOptions, 0, "dnssec-policy", "default")
|
||||||
|
b3.opt(model.ScopeZone, z.ID, "key-directory", `"/tmp"`)
|
||||||
|
if n := len(codes(State(b3.s, Options{}), Error)); n != 3 {
|
||||||
|
t.Errorf("managed options: %v", State(b3.s, Options{}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseDuration(t *testing.T) {
|
||||||
|
for in, want := range map[string]uint32{"86400": 86400, "P1D": 86400, "PT5M": 300, "P1W": 604800, "1d": 86400, "12h30m": 45000, "pt1h": 3600} {
|
||||||
|
if got, ok := parseDuration(in); !ok || got != want {
|
||||||
|
t.Errorf("parseDuration(%q) = %d %v, want %d", in, got, ok, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, bad := range []string{"", "P", "unlimited", "1x"} {
|
||||||
|
if _, ok := parseDuration(bad); ok {
|
||||||
|
t.Errorf("parseDuration(%q) accepted", bad)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -135,6 +135,7 @@ func State(s *model.State, opts Options) []Problem {
|
|||||||
c.checkZones()
|
c.checkZones()
|
||||||
c.checkOptions()
|
c.checkOptions()
|
||||||
c.checkSecurity()
|
c.checkSecurity()
|
||||||
|
c.checkDNSSEC()
|
||||||
sortProblems(c.problems)
|
sortProblems(c.problems)
|
||||||
return c.problems
|
return c.problems
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,216 @@
|
|||||||
|
// The zone page's DNSSEC tab: the zone's signing status, its DS record for
|
||||||
|
// the parent zone, and the steps to turn signing on and off. Every step
|
||||||
|
// that can affect resolvers opens a dialog that says what must be done
|
||||||
|
// first (docs/dnssec.md).
|
||||||
|
import { h, mount, table, badge, modal, toast, errorBox, display, input, select, checkbox, copyBox, fmtTime } from "../ui.js";
|
||||||
|
import { api, get, change, describeResult, state } from "../api.js";
|
||||||
|
import { rerender } from "../app.js";
|
||||||
|
import { publishDS } from "./registrar.js";
|
||||||
|
|
||||||
|
const phaseBadge = {
|
||||||
|
off: ["off", ""], leftover_keys: ["off · old keys", "warn"], starting: ["starting", "accent"],
|
||||||
|
signing: ["signing", "accent"], ready: ["ready for DS", "warn"], ds_pending: ["DS added", "accent"],
|
||||||
|
secure: ["secure", "ok"], removing_ds: ["turning off: remove DS", "warn"], ds_expiring: ["turning off", "accent"],
|
||||||
|
removing_keys: ["turning off", "accent"], unsigned: ["turning off: finished", "ok"],
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function dnssecTab(el, zone) {
|
||||||
|
const [s, zones] = await Promise.all([get("/zones/" + zone.id + "/dnssec"), get("/zones").catch(() => [])]);
|
||||||
|
const admin = state.me && state.me.admin;
|
||||||
|
const others = zones.filter((z) => z.name === zone.name && z.id !== zone.id);
|
||||||
|
const ph = s.phase;
|
||||||
|
const [btext, bkind] = phaseBadge[ph.code] || [ph.code, ""];
|
||||||
|
const signing = s.policy && s.policy !== "insecure";
|
||||||
|
const out = h("div");
|
||||||
|
|
||||||
|
const buttons = [];
|
||||||
|
if (!s.policy) buttons.push(h("button", { class: "primary", onclick: () => enableDialog(zone, s, others) }, "Turn signing on…"));
|
||||||
|
if (s.policy) buttons.push(h("button", { onclick: () => checkDS(zone, out) }, "Check DS at parent"));
|
||||||
|
if (signing) buttons.push(h("button", { onclick: () => disableDialog(zone, s) }, "Turn signing off…"));
|
||||||
|
if (s.policy === "insecure") buttons.push(h("button", { class: ph.can_finish ? "primary" : "", disabled: !ph.can_finish, title: ph.can_finish ? "" : "Not yet: " + (ph.next || ph.summary), onclick: () => finishDialog(zone) }, "Finish turning off"));
|
||||||
|
if (admin && (s.policy || s.keys.length)) buttons.push(h("button", { class: "danger", onclick: () => wipeDialog(zone, s) }, "Wipe (clean slate)…"));
|
||||||
|
|
||||||
|
const parts = [h("div", { class: "panel" },
|
||||||
|
h("div", { class: "page-head" },
|
||||||
|
h("h2", { class: "grow" }, "DNSSEC signing ", badge(btext, bkind)),
|
||||||
|
h("div", { class: "actions" }, buttons)),
|
||||||
|
h("p", null, ph.summary),
|
||||||
|
ph.next ? h("div", { class: "msg " + (ph.code === "removing_ds" || ph.code === "ready" ? "warn" : "info") }, h("strong", null, "Next: "), ph.next) : null,
|
||||||
|
s.policy ? h("dl", { class: "kv small" },
|
||||||
|
h("dt", null, "Policy"), h("dd", { class: "mono" }, s.policy === "insecure" ? "insecure (turning off)" : s.policy),
|
||||||
|
s.named && s.named.secure ? [h("dt", null, "Signed serial"), h("dd", { class: "mono" }, s.named.signed_serial + " (zone file " + s.named.serial + ")")] : null,
|
||||||
|
s.named && s.named.next_key_event ? [h("dt", null, "Next key event"), h("dd", null, s.named.next_key_event)] : null,
|
||||||
|
h("dt", null, "Key directory"), h("dd", { class: "mono" }, s.key_dir)) : null,
|
||||||
|
s.named_error ? h("div", { class: "msg warn small" }, "named: " + s.named_error) : null,
|
||||||
|
s.key_error ? h("div", { class: "msg err small" }, "The keys can't be read: " + s.key_error) : null,
|
||||||
|
!s.policy && !s.keys.length ? h("p", { class: "muted small" },
|
||||||
|
"Signing lets resolvers that validate DNSSEC detect forged answers for the zone. It only matters for a zone on the internet: validation needs a DS record in the parent zone (at your registrar), and resolvers on your own network don't validate zones this server answers itself.") : null,
|
||||||
|
out)];
|
||||||
|
|
||||||
|
const live = s.keys.filter((k) => k.ds && k.goal === "omnipresent");
|
||||||
|
if (live.length && s.policy !== "insecure") parts.push(dsPanel(zone, s, live));
|
||||||
|
if (s.keys.length) {
|
||||||
|
parts.push(h("div", { class: "panel" },
|
||||||
|
h("h2", null, "Keys"),
|
||||||
|
table([
|
||||||
|
{ label: "Tag", render: (k) => k.tag, tdClass: "mono" },
|
||||||
|
{ label: "Role", render: (k) => k.role },
|
||||||
|
{ label: "Algorithm", render: (k) => k.algorithm_name || k.algorithm, tdClass: "small" },
|
||||||
|
{ label: "Goal", render: (k) => stateBadge(k.goal) },
|
||||||
|
{ label: "DNSKEY", render: (k) => stateBadge(k.dnskey_state) },
|
||||||
|
{ label: "DS at parent", render: (k) => stateBadge(k.ds_state) },
|
||||||
|
{ label: "Created", render: (k) => k.created ? fmtTime(k.created) : "–", tdClass: "small" },
|
||||||
|
], s.keys),
|
||||||
|
h("p", { class: "muted small" }, "States are named's: rumoured = published, but caches may not have it yet; omnipresent = everyone has it; unretentive = removed, but caches may still have it; hidden = gone.")));
|
||||||
|
}
|
||||||
|
mount(el, parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stateBadge(st) {
|
||||||
|
if (!st) return h("span", { class: "muted" }, "–");
|
||||||
|
return badge(st, { omnipresent: "ok", rumoured: "accent", unretentive: "warn" }[st] || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function dsPanel(zone, s, keys) {
|
||||||
|
const ph = s.phase;
|
||||||
|
const where = s.parent_zone
|
||||||
|
? ["The parent zone ", h("a", { href: "#/zones" }, display(s.parent_zone)), " is in Jarl: add this as a DS record there (name ", h("code", null, display(zone.name)), ")."]
|
||||||
|
: "Give this to your registrar (at Porkbun: the domain's DNSSEC settings). Registrars ask either for the whole record or for its four fields.";
|
||||||
|
return h("div", { class: "panel" },
|
||||||
|
h("h2", null, "DS record for the parent zone"),
|
||||||
|
ph.can_publish_ds
|
||||||
|
? h("div", { class: "msg ok" }, ph.code === "secure" ? "The parent has this DS record." : "Ready: the DS record can be added at the parent now. Then click Check DS at parent.")
|
||||||
|
: h("div", { class: "msg warn" }, h("strong", null, "Not yet. "),
|
||||||
|
ph.ds_ready_at ? "Wait until " + fmtTime(ph.ds_ready_at) + "." : "Wait until named says the zone is ready.",
|
||||||
|
" Adding the DS earlier can make the zone fail to validate for resolvers that still have unsigned answers cached."),
|
||||||
|
h("p", { class: "small" }, where),
|
||||||
|
s.registrar && state.me && state.me.admin && ph.code !== "secure" && ph.code !== "ds_pending"
|
||||||
|
? h("p", null, h("button", { class: ph.can_publish_ds ? "primary" : "", onclick: () => publishDS(zone) }, "Publish at Porkbun…"),
|
||||||
|
h("span", { class: "muted small" }, " Jarl checks that it's safe first; the Registrar tab shows everything at Porkbun.")) : null,
|
||||||
|
keys.map((k) => h("div", { class: "ds-record" },
|
||||||
|
h("label", { class: "small muted" }, "Key " + k.tag + " — DS record"),
|
||||||
|
copyBox(k.ds.record.replace(/\t/g, " ")),
|
||||||
|
h("dl", { class: "kv small" },
|
||||||
|
h("dt", null, "Key tag"), h("dd", null, copyBox(String(k.ds.key_tag))),
|
||||||
|
h("dt", null, "Algorithm"), h("dd", null, copyBox(String(k.ds.algorithm)), h("span", { class: "muted" }, " " + (k.algorithm_name || ""))),
|
||||||
|
h("dt", null, "Digest type"), h("dd", null, copyBox(String(k.ds.digest_type)), h("span", { class: "muted" }, " SHA-256")),
|
||||||
|
h("dt", null, "Digest"), h("dd", null, copyBox(k.ds.digest))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function apply(zone, policy) {
|
||||||
|
const r = await change("PATCH", "/zones/" + zone.id, { dnssec_policy: policy }, { immediate: true });
|
||||||
|
toast(describeResult(r));
|
||||||
|
rerender();
|
||||||
|
}
|
||||||
|
|
||||||
|
function steps(items) {
|
||||||
|
return h("ol", { class: "small" }, items.map((i) => h("li", null, i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function enableDialog(zone, s, others) {
|
||||||
|
const pol = select(s.policies.map((p) => [p, p === "default" ? "default (BIND's built-in policy)" : p]), "default");
|
||||||
|
const err = h("div");
|
||||||
|
const split = others.length ? h("div", { class: "msg warn small" },
|
||||||
|
"This signs the zone in view ", h("strong", null, zone.view || "default"), " only; ",
|
||||||
|
others.map((o) => display(o.name) + " in view " + o.view).join(", "),
|
||||||
|
" stays unsigned. That's the usual split-DNS setup. Once the DS record is at the parent, a device that validates DNSSEC itself (a Pi-hole or Unbound with DNSSEC on, systemd-resolved with DNSSEC=yes) and gets the unsigned copy rejects it; resolvers asking this server directly are fine, because BIND doesn't validate zones it serves itself.") : null;
|
||||||
|
await modal("Turn signing on for " + zone.display_name, [
|
||||||
|
h("p", null, "named creates a key and signs the zone: Jarl keeps writing the zone as before, and named keeps a signed copy next to it. ",
|
||||||
|
h("strong", null, "Nothing changes for resolvers yet"), ": they only start validating once the zone's DS record is added at the parent zone, which this page tells you when to do."),
|
||||||
|
h("p", { class: "small" }, "Before you start:"),
|
||||||
|
steps([
|
||||||
|
"The server's clock must be right (NTP): signatures are valid for a fixed time window.",
|
||||||
|
"TTLs in the zone must be at most a day; Jarl refuses longer ones.",
|
||||||
|
"Secondaries get the signed zone by zone transfer; they need nothing else.",
|
||||||
|
"With the default policy the key is never replaced, so the DS at your registrar never has to change. Keep backups: the daily backup includes the keys.",
|
||||||
|
]),
|
||||||
|
split,
|
||||||
|
s.policies.length > 1 ? h("div", { class: "form-grid" }, h("label", null, "Policy"), pol) : null,
|
||||||
|
err,
|
||||||
|
], [
|
||||||
|
{ label: "Cancel", value: null },
|
||||||
|
{ label: "Turn signing on", kind: "primary", onclick: async () => {
|
||||||
|
try { await apply(zone, pol.value); } catch (e) { mount(err, errorBox(e)); return false; }
|
||||||
|
} },
|
||||||
|
], { wide: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function disableDialog(zone, s) {
|
||||||
|
const err = h("div");
|
||||||
|
const hadDS = s.keys.some((k) => k.ds_published || k.ds_state === "omnipresent");
|
||||||
|
await modal("Turn signing off for " + zone.display_name, [
|
||||||
|
h("p", null, "Signing is turned off in steps, so the zone is never unsigned while the parent zone still has its DS record (validating resolvers would then reject the whole domain):"),
|
||||||
|
steps([
|
||||||
|
[h("strong", null, "Now: "), "the zone switches to BIND's insecure policy. named keeps it signed and publishes a CDS \"delete\" record. Nothing breaks."],
|
||||||
|
[h("strong", null, "You: "), "remove the DS record at your registrar (", s.registrar ? "the Registrar tab can do that at Porkbun" : "at Porkbun: the domain's DNSSEC settings", "), then click Check DS at parent so named knows it's gone."],
|
||||||
|
[h("strong", null, "named: "), "waits until resolvers have forgotten the DS (the parent's DS TTL, often a day), then removes the keys and signatures."],
|
||||||
|
[h("strong", null, "Then: "), "this page lets you finish, which switches DNSSEC off."],
|
||||||
|
]),
|
||||||
|
hadDS ? null : h("p", { class: "muted small" }, "named has never seen a DS for this zone at its parent, so this will go quickly. If you're sure the parent never had one, Wipe switches off at once."),
|
||||||
|
err,
|
||||||
|
], [
|
||||||
|
{ label: "Cancel", value: null },
|
||||||
|
{ label: "Start turning off", kind: "primary", onclick: async () => {
|
||||||
|
try { await apply(zone, "insecure"); } catch (e) { mount(err, errorBox(e)); return false; }
|
||||||
|
} },
|
||||||
|
], { wide: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function finishDialog(zone) {
|
||||||
|
const err = h("div");
|
||||||
|
await modal("Finish turning signing off", [
|
||||||
|
h("p", null, "The parent zone has no DS record for ", h("strong", null, zone.display_name), " any more, and named has stopped counting on it. Switching DNSSEC off now is safe: named serves the zone unsigned."),
|
||||||
|
h("p", { class: "muted small" }, "The old keys stay in the key directory (named keeps them retired); Wipe deletes them."),
|
||||||
|
err,
|
||||||
|
], [
|
||||||
|
{ label: "Cancel", value: null },
|
||||||
|
{ label: "Switch DNSSEC off", kind: "primary", onclick: async () => {
|
||||||
|
try { await apply(zone, ""); } catch (e) { mount(err, errorBox(e)); return false; }
|
||||||
|
} },
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function wipeDialog(zone, s) {
|
||||||
|
const err = h("div");
|
||||||
|
const confirmName = input({ placeholder: zone.display_name, class: "mono", autocomplete: "off" });
|
||||||
|
const force = checkbox("The parent can't be checked from here, and I'm sure it has no DS record for this zone (for example, the zone isn't on the internet)", false);
|
||||||
|
await modal("Wipe DNSSEC from " + zone.display_name, [
|
||||||
|
h("div", { class: "msg err" },
|
||||||
|
h("strong", null, "This can take the domain offline. "),
|
||||||
|
"Wipe switches signing off at once and deletes the zone's keys and named's signed copy. If the parent zone still has a DS record for the zone, or resolvers still have one cached, every validating resolver rejects the whole domain until it's gone and its TTL has passed (often a day). The deleted keys can't be brought back except from a backup."),
|
||||||
|
h("p", null, "Jarl asks the parent zone's servers first and refuses while they have a DS record. Use Turn signing off instead if the zone is on the internet and ever had a DS."),
|
||||||
|
s.policy ? null : h("p", { class: "small" }, "Signing is already off; this deletes the old keys left in the key directory."),
|
||||||
|
h("div", { class: "form-grid" }, h("label", null, "Type the zone name to confirm"), confirmName),
|
||||||
|
force,
|
||||||
|
err,
|
||||||
|
], [
|
||||||
|
{ label: "Cancel", value: null },
|
||||||
|
{ label: "Wipe", kind: "danger", onclick: async () => {
|
||||||
|
if (confirmName.value.trim().replace(/\.$/, "").toLowerCase() !== zone.display_name.toLowerCase()) {
|
||||||
|
mount(err, h("div", { class: "msg err" }, "Type the zone name to confirm."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const r = await api("POST", "/zones/" + zone.id + "/dnssec/wipe", { body: { force: force.input.checked } });
|
||||||
|
toast("Wiped: " + r.removed.length + " files removed");
|
||||||
|
rerender();
|
||||||
|
} catch (e) { mount(err, errorBox(e)); return false; }
|
||||||
|
} },
|
||||||
|
], { wide: true, sticky: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkDS(zone, out) {
|
||||||
|
mount(out, h("div", { class: "muted" }, "Asking the parent zone's servers…"));
|
||||||
|
try {
|
||||||
|
const r = await api("POST", "/zones/" + zone.id + "/dnssec/check-ds");
|
||||||
|
const p = r.parent;
|
||||||
|
mount(out, h("div", { class: "msg " + (p.error ? "err" : "info") },
|
||||||
|
p.error ? p.error : [
|
||||||
|
"Parent zone ", h("strong", { class: "mono" }, display(p.parent)), " (" + p.reached + " of " + p.parent_servers.length + " servers answered): ",
|
||||||
|
p.delegated ? (p.ds.length ? "DS record" + (p.ds.length > 1 ? "s" : "") + " for key " + p.ds.map((d) => d.key_tag).join(", ") : "no DS record") : "the zone isn't delegated",
|
||||||
|
"."],
|
||||||
|
r.marked.map((m) => h("div", null, "named told: " + m)),
|
||||||
|
r.notes.map((n) => h("div", { class: "small" }, n))));
|
||||||
|
if (r.marked.length) setTimeout(rerender, 1500);
|
||||||
|
} catch (e) { mount(out, errorBox(e)); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// The zone page's Registrar tab: the domain's name servers, glue records
|
||||||
|
// and DS records at Porkbun, next to what the zone says. Every change is
|
||||||
|
// first run as a dry run, whose checks (will this break the domain?) the
|
||||||
|
// dialog shows before anything is changed (docs/dnssec.md#porkbun).
|
||||||
|
import { h, mount, table, badge, modal, toast, errorBox, checkbox } from "../ui.js";
|
||||||
|
import { api, get } from "../api.js";
|
||||||
|
import { rerender } from "../app.js";
|
||||||
|
|
||||||
|
const lvl = { ok: "ok", info: "info", warning: "warn", error: "err" };
|
||||||
|
|
||||||
|
export async function registrarTab(el, zone) {
|
||||||
|
const r = await get("/zones/" + zone.id + "/registrar");
|
||||||
|
if (r.error) {
|
||||||
|
mount(el, h("div", { class: "panel" },
|
||||||
|
h("h2", null, "Registrar: Porkbun"),
|
||||||
|
h("div", { class: "msg err" }, r.error),
|
||||||
|
h("p", { class: "muted small" }, "Check the API key in jarl.yaml (porkbun:), that \"API Access\" is switched on for the domain at porkbun.com, and that the key may manage it.")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const z = "/zones/" + zone.id + "/registrar";
|
||||||
|
const toDo = r.glue.filter((g) => g.action).length;
|
||||||
|
mount(el,
|
||||||
|
h("div", { class: "panel" },
|
||||||
|
h("h2", null, "Registrar: Porkbun ", h("span", { class: "muted small" }, r.domain)),
|
||||||
|
r.findings.map((f) => h("div", { class: "msg " + lvl[f.level] }, f.message))),
|
||||||
|
|
||||||
|
h("div", { class: "panel" },
|
||||||
|
h("div", { class: "page-head" },
|
||||||
|
h("h2", { class: "grow" }, "Name servers ", r.ns_match ? badge("match the zone", "ok") : badge("differ from the zone", "warn")),
|
||||||
|
h("div", { class: "actions" }, h("button", { disabled: r.ns_match, onclick: () => guarded({
|
||||||
|
title: "Delegate " + r.domain + " to the zone's name servers",
|
||||||
|
intro: [
|
||||||
|
h("p", null, "Porkbun will point the whole domain at ", h("strong", { class: "mono" }, r.jarl_ns.join(", ")), " instead of ", h("span", { class: "mono" }, r.ns.join(", ")), "."),
|
||||||
|
h("p", { class: "small" }, "Jarl checks first that every one of them answers for the zone with the current serial, that the ones inside the domain have matching glue records, and that any DS record at Porkbun matches the zone's keys. Resolvers may keep using the old name servers for a day or two, so keep those serving the zone until then."),
|
||||||
|
],
|
||||||
|
method: "PUT", path: z + "/ns", ok: "Set name servers",
|
||||||
|
}) }, "Set name servers…"))),
|
||||||
|
table([
|
||||||
|
{ label: "", render: (row) => h("strong", null, row[0]) },
|
||||||
|
{ label: "Name servers", render: (row) => row[1].join(", ") || h("span", { class: "muted" }, "none"), tdClass: "mono" },
|
||||||
|
], [["At Porkbun", r.ns], ["In the zone (NS records)", r.jarl_ns]])),
|
||||||
|
|
||||||
|
h("div", { class: "panel" },
|
||||||
|
h("div", { class: "page-head" },
|
||||||
|
h("h2", { class: "grow" }, "Glue records"),
|
||||||
|
h("div", { class: "actions" }, h("button", { disabled: !toDo, onclick: () => guarded({
|
||||||
|
title: "Sync the glue records",
|
||||||
|
intro: h("p", null, "Name servers inside the domain (like ns1." + r.domain + ") can only be found through glue records at the registry. Each one gets all of its A and AAAA records from the zone. Changing the glue of a name server the domain already uses sends resolvers to the new addresses at once, so Jarl checks they answer for the zone first."),
|
||||||
|
method: "POST", path: z + "/glue", ok: "Sync glue",
|
||||||
|
}) }, "Sync glue…"))),
|
||||||
|
r.glue.length ? table([
|
||||||
|
{ label: "Name server", render: (g) => g.host, tdClass: "mono" },
|
||||||
|
{ label: "At Porkbun", render: (g) => g.registry.join(", ") || h("span", { class: "muted" }, "none"), tdClass: "mono small" },
|
||||||
|
{ label: "In the zone", render: (g) => g.needed ? (g.jarl.join(", ") || h("span", { class: "muted" }, "no address record")) : h("span", { class: "muted" }, "not a name server of the zone"), tdClass: "mono small" },
|
||||||
|
{ label: "", render: (g) => g.action ? badge(g.action === "create" ? "missing" : "differs", "warn") : g.needed ? badge("matches", "ok") : g.in_use ? badge("in use", "") : badge("unused", "") },
|
||||||
|
], r.glue) : h("p", { class: "muted small" }, "None needed: no name server of the zone is inside the domain.")),
|
||||||
|
|
||||||
|
h("div", { class: "panel" },
|
||||||
|
h("div", { class: "page-head" },
|
||||||
|
h("h2", { class: "grow" }, "DNSSEC: DS records at Porkbun"),
|
||||||
|
h("div", { class: "actions" }, h("button", { onclick: () => publishDS(zone) }, "Publish the zone's DS…"))),
|
||||||
|
r.ds.length ? table([
|
||||||
|
{ label: "Key tag", render: (d) => d.key_tag, tdClass: "mono" },
|
||||||
|
{ label: "Algorithm", render: (d) => d.algorithm },
|
||||||
|
{ label: "Digest type", render: (d) => d.digest_type },
|
||||||
|
{ label: "Digest", render: (d) => d.digest, tdClass: "mono small break" },
|
||||||
|
{ label: "", render: (d) => d.matches ? badge("matches the zone's key", "ok") : badge("matches no key", "err") },
|
||||||
|
{ label: "", render: (d) => h("button", { class: "small danger", onclick: () => guarded({
|
||||||
|
title: "Remove the DS record for key " + d.key_tag,
|
||||||
|
intro: [
|
||||||
|
d.matches
|
||||||
|
? h("div", { class: "msg warn" }, "This DS record points at the zone's key. Without it, resolvers stop validating the domain; the zone stays signed. This is the right step after starting to turn signing off (DNSSEC tab); otherwise, turn signing off first.")
|
||||||
|
: h("div", { class: "msg info" }, "This DS record matches none of the zone's keys, so validating resolvers reject the domain while it's there: removing it fixes that."),
|
||||||
|
h("p", { class: "small muted" }, "Resolvers may keep it cached for its TTL (often a day). Porkbun notes that most registries remove every DS record with the same key data."),
|
||||||
|
],
|
||||||
|
method: "DELETE", path: z + "/ds/" + d.key_tag, ok: "Remove DS record", kind: "danger",
|
||||||
|
}) }, "Remove…") },
|
||||||
|
], r.ds) : h("p", { class: "muted small" }, "None: resolvers treat the domain as unsigned.")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// publishDS publishes the zone's DS record at Porkbun (from the DNSSEC tab
|
||||||
|
// too).
|
||||||
|
export function publishDS(zone) {
|
||||||
|
return guarded({
|
||||||
|
title: "Publish the DS record at Porkbun",
|
||||||
|
intro: [
|
||||||
|
h("p", null, "Porkbun adds the zone's DS record to the parent zone, and from then on validating resolvers check the zone's signatures."),
|
||||||
|
h("p", { class: "small" }, "Jarl checks first that named says the zone is ready, and that the domain is delegated to name servers that serve this signed zone: a DS record that points at servers serving it unsigned (or with other keys) takes the domain offline for validating resolvers."),
|
||||||
|
h("p", { class: "small muted" }, "Afterwards, once the parent zone has it (minutes to hours), click Check DS at parent on the DNSSEC tab."),
|
||||||
|
],
|
||||||
|
method: "POST", path: "/zones/" + zone.id + "/registrar/ds", ok: "Publish DS record",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// guarded runs a registrar change as a dry run, shows its checks, and
|
||||||
|
// makes the change when confirmed. Errors block it unless the user
|
||||||
|
// explicitly overrides them.
|
||||||
|
async function guarded({ title, intro, method, path, ok, kind = "primary" }) {
|
||||||
|
const body = h("div", null, h("div", { class: "muted" }, "Checking…"));
|
||||||
|
const out = h("div");
|
||||||
|
let blocked = false;
|
||||||
|
const override = checkbox("I understand the checks above and want to make this change anyway", false);
|
||||||
|
const done = modal(title, [intro, body, out], [
|
||||||
|
{ label: "Cancel", value: null },
|
||||||
|
{ label: ok, kind, onclick: async () => {
|
||||||
|
if (blocked && !override.input.checked) {
|
||||||
|
mount(out, h("div", { class: "msg err" }, "The checks found problems: tick the box to go ahead anyway."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const r = await api(method, path, { body: method === "DELETE" ? undefined : { force: blocked } , query: method === "DELETE" && blocked ? { force: "1" } : undefined });
|
||||||
|
toast(r.done.length ? r.done.join("; ") : "Nothing to change", "ok", 6000);
|
||||||
|
for (const w of r.warnings) toast(w, "ok", 9000);
|
||||||
|
rerender();
|
||||||
|
} catch (e) { mount(out, errorBox(e)); return false; }
|
||||||
|
} },
|
||||||
|
], { wide: true, sticky: true });
|
||||||
|
try {
|
||||||
|
const r = await api(method, path, { body: method === "DELETE" ? undefined : { dry_run: true }, query: method === "DELETE" ? { dry_run: "1" } : undefined });
|
||||||
|
blocked = r.checks.some((c) => c.level === "error");
|
||||||
|
mount(body,
|
||||||
|
r.checks.map((c) => h("div", { class: "msg " + lvl[c.level] }, c.message)),
|
||||||
|
r.done.length ? [h("p", { class: "small" }, "This will:"), h("ul", { class: "small" }, r.done.map((d) => h("li", null, d)))] : h("p", { class: "muted" }, "Nothing to change."),
|
||||||
|
blocked ? override : null);
|
||||||
|
} catch (e) { mount(body, errorBox(e)); }
|
||||||
|
return done;
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import { rerender } from "../app.js";
|
|||||||
import { optionsEditor } from "./options.js";
|
import { optionsEditor } from "./options.js";
|
||||||
import { emailOf, pendingBadge } from "./zones.js";
|
import { emailOf, pendingBadge } from "./zones.js";
|
||||||
import { isReverseZone, reverseInfo, ptrOwner, addressOf } from "../names.js";
|
import { isReverseZone, reverseInfo, ptrOwner, addressOf } from "../names.js";
|
||||||
|
import { dnssecTab } from "./dnssec.js";
|
||||||
|
import { registrarTab } from "./registrar.js";
|
||||||
|
|
||||||
export async function render(el, params, query) {
|
export async function render(el, params, query) {
|
||||||
const id = params.id;
|
const id = params.id;
|
||||||
@@ -15,6 +17,8 @@ export async function render(el, params, query) {
|
|||||||
["options", "Options"],
|
["options", "Options"],
|
||||||
zone.type === "primary" ? ["file", "Zone file"] : null,
|
zone.type === "primary" ? ["file", "Zone file"] : null,
|
||||||
["primary", "secondary", "mirror"].includes(zone.type) ? ["servers", "Name servers"] : null,
|
["primary", "secondary", "mirror"].includes(zone.type) ? ["servers", "Name servers"] : null,
|
||||||
|
zone.type === "primary" ? ["dnssec", "DNSSEC"] : null,
|
||||||
|
zone.registrar && state.me && state.me.admin ? ["registrar", "Registrar"] : null,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
const body = h("div");
|
const body = h("div");
|
||||||
mount(el,
|
mount(el,
|
||||||
@@ -26,6 +30,7 @@ export async function render(el, params, query) {
|
|||||||
zone.pending ? [pendingBadge(zone.pending), " "] : null,
|
zone.pending ? [pendingBadge(zone.pending), " "] : null,
|
||||||
zone.view ? ["view ", h("a", { href: "#/views" }, zone.view), " · "] : null,
|
zone.view ? ["view ", h("a", { href: "#/views" }, zone.view), " · "] : null,
|
||||||
zone.type === "primary" ? "serial " + zone.soa.serial + " · " : null,
|
zone.type === "primary" ? "serial " + zone.soa.serial + " · " : null,
|
||||||
|
zone.dnssec_policy ? [h("a", { href: "#/zones/" + id + "/dnssec" }, badge(zone.dnssec_policy === "insecure" ? "DNSSEC: turning off" : "DNSSEC", zone.dnssec_policy === "insecure" ? "warn" : "ok")), " "] : null,
|
||||||
zone.zone_file ? h("span", { class: "mono small" }, zone.zone_file) : null)),
|
zone.zone_file ? h("span", { class: "mono small" }, zone.zone_file) : null)),
|
||||||
h("div", { class: "actions" },
|
h("div", { class: "actions" },
|
||||||
h("button", { class: "danger", onclick: () => deleteZone(zone) }, "Delete zone"))),
|
h("button", { class: "danger", onclick: () => deleteZone(zone) }, "Delete zone"))),
|
||||||
@@ -36,6 +41,8 @@ export async function render(el, params, query) {
|
|||||||
else if (tab === "options") await optionsEditor(body, { scope: "zone", scope_id: zone.id, catalogScope: "zone:" + zone.type, title: "Zone options" });
|
else if (tab === "options") await optionsEditor(body, { scope: "zone", scope_id: zone.id, catalogScope: "zone:" + zone.type, title: "Zone options" });
|
||||||
else if (tab === "file") await fileTab(body, zone);
|
else if (tab === "file") await fileTab(body, zone);
|
||||||
else if (tab === "servers") await serversTab(body, zone);
|
else if (tab === "servers") await serversTab(body, zone);
|
||||||
|
else if (tab === "dnssec") await dnssecTab(body, zone);
|
||||||
|
else if (tab === "registrar") await registrarTab(body, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- name servers: serials on the other servers, and the delegation
|
// ---- name servers: serials on the other servers, and the delegation
|
||||||
|
|||||||
@@ -243,6 +243,13 @@ button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|||||||
.grants { font-family: var(--mono); font-size: 12px; }
|
.grants { font-family: var(--mono); font-size: 12px; }
|
||||||
.copy-box { display: flex; gap: 6px; align-items: center; }
|
.copy-box { display: flex; gap: 6px; align-items: center; }
|
||||||
.copy-box input { flex: 1; font-family: var(--mono); }
|
.copy-box input { flex: 1; font-family: var(--mono); }
|
||||||
|
.ds-record { margin: 12px 0 16px; }
|
||||||
|
.ds-record > .copy-box { max-width: 900px; }
|
||||||
|
.ds-record .kv { margin-top: 8px; align-items: center; grid-template-columns: max-content minmax(0, 1fr); }
|
||||||
|
.ds-record .kv dd { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
|
||||||
|
.ds-record .kv dd .copy-box { flex: 1 1 200px; max-width: 640px; min-width: 0; }
|
||||||
|
.copy-box input { min-width: 0; }
|
||||||
|
td.break { word-break: break-all; }
|
||||||
.sortable-row { display: flex; align-items: center; gap: 8px; }
|
.sortable-row { display: flex; align-items: center; gap: 8px; }
|
||||||
@media (max-width: 700px) {
|
@media (max-width: 700px) {
|
||||||
.form-grid { grid-template-columns: 1fr; }
|
.form-grid { grid-template-columns: 1fr; }
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ bind:
|
|||||||
zone_dir: $E/zones
|
zone_dir: $E/zones
|
||||||
cache_dir: $E/cache/jarl
|
cache_dir: $E/cache/jarl
|
||||||
file_group: ""
|
file_group: ""
|
||||||
|
named_user: $(id -un)
|
||||||
named_checkconf: $CHECKCONF
|
named_checkconf: $CHECKCONF
|
||||||
named_checkzone: $CHECKZONE
|
named_checkzone: $CHECKZONE
|
||||||
rndc: $RNDC
|
rndc: $RNDC
|
||||||
@@ -305,9 +306,32 @@ contains "soon"
|
|||||||
run "status lists the expiring token" 0 $J status
|
run "status lists the expiring token" 0 $J status
|
||||||
contains "Token:.*soon"
|
contains "Token:.*soon"
|
||||||
|
|
||||||
|
# DNSSEC: sign the external view's zone (the parent can't be asked here).
|
||||||
|
api() { curl -s -H "Authorization: Bearer $(cat $E/admin.token)" -H 'Content-Type: application/json' "$@"; }
|
||||||
|
run "dnssec status: off" 0 $J zone dnssec status adbraun.test --view external
|
||||||
|
contains "Policy:.*none"
|
||||||
|
run "dnssec enable" 0 $J zone dnssec enable adbraun.test --view external
|
||||||
|
contains "named is signing"
|
||||||
|
for i in $(seq 50); do $J zone dnssec status adbraun.test --view external 2>/dev/null | grep -q "signed serial" && break; sleep 0.2; done
|
||||||
|
run "dnssec status: signing" 0 $J zone dnssec status adbraun.test --view external
|
||||||
|
contains "CSK.*ECDSAP256SHA256"
|
||||||
|
contains "named:.*signed serial"
|
||||||
|
contains "DS record for the parent zone"
|
||||||
|
contains "not yet: wait until"
|
||||||
|
run "dnssec: switching off at once is refused" 0 api -X PATCH -d '{"dnssec_policy":""}' "http://127.0.0.1:$HTTP/api/v1/zones/adbraun.test?view=external"
|
||||||
|
contains "switching DNSSEC off at once"
|
||||||
|
run "dnssec: a TTL over a day is refused" 6 $J record add adbraun.test longttl A 203.0.113.9 --view external --ttl 172800
|
||||||
|
contains "max-zone-ttl"
|
||||||
|
run "record in the signed zone" 0 $J record add adbraun.test signed A 203.0.113.5 --view external
|
||||||
|
run "check-ds without a reachable parent (exit 2)" 2 $J zone dnssec check-ds adbraun.test --view external --resolver 127.0.0.1
|
||||||
|
contains "named wasn't told anything"
|
||||||
|
KEYS=$(ls $E/zones/dnssec-keys/*/Kadbraun.test.+013+*.private 2>/dev/null | head -1)
|
||||||
|
if [ -n "$KEYS" ]; then ok "named's key is in Jarl's key directory"; else bad "no key in $E/zones/dnssec-keys"; fi
|
||||||
|
|
||||||
# Backups and restore
|
# Backups and restore
|
||||||
run "jarld backup" 0 $JARLD -c jarl.yaml backup
|
run "jarld backup" 0 $JARLD -c jarl.yaml backup
|
||||||
contains "Database backed up to $E/backups/jarl-"
|
contains "Database backed up to $E/backups/jarl-"
|
||||||
|
contains "with 3 DNSSEC key files"
|
||||||
run "status shows the backup" 0 $J status
|
run "status shows the backup" 0 $J status
|
||||||
contains "Backup:.*$E/backups/jarl-"
|
contains "Backup:.*$E/backups/jarl-"
|
||||||
run "restore refused while jarld runs" 1 $JARLD -c jarl.yaml restore latest --yes
|
run "restore refused while jarld runs" 1 $JARLD -c jarl.yaml restore latest --yes
|
||||||
@@ -317,20 +341,39 @@ contains "in use by a running jarld"
|
|||||||
run "record after the backup" 0 $J record add adbraun.test afterbackup A 192.168.1.99 --view internal
|
run "record after the backup" 0 $J record add adbraun.test afterbackup A 192.168.1.99 --view internal
|
||||||
expect_dig "afterbackup A" "192.168.1.99" afterbackup.adbraun.test A
|
expect_dig "afterbackup A" "192.168.1.99" afterbackup.adbraun.test A
|
||||||
kill $JARLD_PID; wait $JARLD_PID 2>/dev/null
|
kill $JARLD_PID; wait $JARLD_PID 2>/dev/null
|
||||||
|
KEYSUM=$(sha256sum "$KEYS" | cut -d' ' -f1)
|
||||||
|
rm -f "$KEYS"
|
||||||
run "jarld restore lists backups" 0 $JARLD -c jarl.yaml restore
|
run "jarld restore lists backups" 0 $JARLD -c jarl.yaml restore
|
||||||
contains "jarl-.*\.db"
|
contains "jarl-.*\.db"
|
||||||
run "jarld restore latest" 0 $JARLD -c jarl.yaml restore latest --yes
|
run "jarld restore latest" 0 $JARLD -c jarl.yaml restore latest --yes
|
||||||
contains "previous database is in"
|
contains "previous database is in"
|
||||||
|
contains "Put back 3 DNSSEC key files"
|
||||||
|
if [ "$(sha256sum "$KEYS" 2>/dev/null | cut -d' ' -f1)" = "$KEYSUM" ]; then ok "the private key is back"; else bad "the private key wasn't restored"; fi
|
||||||
$JARLD -c jarl.yaml serve >> jarld.log 2>&1 &
|
$JARLD -c jarl.yaml serve >> jarld.log 2>&1 &
|
||||||
JARLD_PID=$!
|
JARLD_PID=$!
|
||||||
for i in $(seq 50); do curl -s -o /dev/null http://127.0.0.1:$HTTP/healthz && break; sleep 0.2; done
|
for i in $(seq 50); do curl -s -o /dev/null http://127.0.0.1:$HTTP/healthz && break; sleep 0.2; done
|
||||||
run "restored database lacks the later record" 0 $J record list adbraun.test --view internal
|
run "restored database lacks the later record" 0 $J record list adbraun.test --view internal
|
||||||
if echo "$OUT" | grep -q afterbackup; then bad "afterbackup still there after restore"; else ok "afterbackup gone after restore"; fi
|
if echo "$OUT" | grep -q afterbackup; then bad "afterbackup still there after restore"; else ok "afterbackup gone after restore"; fi
|
||||||
run "resync after restore" 0 $J resync --force
|
run "resync after restore" 0 $J resync --force
|
||||||
|
contains "serial"
|
||||||
expect_dig "afterbackup gone from named" "" afterbackup.adbraun.test A
|
expect_dig "afterbackup gone from named" "" afterbackup.adbraun.test A
|
||||||
run "audit shows the restore" 0 $J audit --action system.restore
|
run "audit shows the restore" 0 $J audit --action system.restore
|
||||||
contains "system.restore"
|
contains "system.restore"
|
||||||
|
|
||||||
|
# Turning DNSSEC off: insecure first; the DS never reached a parent, so
|
||||||
|
# named can finish at once. Then wipe the old keys.
|
||||||
|
run "dnssec disable starts turning off" 0 $J zone dnssec disable adbraun.test --view external --yes
|
||||||
|
contains "remove the DS record"
|
||||||
|
for i in $(seq 75); do $J zone dnssec status adbraun.test --view external 2>/dev/null | grep -q "Turning DNSSEC off: the parent has no DS\|has finished" && break; sleep 0.2; done
|
||||||
|
run "dnssec disable finishes" 0 $J zone dnssec disable adbraun.test --view external --yes
|
||||||
|
contains "DNSSEC is off"
|
||||||
|
run "dnssec status: old keys left" 0 $J zone dnssec status adbraun.test --view external
|
||||||
|
contains "keys from when the zone was signed"
|
||||||
|
run "dnssec wipe" 0 $J zone dnssec wipe adbraun.test --view external --yes --force --resolver 127.0.0.1
|
||||||
|
contains "removed .*Kadbraun.test"
|
||||||
|
run "dnssec status: clean" 0 $J zone dnssec status adbraun.test --view external
|
||||||
|
contains "Status:.*DNSSEC is off.$"
|
||||||
|
|
||||||
run "status at the end" 0 $J status
|
run "status at the end" 0 $J status
|
||||||
contains "Drift:.*none"
|
contains "Drift:.*none"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user