Caretaker Express · PostgreSQL · Cedar

A follow-along course · 11 modules · 50 lessons · about 40 hours

Build a multi-tenant app from an empty folder, then give its authorization to Cedar.

You build Caretaker, a building-maintenance application, with Express, PostgreSQL and server-rendered pages. When the hand-written permission checks start to hurt, you replace them with Cedar policies, one route at a time, with the same tests passing. Nothing is a black box: you trace every request from the session cookie to the Cedar decision.

Every command, output and screenshot in the lessons comes from an automated replay that builds the application from an empty directory. How the course is verified.

What you will build

localhost:3000signed in as alice
Issues list for Alice: buildings 10 and 20, with filters, sorting and pagination.
Issues list for Alice: buildings 10 and 20, with filters, sorting and pagination.
localhost:3000signed in as alice
An issue page. Edit and Delete appear only when Cedar allows them.
An issue page. Edit and Delete appear only when Cedar allows them.
localhost:3000signed in as alice
Inspection 202: Alice created it, so a forbid policy stops her approving it.
Inspection 202: Alice created it, so a forbid policy stops her approving it.
localhost:3000signed in as alice
Building access management: grants and revokes are authorized and logged.
Building access management: grants and revokes are authorized and logged.

What you will understand

  • How an HTTP request flows through Express middleware, a route, SQL and a template.
  • How to design tables, constraints and migrations, and why every query is parameterized.
  • How sessions, cookies, password hashing and CSRF protection fit together.
  • Why hand-written role checks explode as buildings and roles grow.
  • Exactly where Cedar's principal, action, resource, context and entity attributes come from.
  • RBAC, ABAC, parent relationships, forbid rules and policy templates, on one scenario.
  • How to filter lists without leaking data across tenants, and how to test it.
  • Which data the server can trust, and what Cedar cannot protect you from.

Before you start

  • You can read JavaScript and know what a function, an object and a Promise are.
  • You have used a terminal a little. Lesson 0.3 covers what we need.
  • A Mac, Linux machine, or Windows with WSL 2. macOS is the main walkthrough.
  • Node.js 22 or 24 LTS, Git, Docker Desktop and an editor. Lesson 0.2 installs and checks them.
  • No cloud account, no paid service and no AWS credentials. Everything runs locally.

How a request becomes a Cedar decision

This animation replays a real request from the finished application: Alice opens issue 101. Step through it now, or come back after Module 6. The values are the actual values from the reference implementation.

Loading the request trace…

The technology, and why

LayerChoiceWhy
RuntimeNode.js 22/24 LTS, ES modulesBuilt-in test runner, --watch and --env-file mean fewer dependencies.
WebExpress 5Small and explicit. You can see every middleware.
DatabasePostgreSQL 18 in Docker ComposeReal constraints and transactions, identical on every machine.
Data accesspg, parameterized SQL, no ORMAuthorization depends on exact queries. You should see them.
UIEJS, HTML, CSS, a little JavaScriptServer-rendered pages keep the trust boundary visible.
AuthenticationSessions in PostgreSQL, argon2id, CSRF tokensStandard, inspectable and easy to revoke.
Authorization@cedar-policy/cedar-wasm 4.14.0The official open-source Cedar engine, in-process, no service to run.
Testsnode:test + Supertest + a test databaseReal HTTP requests against the real app and real SQL.

The journey

  1. 0Orientation and environment setupSee the finished application, meet the scenario, and prepare a working toolchain.3 lessons · ≈ 1 h
  2. 1Our first Express applicationHTTP, routing, middleware, errors, EJS views and the first tests, with data kept in memory.5 lessons · ≈ 4 h
  3. 2Persistence and the relational data modelPostgreSQL in Docker, tables and constraints, migrations, seed data, and an app that reads and writes with parameterized SQL.6 lessons · ≈ 4.5 h
  4. 3Build real CRUD featuresOrganisations, buildings, issues and inspections with forms, validation, safe deletes, paging, sorting, filters and transactions.6 lessons · ≈ 7 h
  5. 4Authentication and user managementUsers, argon2id password hashing, sessions in PostgreSQL, login and logout, session fixation, cookie settings, CSRF and login throttling.4 lessons · ≈ 4.5 h
  6. 5Authorization before CedarMemberships and building roles, permission checks in plain JavaScript, tenant isolation for every list, and the point where hand-written rules stop scaling.5 lessons · ≈ 5 h
  7. 6Introduce CedarInstall the real Cedar engine, make the smallest real decision, add a schema, map database rows to entities, and move every route behind Cedar without changing behaviour.6 lessons · ≈ 4.5 h
  8. 7RBAC, ABAC, scoped roles and policy managementRoles as facts, parents and action groups, templates as a comparison, controlled onboarding, and grant/revoke that is itself authorized.4 lessons · ≈ 3.5 h
  9. 8Lists, writes and multi-tenant isolationKeep SQL list filters and Cedar policies aligned and prove it, make per-item checks fast, authorize creates and moves against the right parents, and test isolation everywhere.3 lessons · ≈ 2 h
  10. 9Trust boundaries and architectureForged input, what Cedar cannot detect, PDP/PIP/PEP/PAP, an optional authorization service, and defence in depth in the database.3 lessons · ≈ 1.5 h
  11. 10Complete, test and operate the applicationHardening and safe logging, the whole application as six users, a run from a clean checkout, production considerations, and a capstone feature.5 lessons · ≈ 3.5 h