Secret references and resolution
Secret resolution turns an active profile's secret declarations into values that commands and child processes can use. It combines provider lookups, defaults, environment values, and provider configuration references while preserving clear rules for precedence, missing values, and output handling. Provider configuration is resolved recursively before a provider reads a value. See the parent page, Configuration and secret resolution, for the wider configuration flow. Related topics are Configuration discovery and profiles and Encryption and local secret storage.
Secret declarations
Secret sources
A secret declaration names a value and describes where fnox should obtain it. The provider and value fields identify a provider and its provider-specific input. The value field is not returned directly when a provider is selected; it is passed to that provider.
The declaration can also provide a default, an if_missing policy, and an optional transformation. A sync entry supplies cached provider data and takes the place of the normal provider and value pair during resolution.
[secrets]
DATABASE_URL = { provider = "vault", value = "database/url", default = "postgres://localhost/app" }
API_TOKEN = { default = "${SHARED_TOKEN}" }
JSON_SECRET = { provider = "plain", value = '{"token":"abc"}', json_path = "token" }
References: crates/…/config.rs• L205-282 crates/…/secret_resolver.rs• L571-613
Provider configuration references
Provider configuration fields can contain either a literal string or a reference such as { secret = "VAULT_TOKEN" }. A provider reference lets a provider use a credential that fnox manages as another secret instead of placing that credential in provider configuration. Required fields must resolve to a string. Optional fields may remain unset. A provider-backed reference resolves a value from the named provider and lookup key.
The reference resolver first looks for the named secret in the effective profile. A provider-backed secret causes fnox to resolve that provider before it creates the original provider. If the named secret has a default, fnox uses that default. If it is not defined in configuration, fnox checks the process environment.
[providers.vault]
type = "vault"
address = "https://vault.example.com"
token = { secret = "VAULT_TOKEN" }
[secrets]
VAULT_TOKEN = { provider = "age", value = "encrypted-token" }
This creates a dependency chain: fnox resolves VAULT_TOKEN, uses it to build the Vault provider, and then uses Vault to resolve the requested secret. A missing reference or a circular provider chain is an error because the provider cannot be made ready. Providers that need interactive authentication also fail in non-interactive mode instead of prompting.
References: crates/…/secret_ref.rs• L21-32 crates/…/resolver.rs• L66-235 crates/…/resolver.rs• L237-318
Effective secret set
Profile overlays
Before fnox resolves a value, it builds the effective secret set for the active profile stack. Top-level secrets form the base. Named profiles overlay that base in order, so a later profile replaces an earlier declaration with the same name.
Top-level secrets remain available to named profiles unless no_defaults is active. This means a profile can change only the values it owns while still using shared declarations. The same profile stack also selects the providers available to those declarations.
References: crates/…/config.rs• L1418-1489 crates/…/config.rs• L1523-1537 test/toplevel_secrets.bats• L12-102
Provider selection
Each secret can name its provider. If it has a provider input but no explicit provider, fnox uses the active profile's default provider. A configured default_provider wins over automatic selection. When no default is configured, fnox can auto-select the only configured provider; with multiple providers it leaves the choice unresolved.
If a secret has no usable provider input, fnox does not call a provider for it. It moves to the default and environment stages instead. This keeps a declaration with only a default or only an environment value independent from provider setup.
References: crates/…/config.rs• L1523-1617 crates/…/secret_resolver.rs• L571-613 test/secret_resolution_priority.bats• L210-231
Resolution precedence
Single-secret resolution
The single-secret path applies one ordered source chain. It returns the first usable value and then applies the declaration's transformation rules.
- A configured provider resolves the provider input. A
syncentry uses its cached provider and input. - A declared default is used when the provider is not usable or no provider input exists.
- The environment variable with the secret's name is used when no provider value or default is available.
- The missing-value policy decides what happens when all sources are empty.
The provider source has the highest priority. A provider failure can fall back to a declared default. Without a default, the provider failure is returned to the caller rather than being silently replaced by the environment value. This prevents an unavailable configured source from looking like a valid environment override.
References: crates/…/secret_resolver.rs• L473-569 crates/…/secret_resolver.rs• L571-613 test/secret_resolution_priority.bats• L17-120
Default interpolation
A default can contain ${NAME} references to other secrets. fnox resolves the referenced secrets first, then renders the default with their results. This supports composed values such as a URL built from a host and port without moving those values into application code.
When several secrets are resolved together, fnox orders them by provider dependencies and default references. Independent secrets can resolve at the same time. Resolved values are made available to later provider stages as environment inputs, which supports chains such as an encrypted credential enabling a cloud provider. Provider configuration is resolved as part of the dependent provider lookup, so a reference can add another provider step to the chain.
Undefined references and hard default cycles are configuration errors. Provider dependency cycles are also detected and reported instead of causing an endless lookup. A batch cycle that only blocks provider ordering is warned about and resolved on a best-effort basis, while a cycle that blocks a required default is an error.
References: crates/…/secret_resolver.rs• L107-259 crates/…/secret_resolver.rs• L412-470 crates/…/secret_resolver.rs• L719-901 crates/…/resolver.rs• L18-125
Value transformation
After a source produces a value, fnox can select part of it before returning the result. json_path reads a dotted path from JSON. line selects a one-based line from a multi-line value. The two options cannot be used together.
The same transformation applies to provider values, defaults, and environment values. Invalid JSON, a missing JSON path, an empty path, or an invalid line number is a data or configuration error. The missing-value policy does not hide these errors.
References: crates/…/secret_resolver.rs• L14-104 crates/…/secret_resolver.rs• L533-565 test/json_secrets.bats• L12-90 test/json_secrets.bats• L210-242
Missing-value behavior
Policy precedence
if_missing controls the result when fnox has no usable value. The effective policy is selected from the most specific and current setting. A command-line setting or FNOX_IF_MISSING overrides the secret declaration. The secret declaration overrides the top-level configuration. FNOX_IF_MISSING_DEFAULT supplies the final configurable fallback, and warn is the built-in default.
| Policy | Result |
|---|---|
error | Stop with an error. |
warn | Print a warning and return no value. |
ignore | Return no value without a warning. |
In batch resolution, provider failures are handled per secret after default fallback. One optional secret can therefore be absent without hiding a separate required secret failure. A direct provider failure without a default remains an error on the single-secret path. A provider that needs interactive authentication is treated as unavailable in non-interactive mode and follows the same per-secret fallback policy in batch resolution.
References: crates/…/secret_resolver.rs• L297-346 crates/…/secret_resolver.rs• L348-377 crates/…/secret_resolver.rs• L678-699 crates/…/secret_resolver.rs• L1169-1205 docs/…/missing-secrets.md• L11-20
Resolver results
Batch resolution
The batch resolver returns an ordered map from secret name to an optional value. Some(value) is consumable secret data. None means that the declaration was allowed to remain unresolved, so consumers omit it rather than inject an empty value.
The daemon can serve the same single and batch resolution requests when it is enabled. Otherwise callers use the shared resolver directly. This keeps get, shell integration, export, and command execution aligned on source precedence and missing-value behavior. Batch provider failures are handled per secret after default fallback, and an authentication retry can occur before that policy is applied.
References: crates/…/secret_resolver.rs• L736-939 src/daemon.rs• L194-309 src/…/get.rs• L49-95
Consumer values
Consumers decide how to expose a resolved Some(value). get prints it or returns a persistent file path when as_file is set. exec places values in the child environment and can use short-lived files for file-based secrets. Shell integration loads only secrets allowed in the shell, while export omits non-shell secrets unless the caller requests all modes.
This separation matters because resolution answers “what is the value?” while the consumer answers “where may the value go?”. A secret can resolve successfully and still be excluded from a shell or child process by its environment mode.
References: src/…/get.rs• L67-94 src/…/exec.rs• L77-210 src/…/hook_env.rs• L264-339 src/…/export.rs• L75-125
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the single-secret and batch paths aligned on provider, default, environment, and missing-value precedence.
- When adding a provider configuration field that can hold a secret reference, update both literal and reference resolution so provider construction receives the same resolved type.
- When changing profile overlays or the
no_defaultsrule, check both secret lookup and provider lookup because a secret can inherit from one layer while its provider comes from another. - When changing default interpolation or provider environment dependencies, preserve dependency ordering and cycle errors before consumers receive partial results.
- When changing provider-backed references, preserve recursive provider resolution and the cycle path used for provider configuration errors.
- When changing interactive-auth handling, check both direct and batch resolution because non-interactive callers must not receive a prompt.
- When changing
json_pathorline, keep post-processing consistent across provider, default, and environment sources. - When changing
envoras_file, check each consumer's filtering and file-lifetime rules after resolution.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A secret names a provider that is not in the active profile | Resolution fails or falls back to the declaration's default when one exists | Define the provider in the effective profile or provide a deliberate default. |
| A provider configuration references an undefined secret | Provider construction fails before the requested secret can be read | Define the referenced secret or expose its value in the environment. |
| Provider references form a cycle | Resolution stops with a cycle error | Keep provider credentials on an acyclic dependency path. |
| A provider requires interactive authentication in non-interactive mode | The provider lookup fails without a prompt | Run the lookup in an interactive context or use a deliberate default. |
| A default references an undefined secret or contains a hard cycle | Batch resolution returns a configuration error | Define every interpolation name and keep defaults acyclic. |
| A configured provider fails without a default on the single-secret path | The provider error reaches the command instead of falling through to the environment | Add a default for controlled fallback or fix provider access. |
| A JSON path is invalid or a line number is out of range | The result fails even when the source secret exists | Validate the source shape and transformation setting together. |
| A required secret resolves to no value | The command stops under if_missing = "error" | Set the required value or choose an explicit optional policy. |
Key files
| File | Why to read it |
|---|---|
| crates/…/secret_resolver.rs | Defines source precedence, default interpolation, batch ordering, post-processing, authentication fallback, and missing-value results. |
| crates/…/config.rs | Defines secret declarations, profile overlays, provider selection, and the effective secret set. |
| crates/…/secret_ref.rs | Defines the configuration shapes for literal strings and named secret references. |
| crates/…/resolver.rs | Explains recursive provider configuration resolution, required and optional references, and provider cycle errors. |
| src/daemon.rs | Shows how callers use the shared single and batch resolver with or without the daemon. |
| src/…/exec.rs | Shows how resolved values become child-process environment values or temporary file paths. |
| src/…/hook_env.rs | Shows shell filtering and session updates after resolution. |
test/secret_resolution_priority.bats | Verifies the source precedence and missing-value contract from a user-facing command. |
test/secret_refs.bats | Verifies provider credentials supplied through secret references and chained providers. |