Table of Contents

Instances — the user/group tenant partition (there is no TenantId)

Grounded against origin/releases/7.0 (MibServer3 UserViewData/UserRepository/ContentCriteriaComponent fresh; the AUTH_INSTANCES DDL + the scoping filter on MibAuthorizationServer, a long-stable 2018 migration).

An "instance" is a multi-tenant partition that scopes USERS and GROUPS — not content rows. A user belongs to one instance (ADM_USERS.INSTANCE_ID → AUTH_INSTANCES.ID); a non-admin only sees users/groups in their own instance. There is no TenantId anywhere, and content is NOT tagged with an instance — a content row records OWNER (a user id), not an instance. This is the single most-mismodeled MIB concept: agents assume a SaaS-style TenantId column on every table. There isn't one.

What an instance is

AUTH_INSTANCES is a flat table { ID, DATEINS, NAME } on the authorization service (MibAuthorizationServer · …/Migrations/201806291912560_Mib_InstanceTable.cs:22-30). Users and groups carry a nullable FK to it:

  • ADM_USERS.INSTANCE_ID → AUTH_INSTANCES.ID (nullable)
  • ADM_GROUPS.INSTANCE_ID → AUTH_INSTANCES.ID (nullable)

The logged user's instance is surfaced to the frontend as UserViewData.InstanceId (int?) (MibServer3 · …/UI/User/UserViewData.cs:54, populated from the auth service in UserRepository.cs:80). Instances are flat — the table has no parent column (hierarchy: CANNOT-CONFIRM in 7.0).

How scoping actually happens (query-time, users/groups only)

A non-admin's view of adm_users / adm_groups is filtered in the authorization service, at query time:

