Command execution and environment injection
fnox turns selected resolved secrets into command input or human-readable output. exec creates an environment for a target process, get returns one value, list describes the configured set, and export serializes values for another tool or shell. These paths share profile selection and secret resolution, but each path applies its own exposure and lifetime rules. See Execution and environment integration for the parent model, Environment inspection and serialization for output formats, Shell hooks and activation for the interactive shell path, and Secret exposure safeguards for the safety model.
Command data flow
Secret selection and resolution
The command starts with the effective secrets for the selected profiles. A shared resolver obtains values from their configured sources and applies the command's missing-value policy. --only narrows the selected roots and avoids fetching unrelated providers, while --except removes matching secrets from the command result after selection. Dependencies needed to resolve a selected secret can still be fetched, but they are not passed to the command unless they are selected themselves.
--refresh re-fetches named profile secrets before the environment plan is built; other secrets can continue to use the daemon cache. Lease resolution follows the selection filter, so a lease runs only when its produced variable is selected. The command then decides whether each resolved value may cross its output boundary.
The environment mode is the main boundary:
| Mode | exec process | Shell-oriented export | get and list --values |
|---|---|---|---|
true or unset | Included | Included | Available |
"exec" | Included | Excluded by default | Available |
false | Excluded | Excluded by default | Available |
The --all export option widens export selection. It does not change the secret's configured mode for other commands. A missing value can stop a command when its policy is error; warn and ignore allow the command to continue without that value.
References: crates/…/config.rs• L212-247 crates/…/config.rs• L517-546 src/daemon.rs• L194-231 src/…/exec.rs• L126-189 src/…/export.rs• L74-92
Consumer representations
Each consumer presents a resolved value in the form that its next system expects. A normal secret remains text, while an as_file secret is represented by a path to a restricted temporary file. This lets a program that needs file input receive a path instead of a raw value in its environment or output.
| Consumer | Primary result | File-backed result |
|---|---|---|
exec | Child environment variable | Temporary path valid while the command runs |
get | Printed value | Persistent path printed to the terminal |
list --values | Table value | The resolved value is shown as a value |
export | Serialized value | Persistent export file path |
The command paths do not all share the same file lifetime. exec owns its files for one command invocation, while get and export create files that remain after the command returns.
References: crates/…/temp_file_secrets.rs• L10-64 src/…/exec.rs• L188-211 src/…/get.rs• L58-97 src/…/get.rs• L249-267 src/…/export.rs• L94-125
Process execution
Child process invocation
fnox exec is the main injection path. It resolves the active profile before launching the requested command, keeps inherited environment values unless the command policy removes them, and adds permitted resolved secrets to the target environment. The command receives lease-issued credentials when configured, and those credentials take precedence over ordinary secrets with the same environment key.
The normal process path follows this sequence:
flowchart LR
A[Command and active profiles] --> B[Resolve selected secrets]
B --> C[Resolve configured leases]
C --> D[Build target environment]
D --> E{Secret representation}
E -- Text --> F[Set environment value]
E -- File --> G[Create temporary file and set path]
F --> H[Start target command]
G --> H
H --> I[Wait and return target status]
The target is not started when required resolution fails. When the target exits, fnox returns its status and removes command-scoped temporary files. On Unix, signals received during the normal wait path are forwarded to the child.
References: src/…/exec.rs• L11-29 src/…/exec.rs• L163-211 src/…/exec.rs• L262-283 src/…/exec.rs• L336-367
Environment boundary
The target must receive the resolved application secrets, not the credentials that fnox used to resolve or decrypt them. The command path therefore removes ambient age identity variables in replacement mode and removes values whose mode forbids exec injection. Explicitly selected secrets are applied after this cleanup, so a configured secret can intentionally use a name that fnox normally reserves for resolution.
Lease creation may need master credentials in fnox's temporary process environment. That setup is removed before the target starts, while lease credentials are kept in the target command environment. Lease keys are recorded before ordinary secrets are applied, so an ordinary secret cannot overwrite a short-lived credential with the same name.
References: src/…/exec.rs• L191-211 crates/…/lease.rs• L263-277 crates/…/lease.rs• L441-468
Output redaction
Optional execution redaction protects secret values in non-terminal output streams. When enabled, fnox pipes stdout and stderr through separate filters so interactive terminals remain unchanged, and it does not redact empty values or values shorter than three characters. Redaction is a display safeguard rather than a process boundary because the target can transform a secret before printing it.
The output readers continue draining a stream after a downstream write error when possible. This prevents the child from blocking on a full pipe, while a failed copy makes a successful command fail instead of reporting misleading success. --replace cannot use explicit redaction, and configured redaction is also rejected when replacement would need to filter a non-terminal stream.
References: src/…/exec.rs• L26-30 src/…/exec.rs• L137-145 src/…/exec.rs• L224-265 src/…/exec.rs• L285-351
Process replacement
On Unix, fnox exec --replace makes the target command take over fnox's process instead of running as a child. The target keeps the same process ID and receives signals as the replacement process. Its exit status becomes fnox's exit status because fnox no longer remains as a parent after replacement.
Replacement is limited to values that can be carried directly in the target environment. It rejects file-backed secrets, credential leases, and incompatible redaction before provider resolution starts. While fnox resolves the replacement environment, default SIGINT and SIGTERM handlers exit with the matching signal status; after replacement, the target owns those signals. Non-default handlers are left unchanged.
References: src/…/exec.rs• L96-104 src/…/exec.rs• L121-160 src/…/exec.rs• L213-222 src/…/exec.rs• L442-466 test/exec_replace.bats• L93-128 test/exec_replace.bats• L253-276
Value and inventory operations
Single-value retrieval
fnox get KEY is the direct value interface. It can read a secret regardless of its environment mode, which makes it the intended access path for values marked env = false. It prints the resolved text, optionally decodes base64, or prints a persistent file path when the secret is file-backed. The separate --file form reads a configured profile file rather than resolving a secret.
The command checks lease declarations before ordinary profile secrets. If a lease produces KEY, the last matching lease wins. A plaintext cached lease credential can satisfy the request without secret resolution or provider work. An encrypted cache entry or a new lease first resolves the profile secrets needed by the lease and its cache-encryption provider, makes them available only for that lookup, and then decrypts the cached credential or creates a fresh lease. If the cached credential cannot be used, lease resolution can fall back to fresh creation. A lease that does not produce KEY is a contract error rather than an empty result.
For an ordinary secret, get first tries to resolve the requested value alone. If that attempt needs credentials held by other profile secrets, it resolves the needed dependency set and retries with those credentials available. Credentials already supplied in the process environment are preserved. With if_missing = warn or ignore, an unavailable ordinary value produces no stdout value and exits successfully.
References: src/…/get.rs• L58-97 src/…/get.rs• L99-145 src/…/get.rs• L164-247 src/…/get.rs• L249-285 src/…/get.rs• L287-434 src/…/get.rs• L436-448 docs/…/get.md• L3-19
Secret inventory
fnox list shows the effective secret declarations without resolving values by default. It helps an engineer inspect names, source types, provider keys, descriptions, and optional source file paths. The --values form asks the resolver for a batch of values and adds the available results to the table.
The inventory preserves the configured order. When a requested value is unavailable, the table shows <not available> instead of stopping the whole inventory. The hidden completion form emits only names, so shell completion does not need secret values. The table can also show the source file for each declaration when requested.
References: src/…/list.rs• L12-18 src/…/list.rs• L110-173 src/…/list.rs• L205-345 docs/…/list.md• L3-22
Export boundary
Serialized environment output
fnox export creates a portable representation of the resolved secret set. By default it includes secrets allowed in shell use and writes to standard output or a chosen file. The output can use dotenv-style KEY=value, sourceable POSIX shell assignments, JSON, YAML, or TOML.
The shell format quotes values for shell use. The env format quotes values for dotenv readers and protects dollar expressions from interpolation where possible; it does not promise sourceable shell syntax. JSON, YAML, and TOML preserve the values as structured data. Optional headers add profile, time, and count metadata to environment and shell output.
References: src/…/export.rs• L12-51 src/…/export.rs• L135-174 src/…/export.rs• L176-273 docs/…/export.md• L3-40
Export selection and persistence
Export is an environment injection surface because other tools may evaluate or source its result. It excludes env = "exec" and env = false secrets unless --all is present, and it filters before resolution so excluded secrets do not trigger provider work or authentication.
When export includes an as_file secret, it writes the raw value to a restricted persistent temporary file and places the path in the exported map. If file creation fails, export warns and falls back to the raw value. This fallback preserves output but reduces the protection normally provided by file-backed delivery.
References: src/…/export.rs• L66-92 src/…/export.rs• L94-125 crates/…/temp_file_secrets.rs• L60-121 test/env_mode.bats• L47-61
Failure boundaries
Resolution and command start
Resolution happens before command invocation. The selected if_missing behavior controls whether an unavailable value aborts the operation or produces an absent value. In strict mode, exec and export fail before their downstream action; in warning or ignore mode, they can complete without the missing secret.
References: src/…/exec.rs• L176-189 src/…/export.rs• L83-92 test/exec_if_missing.bats• L9-93 test/export_if_missing.bats• L9-96
Credential and file lifetime
Temporary resources are part of the consumer contract. Command files must remain available until the target exits, while persistent files can outlive the creating command. Lease master credentials must be removed before the target starts, and lease output must not be overwritten by a same-named ordinary secret.
References: src/…/exec.rs• L191-211 crates/…/lease.rs• L263-277 crates/…/temp_file_secrets.rs• L10-121
Output forwarding
Redacted output uses background readers for stdout and stderr. If a reader becomes idle after the child exits because another process still holds the pipe, fnox stops waiting after its grace period; it does not cut off a reader that is still moving data or writing to a slow consumer.
References: src/…/exec.rs• L285-351 src/…/exec.rs• L371-439
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the three-way environment mode contract aligned across configuration,
exec, shell-oriented export, and hook consumers. - Keep
--only,--except, and--refreshaligned with provider selection, dependency resolution, lease selection, and daemon-cache behavior. - Preserve the order of environment cleanup and explicit secret injection so reserved resolver variables cannot leak while intentional configured names still work.
- Keep lease-produced environment keys ahead of ordinary resolved secrets. A collision can silently replace short-lived credentials with long-lived ones.
- Keep
as_filelifetime rules distinct for child commands, direct retrieval, and export. A change to one path must not shorten or expose another path's files. - Keep
--replacevalidation ahead of provider resolution. Otherwise a rejected mode can still cause authentication prompts or external calls. - Keep replacement signal setup limited to the resolution window and preserve the target's direct signal ownership after process replacement.
- Keep redaction limited to non-terminal streams and preserve its pipe-drain and copy-error behavior. Otherwise interactive commands can break or lost output can look successful.
- Keep each export format's quoting contract stable for its downstream reader. Shell-sourceable output and dotenv output are different interfaces.
- Keep
get's two-stage dependency lookup from overwriting credentials already supplied by the user. Otherwise a provider may authenticate with a different credential than the one the user selected. - Keep
get's lease cache and fresh-lease paths aligned with the credentials required by both the lease backend and cache encryption provider. Otherwise direct retrieval can fail or create avoidable provider calls. - Keep lease lookup's last-match behavior and its contract error when the lease does not produce the requested key. Otherwise direct retrieval can disagree with command execution.
- Keep
list --valuesas an explicit resolution path. The default inventory must remain useful without provider access, and an unavailable value must remain visibly distinct from an empty value.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
Required secret resolution fails before exec | The target command does not start | Set an intentional if_missing policy and resolve all required providers before invocation. |
--only excludes a lease-produced variable | The lease does not run and its credential is absent | Select the variable produced by the lease when the command needs that credential. |
Secret uses env = "exec" and is expected in an exported shell environment | The secret is absent from export by default | Use fnox exec or pass --all when export is the intended boundary. |
--replace is used with a file-backed secret, lease, or incompatible redaction | The operation is rejected before the target runs | Use normal fnox exec when fnox must own files, lease state, or output filtering. |
| A lease credential key matches an ordinary secret key | The target could receive the wrong credential | Preserve lease-key precedence during environment construction. |
An as_file export file cannot be created | Export falls back to placing the raw value in output | Treat file creation failure as a security-relevant warning and fix the temp-file path or permissions. |
| A command exits because of a signal | The caller may lose the target's standard signal status | Use normal exec for child signal forwarding or --replace when direct process signaling is required. |
A non-default SIGINT or SIGTERM disposition is present during --replace | fnox does not replace that handler and the caller's signal policy remains in effect | Use the normal child mode or start replacement with the intended default signal disposition. |
| Redaction is enabled for a non-terminal stream and the downstream reader or pipe fails | Output can be lost or the command can fail even after the child reports success | Keep draining the child stream after downstream write failures and treat copy errors as execution errors. |
A dotenv value contains $ and is consumed by an interpolating reader | The reader can expand part of the secret instead of preserving it | Use the generated dotenv quoting or choose the sourceable shell format for shell evaluation. |
A get dependency retry replaces a credential already present in the process environment | The provider can read an unintended credential | Preserve supplied credentials and inject only unresolved dependencies. |
| A lease declares the requested key but does not return it | get returns a lease contract error instead of a value | Keep lease output names aligned with the requested key. |
list --values cannot resolve one declared secret | The inventory shows <not available> for that row | Treat the marker as a missing value and inspect the source or provider without assuming the value is empty. |
Key files
| File | Why to read it |
|---|---|
| src/…/exec.rs | Primary flow from selection and resolution through environment construction, redaction, process replacement, and command status. |
| src/…/get.rs | Direct value retrieval, configured-file retrieval, dependency injection for provider access, and lease-produced credential handling. |
| src/…/list.rs | Non-secret inventory output, optional batch value display, configured order, and completion output. |
| src/…/export.rs | Export selection, formats, quoting, and file-path conversion. |
| crates/…/config.rs | Secret environment modes and as_file policy. |
| src/daemon.rs | Shared cache and batch resolution handoff used by command consumers. |
| crates/…/lease.rs | Temporary environment cleanup and lease credential setup. |
| crates/…/temp_file_secrets.rs | Restricted temporary file creation and lifetime primitives. |
| docs/…/exec.md | User-facing command and replacement semantics. |
test/env_mode.bats | Cross-command guarantees for shell, exec-only, and hidden secrets. |
test/exec_replace.bats | Process identity, signal, status, and replacement constraints. |