Skip to content

About

Hardened enterprise Python 3.12+ (FastAPI / Django / Celery) runtime for Stratum Sovereign Multi-Tenant Architecture. Features Zero Host Ports, multi-stage build, dual-mode persistence (L4 Proxy & Standalone), sovereign Redis, and non-root execution.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Stratum-Python · Enterprise Workload Architecture

(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)

Platform Architect & Designer Umbrella Organization Implementation Cache Security License

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)


1. Overview

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 test for local development and CI.
  • Three Exclusive Deployment Modes (delegated, isolated, test): Every service in docker-compose.yml and docker-compose.outbound.yml declares explicit profiles:. 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-root appuser (1000:1000) with read_only: true, cap_drop: [ALL], no-new-privileges:true, noexec tmpfs /tmp, and memswap_limit. Production containers bake /app/src into the image.
  • Valkey 8.1 Prefix-Scoped ACL & Celery Confinement (BSD-3-Clause, ADR-0005): Dedicated valkey runs user default off, user healthcheck -@all +ping, and app ACL <CACHE_USER> scoped strictly to ~${CACHE_PREFIX}* &${CACHE_PREFIX}* blocking dangerous commands. Celery uses global_keyprefix with 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 only app-delegated or app-isolated to stratum_outbound (external: true).

2. Three Deployment Modes & Service Matrix

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

3. Architecture & Confinement Topology

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
Loading

4. Valkey 8.1 Migration, Celery ACLs & Nominative Trademark Notice

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.

Celery / Kombu Prefix-Scoped ACL Configuration

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} and result_backend_transport_options={"global_keyprefix": CACHE_PREFIX}
  • worker_enable_remote_control=False, worker_send_task_events=False
  • PYTHON_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.)

Nominative Trademark Notice (Redis®)

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.


5. Uniform Environment Contract (.env.example)

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).

6. Quick Start

6.1 Production (delegated, isolated)

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 -d

6.2 Local Test & CI (--profile test)

cp .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

7. Security Hardening & Shared Responsibility

  • Shared Responsibility (delegated mode): Peer workloads in the same organization share stratum_${TENANT_ORG}_internal. Stratum provides inter-organization isolation, DOCKER-USER egress firewalling (in stratum-core), per-app Valkey prefix ACLs, and container sandboxing; operators assume shared responsibility for intra-organization lateral risk and should deploy --profile isolated for sensitive workloads.
  • Production Info Hygiene: src/main.py disables /docs, /redoc, and /openapi.json when APP_ENV=production, strips internal hostnames/exceptions from /health HTTP responses, and URL-encodes CACHE_USER and CACHE_PASSWORD via urllib.parse.quote_plus in Celery broker URIs.

8. Architecture, Governance and License

  • 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.

About

Hardened enterprise Python 3.12+ (FastAPI / Django / Celery) runtime for Stratum Sovereign Multi-Tenant Architecture. Features Zero Host Ports, multi-stage build, dual-mode persistence (L4 Proxy & Standalone), sovereign Redis, and non-root execution.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages