Authorization#
Users are registered by the Platform Owner or a Platform Admin, by accepting a Platform Invite, or through self-registration with e-mail verification when MF_USERS_SELF_REGISTER_ENABLED is true (the default).
Once registered, a user needs certain rights to manage entities within the system. Mainflux uses roles to control permissions for entities at two levels: at the Organization level and at the Group level.
More information about creating a user can be found at Users API.
Roles#
Roles determine the permissions a User has within an Organization or Group. Below are the predefined roles in the system:
Viewer#
- Can only view entities (read-only access).
- Applies to both Organization and Group levels.
Editor#
- Can create, delete, and view entities within the Organization or Group (more details are in the table below).
Admin#
- Has all the permissions of an editor.
- Can assign and unassign Members to the Organization or Group.
Owner#
- Has all the permissions of an admin.
- Has access to all entities within the Organization or Group they own.
Platform Owner#
- Has all permissions across all Organizations and Groups (and entities within them).
- Acts as the primary administrator for the entire platform.
- Is the only User who can assign and unassign the
Platform Adminrole, back up and restore Users, and impersonate aPlatform Admin.
Platform Admin#
- Has the same permissions as the
Platform Ownerwithin all Organizations and Groups, as shown in the tables below. - Can impersonate any enabled user other than the
Platform Owneror anotherPlatform Admin. - Cannot assign or unassign the
Platform Adminrole, back up or restore Users, or enable, disable or change the password of thePlatform Owneror of anotherPlatform Admin. - Cannot be disabled while holding the role.
Operations that require admin privileges are available to the Platform Owner and to every Platform Admin.
Although these roles are the same for an Organization and a Group, they operate completely separately at those levels, which means that one User can have different roles in an Organization and a Group within that Organization. The exception is the Organization
OwnerandAdmin, who can access every Group in their Organization without Group membership.
Org Members#
When a logged-in User creates an Organization, they become the Owner of that Organization.
Within it, they can add other registered users by assigning them appropriate roles defined in the table above.
The Organization Owner and Admin can view, update and delete every Group in their Organization and manage its Members and entities without Group membership.
Organization Editor and Viewer need Group membership to access a Group.
For a simpler understanding of access control in an Org, the table below provides a clear overview:
| Operation | Viewer | Editor | Admin | Owner | Platform Owner | Platform Admin |
|---|---|---|---|---|---|---|
| View Org | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Update Org | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
| Delete Org | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
| Assign/Unassign Members | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
| Create Groups | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
The operation 'Create Org' is omitted from the table because every registered (and logged-in) user has the right to do so.
An example of assigning Members to an Organization can be found at Org Members API.
Examples of unauthorized access#
Let's imagine that we have one Organization and four Members of that Organization with different roles:
| org_id | member_id | role |
|---|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | 3f3f9cc2-1a84-40cd-a7fb-02d9c5e1e5c8 | viewer |
| 550e8400-e29b-41d4-a716-446655440000 | 6b9e77a1-22f8-4e72-b2f3-122ad8b37f48 | editor |
| 550e8400-e29b-41d4-a716-446655440000 | c9b8f7d5-8143-47b4-9d72-f83d3f73834e | admin |
| 550e8400-e29b-41d4-a716-446655440000 | f1c6e7b3-4b29-496a-810b-bf7397dc3842 | owner |
- If a
Viewertries to create a Group within that Organization, they will receive a message indicating that the creation has failed:
{"error": "failed to perform authorization over the entity"}
- In the second case, if a
ViewerorEditortries to invite new users to the Organization, they will also get the above error message. - Next case, if an
Editorattempts to access entities within that Organization's Groups (of which they are not a Member), access will also be denied. - The same error message will be received if the
Owner, or any other Organization Member who is not thePlatform Owneror aPlatform Admin, tries to access an Organization in which they are not Members.
Group Members#
In order to enable the correct management of the entities within the Group, the rights that the members have over these entities are checked. Rights over entities are defined based on the role in the Group in which they belong.
As previously emphasized, Group roles are independent of Organization Editor and Viewer roles, which means that if a User is a Viewer in an Organization and a Group Admin adds them to the Group as an Editor, they will have higher rights in the Group than the rights they have in the Organization.
The Organization Owner and Admin hold the Group Owner role in every Group of their Organization through their Organization role.
They are listed as Group Owner members, and they cannot be added to a Group, invited to a Group, updated or removed.
When an Organization Editor creates a Group, they become its Admin.
For a simpler understanding of access control in a Group, the table below provides a clear overview:
| Operation | Viewer | Editor | Admin | Owner | Platform Owner | Platform Admin |
|---|---|---|---|---|---|---|
| View Group | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Update Group | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
| Delete Group | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
| Assign/Unassign Members | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
| Create Group Entities | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| View Group Entities | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Update Group Entities | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Delete Group Entities | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
The Organization Owner and Admin have Group Owner rights in every Group of their Organization.
The 'Create Group' operation is omitted from the table because the rights are defined in the Org table, where it can be clearly seen that everyone except the Organization Viewer can create a Group.
If we keep the data from the previous table and expand it with new data by creating Groups within the Organization and assigning Group roles to the existing members of the Organization, the additional table would look like this:
| org_id | group_id | member_id | role |
|---|---|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | 9f8e7a61-d34e-4a7a-9836-df8c3f54d3a1 | 3f3f9cc2-1a84-40cd-a7fb-02d9c5e1e5c8 | editor |
| 550e8400-e29b-41d4-a716-446655440000 | 15ee88e2-3632-41fb-acfa-2625645a2b8d | 6b9e77a1-22f8-4e72-b2f3-122ad8b37f48 | viewer |
| 550e8400-e29b-41d4-a716-446655440000 | 565ddcfb-bf64-4e6b-80ac-371516bd0e01 | c9b8f7d5-8143-47b4-9d72-f83d3f73834e | owner |
We can notice that the User who has the role of Viewer in the Organization now has the role of Editor in the group with ID 9f8e7a61-d34e-4a7a-9836-df8c3f54d3a1.
This means that the User now has all the rights provided by that role.
On the other hand, the User with ID 6b9e77a1-22f8-4e72-b2f3-122ad8b37f48 who is an Organization Editor now has the Group's Viewer role.
Therefore, that Member has no rights in the Group other than viewing.
The Admin of the Organization is listed as the Owner of the Group with ID 565ddcfb-bf64-4e6b-80ac-371516bd0e01, because an Organization Admin holds the Group Owner role in every Group of the Organization.
Based on the above examples of unauthorized access within the Organization, the same rules are applied within the Group based on the roles of the Members.
In addition to the basic access rights that apply to Members, note the case of Thing creation. When creating a Thing, it needs to be assigned a specific Profile by specifying its ID. The Profile being assigned and the Thing must belong to the same Group.
An example of assigning Members to a Group can be found at Group Members API.