(Python 3.12+ · FastAPI / Django / Flask / Celery Microservices)
«Aislamiento por diseño, no por disciplina» — (“Isolation by design, not by discipline”)
📖 Step-by-Step Operations and Deployment Manual · 📜 Third-Party Notices (Licenses & Redis® Fair Use)
Product Suite: Stratum Sovereign Multi-Tenant Architecture
Repository: stratum-python (python-stratum)
Component: consumer-workload
Pattern: Stratum Sovereign Consumer (Tier 3)
Revision: 3.1.0
Status: Production (Unattended & Scalable)
stratum-python provides an enterprise-ready, code-agnostic container environment and hardened runtime for Python 3.12+ applications (FastAPI, Django, Flask, Celery) operating as a Tier 3 Consumer Workload within the Stratum Sovereign Multi-Tenant Architecture. Whether deploying one organization or many, each organization runs as an isolated stratum-org island.
Isolation across modes is enforced through Linux kernel network namespaces (internal: true, enable_ipv6: false), netfilter DOCKER-USER firewall chains (in stratum-core), and immutable container hardening (not physical hardware separation):
- Zero Public Ports (
0.0.0.0/::prohibited, ADR-0007): Production modes (delegated,isolated) publish zero host ports. Loopback binding (127.0.0.1:${APP_LOCAL_PORT}:8000) is permitted solely in--profile testfor local development and CI. - Three Exclusive Deployment Modes (
delegated,isolated,test): Every service indocker-compose.ymlanddocker-compose.outbound.ymldeclares explicitprofiles:. Mode-scoped workers (delegated-worker,isolated-worker,test-worker) run cleanly alongside their mode. - Immutable Hardened Runtime (
read_only: true): Multi-stage Dockerfile (python:3.12-slim) compiles wheels in a builder stage and executes as non-rootappuser(1000:1000) withread_only: true,cap_drop: [ALL],no-new-privileges:true,noexectmpfs /tmp, andmemswap_limit. Production containers bake/app/srcinto the image. - Valkey 8.1 Prefix-Scoped ACL & Celery Confinement (
BSD-3-Clause, ADR-0005): Dedicatedvalkeyrunsuser default off,user healthcheck -@all +ping, and app ACL<CACHE_USER>scoped strictly to~${CACHE_PREFIX}* &${CACHE_PREFIX}*blocking dangerous commands. Celery usesglobal_keyprefixwith remote-control/gossip/mingle disabled so tasks run seamlessly inside prefix ACLs (interactive Celery events/Flower require--profile isolated). - Optional Outbound Override (
docker-compose.outbound.yml): Off by default. Attaches onlyapp-delegatedorapp-isolatedtostratum_outbound(external: true).
Profile (--profile ...) |
Services Started | Network Attachment(s) | Persistence & Broker Targets |
|---|---|---|---|
delegated (+ delegated-worker) |
app-delegated (+ worker-delegated) |
tenant_network (stratum_${TENANT_ORG}_internal, external: true) |
Central DB via stratum-database-nginx:5432 + Org Valkey (valkey:6379, prefix <org>_<app>:) |
isolated (+ isolated-worker) |
app-isolated, postgres, valkey (+ worker-dedicated) |
Web: tenant_network + app_internal (internal: true)worker-dedicated, postgres, valkey: app_internal ONLY |
Dedicated postgres:5432 (scram-sha-256) + dedicated valkey:6379 (prefix ACL) |
test (+ test-worker) |
app-test, postgres, valkey (+ worker-dedicated) |
app-test: app_internal + test_local (enable_icc=false, 127.0.0.1:${APP_LOCAL_PORT}:8000) |
Dedicated postgres:5432 + valkey:6379; mounts ./src:/app/src:ro |
flowchart TB
CF["Cloudflare Zero Trust Tunnel (stratum-org/tunnel)"]
BAY["Org Bay: stratum_${TENANT_ORG}_ingress (/28 pool, internal: true)"]
NPM["Central NPM (stratum-core/gateway @ stratum_dmz 10.201.0.10)"]
ORG_RTR["nginx-org-boundary (stratum-org)"]
CORE_DB["stratum-database-core (stratum_dmz -> stratum_database_internal)"]
subgraph OrgNet ["tenant_network: stratum_${TENANT_ORG}_internal (internal: true)"]
ORG_VK[("Org Valkey 8.1 ACL (~org_app:*)")]
APP_DEL["app-delegated (:8000)"]
W_DEL["worker-delegated (delegated-worker)"]
APP_ISO["app-isolated (:8000)"]
end
subgraph AppInternal ["app_internal: stratum_${APP_PROJECT}_internal (internal: true)"]
W_DED["worker-dedicated (isolated-worker / test-worker)"]
PG_DED[("postgres:16-alpine (scram-sha-256)")]
VK_DED[("valkey:8.1-alpine (--aclfile)")]
end
CF --> BAY --> NPM -->|"stratum_dmz"| ORG_RTR
ORG_RTR --> APP_DEL
ORG_RTR --> APP_ISO
APP_DEL --> ORG_VK
W_DEL --> ORG_VK
APP_DEL -->|":5432"| ORG_RTR --> CORE_DB
W_DEL -->|":5432"| ORG_RTR --> CORE_DB
APP_ISO --> AppInternal
AppInternal --> W_DED
AppInternal --> PG_DED
AppInternal --> VK_DED
Warning
Mandatory Queue Drain Before Migrating from Legacy Redis to Valkey 8.1:
Stratum executes Valkey in volatile memory-only mode (--save "" --appendonly no, per ADR-0003 / ADR-0005). When upgrading an existing deployment from Redis to valkey/valkey:8.1-alpine, drain all active Celery queues and finish in-flight background tasks before stopping Redis and starting Valkey.
To comply with per-service Valkey ACL confinement (~${CACHE_PREFIX}* &${CACHE_PREFIX}* and disabled admin/Lua/pidbox channels), src/main.py and .env.example automatically set:
broker_transport_options={"global_keyprefix": CACHE_PREFIX}andresult_backend_transport_options={"global_keyprefix": CACHE_PREFIX}worker_enable_remote_control=False,worker_send_task_events=FalsePYTHON_WORKER_ENTRYPOINT="celery -A main.celery_app worker --loglevel=info --without-gossip --without-mingle --without-heartbeat"
(Note: Interactive celery inspect remote-control commands and Flower event monitoring require broad Pub/Sub/pidbox channels unavailable on shared delegated ACLs; run --profile isolated when interactive Celery inspection/Flower is required.)
References to redis://, redis-py (src/requirements.txt), REDISCLI_AUTH, the redis network compatibility alias, and fallback environment variables (REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD, REDIS_PREFIX) are retained strictly in a nominative, descriptive sense for RESP2/RESP3 wire-protocol compatibility with Valkey 8.1.
| Variable | Default | Description |
|---|---|---|
APP_PROJECT |
python |
Application slug (used for container/DB/ACL derivation). |
TENANT_ORG |
tenant |
Organization slug (required in delegated/isolated; default slug in test). |
APP_PORT |
8000 |
Internal application listening port. |
APP_LOCAL_PORT |
8000 |
Loopback port bound strictly to 127.0.0.1 in test mode only. |
TENANT_NETWORK |
(derived) | Overrides stratum_${TENANT_ORG}_internal (external: true). |
APP_INTERNAL_NETWORK |
(derived) | Overrides stratum_${APP_PROJECT}_internal (internal: true). |
APP_TEST_NETWORK |
(derived) | Loopback bridge used only in --profile test (enable_icc=false). |
STRATUM_OUTBOUND_NETWORK |
stratum_outbound |
Optional egress network used only with docker-compose.outbound.yml. |
DB_CONNECTION / DB_HOST / DB_PORT |
pgsql / stratum-database-nginx / 5432 |
Database coordinates (postgres:5432 in isolated/test). |
DB_NAME / DB_USER / DB_PASSWORD / DB_SSLMODE |
tenant_python / tenant_python / (required) / prefer |
PostgreSQL credentials (src/main.py falls back to DB_DATABASE/DB_USERNAME). |
CACHE_HOST / CACHE_PORT / CACHE_USER / CACHE_PASSWORD / CACHE_PREFIX |
valkey / 6379 / tenant_python / (required) / tenant_python: |
Valkey 8.1 ACL contract (src/main.py falls back to REDIS_*). |
VALKEY_HEALTHCHECK_PASSWORD |
(required in isolated/test) |
Separate ACL secret for healthcheck user (-@all +ping; never equals CACHE_PASSWORD). |
PYTHON_IMAGE / PYTHON_IMAGE_TAG / PYTHON_BASE_TAG |
stratum-python / 3.1.0 / 3.12-slim |
Pinned application and base image tags (zero :latest). |
cp .env.example .env && chmod 600 .env
# Provision delegated Postgres + Valkey ACLs:
stratum db create <TENANT_ORG> <APP_PROJECT> -e postgres
stratum db create <TENANT_ORG> <APP_PROJECT> -e valkey
docker compose --profile delegated up -d --build
# With Celery worker:
docker compose --profile delegated --profile delegated-worker up -d --build
# Or dedicated isolated engines:
docker compose --profile isolated --profile isolated-worker up -d --build
# Optional web-only outbound internet egress:
docker compose -f docker-compose.yml -f docker-compose.outbound.yml --profile delegated up -dcp .env.example .env && chmod 600 .env
docker compose --profile test --profile test-worker up -d --build
docker compose --profile test ps
curl -fsS http://127.0.0.1:8000/health- Shared Responsibility (
delegatedmode): Peer workloads in the same organization sharestratum_${TENANT_ORG}_internal. Stratum provides inter-organization isolation,DOCKER-USERegress firewalling (instratum-core), per-app Valkey prefix ACLs, and container sandboxing; operators assume shared responsibility for intra-organization lateral risk and should deploy--profile isolatedfor sensitive workloads. - Production Info Hygiene:
src/main.pydisables/docs,/redoc, and/openapi.jsonwhenAPP_ENV=production, strips internal hostnames/exceptions from/healthHTTP responses, and URL-encodesCACHE_USERandCACHE_PASSWORDviaurllib.parse.quote_plusin Celery broker URIs.
- Architect & Designer: Sandra Gabriela Puerto Torres (SGPT) (not the code creator) (LinkedIn · GitHub)
- Umbrella Organization: Isora Cloud Group (ICG) (isora.com.co) (non-commercial project organization; released freely to the community)
- Code Generation & AI Engineering: Google Antigravity AI · DeepSeek (initial v1 code generation)
- License: Apache License, Version 2.0 (Apache-2.0). See THIRD-PARTY-NOTICES.md for upstream container and dependency licenses.