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 / encryption-and-local-secret-storage

Encryption and local secret storage

fnox gives a project several ways to keep secret material outside plain text configuration. It can store encrypted values in the project, keep key material in a local secure store, place resolved values in short-lived files for consumers, and refresh stored ciphertext when keys or recipients change.

Storage boundary

fnox separates a secret's value from the place that owns it. An encryption provider stores ciphertext in configuration and returns plaintext only during resolution. A local storage provider keeps the value in a machine store and leaves a name or key in configuration. A plain provider does neither, so it is suitable only for non-sensitive values and tests.

This boundary lets one project mix local encrypted values with bootstrap material in a keyring or with remote providers. The broader provider model and its remote alternatives are described in Secret provider integrations. The active profile and configuration layers that choose these providers are described in Configuration and secret resolution.

Encrypted configuration values

An encryption provider turns a value into ciphertext before fnox writes the secret declaration. On a later read, the provider uses its key material to decrypt the stored value. The configuration therefore carries the provider name and provider-specific encrypted data rather than the usable secret.

The age provider is the main local file-encryption path. It encrypts for one or more age recipients. Recipients may be native age keys, supported SSH public keys, or age plugin recipients. Cloud KMS and hardware-backed providers use the same provider boundary, but their key access comes from a cloud service or a physical authenticator.

For batch writes, age can protect a group of values with one recipient-wrapped batch key. This keeps the group under the same recipient set while allowing fnox to resolve the values through the normal provider contract.

The fnox set and fnox import flows use the selected provider's encryption capability before saving. A provider that only reads or stores remote values follows a different path and keeps a reference instead of ciphertext. See Secret references and resolution for how the saved provider input becomes a value at read time.

References: crates/…/mod.rs• L44-53 crates/…/mod.rs• L195-228 crates/…/age.rs• L168-279 crates/…/age.rs• L281-363 src/…/set.rs• L184-227 src/…/import.rs• L225-258

Whole-configuration encryption

The fnox encrypt and fnox decrypt commands protect the complete secret map as one age-encrypted configuration value. This is separate from provider-backed secret values: encryption moves the project secrets into the configuration's encrypted data, while decryption restores them to the normal secret map.

The encrypt flow requires age recipients and refuses to replace existing encrypted data. The decrypt flow uses an explicit identity path when given one. Otherwise it can use FNOX_AGE_KEY, the default fnox age identity file, or an SSH identity fallback. Each command writes the changed configuration back only after the corresponding transform succeeds.

This mode is useful when the whole set of project secrets must remain opaque at rest. Provider-backed encryption is more selective because each secret keeps its own provider declaration and resolution behavior.

References: src/…/encrypt.rs• L15-80 src/…/decrypt.rs• L17-87 src/…/decrypt.rs• L90-136

Age key access

Age decryption needs a private identity while encryption needs only the configured recipients. fnox can take the private identity inline from FNOX_AGE_KEY, from a provider-configured identity, or from a key file. If no provider key file is set, it checks the configured legacy setting and then the default ~/…/age.txt path. A direct SSH key fallback is also available to the explicit decrypt path.

An age identity is a provider-backed reference. For example, a keychain entry can hold the age private key, so the project file contains a reference to the keychain item rather than the key itself. fnox resolves that reference before it asks age to decrypt. The resolver detects a provider chain that refers back to itself and stops with a cycle error.

The key source affects where trust and access live. Inline keys fit CI inputs. Key files fit local or SSH-based use. A keychain or hardware provider keeps the key outside the project and can require local user action. Relative key-file paths are tied to the configuration file that declares the age provider.

Age also loads plugin identities through the matching age plugin when a configured identity uses that form. Plugin recipients are handled in the same provider boundary, so encryption and decryption still depend on the matching plugin and its local access flow.

References: crates/…/age.rs• L17-24 crates/…/age.rs• L64-93 crates/…/age.rs• L121-165 crates/…/age.rs• L181-231 crates/…/age.rs• L380-455 crates/…/age.toml• L1-24 docs/…/environment.md• L62-107

