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-and-secret-resolution

Configuration and secret resolution

fnox turns configuration files, runtime settings, profile choices, and provider data into one effective set of secret declarations. It then resolves those declarations for commands and other consumers while keeping provider inputs, fallback rules, and missing-value behavior consistent.

Configuration assembly

Configuration assembly creates one view from machine-wide settings and project data. The result supplies the active providers, profiles, secret declarations, and policy that later resolution uses.

Configuration layers

The normal load path searches upward from the current directory and applies files from lower to higher priority. A global file is the base layer. Project files, profile files, local overrides, and imports add or replace values above it. An explicit non-default path skips the directory search but still loads its imports and the global base. The root setting stops the upward search without removing the global base.

The layer order matters because a later value with the same name replaces an earlier value. Imports are relative to the file that declares them. Paths in provider settings use the declaring file as their base, so moving a config file can change which local resource it names. A profile-specific file maps its top-level provider and secret entries to that profile instead of treating them as default entries. See configuration discovery and profiles for the full discovery and profile model.

This diagram shows how fnox turns several sources into the loaded configuration.

flowchart TD
    G[Global config] --> M[Layered config]
    P[Parent project files] --> M
    C[Current project files] --> M
    R[Active profile files] --> M
    L[Local overrides] --> M
    I[Imported files] --> M
    M --> E[Effective configuration]

References: crates/…/config.rs• L54-138 crates/…/config.rs• L683-746 crates/…/config.rs• L854-987 crates/…/config.rs• L1005-1043

Profile overlays

An active profile stack selects the secret and provider set for a run. Command-line profile choices take priority over the profile environment setting and the saved settings value. If no profile is selected, default represents the top-level configuration.

Profile inheritance expands each named profile by applying its inherited profiles before the profile that names them. Top-level providers and secrets form the base unless no_defaults removes top-level secrets for a non-default profile. Named profiles then overlay that base in order, so a later profile wins when names collide. A profile-specific file contributes to the matching named profile through the same overlay rules.

The same profile stack selects the default provider. A configured default provider must exist; one provider can be selected automatically when no default is named. Secret names must be valid portable environment variable names before fnox returns the effective set.

The effective secret set is a declaration set, not a guarantee that every value is available. A declaration can still resolve to no value when its provider fails or its environment fallback is absent. See configuration discovery and profiles for profile selection, inheritance, and file naming.

References: crates/…/config.rs• L140-164 crates/…/config.rs• L779-816 crates/…/config.rs• L1536-1710 crates/…/config.rs• L1772-1985

Secret value resolution

Secret value resolution maps each effective declaration to an optional value. It uses the configured provider when possible, applies a declared fallback when needed, and only then checks the process environment.

Secret sources

For one secret, fnox uses this order:

  1. The selected provider, using the declaration’s value as provider input.
  2. The declaration’s default value.
  3. An environment variable with the secret’s name.

The value field is not a direct result by itself. It is a name, ciphertext, or other provider input. A provider result and every fallback source pass through the same optional post-processing, such as JSON field or line selection. Encrypted local values are therefore one provider-backed source in this flow; see encryption and local secret storage for that storage path.

References: crates/…/secret_resolver.rs• L476-586 crates/…/secret_resolver.rs• L588-693 crates/…/secret_resolver.rs• L718-734 crates/…/config.rs• L261-331

Resolution dependencies

Some values cannot resolve independently. A provider may need an environment variable supplied by another secret. A default may also contain ${NAME} and depend on another declared secret. fnox resolves these dependencies in levels, makes completed values available to later providers, and resolves independent values in parallel.

Provider results take precedence over interpolated defaults. If a provider fails and a fallback exists, fnox evaluates the fallback and its referenced secrets. Undefined references and cycles in evaluated fallback paths are configuration errors. A cycle that does not affect a hard fallback can be handled as a best-effort provider resolution, but a required fallback cycle fails.

References: crates/…/secret_resolver.rs• L107-259 crates/…/secret_resolver.rs• L736-940 crates/…/secret_resolver.rs• L942-1014 crates/…/secret_resolver.rs• L1016-1452

Missing-value policy

When no provider, fallback, or environment value succeeds, fnox applies the if_missing policy. The policy is selected from the command or environment first, then the secret declaration, the top-level config, a base environment default, and finally warn.

The policy controls the consumer contract. error stops resolution. warn reports the missing value and returns no value. ignore skips the value without a message. Consumers such as the library get operation can therefore receive an optional value even when the secret is declared correctly.

