Role-Based Access Control in NoSQL
One of the most common methods of securing data in NoSQL is to assign each record (or document or graph, depending on your database type) with a set of permissions linked to roles. This is role-based access control, or RBAC for short.
Consider a news release for a website that is being stored in a document (aggregate) NoSQL database. The editor role may have update permissions for the document, whereas a more public role may have only read permissions.
This use case requires assigning role permissions, not user permissions. Users can be assigned to one or more roles. Thus, users inherit permissions based on the sum of their roles.
Having to create a role in order to give a user permission to perform a particular function may seem like extra work, but this approach is very useful. Consider a user who moves to another department or who leaves entirely.
You don’t want to have to look manually for every document whose permissions mention this user and change or remove them. Instead just change that user’s role assignments in a single operation. Using role-based access control (RBAC) is much easier for long‐term maintenance of security permissions.
Watch how databases handle permissions and role inheritance. Consider underwriters in an insurance company, where there may be trainee, junior, and senior underwriters, each with increasing access to different types of information.
You could assign the junior underwriters the permissions the trainees are assigned, plus a few more. Then you could assign all the junior underwriters’ permissions to senior underwriters, plus a few more, again. If you want to add extra permissions to all these roles, though, you have to make three identical changes.
If you have five levels of roles, that’s five copies. Also, every system will have a multitude of roles like these. There is a better way than performing the same mundane task over and over again: Role inheritance.
Some systems include role inheritance. In this case, the JuniorUnderwriter role inherits from the TraineeUnderwriter role, and the SeniorUnderwriter role inherits from the JuniorUnderwiter role. Now all you need to do to add a permission to all roles is to add it to only the TraineeUnderwriter role (the lowest level of inheritance), and all roles will inherit the permission. Role inheritance is much easier to understand and maintain.
Role permission logic is generally implemented with OR logic. That is, if you assign three roles — RoleA, RoleB, and RoleC — to a record with a read permission, a user has this permission if he has RoleA OR RoleB, OR RoleC. If you don’t assign role read permissions to a record, then no user has read permissions on that record (inheritance aside, of course).