Authorization: roles, attributes and deny by default

Unit 4 of 5 in Identity and access.

You will be able to describe role-based and attribute-based access control and apply deny by default and least privilege to an app.

Lesson

Three rules every app should follow

OWASP's authorization advice starts with three rules. Enforce least privilege: assign users only the minimum privileges necessary to complete their job, and apply it both horizontally (an accountant and a sales representative at the same level need different resources) and vertically. Deny by default: even when no rule matches, the application must make a decision, so unmatched requests are refused. Validate permissions on every request, whatever started the request, because an attacker only needs to find one way in and a single missed check is enough.

These are the design rules from the security principles class, written as application code requirements.

Roles: access by job

In role-based access control, access is granted or denied based on the roles assigned to a user. Permissions are not assigned directly to a person; they are assigned to roles, and people are assigned to roles. NIST describes the model as pre-defined roles that carry a specific set of privileges and to which subjects are assigned: a Manager role reaches different objects than an Analyst role.

Roles are easy to explain and audit. Their weakness is that real rules often depend on more than the job, and roles multiply to fill the gaps.

Attributes: access by facts

Attribute-based access control decides by evaluating attributes of the subject, the object, the requested operation and sometimes the environment against policy. For example: allow a doctor to read a record if the patient is on their ward and it is during their shift. OWASP recommends preferring attribute- and relationship-based models over plain roles for complex systems, and says the decision between models should be made as early as possible because it affects the whole development cycle.

Test the rules

Authorization logic is easy to get subtly wrong, so OWASP also advises creating unit and integration tests for it and logging authorization failures. A rule you have not tested to refuse is a rule you only hope refuses.

Key points

Sources

Lecture

Authorization models: RBAC, ABAC and OAuth: A talk that compares roles, attributes and OAuth scopes with worked examples.

Practice in the labs

Build role checks into a small web app and write a least-privilege policy.

Knowledge check

  1. What does 'deny by default' mean in application authorization? Answer: If no rule explicitly allows a request, it is refused. OWASP: when no access control rules match, the application must still decide, and the safe decision is to deny.
  2. How does RBAC assign permissions? Answer: To roles, with people assigned to roles. In RBAC permissions are assigned to roles, and users receive them by being assigned to the roles.
  3. Why validate permissions on every request? Answer: An attacker only needs one missed check. OWASP notes that an attacker only needs to find one way in, so even a single missed access check can undo the rest.

Back to the syllabus or see all classes.

Related