Part 4 · Blueprint 22
Security Architecture, Zero-Trust & Multi-Tenancy
14 min reading · Sources · Editorial review pending
A correctly signed identity token does not prove current permission to every cached copy.
Page details
Published date · Last edited:
Draft edition. Editorial review and supplementary reading recommendations are still being completed.
Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: SQL vs. NoSQL vs. NewSQL Storage Engines, Idempotency Keys & Distributed Retries.
Sixty-second mental model
Problem: A correctly signed identity token does not prove current permission to every cached copy.
Use: Enforce scope at each disclosure boundary.
Design boundary: Carry tenant and resource authorization through every storage and asynchronous boundary. Authentication identifies a principal; authorization decides whether that principal may perform this operation on this resource now.
Layer 1 · Intuition
Hypothetical scenario: Northwind is designing tenant security. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one access decision means and which component owns the authorization policy.
Think of a building with separate identity checks and locked filing rooms. Separate the requester from authorization policy, then identify the retained evidence needed after failure.
- Authority
- The entitled state owner.
- Invariant
- A rule preserved across concurrency and failures.
- Cookie
- Browser-managed data sent with requests according to origin and scope rules. Analogy: A browser-held ticket shown at the relevant service desk.
- JWT
- JSON Web Token: a compact claims representation that can be signed or encrypted. Analogy: A structured pass whose signature can be checked.
- Session
- Interaction state associated with a client across requests. Analogy: An open customer file used over several visits.
Architecture and worked reasoning
Design boundary: Carry tenant and resource authorization through every storage and asynchronous boundary. Authentication identifies a principal; authorization decides whether that principal may perform this operation on this resource now.
Responsibilities on the request path
Workload and limiting resource
Hypothetical batch contains 1,000 documents from 10 tenants, 100 each. Filtering only after retrieving a global top-20 result can return fewer than 20 authorized documents and exposes an unsafe intermediate path. Constrain candidate selection by authorized scope; increasing top-k alone does not prove isolation.
Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.
Mutation or publication path
- Authenticate the actor and derive trusted tenant context.
- Authorize the specific operation and resource.
- Persist the scope needed for delayed work without granting unlimited future access.
Observation and recovery path
- Resolve records with tenant scope included.
- Recheck permissions at the protected observation/effect boundary.
- Apply equivalent scope to caches, search and exports.
Failure that changes the decision
Hypothetical scenario: A background export uses the permission snapshot from submission after the user was revoked. Decide whether the export is an already authorized capability or requires current permission, then enforce that policy at execution and download.
Attempt this decision before reading the explanation
Is an unguessable object identifier sufficient authorization?
No. Identifiers can leak, be logged or be shared. Verify access under trusted principal/tenant context, including indirect paths such as signed downloads and derived search entries.
Supporting mechanism analysis
Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.
Hypothetical scenario. Northwind grants support access to one tenant’s pending reservations. Dev filters the initial database query. Priya follows the same request into a cache, a background message and an object download, asking which identity authorizes each disclosure.
Build an authorization argument across the whole data path. Keep recognized identity, tenant membership and permission for a particular action distinct. Support inspection is an explicit new feature; the selected recheck exercise is not a revision of catalogue demand.
A later cache, queue or download can disclose through another boundary. Explain where its scope comes from and what evidence authorizes the particular action.
This connects the support contract to actual disclosures, including delayed work and revocation. A tenant identifier alone is not permission.
Authentication establishes which principal the service recognizes under a chosen credential contract. Authorization decides whether that principal may perform this action on this resource now. Tenant membership is one input to that decision; knowing a tenant identifier is not itself evidence of membership.
The application validates credentials and maps the principal to a permitted tenant context. It must not let a caller replace that context with an arbitrary request parameter after authentication. Administrative cross-tenant access needs an explicit, separately authorized capability, a narrow purpose and appropriate evidence. A support role should not inherit unrestricted access merely because its interface is internal.
Resource identifiers also do not supply authority. A hard-to-guess reservation key can reduce accidental discovery but does not decide whether the current caller may see its receipt. Repeated operation lookups must reapply the permission rule before returning stored results. Idempotency is not permission to replay another tenant’s response.
A tenant filter in the first SQL query cannot protect a later shared cache entry whose key omits tenant or permission dependencies. Nor can it protect an object URL that grants broader access than intended. Trace the representation through every layer and identify the boundary that decides whether the caller can receive it.
Northwind proposes PostgreSQL row-level security as an additional database enforcement layer for selected shared tables. Its policy must use trustworthy session context and be evaluated under the actual application role. Privileged roles and ownership behavior need explicit review. Row-level security supplements application authorization; it does not govern external object storage automatically.
Hypothetical scenario. Tenant T requests a receipt by identity R. The service authenticates the caller, resolves tenant scope and checks current authorization before reading the receipt or returning a saved response. Possession of R or a retry key is not the permission check.
A PostgreSQL row-security policy is one concrete enforcement layer, with its documented owner and bypass behavior. The application still owns correct tenant context, object-storage capabilities, cache sharing, search results and background tasks. A privileged worker cannot safely infer authority from an untrusted tenant field inside a message.
Bind asynchronous work to its authorized operation and recheck current permission where the chosen contract requires it. A capability's expiry may outlive the permission cache that issued it; compose those intervals explicitly. Logs and exports are additional disclosure paths. Revocation design must state whether already issued capabilities remain valid and which control can stop future disclosure.
A background job may run after the initiating user loses access. Decide which actions should follow the user’s current permission and which represent an already accepted durable business obligation. Generating a new support export usually needs a current access decision. Finishing an accepted settlement may use a narrowly defined service capability governed by the workflow.
Neither answer is universal. The worker must know the kind of authority it is exercising, the resource and tenant scope, the accepted intent and any recheck requirement. Serializing an entire original user token into a queue is not a complete policy. Credentials can expire, leak or retain permissions whose relevance has changed.
Hypothetical worked example. Choose a support permission cache that reuses a decision for thirty seconds. Select a revocation occurring five seconds after the last successful decision. The cached decision has 30 − 5 = 25 seconds of remaining reuse. If the policy permits that reuse, new actions can remain allowed during that interval.
Now choose a download capability issued twenty seconds after revocation using that cached decision, with a sixty-second lifetime. Its expiry occurs 20 + 60 = 80 seconds after revocation. The permission-cache interval and capability lifetime have composed into a longer possible access interval than either label suggested.
This is a selected timeline, not a measured vulnerability or a universal upper bound. It assumes no online reauthorization at download time and no capability revocation. If the product requires prompt denial of new downloads, change the enforcing boundary rather than claiming that a short local cache timer already provides it.
PostgreSQL’s row-security documentation describes policy behavior and roles that can bypass it. Use the actual application role when assessing the proposed defense. OWASP’s authorization guidance supports explicit checks at the relevant resource boundaries. Neither source certifies Northwind’s policy configuration.
Hypothetical failure scenario. The API validates the support user and correctly filters its first query. A later receipt cache uses only the operation key. A request from another tenant reaches that cache path and receives the stored receipt before the resource permission check. The response is fast, deduplicated and unauthorized.
Scope lookup and cache eligibility to the authorized resource context, then check permission before disclosure. Where permission depends on a changing policy revision, account for that revision or reauthorize. Guess-resistant keys, encrypted transport and a valid login do not make the missing object-level decision unnecessary.
Record who authorized a sensitive action and what operation was accepted through the required durable evidence path. Sampling can help diagnostic telemetry cost, but a sampled trace cannot replace a required audit record. Audit access also needs authorization; collecting more evidence creates another protected dataset.
Use tenant-aware application checks, database policy where suitable, scoped service authority and controlled object access together. Each layer should have a named responsibility and a testable denial path. Avoid relying on a duplicated policy whose independent copies disagree about revocation without a declared consistency rule.
Layer 3 · Internals
Trade-offs and limits
| Approach | Provides | Requires |
|---|---|---|
| Shared storage with enforced scope | Can share operational infrastructure across tenants. | Every query, index and support path must enforce the boundary. |
| Dedicated tenant storage | Can provide a stronger operational separation. | Fleet size, migrations and access administration grow with tenant count. |
Recovery decision
Hypothetical scenario: A background export uses the permission snapshot from submission after the user was revoked. Decide whether the export is an already authorized capability or requires current permission, then enforce that policy at execution and download.
No. Identifiers can leak, be logged or be shared. Verify access under trusted principal/tenant context, including indirect paths such as signed downloads and derived search entries.
Write your design before revealing the review
Is an unguessable object identifier sufficient authorization?
Drafts and self-review are stored only in this browser. They are separate from reading completion.
Compare your decision
No. Identifiers can leak, be logged or be shared. Verify access under trusted principal/tenant context, including indirect paths such as signed downloads and derived search entries.
A background export uses the permission snapshot from submission after the user was revoked. Decide whether the export is an already authorized capability or requires current permission, then enforce that policy at execution and download.
Check your understanding
Is an unguessable object identifier sufficient authorization?
No. Identifiers can leak, be logged or be shared. Verify access under trusted principal/tenant context, including indirect paths such as signed downloads and derived search entries.
How would you recover from this failure: A background export uses the permission snapshot from submission after the user was revoked. Decide whether the export is an already authorized capability or requires current permission, then enforce that policy at execution and download.
Start with the exact boundary that failed. Authenticate the actor and derive trusted tenant context. Authorize the specific operation and resource. Persist the scope needed for delayed work without granting unlimited future access. Then recover evidence through the observation path: Resolve records with tenant scope included. Recheck permissions at the protected observation/effect boundary. Apply equivalent scope to caches, search and exports. Preserve the distinction between a confirmed state change and an unavailable response.
Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?
Hypothetical batch contains 1,000 documents from 10 tenants, 100 each. Filtering only after retrieving a global top-20 result can return fewer than 20 authorized documents and exposes an unsafe intermediate path. Constrain candidate selection by authorized scope; increasing top-k alone does not prove isolation. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Carry tenant and resource authorization through every storage and asynchronous boundary. Authentication identifies a principal; authorization decides whether that principal may perform this operation on this resource now.
Which component in this topology could be removed from a smaller first deployment?
Identity provider, Policy decision, Tenant-scoped data, Job worker name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Authenticate the actor and derive trusted tenant context.
What evidence must a caller have before relying on the observation path?
Resolve records with tenant scope included. Recheck permissions at the protected observation/effect boundary. Apply equivalent scope to caches, search and exports. No. Identifiers can leak, be logged or be shared. Verify access under trusted principal/tenant context, including indirect paths such as signed downloads and derived search entries.
45-minute interview rubric
- 00–05: scope access decision and authorization policy.
- 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
- 12–28: draw authorization policy, numbered writes and reads.
- 28–40: challenge recovery: Enforce scope at each disclosure boundary.
- 40–45: defend tenant_id placement, observations and remaining assumptions.
Go deeper
- PostgreSQL: Documentation: 18: 5.9. Row Security Policies · Primary document · www.postgresql.org. Enforce scope at each disclosure boundary. Verified 2026-10-26.
- Authorization - OWASP Cheat Sheet Series · Primary document · cheatsheetseries.owasp.org. Enforce scope at each disclosure boundary. Verified 2026-10-26.
Decision log
Enforce scope at each disclosure boundary.
Preserve access decision identity and authorization policy ownership.
Revisit changed workload, observations or recovery objectives.