Table of Contents

Configurable permissions — custom, service-defined permission keys per api_client

Grounded against origin/releases/7.0 (MibServer3 BFF + the Permission microservice + MibServerApi).

Configurable permissions are the SCHEMA of permission keys a backend exposes — separate from what a given user HAS. Each backend (BFF, Data API) publishes a catalog at GET /configurablepermissions; each OAuth api_client points at a catalog via API_CLIENTS.CONFIGURABLE_PERMISSIONS_URL; the permission microservice fetches the catalog, merges the user's + group's grants (AUTH_PERMISSIONS), and resolves — per (userId, oauthClientId) — which keys are true. This is how you add a CUSTOM permission (a Boolean key) to gate a menu, a dashboard, or any custom feature — beyond the built-in media-type and SOURCE permissions.

Two things share the word "permission" and trip people up (system_overview.md):

  • Configurable permissions = the schema — "what keys CAN be set" (GenericPermission, published at /configurablepermissions).
  • The Permission enum (CanRead/Write/Delete/…) = instance state — "what this user HAS on a resource, now".

The three permission object types

PermissionObjectType (Permission/…/GenericPermissionItem.cs): Source=1, MediaType=2, Boolean=3, Generic=4. The built-ins (media-type CRUD, SOURCE ownership) are types 2 and 1. A CUSTOM feature permission is a Boolean key (type 3) — a simple on/off you define and check yourself.

1. The catalog a backend publishes

GET /configurablepermissions (BFF: MediaiBox.Cms.FrontEnd.Server/Controllers/PermissionsController.cs:22, [AllowAnonymous] + ETag; routed at AppStart/RouteRegister.cs:106) returns a GenericPermission:

class GenericPermission        { List<GenericPermissionItem> Items;  List<GenericPermissionCategory> Categories; }
class GenericPermissionCategory{ string Key; string Name; bool SupportsHierarchy; Dictionary<string,string> GenericKeys; }
class GenericPermissionItem    { object Id; string Key; string Name; string Title; object ParentId;
                                 PermissionObjectType Type; string CategoryKey /* "category" */; }

The BFF's catalog is defined in code — a developer adds items in MediaiBox.Cms.FrontEnd.Dao/ConfigurationRepository.cs (GetConfigurablePermissions). The Data API generates its media-type/source entries from the DB (MibServerApi:…/MibAnonymousWorkflow.cs).

2. Point an api_client at a catalog

API_CLIENTS.CONFIGURABLE_PERMISSIONS_URL (per row; may be NULL = no configurable permissions) points at a catalog — a backend's /configurablepermissions, or any HTTP-served JSON. mib seeds this from setup.yaml apiClients: (ApiClients.cs, column CONFIGURABLE_PERMISSIONS_URL). The permission MS (Permission/…/Services/PermissionDataRepository.cs:726) reads the URL per client.

