Skip to main content

Module sql_shim

Module sql_shim 

Source
Expand description

The compute sql-shim (PLAN-compute-bindings, Phase 0).

An opaque compute workload (container / micro-VM) cannot import the WASI sql host interface a handler uses. This shim gives it the same per-tenant-scoped SqlBackend over a wire protocol: a single per-node HTTP endpoint speaking libsql’s hrana-over-HTTP /v2/pipeline JSON, so an off-the-shelf libsql client in the guest connects with zero boatramp-specific code.

§Isolation

Requests authenticate with Authorization: Bearer <token>; the token maps to an Arc<dyn SqlBackend> already resolved for exactly one project/site (via the same SqlBackends::database call a handler makes). The wire protocol has no “open database” verb — a request can only run statements against the backend its token was registered with — so a workload is structurally incapable of naming another tenant’s data, exactly like the WASI handler. The token is boatramp-minted and instance-scoped; the operator’s DB credentials never enter the guest.

Structs§

SqlShim
The shim’s token → resolved backend registry, shared with the HTTP handler.
SqlShimResolver
Resolves a workload’s sql ComputeBindings to a shim endpoint + credential injected into the guest env. Holds the same SqlBackends provider a handler uses, the shim registry, the guest-reachable shim base URL, and a per-node secret used to derive a token that is deterministic (recomputable at release / re-register without persisting it) yet unguessable (keyed by the secret).

Functions§

spawn_sql_shim
Activate the compute sql-shim: bind its listener and build the resolver to hand the compute reconcile. shim_url is the guest-reachable base URL (e.g. http://10.0.0.1:8081, or the docker bridge gateway); the shim binds 0.0.0.0:<port-from-url>. Returns None — the feature stays off — when there is no sql provider, no shim_url, or the bind fails.