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
| Scenario | Use | Why |
|---|---|---|
| Database host, port, name | Environment variable | Non-sensitive, changes per environment |
| API base URLs | Environment variable | Configuration that varies between dev/staging/prod |
| Feature flags | Environment variable | Simple on/off toggles |
| Database passwords | Secret | Must not be readable on disk |
| API keys and tokens | Secret | Sensitive credentials |
| TLS passphrases | Secret | Security-critical values |
In This Page
| Section | Description |
|---|---|
| Config Root | How the broker resolves its configuration directory |
| Environment Variables | Plain-text configuration management |
| Secrets | Encrypted credential storage |
| Using in LoT | GET ENV, GET SECRET, KEEP, DELETE syntax |
| Using in Routes | Referencing env vars and secrets in route definitions |
| CLI Commands | Managing env vars and secrets via broker commands |
| Deployment | Windows, Linux, Docker, and Kubernetes setup |
| Resolution Reference | Quick-reference tables for resolution order and syntax |
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:
| Priority | Source | Description |
|---|---|---|
| 1 | .env file (managed) | Set via -setEnv or KEEP ENV. Persisted to disk. |
| 2 | Process environment | Docker environment:, Kubernetes env:, or shell exports. |
| 3 | User environment | OS user-level environment variables (non-Docker). |
| 4 | Machine environment | OS machine-level environment variables (non-Docker). |
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:| Priority | Source | Notes |
|---|---|---|
| 1 | COREFLUX_SECRET_KEY env var | Best for Docker/Kubernetes. Base64-encoded, 32 bytes. |
| 2 | {config_root}/secret.key file | Good for mounted volumes. Base64-encoded, 32 bytes. |
| 3 | Derived from machine GUID | Auto-generated fallback. Machine-specific — secrets become unreadable if moved to a different machine. |
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:
| Placeholder | Resolves To |
|---|---|
{env.NAME} | Environment variable value |
{secret.NAME} | Decrypted secret value |
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
| Command | Description |
|---|---|
-setEnv NAME=value | Set an environment variable (persisted to .env file) |
-removeEnv NAME | Remove an environment variable |
-listEnv | List all managed environment variables |
$SYS/Coreflux/Command to manage environment variables:
Secret Commands
| Command | Description |
|---|---|
-setSecret NAME=value | Set a secret (encrypted and persisted to secrets.json) |
-removeSecret NAME | Remove a secret |
-listSecrets | List secret names (values are never shown) |
$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.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\.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
| Syntax | Where It Works | Resolved By |
|---|---|---|
GET ENV "NAME" | Actions, Models, Route configs | .env file, then process env fallback |
GET SECRET "NAME" | Actions, Models, Route configs | Decrypts from secrets.json |
ENV:NAME | Route ADD CONFIG sections only | Same as GET ENV |
SECRET:NAME | Route ADD CONFIG sections only | Same as GET SECRET |
{env.NAME} | Event queries (WITH QUERY) | Replaced at event execution time |
{secret.NAME} | Event queries (WITH QUERY) | Replaced at event execution time |
Encryption Key Resolution Order
| Priority | Source | Notes |
|---|---|---|
| 1 | COREFLUX_SECRET_KEY env var | Best for Docker/Kubernetes. Base64-encoded, 32 bytes. |
| 2 | {config_root}/secret.key file | Good for mounted volumes. Base64-encoded, 32 bytes. |
| 3 | Derived from machine GUID | Auto-generated fallback. Machine-specific — secrets won’t decrypt on a different machine. |
GetEnv Resolution Order
| Priority | Source | Notes |
|---|---|---|
| 1 | .env file (managed) | Set via -setEnv or KEEP ENV. Persisted to disk. |
| 2 | Process environment | Docker environment:, Kubernetes env:, or shell exports. |
| 3 | User environment | OS user-level env vars (non-Docker). |
| 4 | Machine environment | OS machine-level env vars (non-Docker). |

