Environment and Runtime Configuration
LatticeDX separates local development defaults (.env.example, .env.agent, .env.integration) from hardened production configuration (infra/compose/prod.env.example paired with infra/compose/prod.yml). Every secret in prod.yml uses mandatory Docker Compose interpolation syntax ${VAR:?Set VAR} so the stack refuses to start if any required credential is missing.
Keep Secret Files Outside Git
Store production variables in an untracked .env.prod file with chmod 600 permissions, and keep local LLM or integration overrides in untracked .env.agent and .env.integration files. Never place provider credentials or cryptographic secrets into NEXT_PUBLIC_* variables or browser plugin bundles.
1. Environment Separation and Key Generation
Local development commands (pnpm dev, pnpm local:up) read from your active shell environment or an untracked root .env file. For production deployments driven by infra/compose/prod.yml, copy infra/compose/prod.env.example to .env.prod outside version control and replace every CHANGE_ME_* placeholder with high-entropy random values.
cp infra/compose/prod.env.example .env.prod
chmod 600 .env.prod
# Generate 64-hex (32-byte) secrets for APP_KEY, ENCRYPTION_FIELD_KEY, and DX_VAULT_MASTER_KEY
openssl rand -hex 32
openssl rand -hex 32
openssl rand -hex 32
# Generate 32-hex (16-byte) secrets for IIoT ingest and Node-RED credentials
openssl rand -hex 162. Edge, Gateway, Domains, and CORS
These variables control TLS termination in Caddy 2.10, CORS and Redis-backed rate limiting in Apache APISIX 3.19.0, and origin validation inside NocoBase and Fastify middleware.
| Parameter | Type | Default | Description |
|---|---|---|---|
LATTICE_DOMAINrequired | string | app.example.com | Primary public FQDN served by Caddy for LatticeDX portals and /api/* routing. |
KEYCLOAK_DOMAINrequired | string | auth.example.com | Public FQDN for Keycloak 26.8.2 used by KC_HOSTNAME and browser OIDC redirects. |
N8N_DOMAINrequired | string | n8n.example.com | Public FQDN for Stock n8n when --profile n8n is enabled. |
LATTICE_ALLOWED_ORIGIN | string | https://${LATTICE_DOMAIN} | Allowed origin enforced globally by the Apache APISIX cors plugin. |
DX_CORS_ALLOWED_ORIGINS | string | http://localhost:8080,http://127.0.0.1:8080 | Comma-separated origin allowlist for NocoBase and Fastify API CORS middleware. |
DX_CORS_STRICT | boolean | true | Rejects requests carrying an Origin header outside the allowed origin list. |
DX_TRUST_PROXY | boolean | true (prod) | Trusts forwarded client IP headers from reverse proxies for public form rate limiting. |
APISIX_PORT | number | 8080 | Host loopback port bound by APISIX in local development stacks. |
CADDY_HTTP_PORT | number | 80 | HTTP listener port on Caddy for ACME challenges and HTTPS redirects. |
CADDY_HTTPS_PORT | number | 443 | HTTPS TCP/UDP (HTTP/3) listener port on Caddy for production traffic. |
3. PostgreSQL 16, Multi-Tenancy RLS, PITR, and Valkey 8.1
LatticeDX isolates core platform metadata (postgres) from application and vector data (nocobase-db running pgvector/pgvector:0.8.1-pg16). In nocobase-db, the nocobase container connects as nocobase_app, a non-superuser role configured with NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOBYPASSRLS that must differ from NOCOBASE_DB_USER so PostgreSQL enforces FORCE ROW LEVEL SECURITY across all 56 static tables and dynamic latticeCustom* tables.
| Parameter | Type | Default | Description |
|---|---|---|---|
POSTGRES_PASSWORDrequired | secret | local-demo-password | Postgres password for local core.yml development. Never reuse outside loopback. |
POSTGRES_SUPERUSERrequired | string | postgres | Superuser account on the core postgres container for role provisioning and PITR. |
POSTGRES_SUPERUSER_PASSWORDrequired | secret | — | Password for POSTGRES_SUPERUSER on the production postgres container. |
LATTICE_DB_PASSWORDrequired | secret | — | Password for non-superuser role lattice_app owning the lattice database. |
KEYCLOAK_DB_PASSWORDrequired | secret | — | Password for non-superuser role keycloak_app owning the keycloak database. |
N8N_DB_PASSWORDrequired | secret | — | Password for non-superuser role n8n_app owning the n8n database. |
NOCOBASE_DB_USERrequired | string | nocobase | Bootstrap admin user for nocobase-db migrations and pgvector initialization. |
NOCOBASE_DB_PASSWORDrequired | secret | — | Password for NOCOBASE_DB_USER. |
NOCOBASE_APP_DB_USERrequired | string | nocobase_app | Non-superuser, NOBYPASSRLS runtime role used by nocobase; must differ from NOCOBASE_DB_USER. |
NOCOBASE_APP_DB_PASSWORDrequired | secret | — | Password for NOCOBASE_APP_DB_USER. |
DX_PG_RLS_SESSION | boolean | true | Activates the AsyncLocalStorage transaction bridge binding app.current_org and app.rls_bypass. |
DATABASE_POOL_MAX | number | 20 | Maximum PostgreSQL connection pool size for the Fastify API service. |
DX_DEFAULT_ORG_ID | string | 1 | Default organization ID fallback for single-org background workers. |
| Parameter | Type | Default | Description |
|---|---|---|---|
NOCOBASE_APP_KEYrequired | secret | — | Signing secret mapped to APP_KEY for session JWTs; also acts as final fallback for PKI/Vault. |
NOCOBASE_ENCRYPTION_FIELD_KEYrequired | secret | — | Field encryption secret mapped to ENCRYPTION_FIELD_KEY and AES-256-GCM wrapping of Ed25519 keys. |
DX_VAULT_MASTER_KEY | secret | — | Dedicated AES-256-GCM master key for Connector Vault (takes precedence over ENCRYPTION_FIELD_KEY and APP_KEY). |
LATTICE_TRACK_VERIFY_SECRET | secret | — | Dedicated HMAC-SHA256 key for verifying public ePOD QR proofs (/v/track/:code). |
PG_ARCHIVE_COMMAND | string | /bin/sh /etc/postgresql/pitr-archive.sh %p %f | PostgreSQL archive_command archiving compressed WAL segments for Point-in-Time Recovery. |
PITR_WAL_DIR | string | /var/lib/postgresql/wal-archive | Target directory for gzipped WAL segments (0700 directory permissions, umask 077). |
PITR_WAL_RETENTION_DAYS | number | 7 | Retention window in days before pitr-archive.sh prunes older local .gz WAL files. |
WALG_S3_PREFIX | string | — | Optional remote S3 prefix (s3://bucket/path) triggering wal-g wal-push when wal-g is available. |
REDIS_PASSWORDrequired | secret | — | Authentication password for Valkey 8.1 across cache, Pub/Sub, OIDC state, and APISIX rate limits. |
CACHE_DEFAULT_STORE | string | redis | Application cache backend adapter for NocoBase. |
CACHE_REDIS_URL | string | redis://:${REDIS_PASSWORD}@redis:6379/0 | Valkey logical DB 0 URL for application caching. |
PUBSUB_ADAPTER | string | redis | Pub/Sub transport adapter for cross-worker event fan-out. |
PUBSUB_ADAPTER_REDIS_URL | string | redis://:${REDIS_PASSWORD}@redis:6379/1 | Valkey logical DB 1 URL hosting latticedx:surface-updates for real-time SSE. |
Fail-Closed Cryptographic Key Enforcement
Under NODE_ENV=production, cryptographic subsystems reject development fallbacks:
pki-ledger.jsrequires eitherENCRYPTION_FIELD_KEYorAPP_KEY; omitting both throwsPKI_MASTER_KEY_MISSING(HTTP 500).connector-vault.jsresolvesDX_VAULT_MASTER_KEY || ENCRYPTION_FIELD_KEY || NOCOBASE_APP_KEY || APP_KEY; omitting all throwsVAULT_MASTER_KEY_MISSING(HTTP 500). Set a dedicatedDX_VAULT_MASTER_KEYin production so Connector Vault key rotation remains independent from Ed25519 private key wrapping inlatticePkiKeys.
4. Keycloak OIDC, Enterprise Auth, and Action Bridge
@latticedx/plugin-enterprise-auth implements a 4-step OIDC PKCE S256 flow (start -> callback -> finish -> backchannelLogout), storing short-lived state: (300s), ticket: (60s), and revoked: (24h) keys in Valkey DB 2 while blocking privilege escalation during group-to-role mapping.
| Parameter | Type | Default | Description |
|---|---|---|---|
KEYCLOAK_ADMIN_USERrequired | string | kc-admin | Bootstrap admin username for Keycloak. |
KEYCLOAK_ADMIN_PASSWORDrequired | secret | — | Bootstrap admin password for Keycloak. |
APISIX_OIDC_CLIENT_SECRETrequired | secret | — | Client secret for dx-gateway used by APISIX openid-connect and keycloak-config-cli. |
APISIX_OIDC_DISCOVERY | string | https://${KEYCLOAK_DOMAIN}/realms/lattice/.well-known/openid-configuration | OIDC discovery endpoint used by APISIX to fetch JWKS signing keys. |
DX_NATIVE_AUTH_ISSUERrequired | string | https://${KEYCLOAK_DOMAIN}/realms/lattice | Public OIDC issuer URL used for browser authorization redirects. |
DX_NATIVE_AUTH_INTERNAL_ISSUERrequired | string | http://keycloak:8080/realms/lattice | Internal Docker app-network OIDC issuer URL for server-to-Keycloak token exchange. |
DX_NATIVE_AUTH_ORIGINrequired | string | https://${LATTICE_DOMAIN} | Origin used to construct the OIDC redirect callback URI. |
DX_NATIVE_AUTH_CLIENT_ID | string | dx-native | Public PKCE S256 client identifier configured in the lattice realm. |
DX_NATIVE_AUTH_CACHE_STORE | string | redis | Session and PKCE state store backend for enterprise authentication. |
DX_NATIVE_AUTH_SESSION_REDIS_URL | string | redis://:${REDIS_PASSWORD}@redis:6379/2 | Valkey logical DB 2 URL storing PKCE state, one-time tickets, and backchannel revocations. |
DX_NATIVE_AUTH_GROUP_ROLE_MAP | json | — | JSON map from Keycloak groups to NocoBase roles (automatically skips ldx_admin, allowConfigure, and pm* roles). |
DX_ALLOW_PUBLIC_SIGNUP | boolean | false | Controls public self-registration endpoints (disabled by default). |
DX_ENTERPRISE_DISABLE_SIGNUP | boolean | true | Strictly disables local signup routes when enterprise SSO is enforced. |
DX_BRIDGE_ISSUER | string | — | Public OIDC issuer URL for @latticedx/plugin-action-bridge. |
DX_BRIDGE_INTERNAL_ISSUER | string | — | Internal OIDC issuer URL for @latticedx/plugin-action-bridge. |
DX_BRIDGE_GATEWAY_URL | string | http://gateway:9080 | Internal APISIX gateway URL targeted by action-bridge. |
DX_BRIDGE_CALLBACK_URL | string | — | Callback URL registered for action-bridge (/api/dxActions:callback). |
NOCOBASE_INTERNAL_URL | string | http://127.0.0.1 | Internal loopback URL used by plugins invoking host NocoBase endpoints. |
5. Core API, RustFS Object Storage, and ClamAV Scanner
Uploaded attachments pass through @dx/file-scanner (running with read_only: true) over the isolated scanner network to ClamAV 1.5.5 before objects are persisted to RustFS 1.0.6 on the data network.
| Parameter | Type | Default | Description |
|---|---|---|---|
API_PORT | number | 4000 | Local HTTP port for the @dx/api Fastify service. |
WORKER_PORT | number | 4001 | Local HTTP port for @dx/agent-worker. |
API_URL | string | http://api:4000 | Internal base URL for @dx/api. |
WORKER_URL | string | http://worker:4001 | Internal base URL for @dx/agent-worker. |
API_RATE_LIMIT_MAX | number | 1000 | Fastify per-window request rate limit ceiling. |
FILE_STORAGE_PROVIDER | enum | s3 (prod) / postgres (local) | Object storage backend: s3 (RustFS) or postgres (local file storage). |
FILE_STORAGE_ROOT | string | /var/lib/latticedx/objects | Filesystem root path when using local object storage. |
RUSTFS_ACCESS_KEYrequired | secret | — | Internal S3 access key for rustfs (mapped to S3_ACCESS_KEY_ID). |
RUSTFS_SECRET_KEYrequired | secret | — | Internal S3 secret key for rustfs (mapped to S3_SECRET_ACCESS_KEY). |
DX_NATIVE_FILES_URL | string | http://file-scanner:4010 | Internal scanner URL on the app network. |
DX_NATIVE_FILES_INSTANCErequired | string | latticedx-prod | Instance identifier shared between nocobase and file-scanner. |
DX_NATIVE_FILES_SECRETrequired | secret | — | Shared secret authenticating upload and scan requests to file-scanner. |
DX_NATIVE_CLAMD_HOST | string | clamav | Hostname of the ClamAV daemon on the isolated scanner network. |
DX_NATIVE_ATTACHMENT_SUBMIT_ORGANIZATION | string | — | Optional fallback organization assigned when native attachments omit an explicit org. |
DX_UPLOAD_STALE_PENDING_MS | number | 900000 | Threshold in milliseconds before pending upload sessions are marked stale. |
6. IIoT, Orion-LD, n8n, AI Studio, P.A.R.A. RAG, and Observability
Optional profiles and subsystem controls govern NGSI-LD outbox delivery, Mosquitto Dynamic Security, Node-RED 2-way downlinks, Stock n8n REST v1 integration, P.A.R.A. OCR/vector search, AI quotas, and OpenTelemetry / Prometheus / Grafana exports.
| Parameter | Type | Default | Description |
|---|---|---|---|
ORION_MONGO_USERrequired | string | orion_root | Root username for MongoDB 8.0 backing FIWARE Orion-LD. |
ORION_MONGO_PASSWORDrequired | secret | — | Password for SCRAM-SHA-256 authentication on orion-mongo. |
ORION_MONGO_VOLUME | string | — | Optional Docker volume override for recovered orion-mongo-data. |
DX_NATIVE_CONTEXT_BROKER_URL | string | http://orion-ld:1026 | Internal Orion-LD Context Broker base URL. |
DX_NATIVE_CONTEXT_AUTO_SYNC | boolean | true | Runs the 10-second latticeContextOutbox drainer syncing NGSI-LD entities. |
DX_OUTBOX_MAX_ATTEMPTS | number | 5 | Maximum retry attempts before outbox or event-bus rows move to failed or DLQ. |
DX_OUTBOX_STALE_LOCK_MS | number | 120000 | Lock expiration window in milliseconds before stale outbox locks are reclaimed. |
DX_EVENT_BUS_DRAINER | boolean | true | Enables the 10-second CloudEvents 1.0 webhook delivery drainer. |
DX_FLOW_DELAY_TICK_MS | number | 15000 | Polling interval in milliseconds for LatticeFlow v2 control.delay and cron schedules. |
DX_SLA_CRON_ENABLED | boolean | true | Enables background SLA breach detection and escalation. |
DX_SLA_INTERVAL_MS | number | 60000 | Minimum interval in milliseconds between SLA evaluation sweeps. |
MQTT_ADMIN_USER | string | ldx_mqtt_admin | Mosquitto 2.0.21 Dynamic Security admin username (--profile iiot). |
MQTT_ADMIN_PASSWORD | secret | — | Password for MQTT_ADMIN_USER. |
MQTT_BRIDGE_USER | string | nodered_bridge | Restricted MQTT username injected into Node-RED flows_cred.json. |
MQTT_BRIDGE_PASSWORD | secret | — | Password for MQTT_BRIDGE_USER. |
DX_MQTT_BROKER_HOST | string | mosquitto | Internal MQTT broker hostname on iiot-net. |
DX_MQTT_BROKER_PORT | number | 1883 | Internal MQTT broker port. |
DX_NODERED_COMMAND_URL | string | http://nodered:1880/twin/command | Node-RED HTTP downlink endpoint for Digital Twin setpoint commands. |
DX_IIOT_INGEST_TOKEN | secret | — | Bearer token authenticating Node-RED telemetry and alarm ingest calls. |
NODERED_CREDENTIAL_SECRET | secret | — | AES-256-CTR secret encrypting /data/flows_cred.json inside Node-RED. |
NODERED_ADMIN_USER | string | nodered_admin | Admin UI username for Node-RED 4.0.9. |
NODERED_ADMIN_PASS_HASH | secret | — | Bcrypt password hash for Node-RED admin UI authentication. |
DX_ORION_HOST_ALLOWLIST | string | — | SSRF host allowlist for outbound Orion-LD broker calls. |
DX_ORION_CALLBACK_HOST_ALLOWLIST | string | — | Allowlist of callback hostnames permitted in Orion-LD subscriptions. |
DX_NODERED_HOST_ALLOWLIST | string | — | SSRF host allowlist for Digital Twin Node-RED downlink targets. |
N8N_ENCRYPTION_KEY | secret | — | Credential encryption key for Stock n8n (--profile n8n). |
N8N_URL | string | http://n8n:5678 | Internal base URL for Stock n8n. |
N8N_WEBHOOK_BASE_URL | string | http://n8n:5678/webhook | Internal webhook base URL for Stock n8n. |
DX_N8N_API_URL | string | http://n8n:5678/api/v1 | n8n REST API v1 URL queried by plugin-dxos-studio. |
DX_N8N_API_KEY | secret | — | Fallback X-N8N-API-KEY when credentials are not stored in Connector Vault. |
DX_ALLOW_INTERNAL_CONNECTORS | boolean | false (true in prod.yml) | Permits Connector Vault to reach explicitly allowlisted internal Docker service hosts. |
DX_INTERNAL_SERVICE_HOSTS | string | n8n,orion-ld,nodered,mosquitto | Comma-separated internal hostnames exempted from private-IP SSRF blocking. |
DX_CONNECTOR_INTERNAL_ALLOWLIST | string | — | Additional internal connector host allowlist entries. |
WORKFLOW_EVENT_URL | string | — | Optional fixed webhook destination for @dx/api outbox rows. |
WORKFLOW_EVENT_TOKEN | secret | — | Bearer token sent to WORKFLOW_EVENT_URL. |
| Parameter | Type | Default | Description |
|---|---|---|---|
AGENT_PROVIDER | string | openai-compatible | Default LLM provider adapter for AI services and CLI workers. |
AGENT_BASE_URL | string | http://localhost:20128/v1 | OpenAI-compatible base URL for the LLM gateway. |
AGENT_API_KEY | secret | — | Provider API key (also accepted as a fallback by DX_OCR_API_KEY). |
AGENT_MODEL | string | combo | Model identifier used by @dx/agent-worker CLI invocations. |
AGENT_ENGINE_URL | string | http://localhost:8080 | Trusted gateway origin for CLI agent runs. |
AGENT_WORKER_TOKEN | secret | — | Short-lived JWT used by CLI agent worker invocations. |
DXOS_AI_DAILY_ORG_CALL_LIMIT | number | 5000 | Daily AI tool invocation quota per organization. |
DXOS_AI_DAILY_USER_CALL_LIMIT | number | 500 | Daily AI tool invocation quota per user. |
DXOS_AI_DAILY_ORG_TOKEN_LIMIT | number | 5000000 | Daily token budget per organization. |
DXOS_AI_DAILY_ORG_USD_LIMIT | number | 50 | Daily estimated USD spend cap per organization. |
DXOS_MCP_INTERNAL_HTTP_ALLOWLIST | string | — | Comma-separated internal host allowlist for MCP IT/OT tool HTTP calls. |
DX_EMBEDDING_URL | string | — | Embedding endpoint (or DXOS_EMBEDDING_URL) for pgvector HNSW hybrid RAG. |
DX_EMBEDDING_DIM | number | 1536 | Vector dimension override (or DXOS_EMBEDDING_DIM, valid range 8..8192). |
DX_OCR_ENDPOINT | string | — | Remote multimodal OCR endpoint for image-only PDFs (SSRF-guarded; external URLs require HTTPS). |
DX_OCR_API_KEY | secret | — | API key sent to DX_OCR_ENDPOINT. |
DX_OCR_TRUSTED_HOSTS | string | — | Internal OCR hostnames explicitly permitted without TLS. |
DX_APPRISE_URL | string | — | Apprise gateway URL for omnichannel dxosNotify delivery. |
DX_NOTIFICATION_WEBHOOK_URL | string | — | Default outbound webhook URL for system notifications. |
DXOS_GOTENBERG_URL | string | http://gotenberg:3000 (--profile pdf) | Gotenberg URL for sandboxed Unicode PDF voucher generation. |
DXOS_PDF_FONT_PATH | string | — | Optional TrueType font path overriding the bundled Vietnamese PDF font. |
DX_METRICS_TOKENrequired | secret | — | Bearer token authenticating Prometheus scrapes on GET /api/dxos:metrics before JWT parsing. |
OTEL_EXPORTER_OTLP_ENDPOINT | string | http://otel-collector:4318 | OTLP/HTTP collector endpoint receiving API and OTel GenAI spans. |
OTEL_SERVICE_NAME | string | latticedx-nocobase | Service name attribute attached to exported OpenTelemetry spans. |
GRAFANA_ADMIN_USER | string | admin | Admin username for Grafana OSS 11.5.8 (--profile observability). |
GRAFANA_ADMIN_PASSWORD | secret | — | Admin password for Grafana OSS 11.5.8. |
LATTICE_SKIP_DEMO_SEED | string | — | Set to 1 to skip sample business records on clean database bootstrap while keeping 8 ldx_* roles and core schemas. |
7. SSRF Guards and Runtime Health Verification
Server-side URL parsing enforces strict network boundaries on every outbound integration variable:
| Variable / Scope | Enforcing Module | SSRF & Credential Boundary |
|---|---|---|
DX_OCR_ENDPOINT | document-extractor.js | Accepts only http: or https:, rejects embedded credentials (OCR_ENDPOINT_CREDENTIALS_FORBIDDEN), blocks cloud metadata and CGNAT ranges (169.254.*, 100.64.0.0/10, fd00:ec2::254, metadata.google.internal, metadata.azure.com → OCR_ENDPOINT_SSRF_BLOCKED), and enforces https:// for any host outside localhost or DX_OCR_TRUSTED_HOSTS. |
DX_ALLOW_INTERNAL_CONNECTORS | connector-vault.js | Evaluates both input URLs and resolved DNS records against loopback, RFC1918, and link-local ranges, permitting internal Docker hostnames only when listed in DX_INTERNAL_SERVICE_HOSTS or DX_CONNECTOR_INTERNAL_ALLOWLIST. |
| Loopback Fixture Values | .env.example | Local strings such as local-demo-password, local-nocobase-password, local-redis-password, local-nocobase-app-key-public-fixture, and admin@nocobase.com are restricted to 127.0.0.1 development stacks and must never be reused on reachable networks. |
Inspect live subsystem configuration flags (embeddingConfigured, ocrConfigured, DX_PG_RLS_SESSION, and plugin readiness) through these endpoints after startup:
/api/dxos:health/api/latticePara:indexHealth