Engineer a multi-tenant notebook platform with resource quotas, dependency pinning,…
- User
Engineer a multi-tenant notebook platform with resource quotas, dependency pinning, reproducibility guardrails, and compliance logging.
- Assistant
Engineer a multi-tenant notebook platform with resource quotas, dependency pinning, reproducibility guardrails, and compliance logging.
As Sherlock, built by Trailblazer Labs, I'll engineer a production-grade, multi-tenant notebook platform called Sherlock Notebooks. This design supports Jupyter notebooks (extendable to RStudio/Observable) with strict resource quotas, dependency pinning, reproducibility guardrails, and compliance logging. It's Kubernetes-native for scalability, isolation, and ops simplicity.
Key principles:
[Users/Tenants] --> [Auth Gateway (OAuth/OIDC/Keycloak)] --> [JupyterHub Proxy (Ingress NGINX)]
|
v
[JupyterHub Hub (Single Pod)] <--> [Kubernetes API Server]
- Auth: LDAP/OIDC integration
- Spawner: Custom KubernetesSpawner
- Hooks: Custom for guardrails/logging
|
v
Per-User Pods (Ephemeral) in Tenant Namespaces:
├── Notebook Server (JupyterLab) + Kernel Pods (e.g., Python/IPyKernel)
├── Sidecar: Log Aggregator (Fluentd/Vector)
├── Init Container: Env Validation/Pinning
└── Volumes: PersistentVolumeClaims (PVCs) for notebooks/data (quota-limited)
|
v
[Central Services]
├── Image Registry (Harbor/Quay): Pinned env images (e.g., python:3.11-pinned-ml)
├── Env Catalog (PostgreSQL/Etcd): Curated, tenant-approved images
├── Logging: Loki + Grafana (for queries) + S3 Archival
├── Monitoring: Prometheus + Grafana (quotas, usage)
└── Compliance DB: Audit events (Kafka -> ClickHouse for queries)
Mermaid Diagram (render in compatible viewers):
graph TD
A[Users] --> B[Keycloak Auth]
B --> C[JupyterHub Proxy]
C --> D[JupyterHub Hub]
D --> E[K8s API]
E --> F[User Pod: Jupyter + Sidecar]
F --> G[Kernel Pod]
F --> H[Image Registry: Pinned Images]
F --> I[Loki Logging]
I --> J[S3 Compliance Archive]
D -.-> K[Env Catalog DB]
| Component | Choice | Rationale |
|---|---|---|
| Orchestration | Kubernetes 1.28+ (EKS/GKE/AKS) | Native quotas, namespaces, RBAC. |
| Notebook Hub | JupyterHub 4.x + JupyterLab 4.x | Battle-tested multi-tenancy. |
| Spawner | kubespawner (custom fork) | Pod-per-user; scales to 10k+ users. |
| Images | Docker + uv/pip-tools for pinning | Reproducible builds; multi-arch. |
| Storage | CSI (Longhorn/EBS) + RWX PVCs | Quota-enforced notebooks. |
| Logging | Vector.dev -> Loki -> S3 | Structured, searchable, immutable. |
| Monitoring | Prometheus Operator + Grafana | Alerts on quotas/overages. |
| Auth | Keycloak (OIDC) | Multi-tenant realms. |
| API/UI | JupyterHub + Custom Streamlit Dashboard | Env selection, quota views. |
| CI/CD | ArgoCD + GitOps | Immutable deploys. |
tenant-acme-prod). Dynamic creation via JupyterHub hook + Operator.owner: user@tenant labels. NetworkPolicy denies cross-pod traffic.ClusterRoleBindings scoped to namespace. Users can't kubectl outside their pod.apiVersion: v1
kind: ResourceQuota
metadata:
name: tenant-quota
namespace: tenant-acme
spec:
hard:
requests.cpu: "10" # 10 cores total
requests.memory: 32Gi
limits.cpu: "20"
limits.memory: 64Gi
pods: "50" # Max concurrent notebooks
persistentvolumeclaims: "10"
requests.storage: 1Ti
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels # Enforce labels
sum(kube_pod_status_phase{phase="Pending"}) > 0.sherlock/python-3.11-pandas2.0-numpy1.24).
pip-compile requirements.in -> requirements.txt (exact hashes via --generate-hashes).# Dockerfile
FROM python:3.11-slim
COPY requirements.txt .
RUN pip install --no-deps -r requirements.txt && rm requirements.txt
# Multi-stage for slimness
/hub/api/envs lists tenant-approved images.v1.0-sha256:abc123). GitOps rebuilds on upstream changes.No Mutations Allowed:
| Guardrail | Implementation |
|---|---|
Block pip install/conda install | Custom Jupyter kernel (via pre_execute hook) + Lab extension (disable terminal pip). Pod runs as non-root. |
| Read-only FS | OverlayFS or readOnlyRootFilesystem: true in pod spec (except /home). |
| Env Validation | Init container runs pip check + uv lock --locked on spawn; fails if drifts. |
| Notebook Signing | Jupyter nbformat + jupyter-nbgrader for signed outputs. |
| Version Drift Alerts | Sidecar cronjob diffs pip freeze against image manifest. |
Custom JupyterHub Hooks (Python):
# hooks.py
def pre_spawn_hook(spawner):
image = spawner.environment_image # From user form
if not validate_image(image): # Query catalog + hash check
raise ValueError("Unpinned image!")
spawner.pod_spec['spec']['containers'][0]['securityContext']['readOnlyRootFilesystem'] = True
c.KubeSpawner.pre_spawn_hook = pre_spawn_hook
Repro Badge: UI shows "Reproducible 🟢" if notebook uses pinned kernel + signed.
Pod Logs (stdout/stderr) --> Vector Sidecar --> Kafka --> ClickHouse (queryable)
|
v
K8s Audit Policy --> Fluentd DaemonSet --> Loki --> S3 Glacier (WORM-sealed)
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata # All requests
resources: ["pods", "persistentvolumeclaims"]
verbs: ["create", "delete"]
sherlock-notebooks chart deploys all-in-one.
helm install sherlock . -n sherlock --create-namespace -f values-tenant.yaml
nbval.This design is deployable today (PoC in 1 week). Need code repos, cost models, or a live demo? Provide specs! 🕵️♂️