systemd-resolved: the machine's socket answers routes with outside_writes too (review r2 (5))

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
This commit is contained in:
jochen
2026-11-25 01:17:55 +01:00
parent 8f86aedeae
commit d859380669
2 changed files with 26 additions and 3 deletions
@@ -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
@@ -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) {