References: crates/…/secret_resolver.rs• L297-377 crates/…/secret_resolver.rs• L695-716 crates/…/library.rs• L157-206

Provider configuration references

Provider settings can use either literal strings or references to named secrets. This lets a provider obtain tokens, key paths, or other sensitive settings through the same resolution system instead of storing them in the provider block.

Reference forms

A provider field accepts a literal string or an object such as { secret = "TOKEN" }. An optional field can be absent, literal, or secret-backed. A provider-specific reference can also name a provider and provider input directly. The resolver looks for named secrets in the active profile first and falls back to an environment variable when the name is not declared.

References: crates/…/secret_ref.rs• L21-32 crates/…/secret_ref.rs• L134-142 crates/…/secret_ref.rs• L233-242 crates/…/resolver.rs• L128-180 crates/…/resolver.rs• L237-318

Recursive provider resolution

Resolving a provider can require resolving another provider first. For example, a remote provider can use a token secret stored by an encryption provider. fnox follows this chain, replaces references with values, and then gives the resolved settings to the provider that serves the requested secret.

The resolver tracks the active provider path. If providers refer back to one already being resolved, fnox reports a provider configuration cycle instead of entering an endless loop. Non-interactive consumers also reject providers that require an interactive login.

References: crates/…/resolver.rs• L18-25 crates/…/resolver.rs• L66-125 crates/…/resolver.rs• L191-234

Consumer boundary

The effective values leave this subsystem through read operations and process setup. A consumer receives the value selected by the active profile and resolution rules, not the raw provider input or the layered declaration itself.

Resolved values

The library-facing get operation first checks whether the name exists in the active declaration set. It then resolves that declaration and returns its value or an optional absence according to the missing-value policy. An undeclared name is a separate error because it is not part of the active profile.

Environment injection is controlled by each secret’s env mode or the top-level default. This separates value resolution from exposure: a secret can resolve successfully and still remain available only to an explicit read operation rather than entering a shell or child process environment.

References: crates/…/library.rs• L157-206 crates/…/config.rs• L587-619 crates/…/config.rs• L1772-1819

Change checklist

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

  • Changes to config file names or load order must stay aligned with profile selection and the command that reports loaded files.
  • Changes to profile overlay rules must preserve the same effective secret lookup for both batch resolution and single-secret lookup.
  • Changes to profile-specific file scoping must preserve the distinction between top-level default entries and entries belonging to the selected profile.
  • Changes to provider reference fields must preserve the literal and { secret = "NAME" } forms in schema generation and config parsing.
  • Changes to fallback interpolation must keep undefined-reference and cycle handling consistent for single-secret and batch resolution.
  • Changes to if_missing precedence must preserve the difference between an undeclared secret and a declared secret with no resolved value.
  • Changes to path resolution must account for imported files and provider resources declared outside the current directory.
  • Changes to secret-name validation must preserve compatibility with shell environment injection and profile-specific declarations.

Important failure modes

TriggerConsequenceGuard
No config file is found during default discoveryThe run stops before secret resolutionCreate a config or use an explicit config path
A named profile selects a provider that is not in the effective provider setProvider-backed secrets fail or use their declared fallbackDefine the provider in the active layers or set a valid default provider
A fallback names an undefined secret or creates a required dependency cycleThe fallback cannot be evaluated and resolution failsDefine each referenced secret and keep fallback dependencies acyclic
A provider reference points to a missing config or environment secretProvider configuration cannot be builtDeclare the secret in the active profile or provide the named environment variable
An interactive provider runs in a non-interactive contextThe provider cannot authenticate and affected values may be absent or failAuthenticate before the run or use a provider that supports the execution context
A secret name is not a valid portable environment variable nameConfiguration validation fails before the effective secret set is usedStart the name with a letter or underscore and use only letters, digits, and underscores

Key files

FileWhy to read it
crates/…/config.rsDefines configuration layers, profile overlays, effective providers, and effective secrets.
crates/…/config_path.rsDefines how imported and provider paths relate to their declaring config file.
crates/…/settings.rsDefines the merge of defaults, environment settings, and command-line settings.
crates/…/secret_resolver.rsDefines source priority, fallback interpolation, dependency order, and missing-value behavior.
crates/…/secret_ref.rsDefines the data forms for literal provider fields and secret-backed provider fields.
crates/…/resolver.rsDefines recursive provider setting resolution and provider-cycle checks.
crates/…/library.rsShows the boundary used by library consumers to list and read resolved secrets.