// MibAuthorizationServer · ServiceDomain.cs:82-86 (paraphrased)
if (!loggedUser.IsAdministrator() && (mediaType is "adm_users" or "adm_groups"))
    queryFilter = "(INSTANCE_ID = 0 OR INSTANCE_ID = @userInstanceId OR INSTANCE_ID IS NULL) AND ID <> 1";
  • Admins bypass it (IsAdministrator() → see all instances).
  • INSTANCE_ID = 0 appears to be a shared/system pool (INFERRED from the filter — not documented; flag, don't rely on it as a contract).
  • The filter targets users/groups only — it does not touch content media types.

Instance vs SOURCE (both partition — different axes)

Instance SOURCE (building-block.content-source)
Partitions who — users & groups what — content rows, by provider
Stored on ADM_USERS/ADM_GROUPS.INSTANCE_ID a content row's Source + the SOURCES tree
Enforced query-time filter on user/group lists (auth service) source-permission check on content read/write
Content aware? No — content has no instance column Yes — that's what SOURCE is

They're orthogonal: instance says which tenant a user belongs to; source says which provider owns a content row.

Using the instance from a customization

  • Read the logged user's instance via Context.User.InstanceId (int?, backed by UserViewData.InstanceId). An administrator's InstanceId can come back as 0, so guard is int instanceId && instanceId != 0 — the working example is recipe.audit-list-readonly-scoped (Sample 6).
  • The platform will NOT instance-scope your content for you. New content is tagged OWNER = Context.User.Id (ContentCriteriaComponent.cs:914/967/1001), never an instance. To scope a list by instance you force it yourself, the way recipe.audit-list-readonly-scoped does — in OnSearchCriteriaBuilt, add a non-removable ConditionGroup (Clause = "And") holding Condition { MediaType = criteria.MediaType, Field = "INSTANCE_ID", Operator = "Equal", Value = instanceId.ToString(), Clause = "And" } to criteria.ConditionGroups:
    1. INSTANCE_ID must be a REAL column on the bound media type (add a plain Int — the filter references a physical column; there is no magic per-content instance).
    2. Use ConditionGroups, not GlobalFilters. The page FILTER is already in criteria.GlobalFilter when the seam runs, and a non-blank GlobalFilter replaces GlobalFilters in the request — a Condition appended there is silently discarded on a page with a FILTER. ConditionGroups is AND-combined with it. Set MediaType: without it the BFF writes $relation()[INSTANCE_ID] and mib.api fails. (The string GlobalFilter is mib.api's grammar — INSTANCE_ID_$eq_5, not "INSTANCE_ID=5".) See How a seam's filter combines with the page FILTER.
    3. Adding it in OnSearchCriteriaBuilt makes the scope non-removable by the operator (unlike a UI filter).

Gotchas (grounded)

  1. No TenantId — anywhere. Instance scoping is the ONLY tenant mechanism, and it only covers users/groups. Don't look for (or invent) a TenantId column.
  2. Content is not instance-aware by design. A media type has no INSTANCE_ID unless you add one; cross-instance content leakage is on you if you assumed automatic scoping.
  3. INSTANCE_ID is nullable and the filter includes IS NULL / = 0 — "unscoped/shared" rows exist; account for them.
  4. Admins see everything — don't test instance/source isolation as an admin; it bypasses the filters. The content-admin check is precise: a user is "Administrator" iff ADM_USERS.ID = 1 OR the user is linked (via LINKOBJECTS) to ADM_GROUPS.ID = 1 (the seeded Administrators group) — AuthorizationDataRepository's IS_ADMINISTRATOR subquery; PermissionWorkflow.GetFilterSqlAsync then returns an EMPTY source filter for admins. (IS_AUTH_ADMIN is unrelated — that's the user-management role only.)
  5. AUTH_INSTANCES lives on the authorization service, migrated by that repo — not the customization overlay's metadata DB. Managing instances is an admin-UI/auth concern (InstancePageWorkflow drives the create/edit page).

Creating a login-capable NON-ADMIN test user (+ per-source read grants)

Proving source/instance isolation requires a NON-admin login (gotcha 4) — and everything needed to mint one is plain rows; the password scheme is open source, not "auth-internal" (UserDomain.cs: salt empty ⇒ compare against unsalted hex MD5(password), case-insensitive; the canonical seed stores UPPERCASE). Grounded against the 6.0 auth/API checkouts + the canonical DB repo (table shapes stable across 6.0/7.0). All rows live in the datamodel/core DB (the one mib-cms-auth/mib.api read), never the overlay's metadata DB.

1. The user — required columns only (DATEINS/MIB_LAST_UPDATE/LAST_PASSWORD_CHANGE/LOCK_* default themselves; MIB_PASSWORD_SALT must stay NULL for the MD5 path; ENABLED=1 is enforced at token issuance):

INSERT INTO ADM_USERS (NAME, OWNER, ENABLED, LOGIN, PASSWORD, LOGIN_TRY_NUMBER)
VALUES ('Brand A Editor', 1, 1, 'testuser', '<UPPERCASE_HEX_MD5_OF_PASSWORD>', 0);

2. A non-admin group + membership. Group membership is a generic LINKOBJECTS row (the old AUTH_USER_GROUP table was dropped), accepted in either direction. The group must NOT be ADM_GROUPS.ID = 1 and the user must NOT be ID = 1 (the admin bypass above):

INSERT INTO ADM_GROUPS (NAME, OWNER) VALUES ('Brand A Editors', 1);

INSERT INTO LINKOBJECTS (TLOCAL, VLOCAL, TREMOTE, VREMOTE)
VALUES ((SELECT MIBINDEX FROM MEDIA_TYPES WHERE NAME='ADM_USERS'),  @userId,
        (SELECT MIBINDEX FROM MEDIA_TYPES WHERE NAME='ADM_GROUPS'), @groupId);

3. Grants — AUTH_PERMISSIONS rows keyed to the group (RESOURCE_OWNER_TYPE=2 = group; RESOURCE_OWNER_ID = the group id; upsert key = PERMISSION_KEY + DATA_TYPE + RESOURCE_OWNER_ID + RESOURCE_OWNER_TYPE + API_CLIENT_ID). Three kinds matter:

Grant PERMISSION_KEY DATA_TYPE DATA API_CLIENT_ID (lookup by OAUTH_CLIENT_ID)
per-SOURCE read source_<SOURCES.ID> 1 {"canread":true,"canwrite":false,"candelete":false} mibapi
media-type read mediatype_<MIBINDEX> 2 {"canread":true,...} mibapi
CMS menu/page the page's menu key 3 {"value":true} mibbackend — the client the React render path (DisplayWorkflow.GetRenderV2) actually queries. The legacy mib3Client does not exist on a greenfield: a grant against it inserts NOTHING silently (SDD H35, root cause of a two-spec 403 wall)

Non-admins ALSO need READ grants on ~12 system media types before ANY stock page renders — an Administrator bypasses these implicitly, so the gap only bites real fixtures (SDD H35, discovered one 403 at a time): MEDIA_TYPES, SOURCES, ADM_ENUMTYPES, ADM_ENUMVALUES, ADM_FIELDS, ADM_FILEEXTENSIONS, ADM_RELATEDS, ADM_AUX_USERNAME, ADM_GROUPS, ADM_RIGHTS, ADM_USERS, ADM_PREFERENCES — mib client user create --grant-system-read emits the whole set. RESOURCE_OWNER_TYPE values come from AUTH_RESOURCE_OWNER_TYPES (this seed: 1=User, 2=Group — deployment-specific): a TYPE=1, OWNER_ID=1 row is a USER grant to Administrator, not a conflicting group shape (SDD spec-09 R10, resolved).

At runtime the content API compiles the user's own + their groups' grants per API client; for a non-admin the list query's WHERE becomes (<mt>.SOURCE IS NULL OR <mt>.SOURCE = 0 OR <mt>.SOURCE IN (<granted ids with canread>)) (PermissionWorkflow.GetFilterSqlAsync) — which is exactly what a per-source isolation test needs to observe. Login only validates step 1; steps 2–3 govern what the user sees.

Writers need "canwrite":true on their source_<id> grant — the read-only shape above is the isolation-test fixture. mib.api's WRITE path AND-composes the media-type grant with the grant on the row's current AND new SOURCE values, applies to admins too, and treats an UNGRANTED source non-deterministically (request-shape dependent). Full mechanism + operational rule: source-model.md, "WRITE enforcement (mib.api)".

Tooling: mib client user create <login> --password <pw> mints exactly this fixture (user + group + membership + grants) against the local stack's datamodel DB — see mib client user create --help. In a migration, greenfields use raw SQL for these auth tables (the leading-underscore _Set*Permission helpers are private-repo vendored code a greenfield does not have — see the helper-provenance section of the Migration DDL API).

Discover

mib get building-block.instance-scope · force an instance scope on a list: mib get recipe.audit-list-readonly-scoped · the other partition axis: mib get building-block.content-source · custom permissions: mib get building-block.configurable-permission.