IoT Device Management Example
This example demonstrates how to implement Relationship-Based Access Control (ReBAC) for an Internet of Things (IoT) device management system.
The schema models hierarchical access control where devices are organized into groups, and users have different permission levels based on their relationships with both device groups and individual devices.
Schema
Schema Components
Types
user: Individual users in the systemuser_group: Groups of users that can be assigned permissions collectivelydevice_group: Collections of IoT devices (e.g., "Smart Home - Living Room", "Office Building - Floor 3")device: Individual IoT devices (e.g., smart locks, thermostats, cameras)
Device Group Relations
Device groups support three relationship types:
owner: Full administrative control over the device groupoperator: Can manage devices within the group but cannot modify group settingsguest: Limited access for temporary or restricted users
Device Relations
Individual devices inherit from their parent device group but can also have direct relationships:
parent: Links the device to its device groupowner: Direct owner of the device (can override group permissions)operator: Can operate the deviceguest: Limited access to the device
Permission Hierarchy
The schema implements a hierarchical permission model:
-
Device Group Permissions:
can_add_device: Only owners can add new devices to the groupcan_add_operator: Only owners can grant operator accesscan_add_guest: Only owners can grant guest access
-
Device Permissions (with inheritance):
can_change_code: Device owners or device group owners can change access codescan_view: Owners, operators, or those with view access from the parent groupcan_open: Anyone with view access, guests, or guests from the parent groupcan_add_operator: Device owners or device group owners can add operatorscan_add_guest: Operators or owners can add guests
Use Cases
Smart Home Management
Scenario: A family manages their smart home with multiple device groups (Living Room, Bedroom, Garage) and various devices (smart locks, thermostats, cameras).
- Family Members (Owners): Have full control over all device groups and can add devices, change codes, and manage access
- House Sitter (Operator): Assigned as operator to the "Living Room" device group, can view and operate devices but cannot change codes or add new devices
- Guest (Guest): Temporary access to open the front door lock but cannot view other devices or change settings
Example Relations:
Commercial Building Management
Scenario: An office building with multiple floors, each floor is a device group containing various IoT devices (access control, HVAC, lighting).
- Building Manager (Owner): Full control over all floors and devices
- Floor Manager (Operator): Can manage devices on their specific floor but cannot modify floor-level settings
- Maintenance Staff (Operator): Can operate devices across multiple floors for maintenance purposes
- Temporary Contractor (Guest): Limited access to specific devices for a project
Example Relations:
Multi-Tenant IoT Platform
Scenario: An IoT platform serving multiple organizations, where each organization has device groups and devices.
- Organization Admin (Owner): Full control over their organization's device groups
- Department Head (Operator): Manages devices within their department's device group
- Team Member (Operator): Can operate devices in their team's device group
- External Partner (Guest): Temporary, limited access to specific devices for collaboration
Example Relations:
How It Works
Permission Inheritance
The schema uses hierarchical permission inheritance:
-
Device Group → Device: Permissions from the device group flow down to devices through the
parentrelation- If a user is an
ownerof a device group, they cancan_change_codeon all devices in that group - If a user is an
operatorof a device group, they cancan_viewall devices in that group
- If a user is an
-
Direct Device Relations: Devices can have direct relations that override or complement group permissions
- A device can have its own
ownerwho has full control regardless of group permissions - A device can have its own
guestwho has access even if not a guest of the parent group
- A device can have its own
Access Control Flow
When checking if a user can perform an action on a device:
- Check Direct Relations: First, check if the user has a direct relation to the device
- Check Parent Group: If no direct relation, check if the user has a relation to the parent device group
- Check Permissions: Evaluate permission expressions that may combine multiple relations
- Inherit from Group: Group-level permissions apply to all devices in the group
Example: Checking Access
To check if user alice can open device front-door-lock, you use the Descope SDK to check the can_open permission. The permission is defined as can_open: can_view | guest | parent.guest, which means alice can open if she has can_view permission, is a direct guest of the device, or is a guest of the parent device group.
Complete Implementation Example
Here's a complete example showing how to set up relations and check access for an IoT device:
Implementation Considerations
- Device Registration: When a new device is added, it must be linked to a device group via the
parentrelation - Permission Propagation: Changes to device group permissions automatically affect all devices in the group
- User Groups: Use user groups for role-based assignments (e.g., all "Maintenance Staff" users)
This schema provides a robust foundation for managing IoT device access in scenarios ranging from smart homes to enterprise building management systems.