Keyring-backed material

The OS keychain provider stores a value in the platform's secure credential store and saves only its lookup name in fnox configuration. It provides a local storage path for bootstrap secrets and can also supply private key material to another provider.

Keychain bootstrap

The keychain uses a service name as its namespace and can add a prefix to each entry name. macOS uses Keychain Access, Windows uses Credential Manager, and Linux uses a Secret Service implementation. fnox initializes the platform store when the provider is first used, so a missing or locked backend appears as a provider access error rather than as a project-file problem.

The common pattern is to keep one age identity in the keychain and encrypt many project secrets with age. This reduces repeated keychain access and keeps the bulk of the project data as shareable ciphertext. Direct keychain-backed secrets remain useful for a small number of bootstrap values that unlock another provider.

References: crates/…/keychain.rs• L10-53 crates/…/keychain.rs• L55-103 crates/…/keyring_store.rs• L1-28 docs/…/keychain.md• L80-103

Hardware-backed encryption

FIDO2 and YubiKey providers derive encryption material from a hardware authenticator. They do not put the derived secret in the configuration. Each encrypt or decrypt operation therefore depends on the matching device and its user-presence or unlock flow.

The resulting ciphertext remains in the same configuration boundary as other encryption providers. The difference is the key access path: a missing device, failed touch, or unavailable authenticator prevents fnox from recovering the value. This makes hardware providers a strong local option, but it also limits unattended use.

References: crates/…/hw_encrypt.rs• L1-5 crates/…/hw_encrypt.rs• L23-45 crates/…/yubikey.rs• L74-95 crates/…/fido2.rs• L160-180

Temporary secret files

Some consumers need a file path instead of a value, such as a cloud SDK that reads a credential file. When a secret sets as_file = true, fnox resolves the secret and changes the consumer-facing value from plaintext to a path for a protected temporary file.

Process-scoped files

fnox exec creates an ephemeral file for each file-mode secret and keeps the file handle alive only for the child process. The file is owner-readable and writable on Unix. It is removed when the command finishes or fnox leaves the execution path.

The environment variable given to the child contains the file path. The child does not receive the secret text under that variable. Unix process replacement cannot be combined with file-mode secrets because replacement needs the file to outlive the fnox process; it also cannot be combined with configured leases.

References: crates/…/temp_file_secrets.rs• L10-57 src/…/exec.rs• L47-62 src/…/exec.rs• L184-205 src/…/exec.rs• L213-216

Session-scoped files

Shell hooks, fnox get, and fnox export use persistent temporary files when a path must remain valid after the command that created it returns. Shell integration records those paths in its session state, removes paths that are no longer needed, and cleans them when the shell session ends.

The file value is still the resolved secret. The persistence only changes its lifetime and consumer interface. These paths are not a durable secret store and should be treated as sensitive local files until fnox removes them or the consumer no longer needs them.

The same ephemeral file behavior is used by the MCP execution surface. Its request keeps the file handle alive for the request rather than exposing the secret value as the returned environment value.

References: crates/…/temp_file_secrets.rs• L60-122 src/…/get.rs• L32-47 src/…/get.rs• L77-88 src/…/export.rs• L95-125 src/…/hook_env.rs• L294-339 src/…/hook_env.rs• L342-357 src/mcp_server.rs• L200-215

Credential commands

A credential command is a configured shell command that produces a short-lived provider credential on standard output. It gives a provider such as Vault a way to obtain a token without placing the token directly in provider configuration or requiring fnox to implement the login method.

Command execution

When a provider has no usable configured token, fnox renders its credential command with provider context and runs it through the platform shell. It passes provider-specific environment values such as the Vault address and namespace. Trimmed standard output becomes the credential. Non-zero exit status, timeout, invalid text, and empty output stop provider authentication.

