carlos / platform Public

registry: the read-only worker serves List, from its read-only connection (#328)

Root's pre-claim egress source and its slice naming (registryEgressSource,
registryEgressHosts) list the registry through openServiceRegistryReadOnly.
As root that is the privilege-dropped read-only worker, which answered only
Get, TimersFor and ArtifactHosts: every List failed with "unsupported
remote operation", so on a real box every egress assert closed the slice
as unreadable and no allow was ever written. Unit tests ran unprivileged,
where the open is direct, and never saw it; the root-runner witness did.

The worker now serves List, and a read-only registry's List queries its
own mode=ro, query_only connection instead of opening a fresh read-write
one on the path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 4e7bbc4b60079b75bf27085f60c91b026226781b parent 0a505e3
4 files changed, +24 −10
  • internal/registry/readonly.go +1 −1
  • internal/registry/readonly_test.go +5 −0
  • internal/registry/registry.go +15 −8
  • internal/registry/remote.go +3 −1
diff --git a/internal/registry/readonly.go b/internal/registry/readonly.go
index 3f2f6add7..f6900b4e0 100644
--- a/internal/registry/readonly.go
+++ b/internal/registry/readonly.go
@@ -22,5 +22,5 @@ func OpenReadOnly(path string) (*Registry, error) {
d.Close()
return nil, err
}
- return &Registry{sql: d, path: path}, nil
+ return &Registry{sql: d, path: path, readOnly: true}, nil
}
diff --git a/internal/registry/readonly_test.go b/internal/registry/readonly_test.go
index f0b0e7ad2..7332f95f7 100644
--- a/internal/registry/readonly_test.go
+++ b/internal/registry/readonly_test.go
@@ -67,6 +67,11 @@ func TestRemoteReadOnlyWALRegistry(t *testing.T) {
if err != nil || row == nil || row.Account != "acct" || row.App != "app" {
t.Fatalf("readonly WAL read: %+v %v", row, err)
}
+ // Root's egress source lists every row through this worker (#328).
+ routes, err := reader.List()
+ if err != nil || len(routes) != 1 || routes[0].Host != "readonly" || routes[0].Account != "acct" {
+ t.Fatalf("readonly WAL list: %+v %v", routes, err)
+ }
timers, err := reader.TimersFor("readonly")
if err != nil || len(timers) != 1 || timers[0].Registration != timer.Registration || timers[0].ClaimOwnership != timer.ClaimOwnership || timers[0].ClaimOwner != owner.ClaimOwner || timers[0].ClaimStamp != owner.ClaimStamp {
t.Fatalf("readonly timer identity: %+v %v", timers, err)
diff --git a/internal/registry/registry.go b/internal/registry/registry.go
index 4f86d76bd..b6318d4f5 100644
--- a/internal/registry/registry.go
+++ b/internal/registry/registry.go
@@ -30,6 +30,9 @@ type Registry struct {
remote *remoteClient
sql *sql.DB
path string
+ // readOnly is OpenReadOnly's registry: every read goes through its own
+ // mode=ro, query_only connection, never a fresh read-write one.
+ readOnly bool
}
// Route is one host a deployment serves: an app instance the platform
@@ -958,14 +961,18 @@ func (r *Registry) List() ([]Route, error) {
return out.Routes, err
}
- db, err := sql.Open("sqlite", r.path)
- if err != nil {
- return nil, err
- }
- defer db.Close()
- // busy_timeout only: the DB is already WAL, and this connection only reads.
- if _, err := db.Exec("PRAGMA busy_timeout=5000"); err != nil {
- return nil, err
+ db := r.sql
+ if !r.readOnly {
+ fresh, err := sql.Open("sqlite", r.path)
+ if err != nil {
+ return nil, err
+ }
+ defer fresh.Close()
+ // busy_timeout only: the DB is already WAL, and this connection only reads.
+ if _, err := fresh.Exec("PRAGMA busy_timeout=5000"); err != nil {
+ return nil, err
+ }
+ db = fresh
}
rows, err := db.Query(`SELECT ` + routeCols + ` FROM routes ORDER BY host`)
if err != nil {
diff --git a/internal/registry/remote.go b/internal/registry/remote.go
index 2dd340353..b12281116 100644
--- a/internal/registry/remote.go
+++ b/internal/registry/remote.go
@@ -275,7 +275,9 @@ func serveRemote(path string, input io.Reader, output io.Writer, readOnly bool)
}
}()
for q := range requests {
- if readOnly && q.Method != "Get" && q.Method != "TimersFor" && q.Method != "ArtifactHosts" {
+ // The read-only worker answers reads only. List is root's egress
+ // source and slice naming (#328), served from the mode=ro connection.
+ if readOnly && q.Method != "Get" && q.Method != "List" && q.Method != "TimersFor" && q.Method != "ArtifactHosts" {
out := remoteResponse{}
setResponseError(&out, errRemoteMethod)
if err := enc.Encode(out); err != nil {