Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 80 ยท Authentication and Access Control

Authorization and Access Control Models

Compare DAC, MAC, RBAC and ABAC, learn why broken access control and IDOR top the OWASP list, and build deny-by-default permission checkers in Python.

Authentication answers "who are you?". Authorization answers "what are you allowed to do?". You can have flawless login security and still lose everything because a logged-in user can open someone else's invoice by changing a number in the URL. That kind of failure, broken access control, has been at or near the top of the OWASP Top 10 for years, because it is easy to forget and hard to detect with automated scanners: the application works exactly as coded, it just never asked the right question.

An access control model is a systematic way to decide who may perform which action on which resource. This lesson walks through the four classic models (DAC, MAC, RBAC and ABAC), then the everyday bugs (IDOR, missing function-level checks) and the principles that prevent them. Everything builds on the least-privilege idea from The CIA Triad and Core Principles, and the sessions from Sessions, Cookies and JWTs are how the server knows the subject in the first place.

Vocabulary

  • Subject: the actor making the request (a user, a service account, a process).
  • Object (resource): the thing being accessed (a file, a record, an API endpoint).
  • Action (permission): read, write, delete, approve, and so on.
  • Policy: the rules that map (subject, action, object) to allow or deny.
  • Policy enforcement point: the code that actually asks the question and obeys the answer. Every access must pass through one.

Discretionary access control (DAC)

In DAC, the owner of a resource decides who else gets access. Unix file permissions and sharing a Google Doc are everyday examples. It is flexible and simple, but it depends on every owner choosing well, and a compromised or careless owner can hand out access freely. Malware running as a user inherits all of that user's discretionary rights.

Mandatory access control (MAC)

In MAC, a central authority assigns security labels to subjects and objects, and the system enforces rules no user can override, even the owner. Typical in military and high-assurance systems, and also available on Linux through SELinux and AppArmor. The classic Bell-LaPadula confidentiality rules are:

  • No read up: a subject cannot read objects labelled above its clearance.
  • No write down: a subject cannot write to objects labelled below its level, so secrets cannot leak into a less-protected place.

(The Biba model is the integrity mirror image: no read down, no write up.)

Python DAC permission bits and MAC label rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Role-based access control (RBAC)

RBAC assigns permissions to roles and roles to users. Instead of tracking thousands of user-permission pairs, administrators manage a handful of roles such as viewer, editor, billing-admin. Joiners, movers and leavers become simple: change the user's roles.

Useful RBAC features:

  • Role hierarchies: admin inherits everything editor can do, which inherits viewer.
  • Separation of duties: no single person should be able to both create and approve a payment, so conflicting roles must not be combined.
  • Least privilege: give each role the minimum permissions, and review them regularly to prevent privilege creep as people change jobs.

RBAC's weakness is role explosion: needing roles like editor-for-europe-only-on-weekdays when rules depend on context.

Python An RBAC checker with hierarchy and separation of duties

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Attribute-based access control (ABAC)

ABAC decides using attributes of the subject (department, clearance, location), the object (owner, sensitivity, status), the action, and the environment (time of day, device health, network). A policy might read: "Doctors may read a patient's record only if the doctor is assigned to that patient and the request comes from a hospital network." This handles fine-grained and contextual rules that would need endless roles in RBAC, at the cost of more complexity: policies are harder to audit, and a mistake in one rule can open a wide hole. Policy languages such as XACML, Open Policy Agent's Rego and AWS IAM policies follow this style. Relationship-based access control (ReBAC), as in "editors of a folder can edit its documents", is a close cousin used by large collaboration products.

A good engine uses explicit deny overrides allow, and no matching rule means deny.

Python A small ABAC policy engine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which model should you choose?

Model Decision based on Strengths Weaknesses
DAC Owner's choice Simple, flexible Easy to over-share; malware inherits rights
MAC Central labels Strong, tamper-proof Rigid, heavy to administer
RBAC Role membership Easy to audit and manage Role explosion, coarse context
ABAC Attributes and context Fine-grained, dynamic Complex policies, harder to review

Most real systems mix them: RBAC for broad capabilities plus ABAC-style checks for ownership and context ("editors can edit their own team's documents").

IAM roles, policy-based access and the identity lifecycle

Access control models say how a decision is made. Identity and access management (IAM) is the whole discipline of creating identities, giving them the right access, and removing it when it is no longer justified. This section adds three practical pieces: policy-based access control, privileged access, and the lifecycle that keeps permissions from drifting.

PBAC: policy-based access control

Policy-based access control (PBAC) expresses authorization as policies, written separately from the application and evaluated by a central policy engine. A policy combines elements of RBAC and ABAC: "members of the payroll role may read salary records during business hours from a managed device". Because the rules live in one place, they can be reviewed, versioned, tested and audited, and changed without redeploying every application. Cloud IAM systems and policy engines work this way: a request (who, what action, which resource, which context) is matched against policies, with an explicit deny overriding any allow and a default deny when nothing matches. In practice RBAC, ABAC and PBAC are layers: roles give the broad starting point, attributes add context, and policies state the rules.

Typical administrative roles

Organizations separate powerful responsibilities so that no single account can do everything:

  • System or global administrators manage the platform itself and should be few.
  • Identity administrators create and manage accounts but should not approve their own access.
  • Security administrators and auditors: one group configures security tools, another (read-only) reviews logs and configuration. The people who administer a system should not be the only ones who audit it.
  • Service accounts and machine identities are used by applications. They need an owner, narrow permissions and managed secrets, because they often outnumber humans and are neglected (Randomness, Key Management and Secrets).
  • Break-glass accounts: emergency administrator accounts kept sealed, monitored heavily and used only when normal access fails.

