Daemon and proxy runtime
fnox has two local runtime services with different goals. The daemon keeps selected secret resolutions available across commands for a user session. The proxy lets a child command use destination-scoped credentials without receiving the real secret values. The daemon serves resolution requests, while the proxy uses that resolution to prepare and supervise one child process.
Runtime model
The daemon and proxy sit between the command line and the secret providers. The daemon is a shared background service for repeated reads. The proxy is a short-lived service owned by one fnox proxy run invocation.
Daemon role
The per-user daemon provides memory-only resolution and cache reuse for supported read operations. It communicates through a Unix domain socket or a Windows named pipe. Each request carries the caller's profile, configuration path, working directory, environment, and resolution purpose. This lets one background process serve commands from different project directories without treating them as the same request.
The daemon is used only when the platform supports it and the effective settings allow it. --no-daemon and FNOX_DAEMON=off force direct resolution. FNOX_DAEMON=on forces daemon use when supported, while the configuration normally controls whether supported reads use it.
References: src/daemon.rs• L36-89 src/daemon.rs• L926-940 src/daemon.rs• L1015-1057
Proxy role
The credential proxy gives a child process placeholders instead of real credentials. It accepts local HTTPS CONNECT traffic, checks each request against destination rules, replaces an approved placeholder in the approved header or query parameter, and sends the request to the upstream service. It also replaces real values in response headers and bodies before the child sees them. Rule-domain responses are sent as they arrive, so streaming services can deliver early events while the proxy continues to redact secret values.
The proxy can use either configured secrets or short-lived lease credentials. It keeps the child-facing interface stable while it resolves pending secrets or renews leases when a matching request needs them. Every proxy session has its own access token for proxy clients, so a child must use the session's proxy settings to connect.
fnox proxy run can also place the child in an operating-system sandbox. In that mode, the proxy is the child's only network route and fnox hides its configuration, keys, and common credential locations. Without the sandbox, the proxy still protects the normal child environment and proxy path, but same-user code can bypass those paths unless an outside boundary blocks direct network access and access to fnox state.
References: src/…/plan.rs• L38-55 src/…/policy.rs• L108-128 src/…/server.rs• L94-194 src/…/proxy.rs• L104-110 src/…/proxy.rs• L146-167
Daemon lifecycle
The daemon lifecycle is controlled by the fnox daemon command group. A daemon can be started by an operator or on demand by a supported resolution call. It remains available until it receives a stop request or reaches its idle limit.
Startup and readiness
fnox daemon start checks the daemon for the active resolution context before it starts another process. If no matching daemon is available, fnox launches a detached daemon serve process and waits for its socket or named pipe and status response. A normal daemon-backed read follows the same path: it tries the runtime endpoint first, then starts the background daemon when the endpoint is missing.
The server creates a user-scoped runtime endpoint and rejects a second server for the same context. The endpoint name includes the wire format version and key resolution settings. This keeps incompatible clients and materially different contexts from sharing one service. The wire version also separates clients from older daemons when a change in resolution behavior requires a fresh runtime.
References: src/daemon.rs• L595-675 src/daemon.rs• L677-789 src/daemon.rs• L799-826 src/daemon.rs• L853-877
Status and stopping
fnox daemon status reports whether the daemon for the active context is reachable. When it is running, the result includes its process ID and number of cached entries. --verbose lists each entry's key, profile, purpose, age, and time left on its sliding cache_ttl and absolute max_cache_ttl; --json provides the same status in structured form. Neither output includes secret values. fnox daemon stop sends a shutdown request to that context and treats an already absent daemon as stopped.
Shutdown stops new request acceptance, allows active request tasks a short grace period, and then removes the Unix socket. The Windows named pipe disappears with its last handle. The idle timeout uses the configured duration, with the foreground serve command receiving that value through the daemon process environment.
References: src/…/daemon.rs• L58-94 src/…/daemon.rs• L113-163 src/daemon.rs• L463-480 src/daemon.rs• L583-592 src/daemon.rs• L719-788
Cache clearing
fnox daemon clear clears cached values without stopping the service. It scans the runtime area and sends a clear request to every running daemon context. This is broader than status or stop, which address the context selected by the current command options.
The clear operation can target named secrets. If an older daemon does not understand keyed clearing, callers can fall back to a full clear when they need the selected values removed. A later read can resolve the value again and repopulate the cache.
References: src/…/daemon.rs• L28-33 src/daemon.rs• L482-575 src/daemon.rs• L1154-1171
Resolution coordination
The daemon serializes operations that can affect process-wide resolution state. For each request it temporarily applies the caller's environment and working directory, applies the caller's settings, loads the requested configuration, and restores the prior process state when the request ends.
Batch requests resolve only the requested secrets. A request can include all environment modes when its caller needs them; otherwise daemon-backed resolution limits the set to shell-injectable secrets. The daemon can reuse a cached resolved value when the request purpose, profile, secret declaration, relevant configuration content, and relevant credential environment still match. Missing values are not cache hits, so a later request can retry a provider that may have recovered. A non-interactive request can resolve through the daemon. An interactive cache miss is resolved in the caller and then offered back to the daemon for cache fill. check uses the daemon connection but deliberately bypasses cached values so it can contact providers again.
The daemon also supports cache-only environment reads. These reads return a miss when a lease is involved or when any required root is not cached. They never mint a lease or call a provider.
References: src/daemon.rs• L1116-1321 src/daemon.rs• L1336-1449 src/daemon.rs• L1469-1554 src/daemon.rs• L1589-1760
Proxy command flow
fnox proxy run combines configuration validation, secret resolution, proxy startup, child execution, and cleanup into one bounded flow. fnox proxy rules only validates and displays the effective rules; it does not need to resolve secret values or mint leases.
Command preparation
The proxy command first checks the command and proxy policy. If sandboxing is enabled, it prepares the required operating-system sandbox before resolving any secret. This makes an unsupported or unusable sandbox fail before provider access begins.
The command then gathers the secrets named by proxy rules. It also follows provider environment dependencies and lease parent inputs, so a provider or lease backend can receive the credentials it needs to resolve or mint the requested value. Lease backends are checked before resolution, while lease credentials are minted only when a matching request needs them. The resulting values create a proxy plan with placeholders, child environment mappings, request rules, and destination limits.
The command starts a loopback-only proxy on an available local port, or a sandbox-specific listener when the child runs inside a sandbox. It creates a session certificate authority and a temporary trust bundle that contains the normal system roots plus the session authority. This allows supported child clients to make HTTPS requests through the local interception point.
References: src/…/proxy.rs• L305-355 src/…/proxy.rs• L363-471 src/…/plan.rs• L38-55 src/…/plan.rs• L82-283 src/…/ca.rs• L6-82 src/…/server.rs• L107-163
Child process environment
The child receives placeholders in the names required by the proxy rules. Before launch, fnox removes configured secret names, provider credential-chain inputs, lease inputs, and ambient cloud or local-agent credential settings from the inherited environment. This prevents a child from using an unbrokered credential path instead of the proxy policy.
It then sets the standard proxy and CA variables needed by common HTTP clients. The child also receives FNOX_DAEMON=off and FNOX_NON_INTERACTIVE=1. This prevents the child from starting another daemon-backed resolution path and avoids interactive provider or browser prompts during the proxied command. When sandboxing is enabled, fnox also removes environment values that could expose paths or services outside the sandbox.
The child receives relay settings for fnox mcp when it needs to use the MCP tools served by the live proxy session. The relay uses the session rather than exposing the resolved values in the child environment.
References: src/…/proxy.rs• L11-102 src/…/proxy.rs• L146-167 src/…/proxy.rs• L477-588
Credential session coordination
The proxy keeps a session-wide value map for the credentials named by its rules. A missing secret stays represented by its placeholder. When a request needs it, the proxy can reload the configuration and retry resolution. A value that is replaced or forgotten remains redacted until the session ends, so an earlier request cannot expose an old value in a later response.
Lease rules use the same request path but obtain short-lived credentials from their lease backends. Concurrent requests share one active lease. The proxy renews it before expiry, stops new minting during shutdown, and revokes leases minted by the session. It records enough encrypted lease data for later revocation when configured, but does not make those credentials available to another command.
The proxy can also expose a controlled service to an fnox mcp relay in the child. The relay learns rule metadata, destinations, and placeholders rather than real values. It can pass a value entered by the user back to the live proxy, which validates and uses that value for the rest of the session.
References: src/…/values.rs• L44-68 src/…/values.rs• L107-190 src/…/handle.rs• L1-16 src/…/handle.rs• L41-97 src/…/proxy.rs• L265-283 src/…/leases.rs• L145-199 src/…/leases.rs• L211-316
Request authorization
The proxy first authenticates the child with a session token. It then accepts only the request shape it supports. A matched destination must use HTTPS on port 443. Its exact domain, HTTP method, URL path, and approved header or query parameter must match a rule before a placeholder can become a real value. Query rules compare decoded parameter names and values, then encode only the changed parameter again.
Unmatched destinations follow the egress policy. Strict egress rejects them. Permissive egress tunnels them without credential injection. Configured allowed domains can also permit such tunnels. The proxy resolves destinations once and filters non-public addresses unless they are explicitly allowed. Private-network exceptions can be limited to a port. Wildcard domains match one subdomain label. It rejects ambiguous path encodings and does not follow upstream redirects, which keeps the approved destination boundary intact.
The proxy reads bounded HTTP/1.1 requests. Body-bearing requests require a declared length and remain subject to the request size limit. Rule-domain responses stream to the child with redacted headers and chunked body framing because redaction can change the body length. The proxy holds back only a possible secret match that spans chunks, including percent-encoded and form-encoded forms of query secrets. It sends bodyless responses without body framing and refuses upstream encoded responses that it cannot safely redact.
References: src/…/policy.rs• L45-105 src/…/policy.rs• L268-491 src/…/server.rs• L236-375 src/…/server.rs• L391-595 src/…/tests.rs• L445-740 src/…/tests.rs• L886-1013 src/…/tests.rs• L1193-1292
Process completion
The parent command waits for the child to exit and then shuts down the proxy. Shutdown stops accepting clients and gives active connection handlers a short grace period to finish lease registration and audit records. It then revokes leases minted during the session and flushes the configured audit writer before returning. It removes sandbox mount points before dropping the sandbox state. The temporary CA file and any Unix listener path are owned by the running proxy and are removed when that proxy state is dropped.
Signal handling preserves cleanup and exit semantics. An unsandboxed run forwards termination and hangup signals to the child, while it avoids sending terminal Ctrl-C twice when both processes share the foreground terminal. A sandboxed run stops the child when fnox receives an interrupt so fnox can remove sandbox state. The command returns the child's exit status, including signal-based exits on Unix. When audit is enabled, records can include the method, domain, path, and names of injected secrets. They do not include request headers, request bodies, or secret values.
References: src/…/proxy.rs• L590-715 src/…/server.rs• L48-93 src/…/server.rs• L201-221 src/…/leases.rs• L255-316
Runtime boundaries
The daemon and proxy can cooperate, but they do not share the same lifetime or purpose. A proxy run may use the daemon to resolve its setup values. The child process then runs with daemon use disabled and talks to the short-lived proxy instead.
The daemon is supported on Linux, macOS, FreeBSD, OpenBSD, and Windows. It uses a user-owned runtime location with strict directory and endpoint permissions and peer checks so only the current user can connect. The proxy listens only on loopback unless the sandbox supplies its own listener. Loopback clients must present the session token. Its protection still depends on the child honoring proxy and CA settings when no OS sandbox is used.
For the wider set of long-running surfaces, see Background and interactive runtime. For the terminal UI and Model Context Protocol interfaces that can use daemon-backed resolution, see TUI and MCP interfaces. For the daemon request and response contract, see Daemon client protocol.
Security boundary
The daemon keeps resolved values in process memory and does not persist its cache. Its local endpoint and peer checks protect the IPC channel, but any process with the same user identity remains within the broader local trust boundary.
The proxy removes configured and common ambient credential paths from the child and limits injection to configured routes. It also blocks non-public upstream addresses unless the configuration allows them. A private-network exception can be scoped to a single port. The optional sandbox adds a network and file-access boundary around the child. Without it, the proxy does not prevent direct calls to providers or direct network traffic by a determined same-user process. Use a container, virtual machine, or equivalent boundary for an untrusted agent.
References: src/daemon.rs• L1807-1918 src/…/plan.rs• L12-35 src/…/policy.rs• L108-128 src/…/server.rs• L26-45 src/…/destination.rs• L6-50 src/…/proxy.rs• L363-381 src/…/proxy.rs• L529-588 src/…/tests.rs• L1102-1121
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the daemon request and response wire shapes compatible with clients and already-running background processes. The socket wire version must change when compatibility cannot be preserved.
- Keep the context inputs used for endpoint selection aligned with the settings applied inside a request. A mismatch can send a request to a daemon with the wrong resolution context.
- Keep cache fingerprint inputs aligned with provider authentication and configuration sources. A missing input can return a stale value after credentials or provider state change.
- Keep the rule that missing provider results are not stored as cache hits. Otherwise a temporary provider failure can block later recovery until the cache is cleared.
- Keep keyed cache clearing and its older-daemon fallback aligned with the daemon wire contract. Otherwise refresh can report success while an old value remains in memory.
- Keep proxy session-token creation, child proxy variables, and proxy authentication aligned. A mismatch can make every child request fail or weaken the local client boundary.
- Keep proxy child environment cleanup aligned with each provider's full credential-chain inputs. A new selector, config path, local-agent setting, or TLS setting can bypass the configured proxy policy.
- Keep proxy rule matching, placeholder substitution, response redaction, and child CA variables aligned. A change in one can expose a real value or make supported clients fail.
- Keep streamed response framing aligned with redaction. Redaction can change body length, and a body can contain a value split across upstream chunks.
- Keep destination filtering aligned with both the initial lookup and the upstream client's lookup. A weaker second path can allow a refused address or a DNS rebind.
- Keep private-network allow-list port checks aligned with both tunnel connections and credential-injection connections. A port-scoped exception must not widen into access to other local services.
- Keep lease minting, renewal, ledger recording, and shutdown revocation aligned. A lease that is usable by the child but absent from the ledger can remain active after the proxy exits.
- Keep sandbox readiness checks before secret resolution. A failed sandbox setup must not cause provider access or leave temporary state behind.
- Keep reserved MCP relay environment names separate from proxy rule environment names. A collision can disable the child relay or expose the wrong session metadata.
- Keep daemon-backed proxy setup separate from the child runtime. The child must continue to disable daemon use so its secret access stays within the proxy flow.
- Keep signal handling, child termination, mount cleanup, proxy shutdown, lease revocation, and audit-writer closure in that order. An early process exit can leave temporary state behind or lose a just-minted lease or audit record.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A daemon endpoint exists but belongs to another user or the runtime path is not user-owned | The daemon cannot start or accept the request | Runtime directories and endpoints are checked for ownership and strict permissions. Peer credentials are checked on each connection. |
| A supported read cannot connect to its context daemon | The caller may start a matching background daemon. A second failed connection returns an error | The client distinguishes a missing or refused endpoint from other IPC errors and waits for readiness after startup. |
| A provider returns no value for a cacheable secret | The current request returns no value, but a later request can try the provider again | Only resolved values enter the daemon cache. Missing values remain cache misses. |
| A keyed clear reaches a daemon that does not support that request | A targeted refresh may leave an old value in that older daemon | The caller can fall back to a full clear when required, while broad clear reports older keyed-clear support clearly. |
| A proxy client omits or sends the wrong session token | The proxy returns a challenge or refuses the connection before it can reach an upstream service | The running proxy creates a fresh token. The child receives it in the proxy URL and retries only with that token. |
| A requested sandbox is not available or cannot be prepared | The command fails before it resolves secrets or starts the child | Sandbox support is checked and prepared before secret resolution. The command does not fall back to an unsandboxed run. |
| A proxy rule names an unknown, empty, or unresolved secret | The proxy does not start the child with a usable credential, or refuses the matching request | Rule validation and plan creation require configured, non-empty values when available. Pending values are retried only when a request needs them. |
| A lease backend is missing or its parent credentials are not available | The command fails before it can mint a lease or start the child | Lease backends and their prerequisites are checked before the proxy starts. Required provider and lease inputs are resolved first. |
| A child sends a request outside the rule's domain, method, path, or header/query target | The proxy returns a forbidden response and does not inject the value | The policy checks all route fields and counts placeholder occurrences before replacement. |
| A destination resolves only to a non-public address or to a port outside a private exception | The proxy refuses the connection instead of reaching a local or metadata service | Resolved addresses are filtered against non-public networks and configured private-network exceptions. Port-scoped exceptions are checked against the requested port. |
| A child bypasses proxy environment variables or uses ambient provider credentials | The proxy cannot enforce destination limits for that access path | The command scrubs configured secrets and the full set of known credential-chain inputs. An OS sandbox is required for a stronger network and file-access boundary. |
| A lease mint or renewal fails, or shutdown cannot revoke it | The request is refused or a lease can remain active after the session | Requests share guarded lease state. Failed revocations remain available through the lease ledger or explicit service-side cleanup. |
| An upstream response is encoded or its body read fails after headers are sent | The proxy refuses an encoded response. A failed stream ends without its final chunk, so the client can detect an incomplete body | Responses must be identity-encoded for safe redaction. The proxy sends status and headers first, then streams redacted chunks. |
| A request body has no declared length or exceeds the request limit | The proxy rejects the request before forwarding it | Body-bearing requests require content length and use the request size limit. |
| A signal reaches fnox while a child or sandbox is active | The child can stop without proxy cleanup, or Ctrl-C can be delivered twice | The command registers signal handlers before spawn, forwards signals as needed, stops sandboxed children, and shuts down the proxy before exit. |
| Proxy connection handlers are still active when shutdown begins | A lease or audit record may not be registered before cleanup, or a recent audit record may be missing | The server stops accepting clients, waits up to its handler grace period, and the running proxy closes the audit writer before the command can exit. |
Key files
| File | Why to read it |
|---|---|
| src/daemon.rs | Defines daemon selection, startup, IPC requests, cache coordination, lifecycle, and local security checks. |
| src/…/daemon.rs | Maps the public daemon subcommands to start, status, clear, serve, and stop behavior. |
| src/…/proxy.rs | Shows the command-facing proxy flow from sandbox and rule validation through dependency-aware secret resolution, child environment cleanup, signal handling, and process cleanup. |
| src/…/plan.rs | Turns proxy rules and resolved values into the session policy and child environment. |
| src/…/server.rs | Defines proxy listeners, session authentication, connection-handler lifetime, HTTPS interception, streamed upstream forwarding, audit-drain ordering, and shutdown. |
| src/…/policy.rs | Defines route authorization, placeholder injection, response redaction, and egress decisions. |
| src/…/values.rs | Coordinates pending and replaced values during a live proxy session. |
| src/…/leases.rs | Coordinates lease minting, renewal, ledger records, and revocation at session end. |
| src/…/ca.rs | Defines the per-session trust authority and the CA bundle given to the child. |
| src/…/destination.rs | Defines destination address checks that keep upstream connections within the allowed network boundary. |
| src/…/handle.rs | Defines the limited rule and value interface used by an in-process MCP relay. |