carlos / platform Public

console: CARLOS_DB_FORWARD, the root signer check, the read limits, NewHTTPServer (plan 2, Task 3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1e1f08cb5c74ee5fd5adb5d0f45f059a0c14247a parent a3a1d2f
5 files changed, +147 −7
  • cmd/console/main.go +18 −6
  • internal/console/apidbforward.go +56 −0
  • internal/console/apidbforward_test.go +39 −0
  • internal/console/httpserver.go +22 −0
  • internal/console/server.go +12 −1
diff --git a/cmd/console/main.go b/cmd/console/main.go
index 3d0d11779..845880568 100644
--- a/cmd/console/main.go
+++ b/cmd/console/main.go
@@ -93,7 +93,6 @@ import (
"fmt"
"log"
"net"
- "net/http"
"os"
"path/filepath"
"sort"
@@ -388,6 +387,7 @@ func serve() {
HibernateRegion: dbRegion,
HibernatePrefix: dbPrefix,
Region: placement,
+ DBForward: dbForward(),
ReleasePub: pub,
Key: key,
EdgeIPs: edgeIPs(),
@@ -583,11 +583,7 @@ func serve() {
//
// No Addr: the listener above is already open and Serve takes it
// directly, so Addr would be a field nothing reads.
- httpSrv := &http.Server{
- Handler: srv,
- ReadHeaderTimeout: 10 * time.Second,
- ReadTimeout: 5 * time.Minute,
- }
+ httpSrv := console.NewHTTPServer(srv)
// AFTER the listener is open and the store has migrated (openConsoleDB
// and NewServer both ran above), so readiness means what it says. With
// console.service declared Type=notify, a build that dies before this
@@ -1096,6 +1092,22 @@ func secretsEnvelopeV2() bool {
return b
}
+// dbForward parses CARLOS_DB_FORWARD: "1" turns on forwarding a carlos db
+// read to the region that holds the data (db region forward spec §11.1).
+// Unset, every db door answer is byte-identical to main. Anything else stops
+// the boot, as for the other switches.
+func dbForward() bool {
+ switch v := strings.TrimSpace(os.Getenv("CARLOS_DB_FORWARD")); v {
+ case "":
+ return false
+ case "1":
+ return true
+ default:
+ log.Fatalf("console: CARLOS_DB_FORWARD %q is not 1 (or unset)", v)
+ return false
+ }
+}
+
// reservePlatformDomains parses CONSOLE_RESERVE_PLATFORM_DOMAINS, the opt-in
// for a deployment that hosts apps for other people (the flagship, carloku).
// When it is set, `carlos domains attach` also refuses everything under
diff --git a/internal/console/apidbforward.go b/internal/console/apidbforward.go
new file mode 100644
index 000000000..6046e8849
--- /dev/null
+++ b/internal/console/apidbforward.go
@@ -0,0 +1,56 @@
+// The forwarded `carlos db` read (db region forward spec
+// docs/superpowers/specs/2026-10-22-db-region-forward-design.md): the list
+// door's marker for a cross-region instance, and the one route that admits a
+// read, queues it for a box in the data's region, and relays the box's sealed
+// answer inside the same request.
+package console
+
+import (
+ "crypto/ed25519"
+ "time"
+
+ "github.com/carlosframework/platform/internal/dbreads"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// dbForwardTimes is the forwarded read's timing (spec §5.2, §5.5). Tests
+// shrink it; production uses defaultDBForwardTimes.
+type dbForwardTimes struct {
+ poll time.Duration // how often the console reads picked, result and chunks
+ wait time.Duration // a progress line at least this often
+ stall time.Duration // a write or flush that blocks this long ends the request
+ preHeader time.Duration // everything before the 200 (backhaul waits 30 s for headers)
+ pickup time.Duration // picked must appear this long after issued_at
+ grace time.Duration // after the owner's deadline
+ bound time.Duration // the request's own bound after issued_at
+ call time.Duration // one store call inside the stream (plan review finding 12)
+
+ // beforeWrite, nil in production, runs just before admission checks the
+ // request's context ahead of each write ("audit", "request", "queue",
+ // "serial"): a test ends the request there (plan review finding 28).
+ beforeWrite func(step string)
+}
+
+func defaultDBForwardTimes() dbForwardTimes {
+ return dbForwardTimes{
+ poll: time.Second, wait: 15 * time.Second, stall: 30 * time.Second, preHeader: 20 * time.Second,
+ pickup: dbreads.ConsoleWaitsPicked, grace: dbreads.OwnerGrace, bound: dbreads.RequestBound,
+ call: 5 * time.Second,
+ }
+}
+
+// dbForwardSigner is the root signer when this console forwards: the switch
+// on, no host claims (a host-claim console answers with the residency
+// sentence, as it refuses carlos run), and a key whose public half is the
+// deployment root a box verifies against. A console holding only a scoped
+// key cannot sign a request, and so cannot forward (spec §5.5).
+func (s *Server) dbForwardSigner() (release.Signer, bool) {
+ if !s.cfg.DBForward || s.cfg.HostClaim || s.cfg.Key == nil {
+ return release.Signer{}, false
+ }
+ pub, ok := s.cfg.Key.Public().(ed25519.PublicKey)
+ if !ok || !pub.Equal(s.cfg.ReleasePub) {
+ return release.Signer{}, false
+ }
+ return release.RootSigner(s.cfg.Key), true
+}
diff --git a/internal/console/apidbforward_test.go b/internal/console/apidbforward_test.go
new file mode 100644
index 000000000..285b7acfe
--- /dev/null
+++ b/internal/console/apidbforward_test.go
@@ -0,0 +1,39 @@
+package console
+
+import (
+ "crypto/ed25519"
+ "crypto/rand"
+ "testing"
+ "time"
+)
+
+// The console forwards only with the switch on, a root key whose public
+// half is the deployment's, and no host claims (spec §5.5, §9.1, §11.1).
+func TestDBForwardSignerNeedsTheSwitchAndTheRootKey(t *testing.T) {
+ t.Parallel()
+ pub, priv, _ := ed25519.GenerateKey(rand.Reader)
+ _, other, _ := ed25519.GenerateKey(rand.Reader)
+ for name, c := range map[string]struct {
+ cfg Config
+ want bool
+ }{
+ "on, root key": {Config{DBForward: true, Key: priv, ReleasePub: pub}, true},
+ "off": {Config{Key: priv, ReleasePub: pub}, false},
+ "no key": {Config{DBForward: true, ReleasePub: pub}, false},
+ "not the root's key": {Config{DBForward: true, Key: other, ReleasePub: pub}, false},
+ "host claims": {Config{DBForward: true, Key: priv, ReleasePub: pub, HostClaim: true}, false},
+ } {
+ s := &Server{cfg: c.cfg}
+ if _, ok := s.dbForwardSigner(); ok != c.want {
+ t.Errorf("%s: %v", name, ok)
+ }
+ }
+}
+
+func TestNewHTTPServerKeepsTheConsolesTimeouts(t *testing.T) {
+ t.Parallel()
+ srv := NewHTTPServer(nil)
+ if srv.ReadHeaderTimeout != 10*time.Second || srv.ReadTimeout != 5*time.Minute || srv.WriteTimeout != 0 {
+ t.Fatalf("%+v", srv)
+ }
+}
diff --git a/internal/console/httpserver.go b/internal/console/httpserver.go
new file mode 100644
index 000000000..7a7a0282a
--- /dev/null
+++ b/internal/console/httpserver.go
@@ -0,0 +1,22 @@
+package console
+
+import (
+ "net/http"
+ "time"
+)
+
+// NewHTTPServer is the console's http.Server (cmd/console serves with it):
+// ReadHeaderTimeout 10 s, ReadTimeout 5 minutes for request bodies, and no
+// WriteTimeout, because the doors that stream (the db door, the forwarded
+// read) set their own per-write deadlines. A door that holds a request
+// longer than ReadTimeout extends its own read deadline (the import door,
+// the forwarded read); the forwarded read's long-request tests (T7) serve
+// through this constructor. cmd/console's comment above its call says why
+// each value is what it is.
+func NewHTTPServer(h http.Handler) *http.Server {
+ return &http.Server{
+ Handler: h,
+ ReadHeaderTimeout: 10 * time.Second,
+ ReadTimeout: 5 * time.Minute,
+ }
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index e8f8d7e5f..f24a880df 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -35,6 +35,7 @@ import (
"github.com/carlosframework/platform/internal/appconfig"
"github.com/carlosframework/platform/internal/applog"
"github.com/carlosframework/platform/internal/boxid"
+ "github.com/carlosframework/platform/internal/dbreads"
"github.com/carlosframework/platform/internal/dnsrec"
"github.com/carlosframework/platform/internal/domains"
"github.com/carlosframework/platform/internal/economics"
@@ -562,7 +563,11 @@ type Config struct {
// box agent beside it reconciles with), compared against an instance
// record's Region before any S3 call. Empty on the home region, whose
// records keep region "" too (see HomeRegion).
- Region string
+ Region string
+ // DBForward is CARLOS_DB_FORWARD=1: a carlos db read of an instance in
+ // another region is forwarded to a capable box there (db region
+ // forward spec). It also needs Key to be the deployment root's.
+ DBForward bool
ReleasePub ed25519.PublicKey // pinned channel-pointer verification key
// Key signs channel pointers for promote/rollback (CARLOS_RELEASE_KEY).
// nil is a legal deployment: the console runs read-only, the promotion
@@ -921,6 +926,10 @@ type Server struct {
// is how long one may go without moving a byte (apidb.go).
dbStreams *dbStreamLimits
dbStreamIdle time.Duration
+ // dbReads bounds open forwarded reads per person and per console, held
+ // by each read's request (spec §5.7, J5); dbf is its timing.
+ dbReads *dbStreamLimits
+ dbf dbForwardTimes
// cliRoles is pattern -> allowed roles, recorded by cliRoute as it
// registers each /api/cli/ door (authcli.go). Written once, during
// registerCLIRoutes, before the server serves anything, and only read
@@ -1459,6 +1468,8 @@ func NewServer(cfg Config, st *Store) (*Server, error) {
s.dbReplica = s.cachedReadReplica
s.dbStreams = newDBStreamLimits(dbMaxStreams, dbMaxStreamsPerPrincipal)
s.dbStreamIdle = dbStreamIdleDefault
+ s.dbReads = newDBStreamLimits(dbreads.OpenPerConsole, dbreads.OpenPerPerson)
+ s.dbf = defaultDBForwardTimes()
s.registerCLIRoutes()
// The email API's ten doors (apimail.go, tenant-email task 17) —
// registered separately from registerCLIRoutes because this task's file