A hand-authored catalog (e.g. http://<nginx>/configurable-permissions.json) looks like:

{ "items": [
  { "id": "feature_xyz", "key": "feature_xyz", "name": "Feature XYZ", "title": "Feature XYZ",
    "parent": null, "type": "Boolean", "category": "custom_features" },
  { "id": "brands", "key": "brands", "name": "Brands", "title": "Brands",
    "parent": null, "type": "Boolean", "category": "menu" },
  { "id": 5000, "key": "mediatype_5000", "name": "AGILEONE_BRANDS", "title": "Brands",
    "parent": null, "type": "MediaType", "category": "" }
] }

(Menu visibility uses one Boolean/menu entry per MENU_KEY; CRUD uses a MediaType entry mediatype_<MIBINDEX>.)

3. Grants — AUTH_PERMISSIONS

A grant ties a key to a group or user, under an api_client (Permission/…/Services/PermissionDataRepository.cs:70):

AUTH_PERMISSIONS { RESOURCE_OWNER_ID; RESOURCE_OWNER_TYPE (1=User, 2=Group); PERMISSION_KEY; DATA_TYPE; API_CLIENT_ID; DATA }

For a Boolean grant to a group: PERMISSION_KEY = "feature_xyz", RESOURCE_OWNER_TYPE = 2 (group), RESOURCE_OWNER_ID = <groupId>, DATA_TYPE = 3, DATA = {"value":true}, API_CLIENT_ID = <the client>. Written by POST /permission/v1/save ({ ownerId, ownerType, apiKey, permissions:[{key, boolean, categoryKey}] }), a data-model migration/seed, or the AuthorizationServer admin UI. (How grants are seeded in production — admin UI vs migration vs the save endpoint — is deployment-specific; CANNOT-CONFIRM a single canonical path.)

4. Resolution — the permission microservice

GET permission/v1/fromOauthClient?userId=<id>&oauthClientId=<client> (Permission/…/Controllers/PermissionController.cs:58) → GetCompiledPermissions(userId, oauthClientId): maps the OAuth client id → api_client id, loads that client's cached catalog, and merges the user's + their groups' AUTH_PERMISSIONS grants by key. Returns a list of PermissionEntityDto:

class PermissionEntityDto { object ObjectId; string Name; string Key; int ObjectType; string CategoryKey;
                            bool Boolean;   // <-- the grant value for a Boolean key
                            bool CanRead; bool CanWrite; bool CanDelete; /* + source/mediatype fields */ }

5. How a consumer CHECKS a key (the "use it" part)

The BFF fetches the resolved set once per user (cached by access token) via MediaiBox.Cms.FrontEnd.Dao/UserRepository.cs:181 GetAuthorizationPermissions(clientId) (→ /fromOauthClient). Menus gate on it (Helpers/MenuTreeBuilder.cs:123):

var permission = menuPermissions.FirstOrDefault(p => p.Key == item.MenuKey && p.Type == PermissionObjectType.Boolean);
if (permission != null) menuItemInfo.IsAvailable = permission.Boolean;

There is NO Context.User.HasConfigurablePermission(key) helper — a custom feature checks the list directly:

// server-side (a workflow / custom component)
var perms = await _userRepository.GetAuthorizationPermissions("<clientId>", ct);
bool hasFeature = perms.Any(p => p.Key == "feature_xyz" && p.Boolean);
// client-side (a React remote)
const perms = await fetch(`/permission/v1/fromOauthClient?userId=${userId}&oauthClientId=<client>`).then(r => r.json());
const hasFeature = perms.find(p => p.key === 'feature_xyz')?.boolean === true;

6. End-to-end — add a CUSTOM Boolean permission

  1. Define the key — add a GenericPermissionItem { Key:"feature_xyz", Type:Boolean, CategoryKey:"custom_features" } (+ a GenericPermissionCategory if new) to the BFF's catalog (ConfigurationRepository.GetConfigurablePermissions), OR add it to the JSON the api_client's CONFIGURABLE_PERMISSIONS_URL serves. Rebuild/redeploy the BFF if you edited code.
  2. Wire the URL — ensure the api_client's API_CLIENTS.CONFIGURABLE_PERMISSIONS_URL points at that catalog (setup.yaml apiClients: → mib seeds it).
  3. Grant it — an AUTH_PERMISSIONS row (Boolean, {"value":true}, DATA_TYPE=3, RESOURCE_OWNER_TYPE=2) for the group, under the api_client.
  4. Check it — perms.Any(p => p.Key == "feature_xyz" && p.Boolean) to gate the feature/menu.
  5. Refresh — the permission MS caches catalogs + grants (MetadataRefreshIntervalSeconds, see cms/microservices/permissions.md). After a catalog or grant change, restart the permission microservice + the BFF (or wait the interval) — DB/file edits alone won't show until the cache turns over. The BFF's own copy is keyed to the access token, so a fresh login also re-fetches.

7. Who opens a page — media-type grants, the 403 and the buttons

The media-type entries decide what a page shows (MibServer3 releases/7.0 and main, DisplayWorkflow):

  • Every media type is in the catalog. The Data API client's catalog lists every row of MEDIA_TYPES (712 of 712 on GVP's 7.1 stack); one with no grant comes back CanRead = false. A user's flags are the OR of its own grants and its groups'; user 1 and the members of group 1 get everything. CanCreate follows CanWrite (mib.api MibPermission).

  • A grant row names its owner by type and id. RESOURCE_OWNER_TYPE says whose row it is — the permission service reads User = 1 and Group = 2 (PermissionType, the two rows of AUTH_RESOURCE_OWNER_TYPES) — and user and group ids overlap: on GVP's dev2611, owner 7 is user 7 (718 rows) and group 7, "OB Administrators" (1,376 rows). A greenfield's grants are user 1's own: no group holds one there.

  • A component needs read on more than its own type. VerifyUserPermissions makes a component unavailable — Read = Deny — when the user cannot read its MEDIATYPE, the media type one of its Related fields points to, or a media type it hangs from by a direct 1:N relation (the meta response links both sides of ADM_RELATEDS). One unavailable component is a 403 for the whole page.

  • Then each archetype's GetPermissions:

    Archetype Read Write Create Delete
    Form CanRead per record (mib.api), else DontCare — Deny with DENY_ON_READ_ONLY CanCreate and the source per record, else Deny
    Related lists DontCare, Deny without CanRead ALLOW_EDIT and CanWrite, else DontCare — Deny with DENY_ON_READ_ONLY DontCare DontCare, Deny without CanDelete (unless REMOVE_BUTTON_BEHAVIOR is SetNull)
    List CanRead ALLOW_EDIT and CanWrite ALLOW_ADD_NEW and CanCreate DontCare
  • A MEDIATYPE that is not a media type has no catalog entry. A stock form, list or related list dereferences the missing permission, and BuildComponentPermissions falls back to Read = Allow, Create/Delete = Deny: it reads for everybody. A self-fetch form (ProvidesExternalData) resolves Deny instead — a 403 for every non-admin, unless OnPermissionResolved re-allows.

  • The page opens when no component denies Read (and the menu gate lets it). Save needs one component with Write Allow, none with Deny, and ALLOW_WRITE; New the same with Create, ALLOW_CREATE and an edit page; Delete the same with Delete and ALLOW_DELETE — the three page flags default to true. So a related list over a type the user cannot delete takes the page's Delete away.

  • A duplicated grant locks out a whole group. Two AUTH_PERMISSIONS rows for one group, key and client make the permission service throw An item with the same key has already been added. Key: mediatype_<n>: a 500 for every member of the group, on every page. Administrators are not affected. Seen on GVP's local test seed (gvp2610, gvp2611): the seed grants group Basic {"canread":true} on every media type, and the copy migration GVP_264_4_AddPermissions_To_GVP_SUBSCRIPTIONS_ORDERING adds a second row for mediatype_819 — the group's 20 test users get the 500. dev2611 has no duplicate.

  • None of this guards /api/v2/handler: the route checks no permission, the handler does (Host your own endpoint).

