Files
gt-ai-os-community/apps/tenant-backend/app/middleware/tenant_isolation.py
HackWeasel 310491a557 GT AI OS Community v2.0.33 - Add NVIDIA NIM and Nemotron agents
- Updated python_coding_microproject.csv to use NVIDIA NIM Kimi K2
- Updated kali_linux_shell_simulator.csv to use NVIDIA NIM Kimi K2
  - Made more general-purpose (flexible targets, expanded tools)
- Added nemotron-mini-agent.csv for fast local inference via Ollama
- Added nemotron-agent.csv for advanced reasoning via Ollama
- Added wiki page: Projects for NVIDIA NIMs and Nemotron
2025-12-12 17:47:14 -05:00

48 lines
1.5 KiB
Python

"""
Tenant Isolation Middleware for GT 2.0
Ensures perfect tenant isolation for all requests.
"""
from fastapi import Request, Response
from starlette.middleware.base import BaseHTTPMiddleware
import logging
from app.core.config import get_settings
logger = logging.getLogger(__name__)
settings = get_settings()
class TenantIsolationMiddleware(BaseHTTPMiddleware):
"""Middleware to enforce tenant isolation boundaries"""
async def dispatch(self, request: Request, call_next):
# Add tenant context to request
request.state.tenant_id = settings.tenant_id
request.state.tenant_domain = settings.tenant_domain
# Validate tenant isolation
await self._validate_tenant_isolation(request)
response = await call_next(request)
# Add tenant headers to response
response.headers["X-Tenant-Domain"] = settings.tenant_domain
response.headers["X-Tenant-Isolated"] = "true"
return response
async def _validate_tenant_isolation(self, request: Request):
"""Validate that all operations are tenant-isolated"""
# This is where we would add tenant boundary validation
# For now, we just log the tenant context
logger.debug(
"Tenant isolation validated",
extra={
"tenant_id": settings.tenant_id,
"tenant_domain": settings.tenant_domain,
"path": request.url.path,
"method": request.method,
}
)