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 / template-evaluation

Template evaluation

fnox evaluates Tera templates in configuration values while it resolves secrets. The result becomes the value of a secret or provider setting, and can then flow into the resolved environment used by commands and other consumers. This page complements configuration and secret resolution, configuration discovery and profiles, secret references and resolution, and encryption and local secret storage.

Template model

Template syntax

Tera is the template language for configuration strings. A string becomes a template when it contains an expression marker ({{), a statement marker ({%), or a comment marker ({#); strings without these markers stay unchanged. Use a Tera raw block when a literal value must contain one of these markers. Template output is not HTML-escaped, so it remains suitable for values such as URLs and names.

The template language is separate from fnox secret interpolation. A value can contain both forms, such as {{ fnox.profile }}-${DB_HOST}. fnox first renders the Tera part and then resolves the ${NAME} secret reference.

References: crates/…/template.rs• L1-27 crates/…/secret_resolver.rs• L561-573 test/templates.bats• L19-30

Template context

The Tera context contains only the active profile selection under fnox. It does not contain resolved secret values and fnox does not export this context as FNOX_PROFILE or any other child-process variable.

NameMeaning
fnox.profileThe highest-priority selected profile. It is default when no profile is selected.
fnox.profilesAll selected profiles in priority order from lowest to highest.

The profile selection comes from the effective configuration used for resolution. This lets one configuration value change with the selected profile without turning profile metadata into a process secret.

References: crates/…/template.rs• L30-43 crates/…/template.rs• L45-60 test/templates.bats• L37-70

Evaluation flow

Secret default evaluation

A secret default is rendered when fnox needs that default during resolution. Provider values have priority over defaults, so a malformed default does not block a valid provider result. When the default is used, Tera rendering occurs before ${NAME} interpolation and before shared post-processing such as extraction.

The resolver treats references in the rendered default as dependencies. It resolves those secrets first, then inserts their values into the default. A conditional Tera branch contributes references only from the branch that the active profile selects.

This diagram shows how a configured default becomes a resolved secret value.

flowchart LR
    A[Raw default] --> B[Tera render with profile context]
    B --> C[Resolve selected ${NAME} references]
    C --> D[Apply secret post-processing]
    D --> E[Resolved secret value]

References: crates/…/secret_resolver.rs• L561-621 crates/…/secret_resolver.rs• L810-827 crates/…/secret_resolver.rs• L915-940 crates/…/secret_resolver.rs• L2251-2274

Provider configuration evaluation

Tera templates also apply to literal provider fields that fnox resolves as part of provider setup. These fields use the same profile context, so a provider setting can follow the active profile before the provider reads it.

credential_command is an exception. fnox leaves this field for the provider-specific command renderer because that renderer needs its own values such as address, path, and namespace. A map entry with a longer field name is not treated as this special field.

References: crates/…/resolver.rs• L128-169 crates/…/resolver.rs• L373-457

Resolution order

The resolver uses the rendered default when it builds the dependency graph. It then resolves secrets in dependency order. Values from an earlier level are made available to later provider resolution, which allows provider credentials and interpolated defaults to work together.

A template is rendered from the raw configuration value each time it is needed. fnox does not render an already rendered result again, which preserves raw blocks and prevents their escaped markers from becoming active later.

References: crates/…/secret_resolver.rs• L567-582 crates/…/secret_resolver.rs• L830-837 crates/…/secret_resolver.rs• L974-1007

Error behavior

Render failures

An invalid Tera expression or an undefined Tera variable returns a configuration error. The error names the value being rendered, such as default of secret 'BAD' or 'profile' of provider 'aws', so the failing configuration area is identifiable.

Unused defaults are lazy. If a provider returns a value, fnox can ignore a bad template in that secret's default. If the default is selected, the template must render successfully or resolution fails.

References: crates/…/template.rs• L49-60 crates/…/secret_resolver.rs• L624-659 crates/…/secret_resolver.rs• L2205-2249 test/templates.bats• L73-86

Dependency failures

After Tera rendering, ${NAME} references must resolve when the default depends on them. An undefined reference or an interpolation cycle produces a configuration error for a required default. If the selected Tera branch does not contain a reference, that unselected branch does not create a dependency.

References: crates/…/secret_resolver.rs• L107-175 crates/…/secret_resolver.rs• L919-940 crates/…/secret_resolver.rs• L1009-1025 crates/…/secret_resolver.rs• L2251-2274

Resolved environment entry

Consumer environment

Template output enters the same resolved secret map as values from providers, defaults, and the ambient environment. The command environment planner then selects the values allowed for the requested scope and assembles the child environment. fnox exec passes those values to the child process; other consumers can use the resolved map without exposing the Tera context itself.

This diagram shows the boundary between template evaluation and process execution.

flowchart LR
    A[Configuration] --> B[Secret resolution]
    B --> C[Rendered resolved values]
    C --> D[Environment plan]
    D --> E[Child process environment]

Resolved values can also be placed briefly in fnox's own process environment when later provider or lease work needs them. That temporary use is separate from the template context and is removed after the planning step. A profile used for rendering is therefore not automatically visible to the child process.

References: src/child_env.rs• L378-418 src/child_env.rs• L460-475 src/…/exec.rs• L125-147 test/templates.bats• L55-70

Change checklist

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

  • Keep the Tera context names and profile ordering aligned between crates/…/template.rs and profile selection.
  • Preserve the ordering between Tera rendering and ${NAME} dependency discovery. Changing it can alter both dependency graphs and final values.
  • Keep provider fields that need their own rendering context excluded from the profile-only pass.
  • Keep resolved template output flowing through the same environment scope and env rules as other secret values.
  • Update error field labels when config value paths change so failures still identify the source value.

Important failure modes

TriggerConsequenceGuard
An undefined Tera variable is used in a selected defaultSecret resolution fails with a configuration error that names the defaultUse only fnox.profile and fnox.profiles in the profile context
A literal {{, {%, or {# is not wrapped in a raw blockfnox parses the value as a template and may fail or remove template syntaxWrap literal markers in {% raw %}...{% endraw %}
A rendered default references a missing secretThe required default cannot resolveDefine the referenced secret or select a branch that does not use it
A default contains a dependency cycleBatch resolution fails with an interpolation-cycle errorKeep ${NAME} dependencies acyclic
A profile template is expected to create FNOX_PROFILE in the childThe child sees no such variable even though the rendered secret contains the profile nameTreat profile metadata as template input, not exported environment state

Key files

FileWhy to read it
crates/…/template.rsDefines the Tera markers, profile context, raw-block behavior, and template error boundary.
crates/…/secret_resolver.rsShows when defaults render, how ${NAME} dependencies are resolved, and how results enter batch resolution.
crates/…/resolver.rsShows template handling for provider fields and the credential_command exception.
src/child_env.rsShows how resolved values are selected and assembled into a consumer environment.
src/…/exec.rsShows how the planned values are passed to a child command.
test/templates.batsDemonstrates profile rendering, interpolation order, raw blocks, child isolation, and failure reporting.