Introducing a new way to review your PRs.

Read the announcement

jdx / fnox

encrypted/remote secret manager

View on GitHub

27 documents · Updated Nov 23, 2026

docs / configuration-discovery-and-profiles

Configuration discovery and profiles

fnox builds one effective configuration from global data, project files, imported files, and the selected profile stack. This view gives secret and provider resolution the same set of declarations and policies for the current directory and command.

Configuration discovery

Discovery scope

The default configuration name is fnox.toml. When a command uses this bare name, fnox searches from the current directory toward the file system root. At each directory it checks the files for the active profiles, then it stops when it reaches a file with root = true. The global file remains a base layer even when this stop marker is present.

Profile inheritance can add more profile files to the search. fnox repeats the discovery walk until the selected profiles and their inherited profiles are stable. It then rejects any inherited profile that has no matching profile table or profile file.

The global file is config.toml under FNOX_CONFIG_DIR. By default, this is the user's fnox configuration directory. It can provide machine-wide providers and secrets that project files can use or replace.

The discovery walk uses this order within each directory. Later entries have higher priority:

  1. fnox.toml
  2. .fnox.toml
  3. fnox.<profile>.toml and .fnox.<profile>.toml for each non-default active profile
  4. fnox.local.toml
  5. .fnox.local.toml

The directory nearest the current working directory has higher priority than its parent. This lets a service add or replace values without copying the shared configuration from a monorepo parent.

This diagram shows how the discovery walk turns several file locations into one ordered configuration.

flowchart TD
    A[Current directory] --> B[Check base files]
    B --> C[Check active profile files]
    C --> D[Check local override files]
    D --> E{root = true?}
    E -- No --> F[Move to parent directory]
    F --> B
    E -- Yes --> G[Stop directory search]
    G --> H[Load global config as base]
    E -- At filesystem root --> H
    H --> I[Merge from low to high priority]

References: crates/…/config.rs• L17-119 crates/…/config.rs• L854-898 crates/…/env.rs• L42-55

Explicit configuration paths

An explicit --config path changes the scope. A path such as ./ci.toml or path/…/fnox.toml loads only that file, its imports, and the global file. It does not search parent directories or add adjacent profile and local files. The bare names fnox.toml, .fnox.toml, and the supported local names keep the discovery behavior. The command help presents this distinction so users can select hierarchy or an isolated file by choice.

The config-files command reports the files that this choice would load. For an explicit path it reads the target and validates its imports before it reports the global layer. A missing or invalid target therefore fails instead of showing a load order that cannot occur.

References: crates/…/config.rs• L38-48 crates/…/config.rs• L683-746 src/…/config_files.rs• L20-65 fnox.usage.kdl• L30-35 fnox.usage.kdl• L167-182

Imports

An import adds a file to the configuration base for the file that declares it. Relative import paths use the declaring file's directory. The importing file then overrides the imported values, so imports provide shared bundles without changing the directory search model.

Imports are required to exist during normal loading. fnox loads them as configuration sources and applies the same merge rules to their providers, secrets, profiles, and settings. An import does not make a non-default --config path participate in upward discovery.

References: crates/…/config.rs• L724-746 crates/…/config.rs• L949-969 crates/…/config_path.rs• L25-35

Configuration hierarchy

Layer precedence

The hierarchy merges named entries rather than replacing the whole configuration at each level. A child entry with the same name replaces the parent entry. Entries with new names remain available, which is why a service can use shared providers and secrets while adding only its own declarations.

The broad precedence is:

LayerRolePriority
Global configMachine-wide baseLowest
Parent directoriesShared project or monorepo dataIncreasing upward-to-downward
Current directoryService or application dataHigher
Profile and local files at a directoryActive environment and machine-specific overridesHighest at that directory

The same model applies to top-level providers, secrets, leases, and named profiles. Scalar policy values use the overlay value when one exists. Some security-sensitive policy blocks are replaced as a unit so a partial child block cannot silently widen access.

References: crates/…/config.rs• L1045-1187 crates/…/config.rs• L949-986 test/config_recursion.bats• L12-89

Profile inheritance

Profile inheritance builds a reusable profile stack before fnox composes providers, leases, and secrets. A profile can name profiles to apply first through inherits; inherited profiles are expanded before the profile that names them, and a later overlay replaces entries with the same name.

The expansion keeps shared ancestors from being applied more than once. A cycle or an inherited profile with no matching declaration or profile file fails configuration loading instead of producing an ambiguous result.

References: crates/…/config.rs• L1584-1619 crates/…/config.rs• L1623-1710

Write targets

Read composition and write placement are separate decisions. A write command updates the local configuration target for the selected scope. It does not copy inherited parent entries into the child file. If a child changes an inherited secret, fnox writes a child override and leaves the parent source unchanged.

