Tutorial 1: Authentication and Authorization

Unit 3 ยท Identity and access management

Objectives

Authentication establishes an identity; authorization decides whether that identity may perform an action on a resource. A policy decision should consider subject, action, resource, tenant, device or session context, and time where appropriate.

if (!authenticated(subject)) deny();
if (!policy.allows(subject, action, resource)) deny();
allow();

Never trust an object identifier merely because a user can change it. Enforce authorization on the server at every sensitive boundary, log meaningful decisions without secrets, and make default behavior deny access. Administrative access deserves stronger authentication and narrower scope.

Exercises

  1. Write access rules for student, instructor, and administrator.
  2. Find an insecure direct-object reference in a fictional API.
  3. Specify audit events for permission changes.

Self-check

  1. What does authentication answer?
  2. What does authorization answer?
  3. Why deny by default?

Self-Check Quiz

1. Can a logged-in user read every record?

AnswerNo. Authentication does not imply authorization; access must be checked for the specific action and resource.

2. What is least privilege?

AnswerGranting only the permissions required for an identity's legitimate tasks and no broader access.

Homework

  1. Design authorization for a multi-tenant reporting API.
  2. Write five allow and deny test cases.
  3. Explain how you would prevent tenant data leakage.
Sample answerEvery query is scoped by the authenticated tenant and server-side policy, never only by a client-supplied tenant id. Tests cover same-tenant access, cross-tenant denial, missing identity, role changes, and resource ownership.