The result is cached for a short period within the fnox process. The cache key includes the provider, rendered command, and command environment. A caller can invalidate the matching entry when a credential must be fetched again. This keeps repeated reads efficient without making the credential a permanent local secret.

References: crates/…/credential_command.rs• L9-30 crates/…/credential_command.rs• L31-105 crates/…/credential_command.rs• L108-161 crates/…/vault.rs• L85-149

Decrypt and re-encrypt flows

Decryption is normally part of secret resolution, so fnox get, shell loading, export, and command execution return or pass usable values without first creating a decrypted copy of the configuration. Re-encryption is a separate migration flow for changing the protection applied to stored values.

Read-time decryption

When fnox resolves a secret backed by an encryption provider, it passes the stored provider value to that provider. The provider recovers plaintext only in memory, after any provider settings or key references have been resolved. The result then follows the normal consumer rules: direct output, environment injection, or a temporary file path.

Age can resolve both individual ciphertext values and batch values. For a batch value, it first recovers the shared key through age and then resolves the requested value through the same encryption provider. This keeps batch reads within the normal resolution path.

This model keeps encrypted values at rest while allowing the rest of fnox to use one resolution contract. A key mismatch, malformed ciphertext, missing key material, or unavailable hardware fails at the provider boundary. A provider-backed identity can add another decryption step before the target secret is read.

References: crates/…/mod.rs• L171-201 crates/…/age.rs• L95-117 crates/…/age.rs• L324-363 crates/…/age.rs• L366-481 crates/…/resolver.rs• L66-125 crates/…/secret_resolver.rs• L473-569

Recipient rotation

fnox reencrypt updates ciphertext after an encryption provider's configuration changes. This is needed when a new recipient must read existing values or an old recipient must lose access. The command selects eligible secrets, decrypts each value through its current provider, encrypts it with the current provider settings, and writes the new ciphertext back to each source file and its owning profile.

The command can limit work by secret key, provider, or regular-expression filter. It supports a dry run and asks for confirmation unless forced. It uses raw provider values rather than post-processed results, so settings such as json_path continue to describe the same encrypted source after rotation. It also clears stale sync data for each rewritten secret and removes resolved plaintext from the process environment before it writes results.

This diagram shows the protection change without exposing plaintext as a stored intermediate.

flowchart LR
    A[Stored ciphertext] --> B[Current provider decrypts]
    B --> C[Plaintext in process]
    C --> D[Current provider encrypts]
    D --> E[Updated ciphertext in source file]

References: src/…/reencrypt.rs• L40-143 src/…/reencrypt.rs• L172-249 src/…/reencrypt.rs• L251-316 docs/…/reencrypt.md• L3-31 test/reencrypt.bats• L12-60

Remote-to-local sync

fnox sync is the related migration flow for moving values from a remote provider into an encryption provider. It resolves the source value, encrypts it with the selected target provider, and records the encrypted form as sync data in the chosen configuration layer. Future resolution can use that local encrypted copy according to the normal resolver rules.

Sync and re-encryption solve different problems. Re-encryption keeps the same provider role while changing its current key or recipient set. Sync changes where a value is protected and can target the project file, a local override, or the global configuration.

References: src/…/sync.rs• L12-44 src/…/sync.rs• L75-109 src/…/sync.rs• L222-231 src/…/sync.rs• L233-311 src/…/mod.rs• L172-179

