Open source · vishwajit-vm Designed · Phase 2
Strutvane Auth
Identity, RBAC/ABAC compiled to SQL, multi-tenancy & audit
@strutvane/auth handles who you are, what you may do and which tenant you belong to. Authentication plugs in through adapters (Better Auth by default, or OIDC/SAML providers); authorization, tenancy and audit are native. Policies are written once and compile to SQL, so the database only ever returns rows a user is allowed to see. It works inside Strutvane or standalone in Hono, Express, Fastify, Nest and Next.js apps.
Built for: B2B backend teams that need SSO, roles, tenant isolation and an audit trail.
Packages on npm
@strutvane/auth↗Name reserved · planned for 0.2
↓ Scroll to explore the problem, architecture and stack
The problem
Permission checks scattered through controllers drift out of sync, “filter in memory” leaks data at scale, and multi-tenant apps are one forgotten WHERE clause away from showing one customer another customer’s data.
Why it matters
Writing a rule once and enforcing it in the database — with row-level security as a second wall — makes data leaks structurally hard, and makes every decision explainable with auth:explain.
What you can do with it
How it’s built
A simplified view of the architecture — follow the dots as a request moves down the layers.
A request, step by step
- A request hook turns a session, JWT or API key into an Actor.
- The tenant resolver produces a TenantContext, re-checked against membership on every request.
- Before the query runs, the policy engine adds a filter describing exactly which rows the actor may see.
- That filter compiles to NULL-safe SQL, and row-level security enforces the tenant inside the database.
- Fields the actor may not read are stripped from the response; the audit entry is written in the same transaction.
Tech stack
What I built
- Designed the auth package: identity adapters, the policy engine, tenancy resolution and the audit sink.
- Proved policy-to-SQL compilation in spike 02 (70 tests, 43,930 property-based comparisons, 0 mismatches) and tenant isolation in spike 03 (37 tests, 2,400 concurrent transactions, 0 cross-tenant rows).
- Proved the hardened auth adapter in spike 07 (49 tests on PostgreSQL 18; 3 planted bugs caught; a second engine passes the same contract suite).
- Wrote five mandatory row-level-security rules (ADR-0007) after finding that a session-level SET leaked the tenant to another client through PgBouncer 40 times out of 40.
- Defined a hardened adapter (ADR-0013): shared rate-limit storage, trusted proxies only, sessions revoked on password reset, constant-time resets and a 12-character minimum password.
Hard problems & how I solved them
✅ Two-valued, NULL-safe semantics (IS DISTINCT FROM, COALESCE(…, FALSE)) behind one validation gate; a null actor never matches — which closed a privilege-escalation trap the spike found (ADR-0008).
✅ RESTRICTIVE policies, fail-closed settings, transaction-local set_config only, a runtime role that can’t bypass RLS, and a helper that destroys broken connections (ADR-0007).
✅ A mandatory hardened adapter fixes what the spike exposed: sessions surviving a password reset, timing that revealed which emails exist (419 ms vs 12 ms) and X-Forwarded-For spoofing (ADR-0013).