CodamAIDocs
Topicdone

Model roles

Which role an operation requires: base role, role per action, endpoint role, public access. PATCH uses the update role.

Variants
base role allows everythingaction role replaces the base roleendpoint rolepublicAccesshistory, rollback, downloadabstract model

What this is about

Every model has roles. Before CDMS runs an operation, it checks whether the matching role is in the person’s token. If it is missing, CDMS answers with 403 missing-permission|<role>.

There are two kinds of model roles:

  • The base role is named like the model, e.g. audit-question. It allows every operation for which nothing stricter is set.
  • An action role appends the operation, e.g. audit-question-read. It only exists for operations you marked as requiring a role in the hub.

How the names are built is described in How role names are built.

Which operation requires which role

In the hub, on the Permissions tab, you mark the operations CREATE, READ, UPDATE and DELETE. Every marked operation gets its action role; all others require the base role.

OperationEndpointRequired role
CreatePOST /create, upload on createcreate role
ReadPOST /read/{id}, GET /read/{id}read role
SearchPOST /queryread role
ReplacePUT /update/{id}update role
ChangePATCH /update/{id}, upload on updateupdate role, because PATCH has no role of its own
DeleteDELETE /delete/{id}delete role
DownloadGET /{id}/filefirst the read role (the object is read), then the download role
Read historyPOST /{id}/historyread role and history role
Roll backPOST /{id}/rollback/{revision}rollback role

Download, history and rollback cannot be marked on their own in the hub. That is why they require the base role.

Which role does READ require for model question in folder audit?
READ marked in the hubendpoint with its own roleendpoint with publicAccessRequired role
nononoaudit-question
yesnonoaudit-question-read
–yes, e.g. report-readernoreport-reader
––yesno role, any signed-in person

Variants

How a model sets its roles

When: no operation marked in the hub

  1. 1
    Build
    sets the base role audit-question for every operation
  2. 2
    CDMS
    checks the same role for every operation

Result: One role for everything. Simple, but with no difference between reading and writing.

When: e.g. READ marked in the hub

  1. 1
    Build
    sets audit-question-read for READ and keeps audit-question for all other operations
  2. 2
    CDMS
    checks only audit-question-read when reading and searching
  3. 3
    CDMS
    still checks audit-question when creating, changing and deleting

Result: Readers get audit-question-read; editors get audit-question and audit-question-read if they should also read.

When: model file (YAML): endpoint with roleRequired: <name>

  1. 1
    Build
    takes the name unchanged as the role for this operation
  2. 2
    CDMS
    checks exactly this name

Result: The custom name wins over base and action role. The hub does not have this setting.

When: model file (YAML): endpoint with publicAccess: true

  1. 1
    Build
    sets no role for this operation
  2. 2
    CDMS
    skips the role check

Result: Any person with a valid token may run the operation. It still does not work without a token, see Access without a token. The filters of the row level still apply.

Where the roles come from

A person’s roles are in their token. CIAS reads them on every request and builds the effective roles from them: if a person belongs to several tenants and the organization has its own roles, the roles of the active tenant apply. CDMS checks only against these effective roles. See Effective roles: global or in the tenant.

Abstract models

An abstract model forwards every request to its subtype. The roles checked are then those of the subtype:

  • Creating, reading, changing and deleting through /crm/kunde/… require the roles of privatkunde or firmenkunde, depending on which type is affected.
  • A search over the abstract model reads each hit through its subtype. The person needs the read role of every subtype that appears in the hits.
  • The roles of the abstract model itself apply when another model points to the abstract model through a relation.

See Abstract models and @type.

Pitfalls

Where to go next

Sources in the code and the knowledge base
  • CDMS/cdms-authorization – AbstractAuthorizationLayer (accessGrantedByRole, classAccess, *AccessAllowedByClass)
  • CDMS/cdms-generator – CdmsModelContext (deriveRole, roleFor), CdmsYamlLoader (parseModelRoles, endpoints: roleRequired, publicAccess), DtoMetaProcessor
  • CDMS/cdms-system-layer – AbstractLayer (recursivePrepare, recursiveRead, recursiveQuery, recursiveDelete, queryHistory, downloadFile), AbstractSystemLayer (historyRollback)
  • CDMS/cdms-rest-api – AbstractHubApi
  • CIAS/cias-authentication – TokenParser, EffectiveRoles
  • CDMS/cdms-generator – ModelRoleRestrictionTest; CDMS/cdms-integrationtest – AbstractRoleDenialTest
  • hub-backend/structure/enumerations.yaml (ROLE_TYPE)
Search