Skip to main content

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 .env file
  • Secrets store sensitive credentials (passwords, API keys, tokens) encrypted at rest with AES-256-GCM
Both are accessible from LoT Actions, Models, Routes, and broker CLI commands using a unified syntax — no external tools or services required.
Think of it like a vault and a notebook. Environment variables are the notebook — quick to read, easy to update, visible if someone opens the file. Secrets are the vault — locked with a key, encrypted on disk, only decrypted when the broker needs them at runtime.
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_PATH environment variable is set, it is used as the base path
  • Otherwise, the application directory is used (e.g. /app in Docker, the executable’s folder on Windows/Linux)
  • /Coreflux is always appended automatically
For example, with 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 (via GET 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:
Secret values are only decrypted at runtime when accessed via 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:
If you use the derived key fallback (no explicit key), your secrets are tied to the specific machine. Moving the secrets.json file to another machine or container will make the secrets unreadable. Always use an explicit key for portable deployments.

Using in LoT

Environment variables and secrets can be read, written, and deleted from within LoT Actions, Models, and route configurations.

Reading Values

Use GET ENV to read an environment variable and GET SECRET to read an encrypted secret (decrypted at runtime):

Persisting Values

Use KEEP ENV to save a new environment variable to the .env file, and KEEP SECRET to encrypt and store a new secret:

Deleting Values

Use DELETE 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

Use GET ENV and GET SECRET in route configuration blocks to inject values at runtime:

Legacy Prefix Syntax

The ENV: 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.
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 C:\Coreflux\, the config root is C:\Coreflux\Coreflux\.To use a custom path, set the CONFIG_PATH system environment variable:
The config root becomes 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

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.
On Linux, restrict access to sensitive files to the broker’s service user only:
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.
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.
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.
Last modified on May 22, 2026