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 connector 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, Connectors, 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 picks its data directory (config root) in this order — first match wins:
  1. COREFLUX_DATA_PATH (used as-is)
  2. CONFIG_PATH (used as-is; this is what official Docker images set)
  3. -p / --path (used as-is, applied later in startup — prefer the env vars)
  4. Default: {install directory}/Coreflux
When an env var is set, /Coreflux is not appended. With CONFIG_PATH=/etc/project, files live at /etc/project/.env, not /etc/project/Coreflux/.env. The /Coreflux suffix is only added in the default case (no env var and no -p).

File Layout

Environment and secrets files live in the data directory:
The LoT you deploy is saved in bin/ as plain-text files, one per kind: actions.lot, models.lot, routes.lot and rules.lot, plus Python.Scripts for Python scripts and project-entity-ownership.json, which records which project loaded each entity. Back up bin/ with the rest of the data directory. Do not edit these files while the broker runs; change LoT with the broker commands or a project.
Earlier versions named these files Saul.Ricardo (actions), Marco.Paulo (models), Roberto.Leal (connectors), Ze.Cabra (rules) and Ze.Cabra.project-rules.json (project ownership). On the first start after an upgrade the broker copies each one to its new name and leaves the old file in place, so your LoT carries over and you can still go back to the earlier version. See Update Coreflux.

Broker process environment variables

These names are read by the broker process (Docker environment:, systemd Environment=, Kubernetes env:). They are not the same as values you store in .env for GET ENV — though a name set in the process environment is still visible to GET ENV through the fallback chain. Restart the broker after changing them.

Data path and logging

Secrets and audit

Operational HTTP (/health, /ready, /info, /license, /metrics)

Env vars override the matching fields in broker JSON (OpsEnabled, OpsPort, OpsBindIP). Paths, response shapes, Kubernetes probes, and the Prometheus scrape are on Operational endpoints. GET /license returns the license status also published on the retained $SYS/Coreflux/License topic (tier, limits, usage, fingerprint, activation, enrollment). It is unauthenticated — keep the ops port on a private network. Field meanings: Licensing and Enrollment.

Licensing and enrollment

These names are read from the process environment at boot. They are not the LoT .env file you manage with -setEnv. There is no enrollment-token environment variable — use --enroll / -enroll or {data directory}/config/enrollment-token. Full guide: Licensing and Enrollment.

MQTT

OIDC bearer authentication is not configured with a process environment variable. The Oidc object lives in the broker configuration file. Enrollment writes Oidc.BoundOrg after the broker joins an organization. See OIDC and Bearer Authentication.

Connectors, durability, clustering, Python


Environment Variables

Storage

Environment variables are stored in plain text in {data directory}/.env using standard key=value format:

Resolution Order

When the broker resolves an environment variable (via GET ENV, connector 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 {data directory}/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 connector 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 connector 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 Connectors

Environment variables and secrets can be referenced directly in connector definitions, keeping connection details out of your LoT code.

Standard Syntax

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

Legacy Prefix Syntax

The ENV: and SECRET: prefix syntax is also supported for backward compatibility in connector ADD CONFIG sections:

Event Query Placeholders

In connector 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:
Quote values that contain //, a space, or #. The command is cleaned before it runs. Outside double quotes, //, /* and -- start a comment and cut off the rest of the line, and a space ends the value. Wrap the value in double quotes: -setEnv API_URL="https://api.example.com/v1". The quotes are removed before the value is stored. The same rule applies to -setSecret.

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 data directory defaults to the broker’s executable folder + \Coreflux unless COREFLUX_DATA_PATH is set (used as-is).
1

Locate the data directory

If the broker is at C:\Coreflux\CorefluxMQTTBroker.exe, the default data directory is C:\Coreflux\Coreflux\.To pin a custom path, set a machine environment variable (no extra \Coreflux is appended):
Files then live directly under C:\CorefluxData\.
2

Create the .env File

Create a .env file in the data directory:
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 Connectors portable across dev, staging, and production.
Always mount a persistent volume at the data directory (/etc/project in Docker, /var/lib/coreflux on Linux packages). Without a volume, .env, secrets.json, and broker state are lost when the container is recreated.
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 October 22, 2026