From d85938066966a59dfa421ec8452713ccacdf3a1b Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 01:17:55 +0100 Subject: [PATCH] systemd-resolved: the machine's socket answers routes with outside_writes too (review r2 (5)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It answered an empty outside_writes while the bus answered the kept history; the socket now reads the guard's own history (its own history file, the same the bus's tools() reads in production), so both answer the same (§5, DQ-5). Builds: design 08 sign-in-page §5, §9, DQ-5 --- .../cmd/resolver-tools/guard.go | 8 ++++--- .../cmd/resolver-tools/guard_test.go | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/systemd-resolved/cmd/resolver-tools/guard.go b/modules/systemd-resolved/cmd/resolver-tools/guard.go index 4552d03d1..fbbf6dcd7 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/guard.go +++ b/modules/systemd-resolved/cmd/resolver-tools/guard.go @@ -617,9 +617,11 @@ func (g *Guard) Answer(ctx context.Context, req Request) Reply { case "routes": var routes *Routes if routes, err = g.Resolver.Routes(ctx); err == nil { - // The machine's socket answers routes the same as the bus's (§5, DQ-5), with no outside_writes - // of its own list: a module on the machine reads displaced over its own verb. - result = g.Resolver.RoutesAnswer(routes, nil) + // The machine's socket answers routes the same as the bus's (§5, DQ-5, review r2 (5)): + // outside_writes is the guard's own history too, from the same file the bus's tools() reads + // (History, RunDir/history.json); g.Dir is that directory (RunDir in production, a test's own + // in a test), so both read one history. + result = g.Resolver.RoutesAnswer(routes, ReadHistory(filepath.Join(g.Dir, "history.json"))) } case "route": var routed *Routed diff --git a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go index 6271f4b6d..1337fc2ce 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go +++ b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go @@ -12,6 +12,8 @@ import ( "strings" "testing" "time" + + noderesolver "git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/noderesolver" ) const meshFile = "# Managed by the mesh\nnameserver 10.42.0.2\noptions timeout:3 attempts:2 edns0\n" @@ -188,6 +190,25 @@ func TestNothingIsGuardedBeforeTheFileIsRendered(t *testing.T) { } } +// The machine's socket answers routes with outside_writes too, the guard's own history, the same the bus +// reads (design 08 sign-in-page §5; DQ-5, review r2 (5)). +func TestTheSocketsRoutesAnswersOutsideWritesFromTheGuardsOwnHistory(t *testing.T) { + g, _, _ := aGuardedMachine(t) + write(t, g.Path, vpnFile) + g.Tick() + reply := g.Answer(context.Background(), Request{Verb: "routes"}) + if reply.Error != "" { + t.Fatal(reply.Error) + } + answer, ok := reply.Result.(noderesolver.RoutesAnswer) + if !ok { + t.Fatalf("the result is %T, not a RoutesAnswer", reply.Result) + } + if len(answer.OutsideWrites) != 1 || answer.OutsideWrites[0].Writer != "FortiClient" { + t.Errorf("outside_writes is %+v, want the one the guard just kept", answer.OutsideWrites) + } +} + // The socket: a module routes and takes the write standing now in one call, and the module's file is // back; a bad request and an unknown verb are answered, not dropped; the socket is root's alone. func TestTheVerbsOnTheMachine(t *testing.T) {