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:
- Role-Based Access Control (RBAC): Roles grant permissions for platform operations
- Resource Access Control: Fine-grained permissions for specific resources (hardware, datasets, AI models)
- 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 OperationsExample:
- Identity
0x742d...hasHARDWARE_OWNER_ROLE - → Can register hardware
- → Can update owned hardware
Layer 2: Resource Ownership
Resources are owned by identities:
Resource → Owned By → IdentityExample:
- Hardware
hw-123owned by0x742d... - → 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-123access granted to0x8Ba1... - → 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 Name | Domain | Responsibilities |
|---|---|---|---|
| 1 | ADMIN_ROLE | System-wide | Pause/unpause contracts, transfer ownership, system administration |
| 2 | IDENTITY_OWNER_ROLE | Identity | Change ownership, add/revoke delegates, manage identity lifecycle |
| 3 | HARDWARE_OWNER_ROLE | Hardware | Register hardware, update owned hardware, transfer ownership |
| 4 | HARDWARE_OPERATOR_ROLE | Hardware | Update hardware (if delegated by owner), operate resources |
| 5 | DATASET_OWNER_ROLE | Dataset | Register datasets, update owned datasets, transfer ownership |
| 6 | DATASET_OPERATOR_ROLE | Dataset | Update datasets (if delegated by owner), operate resources |
| 7 | AI_MODEL_OWNER_ROLE | AI Model | Register AI models, update owned models, transfer ownership |
| 8 | AI_MODEL_OPERATOR_ROLE | AI Model | Update models (if delegated by owner), operate resources |
| 9 | ACCESS_MANAGER_ROLE | Access Control | Grant/revoke access to ANY resource |
| 10 | RESOURCE_OWNER_ROLE | Access Control | Grant/revoke access to OWNED resources |
| 11 | BENCHMARKING_REQUESTER | Benchmarking | Request benchmarks, view results |
| 12 | BENCHMARKING_PRODUCER | Benchmarking | Register devices, set results (must own hardware) |
| 13 | SELLER_ROLE | Marketplace | List resources for sale, set prices (must own resource) |
| 14 | BUYER_ROLE | Marketplace | Purchase listed resources, transfer tokens |
| 15 | MARKETPLACE_OPERATOR_ROLE | Marketplace | Remove listings, pause/unpause marketplace |
| 16 | REWARD_ADMIN_ROLE | Rewards | Set/remove reward rules, grant manual rewards |
| 17 | REWARD_DISTRIBUTOR_ROLE | Rewards | Distribute on-chain action rewards |
| 18 | ORACLE_ROLE | Rewards | Distribute off-chain action rewards |
| 19 | TOKEN_ADMIN_ROLE | Tokens | Update token metadata, pause/unpause transfers |
| 20 | TOKEN_MINTER_ROLE | Tokens | Mint new tokens, create supply |
| 21 | TOKEN_USER_ROLE | Tokens | Burn 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
- Completed Authentication, Wallet Management, and Identity Management tutorials
- Active session and wallet
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
| Field | Description |
|---|---|
id | Role identifier (database ID) |
role | Role name identifier |
name | Human-readable role name |
description | Role purpose and capabilities |
uri | Documentation URL |
created | Timestamp (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/rolesRequest
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
| Field | Type | Required | Description |
|---|---|---|---|
walletId | string | Yes | Your wallet ID |
password | string | Yes | Wallet password |
role | string | Yes | Unique role identifier (max 255 chars) |
adminOfRoleId | string | Yes | Parent role ID (must exist) |
name | string | Yes | Display name (max 255 chars) |
description | string | Yes | Role description (max 255 chars) |
uri | string | Yes | Documentation URL (max 255 chars, cannot be empty) |
Response (200 OK)
{
"id": "0000019a9ce6f7e8d9c1b2a3e4f5d6c7"
}Returns the new role’s ID.
Error Responses
| Code | Error | Cause |
|---|---|---|
| 404 | WALLET_NOT_FOUND | Wallet doesn’t exist |
| 404 | ADMIN_OF_ROLE_NOT_EXIST | Parent role ID not found |
| 400 | WRONG_PASSWORD | Wallet password incorrect |
| 400 | INVALID_ROLE | Role identifier empty or too long |
| 400 | ROLE_ALREADY_EXIST | Role identifier already used |
| 400 | INVALID_NAME | Name empty or too long |
| 400 | INVALID_DESCRIPTION | Description empty or too long |
| 400 | INVALID_URI | URI empty or too long |
| 403 | INVALID_WALLET | Wallet doesn’t belong to you |
| 500 | TRANSACTION_ERROR | Blockchain transaction failed |
Step 3: Grant Role to Identity
Assign a role to an identity (blockchain address).
Endpoint
POST /api/v1/roles/grant-roleRequest
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
| Field | Type | Required | Description |
|---|---|---|---|
walletId | string | Yes | Your wallet ID (must have authority to grant this role) |
password | string | Yes | Wallet password |
roleId | string | Yes | Role ID to grant |
did | string | Yes | Identity 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
| Code | Error | Cause |
|---|---|---|
| 404 | WALLET_NOT_FOUND | Wallet doesn’t exist |
| 404 | ROLE_NOT_FOUND | Role ID not found |
| 400 | WRONG_PASSWORD | Wallet password incorrect |
| 400 | INVALID_DID | Identity address format invalid |
| 403 | INVALID_WALLET | Wallet doesn’t belong to you |
| 500 | TRANSACTION_ERROR | Blockchain 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-roleRequest
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
| Code | Error | Cause |
|---|---|---|
| 404 | ROLE_NOT_FOUND | Role ID not found |
| 400 | INVALID_DID | Identity address format invalid |
| 500 | TRANSACTION_ERROR | Blockchain query failed |
Resource Access Control
Resource access control is independent of roles but often used together.
How It Works
- Owner: Identity that registered the resource (automatically has access)
- Access Grants: Owner or
ACCESS_MANAGER_ROLEcan grant access to others - Constraints: Access can have time limits, usage limits, or be indefinite
Access Control vs. Roles
| Aspect | Roles | Access Control |
|---|---|---|
| Scope | Platform-wide operations | Specific resources |
| Granularity | Broad permissions | Fine-grained per resource |
| Assignment | By role admin | By resource owner or access manager |
| Enforcement | Contract-level | Resource-level |
| Example | Can register hardware | Can use this specific hardware |
Access Control Endpoints
Access control is covered in detail in:
- Hardware Access Control - Setting access constraints on hardware
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 roleUsed 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 resourceUsed 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:
| Role | Requires | Reason |
|---|---|---|
HARDWARE_OPERATOR_ROLE | Valid delegation from hardware owner | Delegation checked via IdentityManagement contract |
DATASET_OPERATOR_ROLE | Valid delegation from dataset owner | Delegation checked via IdentityManagement contract |
AI_MODEL_OPERATOR_ROLE | Valid delegation from model owner | Delegation checked via IdentityManagement contract |
BENCHMARKING_PRODUCER | Hardware ownership | Must own the hardware executing benchmark |
SELLER_ROLE | Resource ownership | Must own resource to sell it |
Next Steps
- Hardware Registration - Register hardware (requires roles)
- Resource Access Control - Set fine-grained access permissions
- Benchmarking - Execute benchmarks (requires benchmarking roles)
Related Topics
- Identity Management - Roles are assigned to identities
- Dataset Registration - Resource ownership and access
- AI Model Registration - Resource ownership and access