Roles, tenants and an audit log
Roles, per-tenant isolation and the audit trail an enterprise buyer asks for, with SAML and OpenID Connect sign-in, sessions, group-to-role mapping, JIT provisioning and SCIM de-provisioning
Decides what each signed-in person is allowed to do, keeps one company’s data apart from another’s, and writes down who changed what. It begins after sign-in. You bring the sign-in itself.
A feature of the Playground
This is a feature of the Vibe Coder Playground. It runs inside the Playground, with its audit record and its caveats beside it.
The mistake it removes
Two failures, both silent. A role model with no identity behind it (looks complete, denies nothing), and tenant isolation enforced in application code rather than at the data layer, where one forgotten WHERE clause serves another customer's rows and nothing errors.
What the audit found
Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.
- auditLog throws on meta: null, contradicting its own comment that it never throws minor · Correctness (2) / Claims match behavior (25a) Fixed after the audit in
4a6305622 - The 'second statement' and 'UNION' fixtures do not isolate the guards they name; two mutants survived minor · Verification integrity (28a) Fixed after the audit in
dfbd1de7e - withTenant refuses a numeric tenant id of 0 and gives an unnamed TypeError for a missing params array minor · Correctness (2) Fixed after the audit in
bc09fbf45 - Two prose claims are off by a count: 'five exports' lists six, and 'thirteen kinds of tail' graded covers eight in tests minor · Claims match behavior (25a/25d) Fixed after the audit in
795db8a50 - The tokenizer does not model PostgreSQL E'' escape strings, so a backslash-escaped quote desyncs it; the realistic case refuses loudly minor · Security (1) / Correctness (2) Fixed after the audit in
740093417
What you still have to do
The feature cannot own your secrets, your host or your legal obligations. This is the part it deliberately does not claim.
- Your identity-provider connection, which the block cannot ship: the metadata, this app's entity id and ACS URL, the group-to-role table, the SCIM token, and the routes that call start() and finish(). Until those are wired, can() and assertCan() rank whatever role the caller passes, which is the exact failure the source codebase discloses about itself: a complete ranked role table that could not deny anything, because nothing bound a request to a non-owner role. Row-level security at the database is the other companion, because withTenant() scopes queries in application code only.
- DISCOVERY, SAID PLAINLY: searching this registry for "sso", "saml", "oidc" or "scim" now returns this block, because it now does those things: SAML 2.0 sign-in over the HTTP-POST binding, OpenID Connect sign-in, JIT provisioning with group-to-role mapping, and SCIM 2.0 de-provisioning. Two enterprise sign-in asks it still does NOT answer, and a search for them does not return it: SAML single logout (signing out at the identity provider when the user signs out here) and LDAP (signing in against a directory such as Active Directory directly). It also refuses encrypted SAML assertions and identity-provider-initiated sign-in by name rather than half-supporting them.
- NOT YET RUN AGAINST A REAL IDENTITY PROVIDER: the SAML verifier, the provisioning layer and SCIM are graded by their own conformance bars (test/saml-conformance.mjs, test/provisioning-conformance.mjs) against an in-memory identity provider. Okta, Entra ID and Google Workspace have not been run against them here, and SCIM covers /Users only, with no Groups, bulk or pagination. Point your own identity provider at a staging copy before you rely on it.
- Every sign-in goes through YOUR group-to-role table. Someone whose groups are not in it is refused, not given a default role, so write the table before you switch sign-in on. One createProvisioning() is one identity-provider connection for one tenant, so a buyer with several tenants needs one connection each. Wired that way, can() and assertCan() rank a role the identity provider vouched for instead of one passed by hand.
- withTenant() scopes queries in application code. That is the right first step and it is NOT equivalent to row-level security: one query written without it still reads across tenants. Enable RLS at the database when you take real customer data.
- withTenant() PARSES the query you hand it rather than patching its text: it parenthesizes your WHERE clause and inserts the tenant filter before any ORDER BY, LIMIT, GROUP BY or RETURNING. It scopes ONE SELECT, UPDATE or DELETE over ONE simple table: aliased or schema-qualified is fine. It REFUSES, BY NAME, every statement whose tenant predicate it cannot place with certainty: a CTE ("WITH …"), a JOIN or a comma-separated FROM list, UPDATE…FROM, DELETE…USING, a sub-select ANYWHERE (the select list, the WHERE, a SET value, an EXISTS or IN, the FROM position), since the tenant filter binds to the outer table and never reaches inside one, a table function in the FROM position, an INSERT (put the tenant id in the row you write), a UNION/INTERSECT/EXCEPT (scope each branch first), more than one statement, and any SQL it cannot fully read. WHAT THAT MEANS FOR YOU: a multi-table query, or one with a sub-select, is yours to scope by hand (or run the inner query through withTenant on its own and bind its result), with the tenant condition written where you can see which table it binds to. The refusal is deliberate and it is the safe direction: a query that will not run is visible in seconds, where a filter bound to the wrong table serves, overwrites or deletes another customer's rows silently.
What lands in your project
node
- node/enterprise-kit.js
- node/oidc.js
- node/identity.js
- node/saml.js
- node/provisioning.js
- node/strict-json.js
can()/assertCan() over a ranked role table, withTenant() to scope every query, and auditLog() for the trail SOC 2 asks about. Roles come from the CALLER's identity: the block refuses to guess. node/saml.js: parseIdpMetadata() reads the identity provider's signing certificates, createSamlServiceProvider() sends the AuthnRequest (start) and verifies the POSTed response (finish), and verifySamlResponse() is the check itself. Only saml.js needs packages: `npm i xml-crypto @xmldom/xmldom` (xmldom 0.8.10 or later). node/oidc.js: createOidcClient() runs the OpenID Connect authorization-code sign-in with PKCE, and verifyIdToken() checks the ID token. node/provisioning.js: createProvisioning() maps groups to roles through YOUR table, creates the member on first sign-in, and serves SCIM 2.0 /Users so the identity provider can de-provision. It needs an `audit` recorder (pass auditLog(store)): every new member and every change of role, active or deleted is recorded with the actor, the before and after values and the time BEFORE it is saved, and a recorder that fails refuses the change. Give scim() the body UNPARSED where you can, as request.rawBody (a string or Buffer, e.g. captured by express.json({ verify })) or as a string or Buffer request.body (express.text or express.raw on the SCIM route): it then refuses a body that names a key twice, such as active, with a SCIM 400 invalidSyntax, where a body your framework already parsed has silently kept the last copy. An already parsed object body still works. node/strict-json.js holds that duplicate-key rule, shared by oidc.js and provisioning.js, so ship it with them. node/identity.js: createIdentity() issues and resolves sessions and revokeSubject() ends every session of one person; sessionCookie() and clearSessionCookie() write the cookie, and createCsrf() guards the sign-in POST.
Needs xml-crypto ^6, @xmldom/xmldom ^0.8.10 from npm.
What you supply
- roles: ranked least→most: none, member, admin, owner
- actions: an explicit table: an UNKNOWN action is owner-only, never allowed
- tenantColumn: the column every scoped query filters on (default tenant_id)
Get it
Download the Playground See pricing
A feature of the Vibe Coder Playground.
Questions
- Is Roles, tenants and an audit log audited?
- Yes. A full due-diligence audit was run on 2026-09-29 and the verdict was a pass.
- What do I still have to do myself?
- Your identity-provider connection, which the block cannot ship: the metadata, this app's entity id and ACS URL, the group-to-role table, the SCIM token, and the routes that call start() and finish(). Until those are wired, can() and assertCan() rank whatever role the caller passes, which is the exact failure the source codebase discloses about itself: a complete ranked role table that could not deny anything, because nothing bound a request to a non-owner role. Row-level security at the database is the other companion, because withTenant() scopes queries in application code only.
- How do I get this?
- It is a feature of the Vibe Coder Playground. Download the Playground, and see the pricing page for what each plan includes.
All Playground features · Free code blocks · Learn to build from zero · The coding guide