For a default write, fnox prefers an existing fnox.toml or .fnox.toml. With one non-default profile it prefers that profile's file when it exists. It avoids routing a profile-scoped write into a local override file when that could hide the intended scope. A write with several active profiles needs --write-profile so the destination is unambiguous. The CLI contract applies this rule to secret and provider write commands.

References: crates/…/config.rs• L95-138 crates/…/config.rs• L1712-1740 src/…/set.rs• L23-41 test/config_hierarchy_set.bats• L12-197 fnox.usage.kdl• L62-67

Relative resource paths

A path declared in a configuration file belongs to that file's location. fnox resolves a relative path against the declaring file's directory and expands ~ to the user's home directory. Absolute paths stay unchanged. This rule keeps imported and hierarchical configurations stable when the command runs from another directory.

References: crates/…/config_path.rs• L3-23 crates/…/config_path.rs• L25-51

Source tracking

Configuration sources

Each loaded file is registered with its path and source text before TOML parsing completes. The merged configuration also keeps the source path for providers, secrets, and default-provider values. When a later layer replaces a named entry, its source replaces the earlier source.

This source information supports two related behaviors. Diagnostics can point to the file and exact value that caused an error. Write commands can understand which scope supplied a value while choosing a local override target. Source metadata is runtime information and is not written back into TOML.

References: crates/…/config.rs• L749-786 crates/…/config.rs• L1116-1145 crates/…/config.rs• L2010-2053 crates/…/source_registry.rs• L11-39

Error locations

Scalar values that need precise error messages retain their byte range in the source file. When validation finds an invalid default provider or another source-aware problem, fnox combines that range with the registered file text to show an annotated error instead of only a name or path.

References: crates/…/spanned.rs• L9-23 crates/…/spanned.rs• L77-95 crates/…/config.rs• L1943-1969 crates/…/config.rs• L2147-2162

Settings generation

Settings registry

The settings registry is the source for process-wide options that are not assembled as secret or provider entries. SettingsData declares each setting together with its type, default, environment source, and CLI source. The usage_rs::Config derive creates the typed reader and the settings documentation from that declaration.

The settings cover runtime choices such as the active profile list, whether top-level secrets are excluded, missing-secret policy overrides, encryption key paths, shell output, and request timeouts. Configuration-file fields that belong to the loaded Config still follow the configuration hierarchy; the settings layer supplies command and environment controls around that configuration.

References: crates/…/settings.rs• L1-72 crates/…/settings.rs• L74-142

Settings precedence

Settings use defaults first, then environment variables, then the parsed CLI snapshot. The CLI layer is captured after argument parsing and can refresh the shared settings value. Environment paths expand ~, profile values become an ordered list, and boolean settings accept the supported true forms.

This precedence affects profile selection and controls such as --no-defaults. It does not change the order of TOML files already selected by discovery. The command layer passes the resulting settings and the loaded configuration to the feature that needs them.

References: src/main.rs• L29-38 crates/…/settings.rs• L8-18 crates/…/settings.rs• L153-317

Profile selection

Active profile stack

A profile is a named overlay that selects environment-specific secrets, providers, and lease backends. The special default profile means the top-level sections; fnox does not look for a [profiles.default] section when default is active.

The active stack is chosen in this order:

  1. Repeated or comma-separated --profile or -P values
  2. FNOX_PROFILE
  3. The generated settings default of default

Names are trimmed and validated before use. Invalid names cannot introduce path separators, commas, control characters, or path traversal. If no valid name remains, fnox uses default. The CLI also states that later selected profiles override earlier ones, which makes the order part of the user-facing profile contract.

References: src/…/mod.rs• L45-53 crates/…/config.rs• L1536-1562 crates/…/env.rs• L70-77 crates/…/env.rs• L98-153 fnox.usage.kdl• L38-44

Profile availability

The profile list is the set of default, named profile tables, and profile-specific files that are present in the effective configuration. The profiles command uses this same set. Normal output shows each profile with the number of secrets visible when that profile is used, while its hidden completion mode emits one profile name per line without changing the active stack.

References: crates/…/config.rs• L1573-1582 src/…/profiles.rs• L5-33 fnox.usage.kdl• L834-848

Profile overlays

The top-level providers, secrets, and lease backends form the base of an active stack. Each selected non-default profile overlays that base in the order selected. A later profile wins when two profiles define the same name. This allows one profile to add shared provider settings and another to add environment-specific secret mappings.

By default, a non-default profile still inherits top-level secrets. --no-defaults or FNOX_NO_DEFAULTS removes that top-level secret base when at least one non-default profile is active. Providers and lease backends continue to start from their top-level maps and receive profile overlays.

The effective default provider follows the same profile order. The last profile that declares one wins. If no default provider is declared, fnox can select the only available provider; several providers without a default remain an unresolved choice for the caller.

