Repository navigation
Run the RLS audit on a schedule, and serve what it found - #15
Merged
Merged
Conversation
`rebase cloud resources` printed a Plan line reading "legacy (no plan)" against a column that no longer exists, and `rebase cloud billing` built a `compute_<provider>_<vmSize>` lookup key — a price for a machine on a list this platform does not buy from, dead since `vmSize` was removed on 2026-08-20 and printing a bare label ever since. Both now ask the control plane what the project's dials cost (`POST /api/functions/pricing/quote`) and print the itemised answer. Best-effort: an older control plane has no such endpoint, and a resources listing that failed because a price could not be fetched would be worse than one without it. Four dials the plans used to decide are flags now — `--replicas`, `--spot`, `--scale-to-zero`, `--storage` — and `projects create` takes the same set, so a project can be created at the size it needs rather than resized afterwards. It also stops sending `vm_size`, which the control plane dropped. `--spot false` is parsed to the boolean `false`, not the string. The string is truthy, and would have put a project that asked for on-demand capacity onto preemptible nodes at a third of the price with the restarts it declined. Co-Authored-By: Claude Opus 5 <[email protected]>
`import { defineFunction } from "@rebasepro/server"` reaches the whole
framework — boot, the collection loader, the backup routes, the SPA server,
`@hono/node-server`, `ws`, `jsonwebtoken`, Drizzle. On Node that costs start-up
time and nothing else. It also means a function file can only ever resolve
inside a Node process, however portable the function's own code is, and that
import line is in every function file, template and doc page — so it is not a
thing that can be changed later without breaking everyone who wrote one.
The new entry point carries the authoring surface and nothing else. Its
published bundle imports exactly two things, `hono` and `hono/adapter`, and two
gates keep it that way: a test walks the import graph from source and names the
chain that broke the rule, and the build evaluates the emitted file in a `vm`
context holding web globals and no `process`, `Buffer` or `require` at all.
Both are mutation-tested. Importing from the package root still works and
behaves identically.
Also in the authoring surface, because each was a gap the same move exposed:
- Typed context accessors. `getUser(c)` returns `{ uid, roles, …claims }` with
`roles` always an array, replacing the `c.get("user") as { uid: string;
roles?: string[] } | undefined` cast that every example opened with — an
assertion in a security-relevant position, and wrong for at least one auth
path that reaches it. Plus `requireDriver`, `requireRole`, and guards that
read the resolved identity rather than parsing a token (equivalent inside a
function, where the middleware has already run; fail-closed outside one).
- `waitUntil(c, promise)`. A floating promise at SIGTERM is dropped mid-flight,
so a rolling deploy could always lose a webhook the request had already
answered 200 for; shutdown now drains tracked work, bounded, and reports what
it could not wait for.
- Configuration read from the request: `getEnv`/`env`/`requireEnv`/
`lazyResource`. `new Stripe(process.env.KEY!)` at module scope is a live
defect today — it throws while the file is being imported, and the loader
reports that as a *skipped function*, so the route 404s with the reason in a
boot log. `rebase build` and `rebase doctor` now report those reads.
- `rebase build` records per-function portability in the bundle manifest, so a
host can tell what is in a bundle without booting it.
`packages/server/functions/package.json` is a resolution redirect, not a
package: TypeScript's `moduleResolution: "node"` — which the scaffolded backend
uses — ignores `exports`, and without it the template's own import fails `tsc`
while running fine. `assert-build-output.mjs` verifies redirect targets for the
same reason it verifies entry points: a broken one is silent.
Docs rewritten in all six locales, with the anchors fixed (the machine
translations had kept the English ones), and the scaffolded template and the
three agent skills moved onto the new import. The API-surface gate now tracks
both entry points.
Co-Authored-By: Claude Opus 5 <[email protected]>
`tsc` writes relative specifiers into `.d.ts` exactly as the source wrote them — extensionless, because the source is compiled by a bundler. Every package here is `"type": "module"`, and under `moduleResolution: "nodenext"` an extensionless relative specifier inside an ESM declaration file is an error. TypeScript's response is the part that matters: it does not fail at the consumer's import. It resolves the package, discards every declaration it could not follow, and types the whole import `any`. So there was no diagnostic anywhere near the cause. The first thing a consumer saw was an implicit-any error in *their own file*, pointing at their code, in a project that had done nothing wrong. Measured on `@rebasepro/server`: `bundler` resolution sees 170 value exports, `nodenext` sees zero. It has been that way for the whole life of the packages. Fixed by appending the extension the declarations always needed — `./init` → `./init.js`, and `./auth` → `./auth/index.js` where the target is a directory, resolved against the filesystem rather than guessed, because a dangling specifier degrades to `any` again. Not a trade: TypeScript maps `./x.js` onto `./x.d.ts` under node10, bundler and nodenext alike, so nothing that worked before stops working. 547 specifiers across the five packages that were built to verify it; the step runs in all 21 published builds. The rewriter refuses a `dist` whose realpath is outside its package. That is what a git worktree's symlinked node_modules looks like, and without the guard a build run there silently rewrites the primary checkout's published output. `pnpm check:dts` is the gate, in verify.yml after the build. Nothing in this repository could have caught the original defect, which is the more interesting half: `pnpm typecheck`, the docs verifier and the template checks all map `@rebasepro/*` onto source, and the API-surface gate reads a single `.d.ts` in isolation. Every gate looked at something other than the artifact a stranger installs. So this one installs each built package into a throwaway directory by symlink, imports it, and compares the value exports the type checker can see in each resolution mode — a question that needs no knowledge of any package's API, and so keeps working as they change. It detects a single reverted specifier (167 exports where 170 are expected) and names the file and line that caused it. node10 is expected for package roots always, and for a subpath only where the package ships a redirect directory — with `@rebasepro/server/functions` named explicitly, since the backend `rebase init` scaffolds compiles with `moduleResolution: "node"` and deleting that redirect would otherwise reduce coverage silently rather than fail. Co-Authored-By: Claude Opus 5 <[email protected]>
Building the fourteen packages this worktree had never built turned the gate green across all 21 — and then a mutation test on `@rebasepro/admin` walked straight past it. Reverting one specifier in its `dist/index.d.ts`, exactly the defect the gate exists for, was not caught. The discriminator was value exports: functions, consts, classes. That is the right signal for a package whose surface is mostly values, and blind for one whose surface is mostly types. `admin`'s broken re-export was `./types/index`, which carries no values at all, so nothing it exported could go missing from a count of values. `@rebasepro/types` — the package most consumers feel first — was blind for the same reason along its whole surface. Three changes: - Read the diagnostics off the package's own declarations directly, rather than inferring damage from the export surface afterwards. TS2834/2835 is the exact nodenext rule being broken; it needs no inference and no export to be lost. This meant turning `skipLibCheck` off, because it suppresses precisely the errors under test. - Compare *all* exports across resolution modes, not only the value ones. - Stage every workspace package into the throwaway consumer, not just the one under test, so its layout matches an installed tree. Turning declaration checking on surfaced a false positive immediately: a sibling `@rebasepro/*` import inside a dependency's own `.d.ts` reported TS2307 under node10. That is the probe's fault, not the package's — symlinking means TypeScript resolves from the real repository path, so an upward lookup never reaches the staged node_modules, while a real install has the whole closure flat and resolves it without trouble. TS2307 now counts only for a *relative* specifier, which is an emission defect; for a bare one it is a question the staging cannot honestly answer. Verified by mutation on three shapes it previously could not distinguish: a value-heavy package (server), a pure-type package (types), and the type-only re-export that started this (admin). Plus the node10 redirect deletion. All 21 packages now build and pass; the full run takes ~75s. Co-Authored-By: Claude Opus 5 <[email protected]>
…osed Both scripts were verified by running them and reading the output, which checks that they work on today's input and nothing about the cases they were written to handle. The gate had already stopped gating once within hours of being written, so that is not a hypothetical standard. Writing the fixtures found two more defects in the gate, neither visible by inspection and both of which made it inert rather than wrong: - The diagnostic filter was scoped to `/packages/` — the repository's own directory shape — so it silently exempted any package outside that path. Every fixture is outside it, which is why the first run of the new suite had four failures against a gate that passes the real packages. Scoped to the package under test now, which also makes the earlier cross-package false positive (a sibling's diagnostics reported under `@rebasepro/admin`) impossible by construction rather than by filtering. - The prefix comparison used the literal path. TypeScript reports resolved paths, and on macOS `/var/folders/…` is a symlink to `/private/var/…`, so the comparison matched nothing for anything under the temp directory. Real arguments happened to match; fixtures never could. The suites encode the shapes each script must tell apart. For the rewrite: a directory specifier becoming `<dir>/index.js` rather than `<dir>.js` (guessing dangles the re-export and restores the `any`), a string-literal type and an ambient `declare module` name left alone (claims that lived in a comment and nowhere else), idempotency, the symlinked-dist refusal, and a dangling specifier failing loudly. For the gate: healthy, values-broken, types-broken, a package with no values at all, subpaths with and without a node10 redirect, and a `.css` export that is not a module. Mutation-tested both suites. A naive `+ ".js"` breaks the directory test; a regex-instead-of-AST collector breaks exactly the two tests guarding syntactic position — and getting that mutation to be live took two attempts, because the first one was mis-escaped and passed vacuously. Wired into `test:gates`, which verify.yml already runs. Co-Authored-By: Claude Opus 5 <[email protected]>
Portable @rebasepro/server/functions entry point, plus the .d.ts resolution gates that keep it honest.
CLI prices resources by dial, with no plan left to name.
…reads Co-Authored-By: Claude Opus 5 <[email protected]>
`frameworkVersion` meant the framework the runtime IMAGE ships in `cloud status`, and the framework a BUNDLE installed in `cloud deployments`. The image supplies the server and the bundle supplies the driver, so the two are routinely different — printed under one name they read as the control plane disagreeing with itself about a single number, which is how it was reported. Now `imageFrameworkVersion` and `builtAgainst`, spelled out where they print so neither can be misread. Co-Authored-By: Claude Opus 5 <[email protected]>
…nning a version The security table still named 0.10.x long after 0.10 stopped being the latest minor, so it documented the opposite of the policy it meant. The rule now sits above the table and the table only illustrates it. Co-Authored-By: Claude Opus 5 <[email protected]>
…nto the site copy_changelog.js only ever moved one file; copy_repo_docs.js mirrors any repo-root document, copying rather than moving so existing references keep resolving. check:generated gates the copies so they cannot drift. Co-Authored-By: Claude Opus 5 <[email protected]>
…se study Co-Authored-By: Claude Opus 5 <[email protected]>
The dropdown panels were tall enough to cover the hero: 558px for Product, 410px for Developers at 1440x900. Two of that height came from shape, not content — a two-column grid capped at max-w-3xl, plus a full-width footer row below it holding the overview/docs links. Fold that footer into a third headed column (Explore, Resources), let the grid span the panel's inner width, and tighten the row rhythm. Wider columns also stop most descriptions wrapping to a second line, which pays again in height: Product is 380px now, Developers 298px. Mobile flattens columns into one list, so those links still appear there. Co-Authored-By: Claude Opus 5 <[email protected]>
Ports the wall from the FireCMS site into this file's own structure: INTRINSIC sizing, the shared class constants and the `product` field all stay, and the new entries feed into them rather than around them. Every new entry is tagged `product: "firecms"`. Unlike the existing seventeen this is not a guess: each is a FireCMS Cloud customer verified from signup and project activity, which is the evidence the `product` comment asks for. The tally moves from 1 known / 17 unknown to 1 rebase / 26 firecms / 16 unknown, so the caption still needs its qualifier. INTRINSIC values were read back with `new Image()` as the comment instructs, and that mattered: a viewBox-only SVG reports a 300px natural width, not its viewBox width, so seven entries would have carried numbers 2-6x too large had they been parsed from markup. Also: eight marks were too dark once grayscale and opacity-60 composited over the near-black ground (Team Global Express measured 21 against 153 for white ink); they were dark-coloured marks wrongly flagged `invert: false`. MedicalMotion moves to the white asset already here. withu.png was 84% transparent padding and overflowed its cell. Adds a "companies" type, an optional textClass, matching brightness for text fallbacks, and two-up logos on mobile. Co-Authored-By: Claude Opus 5 <[email protected]>
Three-column mega-nav and the 26-logo client wall. Co-Authored-By: Claude Opus 5 <[email protected]>
The checked-in files predate three generator changes: the users read policy compares `id = rebase.uid()::uuid` rather than casting the column to text, `orders` gained its `order` column, and the search block now emits the immutability guard that refuses to re-apply when a generated column's expression changed underneath it. Regenerating twice produces identical output. Co-Authored-By: Claude Opus 5 <[email protected]>
…write The skills had drifted from the API they describe: `@rebasepro/ui` was said to export `AddIcon`/`DeleteIcon`, which do not exist — it re-exports lucide-react under its own names (`PlusIcon`, `Trash2Icon`); the studio skill named `sideEntityController` rather than `sidePanelController`; and the project-structure tree omitted `backend/functions/`. An agent following any of these writes code that does not compile. Co-Authored-By: Claude Opus 5 <[email protected]>
`@rebasepro/rls-check` is thorough, read-only, and better than the dashboard
advisors it competes with on security specifically. Nobody runs it, because it
is a command, and a command is something you have to remember. A check that has
to be remembered reports a clean database right up until the day it matters.
`rlsAudit: { enabled: true, scan }` runs it on a timer against the database the
server is already using, logs one line per run — `warn` when a finding reaches
`warnAtSeverity`, `info` otherwise — and serves the result at
`GET /api/admin/rls-audit` behind the same admin gate as every other admin
surface. The result carries host and database name only; the checker never
returns credentials, and a test asserts the status cannot leak one.
The scanner is passed in rather than imported. `@rebasepro/server` has no
database driver, deliberately — that is what keeps it usable with Mongo and
Firebase — and `@rebasepro/rls-check` carries `pg`. Importing it here would put
a Postgres driver in every install for a feature most of them cannot use, and
would put a Postgres concept in the one package that is supposed to know nothing
about Postgres. So the schedule, the summary, the status and the route live here
and are engine-agnostic in fact rather than only in principle.
Off by default: it opens its own connection and introspects the whole catalog,
which is cheap but is not nothing, and a background query nobody asked for is a
poor default for a library.
It is an owned singleton alongside the cron scheduler, so a split deployment can
give the scan to one process with `ownership: { rlsAudit: false }`. Unlike those
two it is not claim-protected — every owner scans on its own timer, which is
redundant rather than unsafe, and the docs say so.
A failed scan is logged and recorded, never thrown. Turning a security check into
a new way for the server to fall over is a bad trade in both directions.
Also adds `@rebasepro/rls-check` to the typecheck path map: it was in the include
list but not in `paths`, so a docs snippet importing it could not resolve — which
is how the snippet typechecker caught this one before CI did.
2 of 6 tasks
…r the build
Every pull request has been failing since the portable functions entry point
landed:
FAIL baas
backend/functions/hello.ts(7,8): error TS2307:
Cannot find module '@rebasepro/server/functions'
`check:templates` and `check:eject` compile a *scaffolded project*, which
resolves `@rebasepro/*` through node_modules and its `exports` map. `./functions`
points at `dist/functions/index.d.ts`, so before `pnpm run build` it resolves to
nothing and the baas preset — whose `hello.ts` now imports it — fails to compile.
Both checks ran before the build step.
Nothing caught it locally because a developer's checkout has a `dist` lying
around from the last build; CI installs and has none. Reproduced by deleting
`packages/server/dist/functions` and running the check, which fails identically.
Moved both after `Build packages`, where `check:api-surface` already sits for
exactly this reason — its comment says "Reads dist/index.d.ts, hence after the
build". The cost is that a broken template is reported a few minutes later; the
alternative is a gate that cannot pass on a clean checkout.
Verified the rest of the lane separately: core-types, types-headless, baas-types,
test-scripts, control-chars, untranslated, hooks, unused, api-surface, dts,
deps, headless, names, derived-names and verify:docs all pass on this commit, so
this is the only thing standing between main and a green run.
`check:api-surface` reads `dist/index.d.ts`, so it only sees a new export after a build — and CI builds before it runs. The baseline had not been regenerated, so this branch failed that step while passing every gate that reads source. Additions only: createRlsAudit, summarizeRlsScan, the RlsAudit types, and `RebaseBackendConfig.rlsAudit`.
… not run it `src/boot/role.test.ts` asserts the resolved ownership object exactly, and the new `rlsAudit` key broke it — the same class as `runtime-ownership.test.ts`, missed because the package's test script is `jest` with no path and I had been running `jest test/`, which never reaches `src/**/*.test.ts`. Locally that was 152 suites; the real one is 168. Rather than only widening the assertions, the roles now describe the audit: - `functions` owns it as `false`. That role's whole shape is "runs no timers", and a periodic catalogue scan is a timer. - `REBASE_RLS_AUDIT` overrides it per process, matching `REBASE_CRON_SCHEDULER` and `REBASE_JOB_WORKERS`. A split deployment needs it: unlike those two the audit is not claim-protected, so every owner scans, which is redundant rather than unsafe. One test worth its line: naming a cron override must not silently move the audit. `REBASE_ROLE=api` with `REBASE_CRON_SCHEDULER=false` keeps `rlsAudit` true, and there is now a symmetric case going the other way. 168 suites, 2539 tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third item of #9.
@rebasepro/rls-checkis thorough, read-only, and better than the dashboardadvisors it competes with on security specifically. Nobody runs it, because it's
a command — and a command is something you have to remember. A check that has to
be remembered reports a clean database right up until the day it matters.
Runs it on a timer against the database the server already uses, logs one line
per run, and serves the result at
GET /api/admin/rls-auditbehind the sameadmin gate as every other admin surface.
warnwhen a finding reacheswarnAtSeverity(defaulthigh),infootherwise — so a clean database is quiet and a critical finding isn't.
Why the scanner is passed in rather than imported
@rebasepro/serverhas no database driver, deliberately — that's what keeps itusable with Mongo and Firebase.
@rebasepro/rls-checkcarriespg. Importing ithere would put a Postgres driver in every install for a feature most of them
can't use, and would put a Postgres concept in the one package that's supposed to
know nothing about Postgres.
So the schedule, the summary, the status and the route live here and are
engine-agnostic in fact rather than only in principle.
check:depsenforces it.I'll flag the tradeoff honestly: this means the managed runtime doesn't get the
audit for free — the image would need to carry
@rebasepro/rls-checkand wirescan. That's a deliberate follow-up decision involving a dependency and alockfile change, not something to slip into a feature branch.
Details worth knowing
catalog — cheap, but not nothing, and a background query nobody asked for is a
poor default for a library.
gives the scan to one process via
ownership: { rlsAudit: false }. Unlike cronand jobs it is not claim-protected — every owner scans on its own timer,
which is redundant rather than unsafe. Documented as such.
check into a new way for the server to fall over is a bad trade in both
directions.
only; a test asserts a
postgres://user:pass@…connection string can't surfacethrough
status().Verification
stop(), double-start(), failure isolation,continued scheduling after a failure, both refusal paths,
DATABASE_URLfallback, and the credential assertion
packages/server: 146 suites, 2147 passingpnpm typecheck,check:deps,check:headless,verify:docsall cleanTwo things this turned up on the way:
runtime-ownership.test.tspins the resolved ownership object exactly, so thenew singleton broke it — correctly. Assertions updated.
@rebasepro/rls-checkwas in the typecheckincludelist but not inpaths,so a docs snippet importing it couldn't resolve. The snippet typechecker caught
my snippet before CI did; both are fixed.
Not verified: a scan against a live database from inside a running server. The
scanner is injected and mocked in tests; the checker's own package tests cover
the scanning itself.
Cut from local
main, 17 commits ahead oforigin/main; those appear in thediff until main is pushed.