Env & flags

Env & flags

Keep an app's config, encrypted secrets and feature flags in the repo, per environment. It works offline, needs no account, and the same files feed muster deploy.

How it works

Plain config is stored as cleartext JSON. Secrets are encrypted one value at a time to the people and machines allowed to read them. Feature flags use flagd's format. A schema drives a CI check, .env.example and typed readers.

Quickstart

Terminal
cd my-app                         # any repo; muster.json is optional
muster env init --from .env       # schema + .muster/env, imports your .env
rm .env                           # values now live in .muster/env

muster env set STRIPE_KEY         # hidden prompt, stored encrypted
muster env set PORT=3000          # plain config
muster flag set new_checkout on   # feature flag

muster run -- npm run dev         # app gets PORT, STRIPE_KEY, MUSTER_FLAG_NEW_CHECKOUT…

muster run writes nothing to disk: values go straight into the process environment via exec, so signals and the exit code pass through.

Phase 1 covers local use, the repo and CI. Pushing env to servers, dashboard views and flag targeting rules are on the roadmap.

Use it in CI

Terminal
muster env keygen --ci github --envs staging,production   # prints MUSTER_ENV_KEY once

Store the key as the CI secret MUSTER_ENV_KEY, commit .muster/env/, then:

YAML
- run: muster env check --env production        # exit 1 on missing/invalid keys
- run: muster run --env production -- npm test  # if tests need the values

env check also runs without a key: it checks required keys are present (secret names aren't encrypted) and warns that it couldn't verify secret values or the file MAC.

Typed access in code

Terminal
muster env codegen ts      # → src/env.generated.ts (also py, go, all; --check for CI)
TypeScript
import { env } from "./env.generated";

app.listen(env.PORT);                  // number
stripe(env.STRIPE_KEY.reveal());       // secrets print as [REDACTED]
if (env.flags.newCheckout) { … }       // boolean, from MUSTER_FLAG_NEW_CHECKOUT

The module validates every key when it loads and lists all problems in one error. Python gets a SecretStr wrapper and Go a Secret type. The generated code has zero dependencies.

Feature flags

Flags live in .muster/env/<env>.flags.json in flagd's JSON format (state, variants, defaultVariant). Without an SDK, an app reads each flag as MUSTER_FLAG_<NAME>. muster run also sets MUSTER_FLAGS_FILE to the merged flags, so any OpenFeature flagd provider can read them, and muster flag set --local rewrites that file for hot reload.

TypeScript
import { OpenFeature } from "@openfeature/server-sdk";
import { FlagdProvider } from "@openfeature/flagd-provider";

await OpenFeature.setProviderAndWait(
  new FlagdProvider({
    resolverType: "in-process",
    offlineFlagSourcePath: process.env.MUSTER_FLAGS_FILE,
  }),
);
Terminal
muster flag set NAME on|off|VALUE [--env E] [--local] [--type bool|string|number|json]
muster flag list|get|toggle|unset
muster flag reset --local

How deploys read it

muster deploy, rollback, restart, fleet deploy and skill hooks load the store when muster.json has "env": {"source": "muster"}, or when there is no .env and .muster/env exists. Values are decrypted in memory only, existing variables win, and secret values are masked in logs. Names like PATH, LD_* and NODE_OPTIONS are never injected.

Services with remote.enabled (hooks piped over SSH) don't receive the store yet. Delivering env to servers is Phase 2.

Security model

  • All encryption is in muster-crypt, a small static Go binary (installed with muster when you choose it).
  • Per value: XChaCha20-Poly1305 under a per-file data key, with the env and key name bound as associated data.
  • Per file: an HMAC-SHA256 over the version, env, revision and every entry, so adding, removing or swapping entries outside muster fails the check.
  • Per recipient: the data key is wrapped with hybrid X25519 + ML-KEM-768, the same construction family as Fleet Cloud's E2E v2.
  • Removing a recipient rotates the data key and lists the secrets to rotate at their source.
  • Secrets never go through argv or temp files on the bash side.

It does not protect against someone who can read your private key, or an app that prints its own environment.

Files

PathCommittedWhat
muster.env.schema.jsonyesKeys (type, required, default, enum, pattern, format, min/max), flags, environments
.muster/env/<env>.config.jsonyesNon-secret values
.muster/env/<env>.secrets.jsonyesEncrypted values; key names readable
.muster/env/<env>.flags.jsonyesflagd JSON
.muster/env/recipients.jsonyesPublic keys and the environments each may decrypt
.muster/env/history.jsonlyesWho changed what (secrets as fingerprints)
.muster/env/local.override.jsonnoYour personal overrides
~/.muster/env-keys/identity.keyneverYour private key (0600)

Precedence, lowest to highest: schema defaults, base.config.json, <env>.config.json, secrets, flags, local overrides (env local only), then variables already in your shell (unless muster run --override). The environment comes from --env, $MUSTER_ENV, env.default_env in muster.json, then local.