Access rights management (/permissions/...)

Access rights management (/permissions/...)

Flexible API access restriction: you can prohibit the user from using an entire method or individual fields in a request without re—launching the application.

Content

  • How it works

  • Description of data structures

  • Example

  • Features

  • Resources of the "Permissions" section

How it works

Access is described by three entities:

  1. Resource — which endpoint is protected (URL + HTTP method).

  2. Rule — what exactly is forbidden for this resource: the entire method or specific fields.

  3. Group — a set of rules for convenient assignment to multiple users at once.

A rule is applied to a user either directly or via a group.

For each request the system selects matching rules and decides whether to allow the request or return 403.

Each record belongs to one of the contexts:

Context

Managed by

Restrictions apply to

Context

Managed by

Restrictions apply to

Dealer

Dealer

Only to their own customers and their employees

Customer

Customer

Only to their own employees

Contexts are isolated: a dealer does not see rules of another dealer, and a customer does not see rules of another customer.

Description of data structures

Description of the endpoint that we are protecting.

Name

Type

Mandatory

Description

Name

Type

Mandatory

Description

id

int

Identifier

endpoint

string

yes

The URL template, for example /admin/user/<id>

method

string

yes

HTTP‑method: GET, POST, PUT, DELETE and e.t.c.

login_type

string

no

Who is it applied to: dealer, client, extension_group, extension. If not specified, to all.

Example:

{ "id": 42, "endpoint": "/extension/{extension_id}/agent/{agent_id}", "method": "DELETE", "login_type": "admin" }

What exactly is prohibited on the resource.

Name

Type

Description

Name

Type

Description

id

int

Identifier

resource_id

int

Which resource does it apply to

action

string

Type of action: block_all or block_fields

blocked_fields

array

List of request fields (only for block_fields)

Invariants:

  • for action = "block_all" field blocked_fields it should be empty;

  • for action = "block_fields" list blocked_fields must contain at least one field.

Example:

{ "id": 7, "resource_id": 42, "action": "block_fields", "blocked_fields": ["password", "token"] }

A set of rules that can be conveniently assigned to multiple users at once.

Name

Type

Description

Name

Type

Description

id

int

Identifier

name

string

Name (unique within the context)

comment

string

Free description

created_at

string

Date of creation

Example:

{ "id": 8, "name": "no-delete", "comment": "Prohibition of deletion operations", "created_at": "2024-01-15 10:30:00" }

Example

We need to forbid an administrator with id = 100 from deleting users via the API.

Step 1. Create a resource

Create a resource for DELETE /application/<id>:

POST /api/ver1.0/permissions/resources/ Content-Type: application/json { "endpoint": "/extension/{extension_id}/agent/{agent_id}", "method": "DELETE", "login_type": "extension" }

Example response:

{ "id": 42, "endpoint": "/extension/{extension_id}/agent/{agent_id}", "method": "DELETE", "login_type": "extension" }

Step 2. Create a rule that blocks the entire method

POST /api/ver1.0/permissions/rules/ Content-Type: application/json { "resource_id": 42, "action": "block_all" }

Example response:

{ "id": 7, "resource_id": 42, "action": "block_all", "blocked_fields": [] }

Step 3. Assign the rule to the user

PUT /api/ver1.0/permissions/users/100/rules/ Content-Type: application/json { "rule_ids": [7] }

Done: when the user tries to call

DELETE /extension/{extension_id}/agent/{agent_id}

user 100 will receive:

HTTP/1.1 403 Access denied: method blocked

Option: block only specific fields

If you don’t want to block the entire method, but only some of the data (for example, the password field), use block_fields in step 2:

POST /api/ver1.0/permissions/rules/ Content-Type: application/json { "resource_id": 42, "action": "block_fields", "blocked_fields": ["password"] }

To assign rules to multiple users at once, it is convenient to group them:

POST /api/ver1.0/permissions/groups/ Content-Type: application/json { "name": "no-delete" } PUT /api/ver1.0/permissions/groups/8/rules/ Content-Type: application/json { "rule_ids": [7] } PUT /api/ver1.0/permissions/users/100/groups/ Content-Type: application/json { "group_ids": [8] }

Features

  • Changes take effect automatically.

  • Replacement, not addition.
    The following operations completely replace the set. An empty array clears all bindings:

    • PUT .../groups/{id}/rules/

    • PUT .../users/{id}/groups/

    • PUT .../users/{id}/rules/

  • You cannot go beyond your context.
    For example, a customer cannot create a rule with
    login_type = "dealer".
    Such an attempt returns 403.

  • Links only within the same context.
    A dealer’s group cannot be linked to a rule that belongs to another dealer.

  • Cascading delete.
    Deleting a dealer/customer automatically deletes all their resources, rules, and groups.

  • Creation rate limit.
    No more than 100 requests per hour per user for POST operations.
    If exceeded — 429 Too Many Requests.


“Permissions” section resources

All routes below are available in two contexts:

Context

Prefix

Context

Prefix

Dealer

/api/ver1.0/dealer/<dealer_id>/permissions/...

Customer

/api/ver1.0/customer/<customer_id>/permissions/...

Dealer and customer can use @me instead of their own identifier.


Resources

Get a list of existing resources

Response fields

Name

Type

Name

Type

id

long

endpoint

string

login_type

string

method

string

dealer_id

long

client_id

long

Create a new resource

JSON Parameters

Name

Type

Mandatory

Name

Type

Mandatory

endpoint

string

yes

login_type

string

yes

method

string

yes

Response fields

Name

Type

Name

Type

id

long

endpoint

string

login_type

string

method

string

dealer_id

long

client_id

long

Get information about an existing resource

URL Parameters

Name

Type

Name

Type

resource_id

long

Response fields

Name

Type

Name

Type

id

long

endpoint

string

login_type

string

method

string

dealer_id

long

client_id

long

Edit an existing resource

URL Parameters

Name

Type

Name

Type

resource_id

long

JSON Parameters

Name

Type

Mandatory

Name

Type

Mandatory

endpoint

string

 

login_type

string

 

method

string

 

Response fields

Name

Type

Name

Type

id

long

endpoint

string

login_type

string

method

string

dealer_id

long

client_id

long

Delete an existing resource

URL Parameters

Name

Type

Name

Type

resource_id

long

Get a list of existing rules

Response fields

Name

Type

Name

Type

id

long

resource_id

long

action

string

blocked_fields

object

dealer_id

long

client_id

long

Create a new rule

JSON Parameters

Name

Type

Mandatory

Name

Type

Mandatory

action

string

yes

blocked_fields

string

 

resource_id

long

yes

Response fields

Name

Type

Name

Type

id

long

resource_id

long

action

string

blocked_fields

object

dealer_id

long

client_id

long

Get information about an existing rule

URL Parameters

Name

Type

Name

Type

rule_id

long

Response fields

Name

Type

Name

Type

id