Encrypted DNS health, comparing a zone's views, --local everywhere
jarld checks the DoT and DoH listeners every 10 minutes as a client would (page, dashboard, jarl encrypted-dns health, jarl_encrypted_dns_up). The Compare views tab and jarl zone diff show what differs between a zone's views, with Use this version. --local works on unlinked zones. A changed certificates.dir is followed by encrypted DNS's tls statements. Sharing an already shared version replaces other views' overrides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
67ae0091b3
commit
13ffd8cad4
31 files changed
+1153
-18
No files matched your search
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"jarl/internal/auth"
|
||||
"jarl/internal/encdns"
|
||||
"jarl/internal/engine"
|
||||
"jarl/internal/model"
|
||||
"jarl/internal/porkbun"
|
||||
@@ -488,3 +489,34 @@ func TestCleanLegoError(t *testing.T) {
|
||||
t.Errorf("rate limit: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
// When certificates.dir changes, Start writes the certificates to the new
|
||||
// place and points encrypted DNS's tls statement there.
|
||||
func TestDirChangeFollowed(t *testing.T) {
|
||||
e := newEnv(t, false)
|
||||
ctx := context.Background()
|
||||
admin := &auth.Principal{User: &model.User{Username: "admin", Admin: true}}
|
||||
now := time.Now()
|
||||
certFile, keyFile := filepath.Join(e.dir, "c.pem"), filepath.Join(e.dir, "k.pem")
|
||||
cert, key := makeCert(t, []string{"dns.example.com"}, now.Add(-time.Hour), now.Add(60*24*time.Hour), true)
|
||||
os.WriteFile(certFile, cert, 0o600)
|
||||
os.WriteFile(keyFile, key, 0o600)
|
||||
if _, err := e.m.Create(ctx, Input{Name: model.Ptr("dns"), Source: model.Ptr("file"), CertFile: &certFile, KeyFile: &keyFile, Uses: &[]string{"dns"}}, admin); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e.submit(engine.NewRequest(engine.OpOptionCreate, 0, engine.OptionInput{Scope: model.Ptr(model.ScopeTopLevel), Name: model.Ptr("tls"), Value: model.Ptr(encdns.TLSValue("dns", e.m.cfg.Dir))}))
|
||||
|
||||
moved := filepath.Join(e.dir, "tls-moved")
|
||||
cfg := e.m.cfg
|
||||
cfg.Dir = moved
|
||||
m2 := New(cfg, e.st, e.eng, slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
m2.Start(ctx)
|
||||
if _, err := os.Stat(filepath.Join(moved, "dns", ChainFile)); err != nil {
|
||||
t.Fatalf("not written to the new place: %v", err)
|
||||
}
|
||||
for _, o := range e.state().ScopedOptions(model.ScopeTopLevel, 0) {
|
||||
if o.Name == "tls" && !strings.Contains(o.Value, moved+"/dns/fullchain.pem") {
|
||||
t.Errorf("tls statement still points elsewhere: %s", o.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
legolog "github.com/go-acme/lego/v4/log"
|
||||
|
||||
"jarl/internal/auth"
|
||||
"jarl/internal/encdns"
|
||||
"jarl/internal/engine"
|
||||
"jarl/internal/model"
|
||||
"jarl/internal/porkbun"
|
||||
@@ -766,6 +767,40 @@ func (m *Manager) Start(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
m.followDir(ctx, all)
|
||||
}
|
||||
|
||||
// followDir points the tls statements encrypted DNS wrote (jarl-NAME) at
|
||||
// certificates.dir when it has changed: Start has just written the
|
||||
// certificates there, and named would otherwise keep serving the old
|
||||
// copies, which renewals no longer update.
|
||||
func (m *Manager) followDir(ctx context.Context, all []*model.Certificate) {
|
||||
st, err := m.store.LoadState(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var reqs []engine.Request
|
||||
for _, b := range encdns.TLSBlocks(st) {
|
||||
name, ok := strings.CutPrefix(b.Name, encdns.Prefix)
|
||||
if !ok || filepath.Dir(b.CertFile) == m.FilesDir(name) {
|
||||
continue
|
||||
}
|
||||
i := slices.IndexFunc(all, func(c *model.Certificate) bool { return c.Name == name })
|
||||
if i < 0 || !all[i].HasUse(model.CertUseDNS) {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(m.FilesDir(name), ChainFile)); err != nil {
|
||||
continue // not written there (yet)
|
||||
}
|
||||
reqs = append(reqs, engine.NewRequest(engine.OpOptionUpdate, b.OptionID, engine.OptionInput{Value: model.Ptr(encdns.TLSValue(name, m.cfg.Dir))}))
|
||||
m.log.Info("certificates.dir changed: pointing named at the new files", "tls", b.Name, "was", filepath.Dir(b.CertFile), "now", m.FilesDir(name))
|
||||
}
|
||||
if len(reqs) == 0 {
|
||||
return
|
||||
}
|
||||
if _, err := m.eng.Submit(ctx, reqs, auth.System, "jarld", "certificates.dir changed: tls statements follow it", engine.ApplyOptions{}); err != nil {
|
||||
m.log.Error("pointing named at the moved certificate files failed; run 'jarl encrypted-dns setup' again", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Run renews certificates when they are due and rereads file-source ones
|
||||
|
||||
Reference in new issue
Block a user