Skip to content

Enforce identity and tenant boundaries

10 min reading

Trace authentication, authorization and isolation across data and background work

Page details

System Design · Operate the system

10 min reading · 23 min with practice

Sources

Published · Last edited:

Prerequisite: Observe user outcomes and internal behavior. For basics, use the independent System Design foundations.

More
20px

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.

Dev: “The request includes the tenant identifier.”

Maya: “What establishes that this principal may use it for this action now?”

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.

Who is acting, and what may they do now?

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.

Every copy is a disclosure boundary

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.

Carry authorized scope through copies and delayed workA validated principal receives authorized tenant and action scope. Database, cache, worker and download boundaries each enforce the relevant permission contract. A tenant identifier supplied by the caller does not independently grant permission.Validated principalAuthorized scopeData / cachePermission checkedDownloadBounded accessWorker recheck
One accepted request does not grant indefinite authority to every later reader.

Follow tenant authority through derived copies

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.

Follow tenant authority through derived copies — selected design evidence
Disclosure pathAuthority inputRequired boundary
Receipt lookupCaller + tenant + receipt ownerAuthorize before response
Response cacheTenant and permission equivalenceNo cross-tenant reuse
Worker / exportScoped operation + current ruleReject untrusted context
Object identity locates data; the service must establish authority before returning any copy.Object identity locates data; the service must establish authority before returning any copy. Authenticated caller to Tenant-scoped service: verified identity + scope; Tenant-scoped service to Receipt / cache: authorize selected object.AuthenticatedcallerTenant-scopedserviceReceipt / cacheverified identity + scopeauthorize selected object
Object identity locates data; the service must establish authority before returning any copy. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

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.

Delayed work needs an authority contract

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.

Revocation also affects previously generated artifacts and reusable responses. Define whether new downloads must reauthorize, whether already issued capabilities expire, and what cannot be recalled after a reader has received data. A service cannot honestly promise that revocation makes a prior download unseen.

Derive the exposure in one selected policy

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.

In the wild: documented enforcement has limits

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.

A receipt crosses the tenant boundary

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.

Make investigation useful without broad disclosure

The observability lesson introduced correlation context. Keep sensitive request bodies and credentials out of routine telemetry. Investigators may need selected identifiers and decision reasons, but their access and retention should be narrower than unrestricted production-data access. A trace viewer is another reader of tenant information.

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 layered enforcement with explicit ownership

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.

This chapter does not choose an identity provider or a complete threat model for compromised infrastructure. Its scope is the application’s permission boundaries under the stated service model. A separate deployment and credential review must address who can change those boundaries. The next lesson changes the system while preserving their meaning.

Challenge the proposed mechanism

A cached receipt was authorized for tenant T yesterday. May any caller knowing its key read it today?

Reveal the design reasoning

No. Check current caller authority and cache equivalence under the declared revocation policy. Include a background export and an old capability in the test; front-door authorization alone misses those paths.

Decision and reconsideration: Name every disclosure boundary and its owner. Revisit cache and capability policies together when revocation requirements change.

Follow the permission

  1. A request includes another tenant’s valid identifier. Does authentication authorize that scope?

    Bind principal to permitted resource

    No. The service must establish membership or a separate cross-tenant capability from trusted evidence. The caller’s supplied scope is an input to validate, not a grant.

  2. A background export starts after revocation. Does the original accepted request settle permission?

    Choose delayed-work semantics

    Only if the declared policy gives that accepted obligation continuing authority. A user-data export may require current authorization. The worker must enforce the selected rule explicitly.

  3. Does a thirty-second permission cache bound access to thirty seconds after revocation?

    Compose the download boundary

    Not in the selected example. A later-issued capability survives beyond cache reuse. Its sixty-second lifetime produces expiry eighty seconds after revocation unless another boundary reauthorizes or revokes it.

The running service now has observable outcomes and explicit authority boundaries. Page 37 changes its schema and application version while preserving those contracts and a usable recovery path.

Northwind decision log

Authorize principal, action and resource scope before disclosure.
Define revocation and delayed-work authority at each enforcing boundary.
Next, preserve these contracts through schema and service changes.

Go deeper: API permission boundaries