Caretaker Express · PostgreSQL · Cedar

Checkpoint · Lesson 10.3

From a clean checkout, and what production needs: checkpoint files

Git tag in the reference repository
lesson/m10-l03 (commit 85a65bd)
Replay result
All steps replayed from an empty folder
Tests at this point
pass (tests 131, pass 131, fail 0)

Compare your folder with the reference using Git, if you cloned it: git diff lesson/m10-l03 -- src.

Files changed in this lesson

README.md added

README.md
# Caretaker A multi-tenant building-maintenance application built with Express 5, PostgreSQL 18 and Cedar 4.14,as the project of a follow-along course. All data is synthetic. ## Requirements - Node.js 22 or 24 LTS, npm- Docker with Compose v2 (PostgreSQL runs in a container on port 5433) ## Run it     npm ci    cp .env.example .env    # then put long random values in SESSION_SECRET and AUTHZ_SERVICE_TOKEN, for example:    # node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"    docker compose up -d --wait    npm run db:migrate    npm run db:seed    npm run dev            # http://localhost:3000 Seeded users (password `password123`, local use only): alice, bob, carol, dave, nora, ravi `@example.test`. ## Commands | Command | What it does ||---|---|| `npm run dev` / `npm start` | Start the app (with or without restart on save) || `npm test` | Run every test against the `caretaker_test` database (it migrates and seeds itself) || `npm run check` | Validate the Cedar policies, then run the tests || `npm run db:migrate` / `db:seed` / `db:reset` | Apply migrations / load the scenario / drop, migrate and seed (local only) || `npm run authz:validate` | Validate `src/authz/policies/*.cedar` against `src/authz/schema.cedarschema` || `npm run authz:explain -- alice ViewIssue 101` | Show every value from database rows to Cedar's decision || `npm run authz:service` | Optional separate decision service on port 4000 | ## Authorization in one paragraph Routes load a resource, call `can(user, action, resource)`, then act. `can()` builds Cedar entitiesfrom the session's user ID and database rows (`src/authz/entities.js`, `request.js`) and evaluates themagainst the policies in `src/authz/policies` (`src/authz/cedar.js`), failing closed. Lists are filteredin SQL by `src/models/scope.js`; `test/list-parity.test.js` proves the SQL and the policies agree.

Project tree at this checkpoint

.env.example
.env.test
.gitignore
.npmrc
README.md
compose.yaml
db/init/01-create-test-database.sql
migrations/001_create_organisations_buildings_issues.sql
migrations/002_create_inspections.sql
migrations/003_create_users.sql
migrations/004_create_session_table.sql
migrations/005_create_memberships_and_building_roles.sql
migrations/006_create_permission_changes.sql
package-lock.json
package.json
public/css/style.css
public/js/app.js
scripts/authz-bench.js
scripts/authz-explain.js
scripts/cedar-errors-demo.js
scripts/cedar-hello.js
scripts/forged-entity-demo.js
scripts/migrate.js
scripts/partial-demo.js
scripts/reset.js
scripts/seed.js
scripts/template-demo.js
scripts/validate-policies.js
services/authz-service.js
services/start-authz-service.js
src/app.js
src/authz/authorize.js
src/authz/cedar.js
src/authz/entities.js
src/authz/policies/building-admin.cedar
src/authz/policies/building-read.cedar
src/authz/policies/forbid-building-admin-grants.cedar
src/authz/policies/forbid-self-approval.cedar
src/authz/policies/forbid-self-membership-change.cedar
src/authz/policies/forbid-self-role-change.cedar
src/authz/policies/inspector-create-inspection.cedar
src/authz/policies/inspector-own-inspections.cedar
src/authz/policies/org-admin.cedar
src/authz/policies/org-member.cedar
src/authz/policies/reporter-create-issue.cedar
src/authz/policies/reporter-own-issues.cedar
src/authz/policy-store.js
src/authz/request.js
src/authz/rules.js
src/authz/schema.cedarschema
src/config.js
src/db.js
src/lib/http.js
src/lib/ids.js
src/lib/validation.js
src/middleware/auth.js
src/middleware/csrf.js
src/middleware/flash.js
src/middleware/rate-limit.js
src/middleware/security-headers.js
src/migrate.js
src/models/access.js
src/models/assignments.js
src/models/buildings.js
src/models/dashboard.js
src/models/inspections.js
src/models/issues.js
src/models/members.js
src/models/organisations.js
src/models/scope.js
src/models/users.js
src/routes/account.js
src/routes/auth.js
src/routes/buildings.js
src/routes/inspections.js
src/routes/issues.js
src/routes/organisations.js
src/seed.js
src/server.js
test/access-matrix.test.js
test/access.test.js
test/auth.test.js
test/authz-decisions.test.js
test/authz-service.test.js
test/building-access.test.js
test/buildings.test.js
test/csrf.test.js
test/dashboard.test.js
test/forged-input.test.js
test/hardening.test.js
test/helpers.js
test/inspections.test.js
test/isolation.test.js
test/issue-authz.test.js
test/issue-list.test.js
test/issue-moves.test.js
test/issues.test.js
test/list-parity.test.js
test/members.test.js
test/organisations.test.js
test/policies.test.js
test/rate-limit.test.js
test/require-login.test.js
test/resource-authz.test.js
test/tenant-isolation.test.js
views/account.ejs
views/auth/login.ejs
views/auth/register.ejs
views/buildings/access.ejs
views/buildings/form.ejs
views/buildings/show.ejs
views/dashboard.ejs
views/error.ejs
views/forbidden.ejs
views/inspections/form.ejs
views/inspections/index.ejs
views/inspections/show.ejs
views/issues/form.ejs
views/issues/index.ejs
views/issues/move.ejs
views/issues/show.ejs
views/not-found.ejs
views/organisations/form.ejs
views/organisations/index.ejs
views/organisations/members.ejs
views/organisations/show.ejs
views/partials/foot.ejs
views/partials/head.ejs
views/partials/nav.ejs

Back to lesson 10.3