Skip to content
4. Role Management and Access Control

4. Role Management and Access Control

This tutorial explains the role-based access control (RBAC) system in the dAIEDGE Middleware, how roles work, and how they integrate with resource permissions.

Overview

dAIEDGE Middleware uses a multi-layered access control system:

  1. Role-Based Access Control (RBAC): Roles grant permissions for platform operations
  2. Resource Access Control: Fine-grained permissions for specific resources (hardware, datasets, AI models)
  3. Blockchain Enforcement: All permissions enforced by smart contracts

Key Concepts

  • Role: A named permission set (e.g., HARDWARE_OWNER_ROLE)
  • Identity: A blockchain address that can be assigned roles
  • Resource: Hardware, dataset, or AI model with ownership and access controls
  • Access Grant: Time-limited or usage-limited permission to use a resource

Architecture

Layer 1: Role Management

Roles define what operations an identity can perform:

Identity → Has Role → Can Perform Operations

Example:

  • Identity 0x742d... has HARDWARE_OWNER_ROLE
  • → Can register hardware
  • → Can update owned hardware

Layer 2: Resource Ownership

Resources are owned by identities:

Resource → Owned By → Identity

Example:

  • Hardware hw-123 owned by 0x742d...
  • → Owner has full control
  • → Owner can grant access to others

Layer 3: Access Control

Resource owners can grant limited access:

Resource → Access Grant → Identity (with constraints)

Example:

  • Hardware hw-123 access granted to 0x8Ba1...
  • → Valid until 2025-01-01
  • → Maximum 100 uses
  • → Automatically revoked after expiration

System Roles

The dAIEDGE Middleware includes the following 21 roles by default.

Default Roles Overview

#Role NameDomainResponsibilities
1ADMIN_ROLESystem-widePause/unpause contracts, transfer ownership, system administration
2IDENTITY_OWNER_ROLEIdentityChange ownership, add/revoke delegates, manage identity lifecycle
3HARDWARE_OWNER_ROLEHardwareRegister hardware, update owned hardware, transfer ownership
4HARDWARE_OPERATOR_ROLEHardwareUpdate hardware (if delegated by owner), operate resources
5DATASET_OWNER_ROLEDatasetRegister datasets, update owned datasets, transfer ownership
6DATASET_OPERATOR_ROLEDatasetUpdate datasets (if delegated by owner), operate resources
7AI_MODEL_OWNER_ROLEAI ModelRegister AI models, update owned models, transfer ownership
8AI_MODEL_OPERATOR_ROLEAI ModelUpdate models (if delegated by owner), operate resources
9ACCESS_MANAGER_ROLEAccess ControlGrant/revoke access to ANY resource
10RESOURCE_OWNER_ROLEAccess ControlGrant/revoke access to OWNED resources
11BENCHMARKING_REQUESTERBenchmarkingRequest benchmarks, view results
12BENCHMARKING_PRODUCERBenchmarkingRegister devices, set results (must own hardware)
13SELLER_ROLEMarketplaceList resources for sale, set prices (must own resource)
14BUYER_ROLEMarketplacePurchase listed resources, transfer tokens
15MARKETPLACE_OPERATOR_ROLEMarketplaceRemove listings, pause/unpause marketplace
16REWARD_ADMIN_ROLERewardsSet/remove reward rules, grant manual rewards
17REWARD_DISTRIBUTOR_ROLERewardsDistribute on-chain action rewards
18ORACLE_ROLERewardsDistribute off-chain action rewards
19TOKEN_ADMIN_ROLETokensUpdate token metadata, pause/unpause transfers
20TOKEN_MINTER_ROLETokensMint new tokens, create supply
21TOKEN_USER_ROLETokensBurn owned tokens

The admin role (or other defined admin roles) can grant/revoke child roles. By default the admin role is the only admin role for all roles.

Role Domains

System Administration: ADMIN_ROLE

Identity Management: IDENTITY_OWNER_ROLE

Resource Registration:

  • Hardware: HARDWARE_OWNER_ROLE, HARDWARE_OPERATOR_ROLE
  • Datasets: DATASET_OWNER_ROLE, DATASET_OPERATOR_ROLE
  • AI Models: AI_MODEL_OWNER_ROLE, AI_MODEL_OPERATOR_ROLE

