fix(seed): never auto-seed the shared Bunyip landing tenant (PMS-239) #174
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/mapps-239-demo-seed-shared-tenant"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Fixes PMS-239: in staging every user saw the same demo records and one user's edits showed for all.
Root cause
Not a cross-tenant leak - all those users are in the same tenant. Bunyip access tokens carry no tenant claim yet, so the OIDC JIT path (
auth/middleware.rs::ensure_user_from_bunyip) upserts every SSO user into one shared landing tenant (OIDC_DEFAULT_TENANT_ID, fallback..0001) - a deliberate v1 deferral (PMS-4 AC6 / docs §3.3). Co-tenant users share all rows; the first-visit demo seeder (PMS-157) seeded that shared tenant once, which made the sharing visible.The PMS-139
TenantIdsweep already prevents leaks across tenants and cannot separate users within one. Note mokosh is one-tenant-per-MSP-org, so colleagues are meant to share - "see only your own data" is not the real target; per-org isolation is, and that needs the tenant claim (below).Fix (scope: the demo-data pollution)
SeedServicecapturesOIDC_DEFAULT_TENANT_IDat construction and refuses to auto-seed it - it is a multi-user zone, not a fresh single-owner account. Unconditional (independent of theMOKOSH_DEMO_SEEDkill-switch).with_shared_tenant(..)lets tests pin the excluded tenant without process-global env, so the existing seed tests (env unset) are unaffected.scripts/wipe_demo_seed.sqlremoves rows seeded before this fix: theAcme Corporation (Demo)company + its contacts (cascade) + tickets (deleted first, no cascade) for a given tenant. Runs in a transaction that ROLLBACKs by default (preview); operator reviews counts, then switches to COMMIT. Leavesdemo_seededset so nothing re-seeds.Out of scope (the real fix)
Per-org isolation needs Bunyip to issue a tenant/org claim consumed here instead of the default-tenant funnel - PMS-4 AC6 / docs §3.3. Until then, SSO users genuinely share one tenant by design.
Verification
cargo check --all-targets,cargo clippy --all-targets: clean.cargo test --test seed_demo: 3 pass, incl. newskips_seeding_the_shared_landing_tenant; the two existing seed tests unchanged and green.Operator follow-up
Run
scripts/wipe_demo_seed.sqlagainst staging (preview first) to remove the already-seeded demo rows, then confirm the shared tenant no longer shows them. Not run here (destructive + needs staging DB access).🤖 Generated with Claude Code