Stop Hardcoding Credentials
Every IoT deployment needs connection strings, API keys, and passwords — but embedding them directly in your LoT code or route definitions creates security risks and makes your configuration impossible to reuse across environments. The Coreflux Broker solves this with built-in environment variable and secrets management.- Environment variables store non-sensitive configuration (hostnames, ports, URLs) in a plain-text
.envfile - Secrets store sensitive credentials (passwords, API keys, tokens) encrypted at rest with AES-256-GCM
Environment variables and secrets management is available from Coreflux Broker v1.9.3 and above.
When to Use Each
Config Root
The broker builds its configuration root directory from two parts:- If the
CONFIG_PATHenvironment variable is set, it is used as the base path - Otherwise, the application directory is used (e.g.
/appin Docker, the executable’s folder on Windows/Linux) /Corefluxis always appended automatically
CONFIG_PATH=/data, the config root becomes /data/Coreflux.
File Layout
The environment and secrets files live alongside the broker’s internal data under the config root:Environment Variables
Storage
Environment variables are stored in plain text in{config_root}/.env using standard key=value format:
Resolution Order
When the broker resolves an environment variable (viaGET ENV, route config, or CLI), it checks multiple sources in this order:
If not found in any source, an empty string is returned.
This fallback chain means Docker
environment: variables work even without a .env file — the broker picks them up from the process environment automatically.Secrets
How Secrets Work
Secrets are encrypted at rest using AES-256-GCM and stored in{config_root}/secrets.json. Each secret entry contains the initialization vector, the encrypted value with authentication tag, and a creation timestamp:
GET SECRET or route configuration. They are never logged or displayed — even the -listSecrets command only shows secret names, never values.
Encryption Key
The broker resolves the encryption key in this order:Generating a Key
Use OpenSSL to generate a cryptographically secure 32-byte key:Using in LoT
Environment variables and secrets can be read, written, and deleted from within LoT Actions, Models, and route configurations.Reading Values
UseGET ENV to read an environment variable and GET SECRET to read an encrypted secret (decrypted at runtime):
Persisting Values
UseKEEP ENV to save a new environment variable to the .env file, and KEEP SECRET to encrypt and store a new secret:
Deleting Values
UseDELETE ENV and DELETE SECRET to remove values:
Complete Example
This action reads database configuration from environment variables and credentials from secrets on broker startup, then reports the status:Using in Routes
Environment variables and secrets can be referenced directly in route definitions, keeping connection details out of your LoT code.Standard Syntax
UseGET ENV and GET SECRET in route configuration blocks to inject values at runtime:
Legacy Prefix Syntax
TheENV: and SECRET: prefix syntax is also supported for backward compatibility in route ADD CONFIG sections:
Event Query Placeholders
In route event queries (e.g.WITH QUERY), use curly-brace placeholders that are resolved at execution time:
CLI Commands
Manage environment variables and secrets at runtime by publishing commands to$SYS/Coreflux/Command using any MQTT client (such as MQTT Explorer).
Environment Variable Commands
Publish these messages to
$SYS/Coreflux/Command to manage environment variables:
Secret Commands
Publish these messages to
$SYS/Coreflux/Command to manage secrets:
Subscribe to
$SYS/Coreflux/Command/Output to receive confirmation responses from commands.Deployment
Set up environment variables and secrets across different deployment targets.- Windows
- Linux
- Docker Compose
- Kubernetes
On Windows, the config root defaults to the broker’s executable directory +
\Coreflux unless CONFIG_PATH is set.1
Locate the Config Directory
If the broker is installed at The config root becomes
C:\Coreflux\, the config root is C:\Coreflux\Coreflux\.To use a custom path, set the CONFIG_PATH system environment variable:C:\CorefluxData\Coreflux\.2
Create the .env File
Create a
.env file in the config root with your environment variables:3
Generate an Encryption Key
Generate and save a
secret.key file for encrypting secrets:4
Set Secrets After Start
Start the broker, then set secrets using any MQTT client (such as MQTT Explorer). Publish to
$SYS/Coreflux/Command:Subscribe to
$SYS/Coreflux/Command/Output to confirm the secret was stored.Best Practices
Use explicit encryption keys in production
Use explicit encryption keys in production
Never rely on the derived key fallback for production deployments. Always provide a
COREFLUX_SECRET_KEY environment variable or a secret.key file. The derived key is machine-specific — if you migrate, scale, or recreate a container, your secrets become unreadable.Restrict file permissions
Restrict file permissions
On Linux, restrict access to sensitive files to the broker’s service user only:
Prefer GET ENV over hardcoded values
Prefer GET ENV over hardcoded values
Even for values that seem static (like a database port), use
GET ENV so you can change configuration without redeploying LoT code. This makes your Actions and Routes portable across dev, staging, and production.Use mounted volumes for Docker
Use mounted volumes for Docker
Always mount a persistent volume at
{CONFIG_PATH}/Coreflux in Docker and Kubernetes. Without a volume, your .env, secrets.json, and all broker state are lost when the container stops.Never commit secrets to version control
Never commit secrets to version control
Keep
secret.key, secrets.json, and .env files out of Git. Add them to .gitignore and use your deployment pipeline to inject them at runtime.Resolution Reference
Where Each Syntax Reads From
Encryption Key Resolution Order
GetEnv Resolution Order
Next Steps
Broker Commands
Full reference for all broker CLI commands including env and secret management.
Operations Reference
See GET ENV and GET SECRET in the complete LoT operations reference.

