MicroServices - Permissions
Introduction
The permission microservice is responsible for querying and persisting user permissions.
The functionalities are available through an API, which will be detailed later.
Grounded against
origin/releases/7.0(MibMicroServices/Permission; consumers in MibServer3 and the FileManagement MS). The cited surfaces are byte-identical onreleases/6.0.
Related docs. System Overview — the microservices places the Permission MS in the request path (the BFF caches its decisions per user).
What it does & how it works
The Permission MS is the platform's authoritative permission resolver: given a user (or API/OAuth
client) it returns the compiled effective permissions, and it persists permission edits. It is an
internal service — reached over the cluster network by its consumers, not by end users (no
per-endpoint [Authorize]/JWT scheme is registered in Program.cs).
- Data source. It reads the authorization database (
MibDatabaseConfig) viaPermissionDataRepositoryand compiles raw rows into effective permissions (PermissionCompilationService,PermissionOwnerResolver). - In-memory caches + background refresh. A
PermissionMetadataCacheand aGroupPermissionCacheare filled at startup and refreshed by background loops onMetadataRefreshIntervalSeconds(default 3600) andGroupPermissionRefreshIntervalSeconds(default 60).MetadataInitialFetchTimeoutSecondscontrols startup:<= 0(production) blocks readiness until the cache is populated;> 0starts with an empty cache after the timeout and keeps retrying. - Configurable permissions. It also fetches "configurable" API-client permissions over HTTP
(
IConfigurablePermissionHttpClient); a health check can gate on this (EnableHealthCheckConfigurablePermissions).
Dependencies & consumers
- Depends on: the authorization DB (
MibDatabaseConfig) + an HTTP source for configurable permissions. - Consumed by: the BFF / MibServer3 —
RepositoryFactorybuilds aMibPermissionClientfromMibPermissionMicroServiceClientConfig.UrlMicroService, andUserRepository/InstanceRepositoryresolve permissions through it (then cached per-user in the BFF) — and the FileManagement MS, whoseMibAuthorizationClientinjectsIMibPermissionClientto authorize uploads/downloads. Both register it as a health-check dependency.
Prerequisites
- Docker
- MibConfig via ENVVAR
Required Configuration Files
Some configurations are required by the microservice and for the service that consumes it service.
Server side configurations
MibPermissionMicroServiceServerConfig
MetadataRefreshIntervalSeconds: Defines how frequently the background service polls for updated permission metadata after the initial startup. Behavior: � The background service uses a PeriodicTimer to refresh permission metadata at regular intervals. The effective interval is Math.Max(1, MetadataRefreshIntervalSeconds) seconds, ensuring a minimum of 1 second between refreshes regardless of configuration.
MetadataInitialFetchTimeoutSeconds: Controls the startup behavior when the application first attempts to populate the permission metadata cache. Behavior: � Value <= 0 (Recommended for Production): The host will wait indefinitely for the initial metadata fetch to succeed. The application will not accept requests until the cache is populated, ensuring that no request ever sees empty permissions. This is the preferred setting for production environments where failing readiness probes is better than serving incorrect authorization data. � Value > 0 (Development/Testing): The host will wait up to the specified number of seconds for the initial fetch. If the timeout expires before the fetch completes, the application will start with an empty cache and log a warning. The background refresh loop will continue retrying. This setting allows faster iteration during development when external dependencies might be unavailable.
EnableHealthCheckConfigurablePermissions: Define if configurable permissions are enabled at health check (Default = true).
GroupPermissionRefreshIntervalSeconds: How often (in seconds) the group-permission cache is refreshed after startup (Default = 60).
HomeCardRefreshIntervalSeconds: How often (in seconds) the Home card snapshot is refreshed after startup (Default = 60). Values above 60 are capped to 60, in order that card changes reach users within one minute. See Home cards.
In both time-related config the time informed must be in seconds.
Example:
<?xml version="1.0" encoding="utf-8" ?>
<mibConfig>
<default>
<MetadataRefreshIntervalSeconds>8600</MetadataRefreshIntervalSeconds>
<MetadataInitialFetchTimeoutSeconds>8600</MetadataInitialFetchTimeoutSeconds>
<EnableHealthCheckConfigurablePermissions>false</EnableHealthCheckConfigurablePermissions>
</default>
</mibConfig>
Metadata cache and propagation
The microservice keeps an in-memory snapshot of the configurable permissions (media type and source permission keys) that it fetches from each API client's configurablepermissions endpoint (e.g. MibApi). A background service refreshes the snapshot every MetadataRefreshIntervalSeconds.
Each refresh is a conditional HTTP request (If-None-Match): if the upstream content is unchanged the producer answers 304 Not Modified and the current snapshot is reused (cheap); if it changed, a 200 response replaces the snapshot. For this to work correctly the producer's configurablepermissions ETag must be a hash of the response content, so that adding, editing or removing a source / media type yields a new ETag and the change is picked up on the next refresh. A newly created Content Source therefore becomes visible to permission resolution within one MetadataRefreshIntervalSeconds window — no service restart required.
Tuning: lower MetadataRefreshIntervalSeconds for faster propagation, raise it for lower load — either way correctness is preserved, since unchanged content still short-circuits with 304. On the producer side (MibApi), the object cache that backs the underlying id list (MibObjectCacheConfig.mibconfig, findall section) is invalidated on save, so when enabled it does not add staleness beyond the refresh window.
MibDatabaseConfig
Configuration used to indicate the authorization database.
Example:
<?xml version="1.0" encoding="utf-8" ?>
<mibConfig>
<default>
<type>sql2005</type>
<server>server</server>
<database>database</database>
<username>username</username>
<password>password</password>
</default>
</mibConfig>
Home cards
The microservice resolves which Home cards a user gets, beside the menu permissions it already returns to the BFF. A background service loads every card of ADM_HOME_CARDS, its image row of ADM_HOME_CARD_IMAGES and its switched-off groups of ADM_HOME_CARD_GROUPS into an in-memory snapshot every HomeCardRefreshIntervalSeconds. A failed refresh keeps the last good snapshot and logs the failure as an error, only the first time after a successful refresh, while the next failures are logged in Verbose, and before the first successful refresh nobody gets cards. The groups of the user are read on every request, from the same LINKOBJECTS rows as the menu permissions, so a card is returned when at least one of the user's groups is not switched off for it. A user without groups gets no card; there is no administrator bypass.
The card tables live in the api database. Where the authorization and api tables share one database (Ex: GVP), nothing has to be configured, since the cards are read from the default database. Where the api database is separate, the microservice needs the database alias api, pointing at the api database:
<?xml version="1.0" encoding="utf-8" ?>
<mibConfig>
<default>
<!-- authorization database -->
</default>
<api>
<type>sql2005</type>
<server>server</server>
<database>api database</database>
<username>username</username>
<password>password</password>
</api>
</mibConfig>
Or with environment variables: MIBDATABASECONFIG_API_TYPE, MIBDATABASECONFIG_API_SERVER, MIBDATABASECONFIG_API_DATABASE, MIBDATABASECONFIG_API_USERNAME and MIBDATABASECONFIG_API_PASSWORD. Without the alias in a split installation, the refresh fails, nobody gets cards and the menu is not affected.
MibPermissionMicroServiceClientConfig
Configuration intended for applications that will consume the microservice.
- UrlMicroService: Access URL for the permission microservice (config key
urlMicroService). - MaxCallErrors, int: maximum number of times the microservice is called when the response is unsuccessful (default
1, meaning no retry). Retries stop early on non-retriable statuses (400,401,403). ThehomeCardscall is always made once, whatever this value, since the menu is returned without cards when it fails. - Timeout, int: maximum response time tolerated from the microservice in seconds (default
0, meaning no client-side timeout is applied). When a caller provides its ownCancellationToken, that token takes precedence over this internal timeout.
Example:
<?xml version="1.0" encoding="utf-8" ?>
<mibConfig>
<default>
<urlMicroService>Url from microservice</urlMicroService>
<maxCallErrors>3</maxCallErrors>
<timeout>30</timeout>
</default>
</mibConfig>
These resilience settings mirror the ones already available on the Edit History client. Defaults preserve the previous behavior (a single call, no client-side timeout), so they only take effect once configured.
Applications that access the permission microservice and will require this config:
- MediaiBox.Cms.Api.Server (MibApi)
- MediaiBox.Cms.Authorization.Server (MibAuthorization)
- MediaiBox.Cms.FrontEnd.Server (Mib3)
- MediaiBox.Cms.MicroServices.FileManagement (the FileManagement MS — authorizes uploads/downloads via
IMibPermissionClient)
API Routes
Grounded against
PermissionController@releases/7.0(basepermission/v1/): the routes take query params (validated by anExactQueryParamfilter), not path segments, and Swagger/OpenAPI is generated viaAddSwaggerGen. The response shapes below are as documented.
GET: /permission/v1/fromApiClient?userId={userId}&apiClientId={apiClientId}
Parameters:
- userId: Logged in user id.
- apiClientId: ApiClient id to obtain permissions (referring to table "API_CLIENTS" field "ID").
- Return, body:
[
{
"objectId": 0,
"name": "string",
"title": "string",
"key": "string",
"parentId": 0,
"objectType": 1,
"ownerId": 0,
"ownerType": 1,
"categoryKey": "string",
"canRead": true,
"canWrite": true,
"canDelete": true,
"ownerCanRead": true,
"ownerCanWrite": true,
"ownerCanDelete": true,
"isInherited": true,
"boolean": true
}
]
- ownerType: Indicates whether the permission is for a user(1) or a group(2).
- objectType: Indicates whether the permission is for a source(1), mediatype(2) or boolean(3).
GET: /permission/v1/fromOauthClient?userId={userId}&oauthClientId={oauthClientId}
Parameters:
- userId: Logged in user id.
- oauthClientId: oauthClientId to obtain permissions (referring to table "API_CLIENTS" field "OAUTH_CLIENT_ID").
- Return, body:
[
{
"objectId": 0,
"name": "string",
"title": "string",
"key": "string",
"parentId": 0,
"objectType": 1,
"ownerId": 0,
"ownerType": 1,
"categoryKey": "string",
"canRead": true,
"canWrite": true,
"canDelete": true,
"ownerCanRead": true,
"ownerCanWrite": true,
"ownerCanDelete": true,
"isInherited": true,
"boolean": true
}
]
- ownerType: Indicates whether the permission is for a user(1) or a group(2).
- objectType: Indicates whether the permission is for a source(1), mediatype(2) or boolean(3).
GET: /permission/v1/fromOwnerPermissions?ownerId={ownerId}&permissionType={permissionType}
(a second variant also takes &apiKey={apiKey} to scope to one API client)
Parameters:
- ownerId: Owner ID.
- permissionType: Indicates whether the owner id refers to a user(1) or a group(2).
- Return, body:
{
"Front": {
"items": [
{
"objectId": 0,
"name": "string",
"title": "string",
"key": "string",
"parentId": 0,
"objectType": 1,
"ownerId": 0,
"ownerType": 1,
"categoryKey": "string",
"canRead": true,
"canWrite": true,
"canDelete": true,
"ownerCanRead": true,
"ownerCanWrite": true,
"ownerCanDelete": true,
"isInherited": true,
"canEditRead": true,
"canEditWrite": true,
"canEditDelete": true,
"ownerCanEditRead": true,
"ownerCanEditWrite": true,
"ownerCanEditDelete": true,
"canEditIsInherited": true,
"boolean": true,
"canEditBoolean": true
}
],
"categories": [
{
"key": "string",
"name": "string",
"supportsHierarchy": true
}
]
},
"Api": {
"items": [
{
"objectId": 0,
"name": "string",
"title": "string",
"key": "string",
"parentId": 0,
"objectType": 1,
"ownerId": 0,
"ownerType": 1,
"categoryKey": "string",
"canRead": true,
"canWrite": true,
"canDelete": true,
"ownerCanRead": true,
"ownerCanWrite": true,
"ownerCanDelete": true,
"isInherited": true,
"canEditRead": true,
"canEditWrite": true,
"canEditDelete": true,
"ownerCanEditRead": true,
"ownerCanEditWrite": true,
"ownerCanEditDelete": true,
"canEditIsInherited": true,
"boolean": true,
"canEditBoolean": true
}
],
"categories": [
{
"key": "string",
"name": "string",
"supportsHierarchy": true
}
]
}
}
- Returns a collection of ApiClients containing their respective permissions and categories.
POST: /permission/v1/save
Parameters, body:
{
"ownerId": 0,
"apiKey": "string",
"permissions": [
{
"objectId": 0,
"name": "string",
"title": "string",
"key": "string",
"parentId": 0,
"objectType": 0,
"ownerId": 0,
"ownerType": 0,
"categoryKey": "string",
"canRead": true,
"canWrite": true,
"canDelete": true,
"ownerCanRead": true,
"ownerCanWrite": true,
"ownerCanDelete": true,
"isInherited": true,
"canEditRead": true,
"canEditWrite": true,
"canEditDelete": true,
"ownerCanEditRead": true,
"ownerCanEditWrite": true,
"ownerCanEditDelete": true,
"canEditIsInherited": true,
"boolean": true,
"canEditBoolean": true
}
]
}
- ownerId: Owner ID.
- apiKey: ApiClient key.
- permissions: Owner whitelist.
GET: /permission/v1/homeCards?userId={userId}
Parameters:
- userId: Logged in user id.
- Return, body: the Home cards enabled for at least one of the user's groups. Menu permissions are not applied here; the BFF keeps only the cards whose menu item reached the user with its URL. A user without groups gets
[].
[
{
"menuKey": "movies_list",
"title": "{DICT:HOME/MOVIES}",
"description": "Browse and edit the movie catalog",
"image": {
"storageAreaId": 3,
"fileName": "movies.webp",
"extension": ".webp",
"relativeUrl": "0000/0000/0000/0007_.webp",
"version": "3f9c2a71b04e5d16"
}
},
{ "menuKey": "series_list", "title": null, "description": null, "image": null }
]
- image:
nullwhen the card has no image or its upload did not complete.relativeUrlis the same relative path mib-api exposes in_url, which FileManagement downloads by. - version: first 16 hex characters of the SHA-256 of
IMAGE_ID|FILESIZE|relative URL|MIB_LAST_UPDATE; it changes only when the image changes.
A BFF older than the Permission microservice never calls this route, and a BFF newer than it treats the 404 as "no cards".