Check it without logging in as each user: mib access <pageKey> --group <name> reads the datamodel snapshot's grants; --user <login> asks the permission service, as mib.api does for the BFF. It warns when the snapshot is another database's or older than a week. mib inventory --warnings reports mediatype-not-in-datamodel and permission-grant-duplicate.

Load skills: mib-pages.

Use cases

  • Gate a custom menu item — the #1 use: a Boolean key per MENU_KEY decides sidebar visibility (local-stack-gotchas.md §9 — this is why a fresh stack's React menu is empty).
  • Feature flags per group — show a custom dashboard/action only to groups granted its Boolean key.
  • Per-integration scoping — a service authenticating as its own api_client sees only the catalog + grants for that client.

Gotchas

  1. Three things must line up for a gated menu/feature: the catalog entry (Boolean key), the AUTH_PERMISSIONS grant, AND (for menus) MIB3UX_MENU.IS_REACT=1. Missing any → the key resolves null/false and the item is dropped.
  2. Caching hides changes — always restart the permission MS + BFF (or wait the refresh interval) after editing the catalog or grants.
  3. No helper to check a key — fetch GetAuthorizationPermissions / /fromOauthClient and test p.Key && p.Boolean.
  4. The catalog is per api_client — grant + check under the SAME client the feature runs as (BFF vs Data API).
  5. Related but different: media-type group permissions (recipe.grant-media-type-permission) and SOURCE ownership (building-block.content-source) are the built-in types 2 and 1; a custom feature flag is a Boolean (type 3).