Everyday work should use a normal account; administrative tasks use a separate admin account or an elevated session, so a phishing click on a normal account does not hand over the keys.

Privileged access management (PAM)

Privileged accounts can change configuration, read all data or create other accounts, so they are the favourite target of attackers (The Attack Lifecycle and MITRE ATT&CK). PAM adds extra controls around them:

  • Vault and rotate credentials: shared admin passwords are stored in a vault, checked out per use, and changed afterwards.
  • Just-in-time (JIT) access: privileges are granted only when needed, for a limited time, after approval, then removed automatically. There are no standing administrators.
  • Session recording and monitoring of privileged sessions, with alerts for risky commands.
  • MFA and approval workflows for elevation (Multi-Factor Authentication and Passkeys).
  • Least privilege per task: instead of the full admin role, the narrowest role that does the job.
Python Just-in-time privileged access with expiry

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The privilege disappears without anyone remembering to remove it, and every request leaves an audit record.

The identity lifecycle: joiner, mover, leaver

Permissions drift unless the lifecycle is managed (Authorization and Access Control Models introduced the phrase for RBAC):

  • Joiner: a new person gets an account and the baseline access for their role, ideally automatically from the HR system, with the minimum needed on day one and managers approving extras.
  • Mover: when someone changes teams, access for the old role must be removed, not just the new access added. Otherwise people collect permissions over the years (privilege creep), which also breaks separation of duties.
  • Leaver: on departure, disable accounts promptly (the same hour for sensitive roles), revoke tokens and sessions, recover devices, rotate shared secrets they knew, and transfer ownership of their data and service accounts. Disabled accounts are then deleted after a retention period.
  • Contractors and guests need an end date and a sponsor.
  • Orphaned accounts (no valid owner) are a common source of breaches: they are active, forgotten and unmonitored.

Identity governance and access reviews

Identity governance and administration (IGA) keeps the system honest. The key practice is the access review (also called certification or recertification): managers or resource owners periodically confirm who still needs which access, and reviewers revoke what they cannot justify. Combine it with separation-of-duties rules (for example, nobody should both create and approve a payment) and role mining to clean up roles. Reviews are required by many frameworks (Compliance and Security Frameworks).

Python An access review that finds orphaned accounts and privilege creep

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Run this kind of comparison (directory against HR, access against role baseline) on a schedule rather than once a year, and send each finding to the owner who can fix it.

Broken access control in practice

Models describe the policy; bugs appear in the enforcement. The most frequent patterns:

  • IDOR (insecure direct object reference): the app takes an ID from the request (/invoices/1042) and returns the record without checking that it belongs to the current user. Changing the number reveals other users' data. Using random-looking IDs (UUIDs) makes guessing harder but is not a fix: an ID that leaks in a link, a log or an email still works for anyone.
  • Missing function-level checks: the admin menu is hidden in the UI, but /admin/users answers anyone who types the URL. Hiding a button is never access control.
  • Privilege escalation: changing a role field in a form (role=admin), or using a lower-privileged token against a higher-privileged API (API Security covers mass assignment).
  • Trusting client data: deciding rights from a cookie, hidden field or JWT claim that the user can change.
  • Forced browsing and path traversal to files that were never meant to be public.
  • CORS and CSRF gaps that let another site act as the user (CSRF, SameSite and CORS).
Python IDOR: the missing ownership check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Principles that prevent most of these bugs

  • Deny by default. A permission must be granted explicitly. New endpoints start closed.
  • Enforce on the server, on every request, for every action and every object. Never rely on the client UI, hidden fields or client-side checks.
  • Check the object, not just the role. "Is this user an editor?" is incomplete; ask "may this user edit this document?"
  • Centralize the logic in one policy layer, middleware or framework feature (policies and gates in Laravel, permission_required in Django, Spring Security annotations), rather than scattering ad hoc if statements that someone will forget.
  • Derive identity from the session, never from a user-supplied user_id parameter.
  • Log authorization failures and alert on bursts of denials, which often reveal enumeration (Spotting Attacks in Logs).
  • Test it. Write automated tests that log in as user A and try to read user B's data, and as a low-privilege user hit admin routes.
  • Review access regularly and remove permissions when people change roles or leave.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In which model does the owner of a resource decide who else may access it?

    DAC leaves the decision to the owner, as with Unix file permissions or sharing a document. MAC uses central labels that owners cannot override.
  2. 2. What does 'no read up' mean in Bell-LaPadula?

    No read up protects confidentiality: reading is allowed only at or below your clearance. No write down stops secrets being copied to less-protected places.
  3. 3. What is the best description of an IDOR vulnerability?

    IDOR is an authorization failure at the object level. Using unpredictable IDs only hides the problem; the ownership check is the fix.
  4. 4. Which approach to a request for a new, unconfigured endpoint matches 'deny by default'?

    Deny by default means that access exists only where a policy says so, so forgotten rules fail closed rather than open.
  5. 5. Why might a team add ABAC checks on top of RBAC?

    Attributes let a policy say 'editors can edit documents from their own team during working hours' without a role for every combination.

Summary

  • Authorization decides what an authenticated subject may do to which object; it must be enforced by the server on every request.
  • DAC lets owners decide, MAC enforces central labels, RBAC groups permissions into roles, and ABAC evaluates attributes and context.
  • Combine models: roles for broad capabilities, attribute or ownership checks for specific objects.
  • Broken access control, especially IDOR and missing function-level checks, is a leading real-world vulnerability. Random IDs and hidden buttons are not fixes.
  • Deny by default, check the object as well as the role, centralize policy, test with multiple users and review permissions regularly.

Next: The OWASP Top 10, the start of the Web Application Security chapter, where broken access control is the first of many common web risks.