Add AddressOverride and DomainRule objects for what lived in a ConfigMap and the config file

The address redirects page rewrote an RPZ ConfigMap through the resolver's own
service account, and the domains page rewrote allow_entries/block_entries in the
config file. Both become cluster objects like the rest.

AddressOverride is one name answered with fixed addresses (the name and
everything under it), exactly what an RPZ "name A address" line did. DomainRule
is a block or allow list of inline names. The resolver reads both with the
existing watch: overrides are rendered into the managed RPZ source the blocklist
manager already has, and rule names join the config's inline entries in the
merged overlay, so the file's config is never written to.

Names are checked to be DNS names or wildcard patterns before they are used,
because they are joined into line-oriented parser input and a newline or a
comment character in one would otherwise add a rule of its own.

The console edits both: the address-overrides and domains endpoints now write
objects. The console keeps its added rules in one DomainRule per action
(inline-block, inline-allow) instead of an object per name, and removes a name
from whichever DomainRule holds it, wildcard or not. An end-to-end test drives
the pages' endpoints and checks the resolver's answers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
matsandClaude Sonnet 5.5 committed 2026-10-16 10:08:08 +02:00
1 parent 7fd6a7e7a5
commit 88479b9a12
19 files changed
+912 -18

No files matched your search

+51
View File
@@ -153,4 +153,55 @@ func TestConsoleEditsReachTheResolver(t *testing.T) {
m := h.query("www.edit.test", dns.TypeA)
return !m.Authoritative
})
// Address redirects: the page that used to rewrite a ConfigMap.
ok("PUT", "/api/address-overrides", `{"domain":"pin.test","address":"10.7.7.1"}`)
var ov struct {
Items []struct{ Domain, Address string } `json:"items"`
}
if err := json.Unmarshal([]byte(ok("GET", "/api/address-overrides", "")), &ov); err != nil || len(ov.Items) != 1 || ov.Items[0].Address != "10.7.7.1" {
t.Fatalf("overrides right after save = %+v (%v)", ov, err)
}
eventually(t, "the resolver to answer the override", func() bool {
m := h.query("pin.test", dns.TypeA)
a, isA := dnsFirstA(m)
return isA && a == "10.7.7.1"
})
ok("DELETE", "/api/address-overrides/pin.test", "")
eventually(t, "the deleted override to stop answering", func() bool {
a, isA := dnsFirstA(h.query("pin.test", dns.TypeA))
return isA && a == "203.0.113.7"
})
// Domains: inline rules become DomainRule objects.
ok("POST", "/api/domains", `{"name":"console-blocked.test","action":"block"}`)
ok("POST", "/api/domains", `{"name":"x","action":"block","content":"# a comment\nbulk-one.test\n\nbulk-two.test"}`)
eventually(t, "the resolver to block the new rules", func() bool {
return h.query("console-blocked.test", dns.TypeA).Rcode == dns.RcodeNameError &&
h.query("bulk-two.test", dns.TypeA).Rcode == dns.RcodeNameError
})
if code, out := do("POST", "/api/domains", `{"name":"x.test","action":"redirect"}`, "console-key"); code != http.StatusBadRequest || !strings.Contains(out, "block or allow") {
t.Errorf("unsupported action = %d %s", code, out)
}
if code, _ := do("POST", "/api/domains", `{"name":"a.test\nb.test","action":"block"}`, "console-key"); code != http.StatusBadRequest {
t.Errorf("a name with a newline = %d, want 400", code)
}
ok("DELETE", "/api/domains/console-blocked.test", "")
eventually(t, "the removed rule to stop blocking", func() bool {
return h.query("console-blocked.test", dns.TypeA).Rcode == dns.RcodeSuccess
})
if code, _ := do("DELETE", "/api/domains/never-added.test", "", "console-key"); code != http.StatusNotFound {
t.Errorf("deleting an unknown rule = %d, want 404", code)
}
}
func dnsFirstA(m *dns.Msg) (string, bool) {
if len(m.Answer) == 0 {
return "", false
}
a, ok := m.Answer[0].(*dns.A)
if !ok {
return "", false
}
return a.A.String(), true
}