Access Control: ACCESS_MANAGER_ROLE, RESOURCE_OWNER_ROLE

Benchmarking: BENCHMARKING_REQUESTER, BENCHMARKING_PRODUCER

Marketplace: SELLER_ROLE, BUYER_ROLE, MARKETPLACE_OPERATOR_ROLE

Rewards: REWARD_ADMIN_ROLE, REWARD_DISTRIBUTOR_ROLE, ORACLE_ROLE

Tokens: TOKEN_ADMIN_ROLE, TOKEN_MINTER_ROLE, TOKEN_USER_ROLE


Role Operations

Prerequisites


Step 1: List All Roles

View all roles available in the system.

Endpoint

GET /api/v1/roles?page={page}

Request

curl -X GET "https://middleware-daiedge.bisite.usal.es/api/v1/roles?page=1"

Response (200 OK)

{
  "roles": [
    {
      "id": "0000019a9cb3f4e5d6c7b8a9e1f2d3c4",
      "role": "HARDWARE_OWNER_ROLE",
      "name": "Hardware owner",
      "description": "Can register and manage hardware resources",
      "uri": "https://docs.example.com/roles/hardware-owner",
      "created": 1697000000000
    },
    {
      "id": "0000019a9cc4e5f6d7c8b9a1e2f3d4c5",
      "role": "BENCHMARKING_REQUESTER",
      "name": "Benchmarking requester",
      "description": "Can request and view benchmarks",
      "uri": "https://docs.example.com/roles/benchmark-requester",
      "created": 1697000100000
    }
  ],
  "page": 1,
  "totalPages": 3,
  "total": 68
}

Response Fields

FieldDescription
idRole identifier (database ID)
roleRole name identifier
nameHuman-readable role name
descriptionRole purpose and capabilities
uriDocumentation URL
createdTimestamp (milliseconds)

Pagination

  • Default page: 1
  • Page size: 25 roles per page
  • Navigate: ?page=2, ?page=3, etc.

Step 2: Create Custom Role

Create a new role for your organization.

Endpoint

POST /api/v1/roles

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/roles \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "0000019a9cd5f6e7d8c9b1a2e3f4d5c6",
    "password": "WalletPass123!",
    "role": "CUSTOM_OPERATOR_ROLE",
    "adminOfRoleId": "0000019a9cb3f4e5d6c7b8a9e1f2d3c4",
    "name": "Custom Operator",
    "description": "Custom role for organization operators",
    "uri": "https://myorg.example.com/roles/operator"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesYour wallet ID
passwordstringYesWallet password
rolestringYesUnique role identifier (max 255 chars)
adminOfRoleIdstringYesParent role ID (must exist)
namestringYesDisplay name (max 255 chars)
descriptionstringYesRole description (max 255 chars)
uristringYesDocumentation URL (max 255 chars, cannot be empty)

Response (200 OK)

{
  "id": "0000019a9ce6f7e8d9c1b2a3e4f5d6c7"
}

Returns the new role’s ID.

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
404ADMIN_OF_ROLE_NOT_EXISTParent role ID not found
400WRONG_PASSWORDWallet password incorrect
400INVALID_ROLERole identifier empty or too long
400ROLE_ALREADY_EXISTRole identifier already used
400INVALID_NAMEName empty or too long
400INVALID_DESCRIPTIONDescription empty or too long
400INVALID_URIURI empty or too long
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed

Step 3: Grant Role to Identity

Assign a role to an identity (blockchain address).

Endpoint

POST /api/v1/roles/grant-role

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/roles/grant-role \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "0000019a9cf7e8f9d1c2b3a4e5f6d7c8",
    "password": "WalletPass123!",
    "roleId": "0000019a9cb3f4e5d6c7b8a9e1f2d3c4",
    "did": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesYour wallet ID (must have authority to grant this role)
passwordstringYesWallet password
roleIdstringYesRole ID to grant
didstringYesIdentity DID to grant role to (format: did:ethr:{network}:0x...)

Authorization

You can only grant roles if:

  • You have the admin role for this role, OR
  • You are a platform administrator

Response (200 OK)

