USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksBackend Book
HomeBackend BookProduction Application
PreviousAuthentication, Sessions, and TokensNextFiles, Object Storage, and Safe Ingestion
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

13 sections

Progress0%
1 / 13

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Authorization and Multi-Tenant Isolation

Authorization answers whether an authenticated principal may perform a specific action on a specific resource in context. Multi-tenant isolation must survive every storage and execution path: SQL queries, caches, object keys, queues, search filters, model context, tools, logs, exports, and background jobs. One missing tenant predicate can become a breach.

What will you be able to do?

  • define roles, permissions, and resource policies;
  • derive tenant scope from verified membership;
  • enforce isolation in repositories and infrastructure keys;
  • test horizontal and vertical privilege escalation.

How should the request establish context?

The request may select an organization, but server code verifies that selection against authoritative membership. It creates an AuthorizationContext containing principal, tenant, roles/permissions, assurance level, and trace. Application policy then evaluates an action such as ticket:read against the resource.

python
async def read_ticket( context: AuthorizationContext, ticket_id: UUID, repository: TicketRepository, ) -> Ticket: ticket = await repository.get(context.organization_id, ticket_id) if ticket is None: raise TicketNotFound(ticket_id) policy.require(context, action="ticket:read", resource=ticket) return ticket

The repository query includes tenant scope before returning data. Policy adds fine-grained checks. Returning 404 for inaccessible identifiers can reduce enumeration, but audit logs should preserve the forbidden attempt safely.

Where does tenant scope appear?

  • composite keys and SQL predicates;
  • optional PostgreSQL row-level security, with tested connection context;
  • cache and rate-limit keys;
  • object-storage prefixes and signed URL policy;
  • job payloads derived from trusted records;
  • vector/search metadata filters applied before or during retrieval;
  • model prompts and conversation memory;
  • tool credentials and allowed resources;
  • telemetry access and export pipelines.

Defense in depth is valuable. No single ORM filter or middleware magically covers all paths.

How do you test isolation?

Create tenant A and B with colliding human-readable data. For every read, write, list, export, cache hit, job, retrieval, stream reconnect, and tool call, attempt access from the wrong tenant. Test ordinary users against admin actions. Run repository integration tests against real PostgreSQL, not only mocks.

Why does this matter in AI-native systems?

Prompt injection often tries to reveal hidden context or invoke unauthorized tools. The model must never receive content the user cannot access. Retrieval filters and tool authorization are server-enforced; instructions like “ignore previous rules” cannot change them.

Common mistakes

  • Accepting tenant ID from request/model without membership verification.
  • Filtering a page after global search, which can leak counts or rank signals.
  • Background worker trusts tenant ID inside an unverified payload.
  • Cache key omits role or tenant variation.
  • Administrator means global access when policy intended tenant admin only.

AI Pair-Programmer Prompt

text
Perform a tenant-isolation review of SQL, object storage, Redis, queues, search/vector retrieval, model context, tools, streams, logs, and exports. For each path identify the trusted source of tenant context, enforcement point, denial behavior, audit event, and a negative test. Assume prompt injection and guessed identifiers.

Exercise

Build a tenant-isolation test matrix for ticket read/list/update, cached view, document retrieval, AI draft job, and download link.

Acceptance criteria: every cross-tenant attempt returns no protected content, causes no side effect, and emits a safe audit event; tests run with real persistence adapters where relevant.

Knowledge check

  1. Can client-selected tenant ID be trusted directly?
  2. Why enforce tenant scope in the query and policy?
  3. Can a system prompt replace tool authorization?

Answers

  1. No; verify it against authenticated membership.
  2. Query scoping minimizes exposure; policy enforces resource-specific action rules.
  3. No; server-side code must enforce authority.

Completion checklist

  • Every data path carries verified tenant context.
  • Cross-tenant negative tests pass.
  • Tool and retrieval permissions ignore model instructions.

Primary references

  • OWASP API1: Broken Object Level Authorization
  • PostgreSQL row security