Change checklist

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

  • Keep each encryption provider's capability aligned with its actual write and read behavior. This controls whether set, import, sync, and reencrypt store ciphertext or a remote reference.
  • Keep age identity precedence aligned across provider resolution, environment settings, key-file paths, and the whole-configuration decrypt command.
  • Keep provider-backed identity resolution acyclic. A new key source must preserve the cycle checks used for nested provider references.
  • Keep age plugin recipient and identity handling aligned with the matching plugin's command and access flow.
  • Keep whole-configuration encrypt and decrypt transformations aligned with the configuration fields that hold plaintext secrets and encrypted data.
  • Keep temporary-file lifetime aligned with the consumer. Process-scoped execution, shell sessions, exports, and MCP requests do not have the same cleanup boundary.
  • Keep as_file behavior aligned across get, exec, export, shell hooks, leases, and MCP. A change that returns plaintext in one path can break file-based SDK contracts or expose a value.
  • Keep credential-command template context, environment inputs, timeout, cache, and invalidation behavior aligned with every provider or lease backend that uses it.
  • Keep raw-value handling in sync and re-encrypt flows. Re-encrypting an extracted JSON field instead of the original value can make later resolution fail.
  • Keep source-file and profile write-back rules aligned with layered configuration. A protected value must return to the file and section that own its declaration.

Important failure modes

TriggerConsequenceGuard
An age identity does not match any configured recipientExisting ciphertext cannot be readUse the matching private key or add the identity's public recipient and re-encrypt
An age key file path is moved without updating the declaring configurationProvider setup fails before decryptionKeep the path relative to the provider's config file or use an absolute path
A keychain backend is locked or unavailableKeychain-backed secrets and age identities cannot resolveUnlock the platform store and provide its required backend or session service
A hardware authenticator is absent or rejects the user actionHardware-encrypted values cannot be read or writtenAttach and unlock the matching device in an interactive context
A configured age plugin is missing or cannot complete its access flowPlugin-recipient encryption or decryption failsInstall the matching age plugin and complete its required local access step
Whole-configuration encryption has no age recipientsfnox encrypt refuses to change the configurationConfigure at least one age recipient before encrypting
Whole-configuration decryption has no usable identityfnox decrypt cannot restore the secret mapPass an identity path or provide FNOX_AGE_KEY, the default identity file, or the SSH fallback
A file-mode secret is used with Unix process replacementfnox exec --replace refuses to runUse normal child-process execution or pass the needed file through another supported path
A persistent temporary file is removed while its consumer still runsThe consumer loses access to its credential fileUse the command or shell lifetime that owns the file and do not treat the path as durable storage
A credential command times out, exits with an error, or prints no tokenProvider authentication failsMake the command finish within the timeout and print one usable credential to stdout
Recipients change but stored ciphertext is not re-encryptedNew recipients still cannot decrypt old valuesRun fnox reencrypt for the affected provider and profile
Re-encryption cannot resolve one selected secretThe migration stops before writing a complete safe resultRestore the old provider's key access and resolve the secret before retrying

Key files

FileWhy to read it
crates/…/mod.rsDefines the encryption, storage, and read boundaries shared by providers.
crates/…/age.rsShows age recipient handling, batch protection, and the key-source path used for decrypt and encrypt operations.
crates/…/secret_ref.rsDefines provider-backed references used to obtain key material from another provider.
crates/…/keychain.rsShows how local OS keychain values become provider inputs or stored secret values.
crates/…/keyring_store.rsShows platform keyring setup and retry behavior.
crates/…/hw_encrypt.rsShows the shared boundary for hardware-derived ciphertext.
crates/…/temp_file_secrets.rsDefines protected ephemeral and persistent secret-file lifetimes.
src/…/encrypt.rsShows the whole-configuration encryption command.
src/…/decrypt.rsShows the whole-configuration decrypt command and its identity fallbacks.
src/…/exec.rsShows how resolved file-mode secrets become child-process paths and when cleanup occurs.
src/…/hook_env.rsShows shell-session file creation and cleanup.
crates/…/credential_command.rsDefines credential-command rendering, execution, timeout, caching, and invalidation.
src/…/reencrypt.rsDefines recipient and provider rotation for stored ciphertext.
src/…/sync.rsDefines remote-to-local encryption and sync placement.
src/…/set.rs and src/…/import.rsShow the write paths that encrypt values before saving them.
docs/…/keychain.mdExplains the recommended keychain bootstrap pattern for age.
docs/…/reencrypt.mdLists the user-facing re-encryption controls.