Delegation API & enforcement
Section titled “Delegation API & enforcement”This page is for integrators, operators and engineers who need to act under a delegation programmatically, or to reason about exactly how a delegation is enforced. The administrator’s view (creating, scoping, forwarding and ending a delegation) is Delegation. The gateway plugin is also listed with the other plugins in Gateway operations, and the delegate’s permission resolution in the engine is in Engine: Permissions.
The core delegation entity and the active-delegations endpoint predate the 1.2 milestone. Scope-based permission filtering and administration inheritance were added later, but are also long-standing (pre-1.2).
The delegation record
Section titled “The delegation record”A delegation is a normal data entry of the delegation entity (system id DELEGATION). Its value holds:
| Field | Label | Type | Required | Meaning |
|---|---|---|---|---|
delegator | Delegator | reference (user) | yes | The user whose duties and permissions are delegated. |
delegated_to | Delegated To | reference (user) | yes | The delegate. |
from_date | From Date | date-time | yes | When the delegation becomes active. |
to_date | To Date | date-time | no (nullable) | When it ends. null/absent means open-ended. |
is_active | Is Active | category (DelegationTypeEnum) | yes | ACTIVE or INACTIVE: the manual on/off switch. |
delegation_scope | Delegation Scope | object | yes | What is delegated (see below). |
Delegation scope
Section titled “Delegation scope”| Field | Label | Type | Meaning |
|---|---|---|---|
base | Base | category (DelegationScopeEnum) | The default posture: ALLOW_ALL or DENY_ALL. |
exception | Exception | array of references | System objects the base posture does not apply to. Defaults to []. |
allow_administration | Administration | array of category (DelegationAdministrationEnum), optional | When it contains ALLOWED, the delegate also inherits the delegator’s administration (system) permissions. |
forward_notifications | Forward Notifications | boolean, default off | Deliver a copy of the delegator’s in-app notifications to the delegate. Since 1.10 |
forward_emails | Forward Emails | boolean, default off | Copy the delegate on the delegator’s emails. Since 1.10 |
Enum values: DelegationTypeEnum = ACTIVE, INACTIVE; DelegationScopeEnum = ALLOW_ALL, DENY_ALL; DelegationAdministrationEnum = ALLOWED.
The USER entity carries an implicit relation Delegation (“delegations given by the user”, USER_GIVEN_DELEGATIONS_RELATION) onto DELEGATION through the delegator field. Since 1.6
What the exception picker offers Since 1.8
Section titled “What the exception picker offers Since 1.8”The options offered in Exception are scoped to what the administrator creating the entry can reach:
- A caller with a system-level grant (system viewer, editor or admin) is offered the entire published application tree: modules, views, pages, reports and service actions.
- Any other caller sees only the views, pages and reports they hold an access right on, plus the service actions they may submit or observe, plus the ancestor nodes needed to keep those items attached to the tree.
- An anonymous caller is offered the anonymous-enabled views and pages; a caller with no permissions at all is offered nothing.
This governs only what the picker offers. delegation_scope.exception is applied at request time as a filter over the delegator’s own permissions (see Scope enforcement), so a wider option list can never widen a delegate’s actual access.
When is a delegation active?
Section titled “When is a delegation active?”A delegation is honoured only when all of these hold:
is_activeisACTIVE.from_date <= now.to_dateisnullorto_date >= now.- The entry
stateisActive(not archived or deleted).
The active-delegations query returns the delegations where the given user is the delegate (delegated_to matches). If the same delegator appears more than once, results are de-duplicated so the delegate sees one delegation per delegator. Each returned delegation has its delegator reference resolved with display metadata.
How OSOS enforces delegation
Section titled “How OSOS enforces delegation”Delegation is applied per request via the X-DELEGATION-ID request header. A client that wants to act under a delegation sends the delegation entry’s id in that header; there is no server-side “delegation mode” state, and the header’s presence on each request is what activates delegation for that request. Enforcement is split between the API gateway (delegate binding, time window and identity swap) and the data service (is_active, entry state and scope).
On mobile, selecting a delegation persists the choice and reloads the app; a client-side interceptor (DelegationInterceptor) then attaches the delegation header to every request. On the web, signing out ends the active delegation. Since 1.6
Gateway enforcement
Section titled “Gateway enforcement”Enforcement in the API gateway (Kong) runs through the custom user-delegation plugin (packaged as kong-plugin-user-delegation-0.1.0-1.rockspec, depending on lua-resty-redis-connector 0.11.0). It runs at priority 1000: after token introspection and app-token auth (which establish x-user-id), and before user-space-checker (999) and osos-access (997). The flow:
-
Trigger. Without an
X-DELEGATION-IDheader the plugin passes the request through untouched. -
Require an authenticated user. If
x-user-idis missing, it returns400 MISSING_USER_ID. -
Load delegation details. It looks the delegation up in Redis under a tenant-scoped key,
osos:delegation:v2:<delegation_id>, composed with theenvPrefixand the tenant id (a request whose tenant is unresolved is refused with500 APP_ERRORbefore any lookup). On a miss it callsGET <data_service_url>/api/v1/delegations/<id>with internal service headers (the gateway’s service identity and the shared key, plus the tenant), then caches the result forcache_ttl(default 600 s). Failure modes: a non-200 is forwarded asDELEGATION_API_ERROR; a request that fails outright returns500 DELEGATION_API_REQUEST_FAILED;success: falsereturns500 DELEGATION_API_LOGIC_ERROR; an undecodable body returns500 DELEGATION_API_DECODE_ERROR; a Redis connection failure returns500 REDIS_CONNECTION_ERROR. Infrastructure details (internal hosts, Redis errors) are logged at the gateway, not returned to the caller. -
Bind the delegation to the caller.
Since 1.6The plugin comparesdelegated_towithx-user-id. A delegation granted to someone else is refused with403 DELEGATION_FORBIDDEN(“Delegation does not belong to the current user”); a delegation with nodelegated_tois treated as incomplete (500 DELEGATION_DATA_ERROR). See Delegatee binding. -
Validate the time window.
from_dateandto_dateare parsed from ISO 8601 date-time strings (with or without milliseconds, ending inZor a±HH:MMoffset, which is applied) into UTC timestamps; an impossible calendar date is rejected rather than rolled over. If now is beforefrom_date, or after a presentto_date, the plugin returns403 DELEGATION_EXPIRED. A null or absentto_datemeans no upper bound. Unparseable dates return500 DELEGATION_DATE_PARSE_ERROR. -
Swap identity. On success the plugin rewrites the upstream headers so downstream services see the request as coming from the delegator:
Header Value x-user-idthe delegator’s id x-delegatee-idthe original caller (the delegate) x-is-delegation"true"
The gateway reads the delegation through /api/v1/delegations/{id}, which returns only id, delegator, delegated_to, from_date and to_date. It therefore enforces only the binding, the time window and the identity swap: it does not evaluate is_active, scope or entry state. A delegation toggled to INACTIVE or archived still passes the gateway, and the data service then resolves empty or limited permissions for it.
Delegatee binding Since 1.6
Section titled “Delegatee binding Since 1.6”The X-DELEGATION-ID header is supplied by the client, and the gateway fetches the delegation with an internal service call. Before this check, any signed-in user who presented a delegation id was switched into the delegator’s account. The plugin now requires the caller to be the delegation’s delegated_to, and answers 403 DELEGATION_FORBIDDEN otherwise.
The check needs both halves: the data service returns delegated_to on GET /v1/delegations/{id} (also delivered to the 1.4, 1.6 and 1.8 lines as an update), and the gateway caches under the new v2 key, so details cached before the change, which lack delegated_to, are never read back and rejected. Upgrade the data service before the gateway.
DELEGATION_EXPIRED does not disclose the delegation. The 403 body carries only details.error = "Delegation period is not current.", not the delegator, the period or the gateway’s clock. The refusal is logged at info level with the delegation id, the caller and the trace id, which is how an operator finds the delegator and the period. The web client reads only the code, and clears the active delegation.
Access checks under delegation
Section titled “Access checks under delegation”The downstream osos-access plugin (priority 997) reads X-DELEGATION-ID and, when present, fetches a delegation-scoped user profile from GET /api/v1/users/<userId>/delegation/<delegationId>/profile, cached in Redis under shared:user-profile-<userId>_<delegationId>. With a delegation id present, view access is decided directly by whether the delegator holds the view’s access permission, rather than by the normal ownership-based check. A fixed set of view ids bypasses the delegation path and always uses the normal check:
SERVICE_CATALOG, ONGOING_INBOX, INBOX_REQUESTS,ONGOING_MY_REQUESTS, COMPLETED_MY_REQUESTS,ONGOING_OBSERVER, COMPLETED_OBSERVERScope enforcement in the data service
Section titled “Scope enforcement in the data service”The data service resolves the delegate’s effective permissions in getAllDelegateePermissions(userId, delegationId); this is where delegation_scope takes effect:
- Load the active delegation (same active rules as above). If not found, the delegate gets empty permissions.
- Read
delegation_scope.baseand collectdelegation_scope.exceptionas the exception set. - Start from the delegator’s own full permissions and attach a
delegationblock ({ delegationId, scope, exceptions }) to the resolved permissions. - Administration: all system permissions are inherited when
allow_administrationcontainsALLOWED. Otherwisesystemis emptied, exceptSince 1.10for anALLOW_ALLdelegation with no exceptions, which keeps the System grants below Admin and drops only System Admin. Module and entity permissions are always kept. - Views, pages and reports are filtered against the exceptions:
DENY_ALLwith no exceptions: no views, pages or reports.ALLOW_ALLwith no exceptions: all of the delegator’s views, pages and reports.- With exceptions, each item is matched against the exception patterns (by item id or by its parent module, plus the general patterns
so:all,so:app,so:app:module). InALLOW_ALLmode a match excludes the item; inDENY_ALLmode a match includes it.
Request-time list filtering
Section titled “Request-time list filtering”For the request-style inbox, observer and service-catalog list endpoints, the delegation request filter narrows the query when a delegation is active. It matches specific view URLs and injects a where filter on a per-view field:
| View | Action type | Filter field |
|---|---|---|
SERVICE_CATALOG | Submit | value.relatedEntityId |
| Ongoing/Completed My Requests | MyRequest | value.reference.dataEntity |
| Ongoing/Completed Inbox | Inbox | value.reference.dataEntity |
| Ongoing/Completed Observer | Observe | value.reference.dataEntity |
The operator depends on scope: ALLOW_ALL uses nin (exclude the exception services); DENY_ALL uses inq (include only the exception services). The general exceptions so:all and so:service short-circuit this: under ALLOW_ALL they mean “no filter”, under DENY_ALL they mean “exclude all”. The filter applies to /entries and /count.
Forwarding to the delegate Since 1.10
Section titled “Forwarding to the delegate Since 1.10”With forward_notifications and/or forward_emails on, the delegate receives a copy of what is addressed to the delegator while the delegation is active, and only for work the delegation covers. Forwarded sources are the Send Notification and Send Email reaction actions and, for email, scheduled report deliveries. Each message is attributed to the service, module, report or view it concerns, and the scope is applied to that attribution (Allow All: sent unless excluded; Deny All: sent only when an exception grants that service, module or report, or one of the entity’s views; a message tied to one specific view needs that view granted). Skipped: a missing or deactivated delegate, the delegator themselves, the same delegator–delegate pair counted twice, and, for notifications, a delegate who is already a direct recipient. A copy is never forwarded again. If the delegates cannot be worked out, forwarding is skipped and logged, and the original delivery always goes ahead. Notification-side detail: Notification configuration.
Endpoints
Section titled “Endpoints”Both public endpoints require an authenticated user (OAuth2 introspection) and live in the data service’s delegations controller.
GET /v1/delegations/{id}
Section titled “GET /v1/delegations/{id}”Returns a single delegation projected to MyDelegationsDto, used by the gateway’s user-delegation plugin:
| Field | Type | Notes |
|---|---|---|
id | string | Delegation entry id. |
delegator | reference | The delegating user. |
from_date | date-time | Start of the window. |
to_date | date-time | null | End of the window (nullable). |
delegated_to | reference | The delegate. Since 1.4, needed for delegatee binding. |
The projection omits is_active and delegation_scope.
GET /v1/delegations/my
Section titled “GET /v1/delegations/my”Returns the current user’s active delegations (where they are the delegate), as an array of MyDelegationsDto. Only delegations that pass the full active check are returned, de-duplicated per delegator.
Internal profile endpoint
Section titled “Internal profile endpoint”GET /v1/users/{userId}/delegation/{delegationId}/profile returns the delegated user profile. It validates that the delegation is active and resolves the delegate from delegated_to; a missing or inactive delegation yields 404 Delegation not found. It is consumed by the osos-access gateway plugin, not by end users.
Creating, editing and archiving delegations uses the generic data-entry endpoints on the delegation entity. See Writing data.
Configuring the gateway plugin
Section titled “Configuring the gateway plugin”The user-delegation plugin is configured globally in config/kong.yml:
| Config | Type | Required | Default | Purpose |
|---|---|---|---|---|
data_service_url | string | yes | — | Base URL of the data service used to fetch delegation details. |
shared_key | string | yes | — | Internal shared key sent as X-SHARED-KEY. |
cache_ttl | number | no | 600 | Redis TTL (seconds) for cached delegation details. |
redis.url | string | no | redis://localhost:6379 | Redis connection URL. |
redis.ssl | boolean | no | false | Enable TLS to Redis. |
redis.ssl_verify | boolean | no | false | Verify the Redis server certificate. |
redis.useSentinel | boolean | no | false | Use Redis Sentinel instead of a standalone server. |
redis.sentinel.sentinels[] | array of {host, port} | — | — | Sentinel endpoints. |
redis.sentinel.username / password / masterName | string | — | — | Sentinel auth and master name. |
envPrefix | string | no | — | Prefix prepended to Redis cache keys (per-environment namespacing). |
Action log and audit
Section titled “Action log and audit”Every action performed under a delegation is completed in the name of the delegator, while OSOS records that the real actor is the delegate, so the audit trail can always tell them apart. Delegation identifiers are attached to every workflow and comment request; the delegate’s identifier (x-delegatee-id, with x-is-delegation: true) is passed to the services for auditing. See Monitoring, logs & audit and, for the record level, Timeline.
Button-click history is attributed to the delegate Since 1.8. Before this fix, clicking a system button while acting under a delegation stamped the resulting ButtonClickedHistory record with an empty actor: delegatee was dropped because the controller handling the click never passed it to the history-creation call, although the gateway had already resolved and forwarded it. Value changes and owner reassignments made under a delegation were never affected.
Operational notes and edge cases
Section titled “Operational notes and edge cases”- Caching. The gateway caches delegation details for
cache_ttl(600 s by default) and refetches only on a miss. When a delegation entry is edited or archived, the data service deletes the gateway’s cached copy, so the change applies at the next request.Since 1.8it deletes both key generations, the currentosos:delegation:v2:key and the olderosos:delegation:key, so a cell running gateways of both generations during a rolling upgrade is covered; before, an edited or archived delegation could stay usable at a newer gateway for up tocache_ttl. - Delegated permissions follow permission changes
Since 1.4. A delegate’s cached delegated permissions (kept up to 300 s) are cleared together with the access-right, view and report changes they embed, so a permission revoked from the delegator no longer lingers for the delegate. - Split enforcement. The gateway validates the delegate binding and the time window and performs the identity swap;
is_active,stateanddelegation_scopeare enforced by the data service. - Open-ended delegations. A null
to_datenever expires on its own; end it by settingis_activetoINACTIVE, archiving the entry, or setting ato_date. - Identity downstream. Under an active delegation, downstream services see
x-user-id= the delegator, withx-delegatee-idandx-is-delegation: truecarrying the real caller and the flag. - Guest (anonymous) users have no delegations.
- API tokens are a separate mechanism for external systems, not people. See API tokens.
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27