Fine-Grained Authorization for a Multi-Tenant Document Platform with OpenFGA, OIDC and PostgreSQL Row-Level Security

Replace scattered permission checks in a law-firm document platform with authorization as a designed, tested system: an OpenFGA model for firms, teams, matters, nested folders, guests, links, ethical walls and legal holds; one guard in a TypeScript API with OIDC tokens from Keycloak; PostgreSQL row-level security as a second barrier; a transactional outbox keeping the stores in step, with stated read-after-write and revocation bounds; access-aware listings; audit and explanations; and an independent oracle, drills and a load test, all locally.

Backend Engineer. Advanced.

What you will build and explain

  • Explain authentication, authorization, RBAC, ABAC and relationship-based access control, and choose between them for a product.
  • Design and test an OpenFGA model with inheritance, conditions and overriding rules, and spot a shape that makes checks expensive.
  • Enforce authorization in one place in an API, with statuses that never leak what exists, and fail closed.
  • Validate OIDC access tokens correctly and map identities to subjects.
  • Isolate tenants in PostgreSQL with row-level security, and prove that a missing filter leaks nothing.
  • Keep relationships in step between a database and OpenFGA with a transactional outbox, and reason about read-after-write and revocation.
  • List and paginate only what a person may see, choosing between ListObjects, BatchCheck and a single check.
  • Roll out and roll back model versions safely, audit decisions, and measure and bound the cost of authorization under load.

Before you begin

  • Read TypeScript or JavaScript, including async code, and write SQL with joins, indexes and transactions.
  • Know HTTP APIs and status codes, roughly what a JSON Web Token contains, and run containers with Docker Compose.
  • OpenFGA, relationship-based access control, OIDC token validation, row-level security, the transactional outbox and authorization testing are taught.
  • A machine with Docker and the docker compose plugin, about 6 GB of memory and 10 GB of free disk for Docker, and port 8088 free.

Who this is for

For backend engineers who read TypeScript, know HTTP APIs and SQL and run containers, and want to build authorization as a designed, tested system: relationship-based access with OpenFGA, OIDC tokens from Keycloak, PostgreSQL row-level security, a transactional outbox with stated revocation bounds, access-aware listings and audit.

Curriculum