References: crates/…/config.rs• L1772-1819 crates/…/config.rs• L1869-1904 crates/…/config.rs• L1906-1985

Profile files

An active non-default profile also enables matching files beside each discovered base file. For example, selecting production loads fnox.production.toml and .fnox.production.toml at each directory in the walk. These files use top-level [secrets], [providers], and related sections because the filename already supplies the profile context.

The default profile does not load fnox.default.toml. A profile file is therefore a separate way to store one profile's overlay, while [profiles.<name>] stores several named overlays in a shared file. Both forms enter the same merged configuration and profile selection model.

References: crates/…/config.rs• L54-69 crates/…/config.rs• L140-165 crates/…/config.rs• L779-815 test/profile_config.bats• L12-54 test/profile_config.bats• L131-195

Write profile selection

Read commands can use several profiles because their result is an ordered composition. Write commands need one destination. With one active profile, that profile is the implicit target. With several active profiles, fnox requires --write-profile <name> and writes only the chosen profile scope.

The profiles command lists default and the named profiles present in the effective configuration. It reports the number of secrets visible when each profile is used, or emits only names for shell completion. It does not change the active stack for later commands.

References: crates/…/config.rs• L1712-1740 src/…/profiles.rs• L14-33 src/…/set.rs• L95-117 docs/…/profiles.md• L64-89 fnox.usage.kdl• L62-67 fnox.usage.kdl• L834-848

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the filename order in discovery, config-files, and write-target selection aligned. A mismatch can make the reported load chain differ from the configuration that a write command edits.
  • Keep profile-list parsing aligned with profile filename generation. A name that can be selected must map to the same safe filename in every directory.
  • When adding a profile-scoped configuration entry, check both [profiles.<name>] sections and fnox.<name>.toml files. They must produce the same effective overlay rules.
  • Preserve source-path updates when adding a new mergeable named entry. Diagnostics and local override writes depend on the winning source.
  • When adding a settings source or field, update the SettingsData declaration and its CLI or environment binding together. A missing binding can change settings precedence without changing the TOML configuration.
  • When changing top-level inheritance, check the interaction between profile overlays and --no-defaults. This boundary changes which secrets are visible without changing the provider set.
  • When changing profile inheritance, check both the discovery fixed point and final profile validation. A profile file found only through an inherited profile must be loaded before that profile is validated.
  • When changing the user-facing option contract, keep fnox.usage.kdl aligned with the settings and command behavior. Help text defines the distinction between hierarchical and explicit config paths and the rules for layered profiles and writes.

Important failure modes

TriggerConsequenceGuard
A bare discovery name is replaced with an explicit relative path such as ./fnox.tomlParent files and adjacent profile or local files are skippedUse the bare default name for hierarchy or pass every required file through import
An imported file is missing or invalidConfiguration loading stops before the global layer is usedCheck imports with fnox config-files and keep paths relative to the declaring file
A profile name contains a path separator or commaThe profile is rejected and its profile file cannot be selectedUse a name with safe characters and keep comma as the list delimiter
Profile inheritance contains a cycleConfiguration loading fails instead of producing a stable profile orderKeep inherits relationships acyclic
A profile inherits a name with no profile table or matching profile fileConfiguration loading fails after discovery completesDeclare the profile or add its fnox.<profile>.toml file
Several profiles are active during a write without --write-profilefnox refuses to choose a write destinationSet one explicit write profile
--no-defaults is used with a profile that relies on shared top-level secretsThose inherited secrets are absent from the effective profileDefine the needed secret in the selected profile or remove --no-defaults
A profile selects a missing default providerProvider selection fails with an error tied to the declaring source when availableDefine the provider in the same effective stack or correct the default-provider name

Key files

FileWhy to read it
crates/…/config.rsDefines discovery, global and import loading, merge precedence, source tracking, profile inheritance, profile overlays, and write-profile rules.
crates/…/config_path.rsDefines how imported and other configuration paths resolve from their source directory.
crates/…/settings.rsDeclares runtime settings and explains how defaults, environment values, and CLI values become the shared settings snapshot.
src/…/config_files.rsShows how fnox exposes the discovered file chain and validates explicit targets.
src/…/profiles.rsShows how available profiles and their visible secret counts are presented.
src/…/mod.rsDefines the shared CLI inputs for configuration paths, profiles, defaults, and write targets.
fnox.usage.kdlDefines the user-facing contract for config path scope, profile layering, profile discovery, and write-profile selection.
crates/…/source_registry.rsShows how loaded source text supports source-aware error reports.
test/config_recursion.batsDemonstrates parent search, root stopping, imports, and explicit-path behavior.
test/profile_config.batsDemonstrates profile-file loading and profile-specific overrides across a hierarchy.

The broader configuration and resolution model is described in Configuration and secret resolution. For the next stage, see Secret references and resolution and Encryption and local secret storage.