{}

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
404ROLE_NOT_FOUNDRole ID not found
400WRONG_PASSWORDWallet password incorrect
400INVALID_DIDIdentity address format invalid
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (may be authorization failure)

Step 4: Revoke Role from Identity

Remove a role assignment from an identity.

Endpoint

POST /api/v1/roles/revoke-role

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/roles/revoke-role \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "0000019a9d08f9e1d2c3b4a5e6f7d8c9",
    "password": "WalletPass123!",
    "roleId": "0000019a9cb3f4e5d6c7b8a9e1f2d3c4",
    "did": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72"
  }'

Request Body

Same as Grant Role.

Response (200 OK)

{}

Error Responses

Same as Grant Role.


Step 5: Check Role Assignment

Verify if an identity has a specific role.

Endpoint

GET /api/v1/roles/has-role?roleId={roleId}&did={did}

Request

curl -X GET "https://middleware-daiedge.bisite.usal.es/api/v1/roles/has-role?roleId=0000019a9cb3f4e5d6c7b8a9e1f2d3c4&did=did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72"

Response (200 OK)

{
  "result": true
}

Returns true if identity has the role, false otherwise.

Error Responses

CodeErrorCause
404ROLE_NOT_FOUNDRole ID not found
400INVALID_DIDIdentity address format invalid
500TRANSACTION_ERRORBlockchain query failed

Resource Access Control

Resource access control is independent of roles but often used together.

How It Works

  1. Owner: Identity that registered the resource (automatically has access)
  2. Access Grants: Owner or ACCESS_MANAGER_ROLE can grant access to others
  3. Constraints: Access can have time limits, usage limits, or be indefinite

Access Control vs. Roles

AspectRolesAccess Control
ScopePlatform-wide operationsSpecific resources
GranularityBroad permissionsFine-grained per resource
AssignmentBy role adminBy resource owner or access manager
EnforcementContract-levelResource-level
ExampleCan register hardwareCan use this specific hardware

Access Control Endpoints

Access control is covered in detail in:

Key operations:

  • Grant Access: POST /api/v1/access/grant-access
  • Revoke Access: POST /api/v1/access/revoke-access
  • Check Access: GET /api/v1/access

Authorization Patterns

The platform uses several authorization patterns to control access to operations:

Pattern 1: Simple Role Check

Used for basic operations that only require a specific role:

Operation allowed if:
  - Identity owner matches msg.sender AND
  - Identity has required role

Used in: Hardware registration, dataset registration, AI model registration, benchmark requests

Pattern 2: Role OR Ownership

Used for access control operations where either a manager role or resource ownership grants permission:

Operation allowed if:
  - Identity owner matches msg.sender AND
  - (Identity has ACCESS_MANAGER_ROLE OR
     Identity has RESOURCE_OWNER_ROLE AND owns the resource)

Used in: Access control grant/revoke operations

Pattern 3: Role AND Ownership

Used when both a role and resource ownership are required:

Operation allowed if:
  - Identity owner matches msg.sender AND
  - Identity has required role AND
  - Identity owns the required resource

Used in: Benchmark execution (requires BENCHMARKING_PRODUCER role AND hardware ownership)

Pattern 4: Role OR Delegation

Used for update operations where either the owner or a delegated operator can perform the action:

Operation allowed if:
  - Identity owner matches msg.sender AND
  - (Identity has OWNER_ROLE AND owns resource OR
     Identity has OPERATOR_ROLE AND is delegated by resource owner)

Used in: Update operations (hardware, datasets, AI models)


Role Dependencies

Roles Requiring Additional Resources

Some roles require ownership of specific resources to be functional:

RoleRequiresReason
HARDWARE_OPERATOR_ROLEValid delegation from hardware ownerDelegation checked via IdentityManagement contract
DATASET_OPERATOR_ROLEValid delegation from dataset ownerDelegation checked via IdentityManagement contract
AI_MODEL_OPERATOR_ROLEValid delegation from model ownerDelegation checked via IdentityManagement contract
BENCHMARKING_PRODUCERHardware ownershipMust own the hardware executing benchmark
SELLER_ROLEResource ownershipMust own resource to sell it

Next Steps

Related Topics