Learning topics (15)
  1. Understand the brief and prepare your tools

    In this project you build the authorization system of a document platform for law firms. Firms are tenants; lawyers work in matters; folders and documents inherit access; guests and share links expire; ethical walls and legal holds beat every grant. An OpenFGA model decides each request, Keycloak issues identities, PostgreSQL row-level security isolates firms a second time, and a transactional outbox keeps the two stores in step. Everything runs on your own computer with Dock

  2. Follow one request from a token to an allow or deny

    Quillmark's document platform answers one question on every request: may this person do this to this object? This page explains how the system answers it: who proves the caller's identity, where the rules live, how the data of one law firm is kept from another, and how a change to who may see what reaches every part of the system in a bounded time.

  3. Understand permissions that follow relationships

    At Quillmark, whether Ana may edit a document depends on who she is to it: a member of a team that edits the matter the document's folder belongs to. Ask the same question about her colleague Kai, in the same team, and the answer is no, because Kai has been walled off from that matter. This lesson explains the idea the whole project rests on: store the relationships, and derive the permissions from them with rules. By the end you can read a relationship tuple, follow a permis

  4. Turn requirements into a model that checks fast

    The previous lesson followed one permission through a graph of tuples. This one is about writing the rules that define that graph: OpenFGA's modelling language, how each of Quillmark's requirements became a relation, and why two models that grant exactly the same permissions can differ enough in cost to decide whether OpenFGA keeps up with the load or falls over. By the end you can read every line of authz/model.fga, design relations for a new requirement, and spot a shape th

  5. Change who may do what, safely

    An authorization model is code with an unusual failure mode: a mistake doesn't crash anything. It quietly lets someone delete a document under legal hold, or quietly stops a whole team seeing its matter, and nobody notices until the wrong person does. This lesson covers how Quillmark's model is tested before it reaches OpenFGA, how a new version is rolled out while requests run, and how it's rolled back. By the end you can write a model test that would catch a broken rule, ex

  6. Know who is calling, and validate tokens correctly

    Every decision OpenFGA makes starts with a subject: user:<id>. If the API can be fooled about who is calling, the best model in the world grants the wrong person's access. This lesson covers how Quillmark establishes identity: Keycloak issues signed access tokens, and the API accepts a token only after checking its signature with Keycloak's keys and every claim that matters. By the end you can read a token's parts, list what an API must check before trusting one and why, and

  7. Enforce every decision in one place

    Quillmark's old API checked access in each handler, with role columns and if statements written a little differently every time; one list endpoint returned another firm's titles when a filter was mistyped. This lesson is about the opposite design: a single guard that every request passes through before any handler runs, that asks OpenFGA once, and that answers with a status code which never reveals what the caller isn't allowed to know. By the end you can explain what the gua

  8. Add a second barrier with row-level security

    The guard and the model decide who may enter a firm. But all three firms' documents live in the same PostgreSQL tables, and every query the API runs is one WHERE tenant_id = ... away from leaking: Quillmark's security review found exactly that, a list endpoint that returned another firm's titles when a filter was mistyped. This lesson adds a barrier that doesn't depend on every query being right: PostgreSQL's row-level security, with a separate database role for each process.

  9. Deliver relationship changes with a transactional outbox

    Every relationship in Quillmark lives in two places. PostgreSQL holds it as a row, where the application lists, joins, audits and backs it up; OpenFGA holds it as a tuple, where it's evaluated. A share that reaches one store and not the other is a bug either way: a document shared in the database but not in OpenFGA can't be opened; a removal applied in the database but not in OpenFGA leaves access in place. This lesson is about keeping the two in step with a transactional out

  10. Bound when a change takes effect

    A colleague shares a document with you and says "it's there now". You click, and get "not found". Or worse: a firm removes a guest whose engagement ended, and the guest keeps reading the matter for another ten minutes because some cache still says yes. Quillmark's review found both kinds of problem: permission changes "took minutes to apply in one place and were immediate in another". This lesson is about the two promises that replace that, and what it takes to keep them: a c

  11. Page through documents without leaks

    Checking one document is a question with a yes or no answer. A list is harder: "the first 25 documents Ana may see, in title order, out of 6,800 in her firm" can't be answered by checking all 6,800, and can't be answered by the database alone, because the database doesn't know what OpenFGA decides. This lesson covers the three ways Quillmark's API lists documents, why each exists, and how the pages and cursors avoid both slow requests and leaks. By the end you can choose betw

  12. Apply rules beyond roles

    Roles and inheritance cover most of Quillmark's access. Four requirements don't fit them: a guest's access ends on a date; some firms allow sharing only from their own network; a link gives a person outside the system one document for a while; and two rules must beat every grant, the ethical wall and the legal hold. Quillmark's security review found guests with access months after their engagement ended, and held documents deleted by their owners. This lesson covers how each

  13. Record decisions and explain access

    Two questions come up after any access incident, and Quillmark couldn't answer either: "who could see this document?" needed someone to read code, and "who deleted it, and were they allowed to?" had no record at all. This lesson covers the two answers the system now gives: an append-only audit log of decisions on sensitive actions, and an explanation endpoint that lists everyone with access to a document and one reason each. By the end you can say what an audit record must co

  14. Prove who may do what

    An authorization bug rarely crashes anything. It returns 200 where it should return 404, or hides a document someone should see, and every other test stays green. So authorization needs tests aimed at it: tests that know, independently, what each person should be able to do, and check both directions. This lesson walks through the layers of tests in this project, what each one can and can't catch, and the techniques that make them trustworthy: an independent oracle, a sample

  15. Stay correct under load and when parts fail

    Every request in this system waits for an authorization decision, so the decision service's capacity is the whole API's capacity, and its outages are the API's outages. This lesson is about what happens as load rises and as parts fail: where the capacity limit is, how the API refuses quickly instead of collapsing, what each failure does to users and to data, and what to watch in operation. By the end you can read a capacity ramp, explain why the API sheds load instead of queu

