liveBook · Manning

Role-based access control

As explained in Secure APIs

Role-based access control is an authorization model that grants permissions according to assigned user roles.

Role-based access control (RBAC) grants permissions through user roles or groups. A role represents a permission set, such as admin, doctor, receptionist, driver, or passenger. section 7.7

RBAC protects operations and APIs only when every request checks the caller’s role. Hiding admin paths or assuming that only legitimate users will call them does not enforce authorization. section 1.4 section 4.7

A practical RBAC implementation follows these checks:

  • Configure roles and permission sets in the identity provider, then assign roles to users. section 8.6
  • Include the user’s roles or permissions in the access-token payload as a custom claim. section 7.7
  • Validate the token and check the required role before processing every protected operation. section 7.7 section 8.7
  • Use granular access scopes when users need different operation-level permissions that do not fit discrete groups. section 7.7

Protecting an admin endpoint

An admin-only endpoint can validate the bearer token, inspect its permissions claim, and reject requests without the admin permission. A normal user reaching GET /admin/students represents privilege escalation and should receive a denial response.

Figure 4.15 A good strategy to prevent BFLA is to declare user roles explicitly in access tokens and check those roles on every request across all operations.
figure

Shows the core defense: declare roles explicitly in access tokens and check them across every operation. section 4.7

Test RBAC by sending a normal user’s authenticated token to admin endpoints and asserting denial. Also test malformed, expired, or tampered tokens and distinguish role bypass from same-role object access. section 12.1 section 12.4

How Secure APIs covers it

How deep it goes
Explains role claims, per-operation checks, granular scopes, implementation, privilege escalation, and automated tests.
Examples
Uses healthcare roles, separate role APIs, admin endpoints, permission claims, and tests against GET /admin/students.
What it assumes
Assumes authenticated users and access tokens, while introducing role permissions, claims, authorization checks, and RBAC tests.
What you can do after
Build it from configured roles, token claims, authorization checks, protected endpoints, and tests for privilege escalation.
How it connects
Connects RBAC with authentication, authorization, JSON Web Tokens, access scopes, ABAC, BFLA, and privilege escalation.

Also explained in

Compare how 16 books explain role-based access control →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.