Practical build steps (14)
  1. Prepare and check your computer

    Starting point: a computer with Docker. End point: you know it has the Compose plugin, the memory and the free port the lab needs.

  2. Build the toolbox and run the static checks

    Starting point: Docker works. End point: the toolbox image exists, the API's packages are installed, and the type check, unit tests, both model versions' tests and the scripts' syntax check pass.

  3. Start the core lab: PostgreSQL, OpenFGA and the data

    Starting point: the toolbox works. End point: PostgreSQL holds three synthetic firms with 20,000 documents behind row-level security, and OpenFGA holds the model and the 63,205 tuples that describe them.

  4. Ask OpenFGA directly

    Starting point: the core lab is up. End point: you've asked OpenFGA the questions the API asks, matched its answers with the oracle, and seen an ethical wall override a team's access.

  5. Start the API and the outbox worker

    Starting point: the core lab. End point: Keycloak issues tokens, the API answers on 127.0.0.1:8088, and the outbox worker keeps OpenFGA in step.

  6. Call the API as different people

    Starting point: the full lab. End point: you've seen the API answer 200, 403 and 404 as the model decides, and asked it who may see a document and why.

  7. Share a document and watch the outbox

    Starting point: the full lab. End point: a share has taken effect on the recipient's next request, and a removal has waited in the outbox while the worker was stopped.

  8. Run the integration tests

    Starting point: the full lab. End point: every route has been called as every kind of user and compared with the oracle, and read-after-write and revocation have been measured.

  9. Roll out a model version and roll it back

    Starting point: the full lab. End point: model version 2 has been tested, written, pinned and rolled back while requests ran, without a failed request.

  10. Run the outage drill

    Starting point: the full lab. End point: you've seen the API queue changes while the worker was stopped, refuse requests while OpenFGA was stopped, and end with both stores equal.

  11. Find and repair drift with reconcile

    Starting point: the full lab. End point: you've deleted a tuple behind the API's back, found it with reconcile and repaired it.

  12. Measure the stated load

    Starting point: the full lab, ideally freshly started. End point: you have each kind of request's latency at about 63 requests a second.

  13. Deliver a change, diagnose and resume

    Starting point: a running lab. End point: you can release a code change, roll it back, find the cause of a misbehaving lab, and resume after a break.

  14. Clean up the lab

    Starting point: a lab you've finished with. End point: no container, volume, network, built image or lab file remains.

Access

Learning Access: INR 199 plus 18% GST. Source Pack: INR 399 plus 18% GST. 90 days of online access. No auto-renewal.

Cloud costs and boundaries

Runs entirely on your machine with Docker Compose: about 1 GB of downloads and a synthetic dataset of 20,000 documents generated locally. No cloud account, payment method or hosted lab is used or included. The lessons' load numbers were measured on an 8-vCPU cloud virtual machine; reproducing them on similar hardware is optional and would be at your own cost.

Licence and completion

Vectametric Project Source Licence (2026-09-27): lawfully obtained source may be copied, modified and deployed for personal learning and interview preparation, including personal portfolio demonstrations with attribution. These permissions continue after online access expires. Do not resell or redistribute the Source Pack or its original source files, unchanged or modified. Commercial or client production use requires separate written permission. Packages and container images downloaded when building or running, such as Fastify, the OpenFGA SDK, OpenFGA, Keycloak, PostgreSQL and k6, retain their own licences. See LICENSE.txt and the Project Source Licence section of the site Terms for the full rules.

Questions about projects

Do I need a cloud account?

You can read the project material without deploying it. Running a cloud build requires the accounts, permissions and tools listed in that project's prerequisites. Deployment runs in your environment, not in a hosted Vectametric lab.

Can I read the code with Learning Access?

Yes. Learning Access includes the online source-file browser and explanations. The Source Pack adds the downloadable reference repository where available. The project's licence governs use of the source.

Are cloud charges included?

No. Cloud and CI usage are separate. Read the project's cost notice, set a budget and stop deadline, and follow its destruction and leftover-resource checks.

Does the project include troubleshooting and interview preparation?

The project curriculum lists the available scenarios and interview topics. These focus on understanding the architecture and explaining decisions; they are not a promise of particular interview questions or a job.

How long can I use the project?

The project page and checkout show the online access period for your selected plan. Access does not auto-renew. Downloaded source remains subject to its licence; future releases are not automatically included.

Review the Terms and No-Refund Policy before confirming access. All sales are final; Vectametric does not offer refunds.

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy