Secrets Management
Netherframe provides distinct mechanisms for passing secrets in, generating secrets in-process, keeping short-lived secrets out of state, and masking sensitive values in diffs, logs, JSON output, and TUI recordings.
Quick decision table
| Need | Use | Stored in state? |
|---|---|---|
| Pass an existing secret into an app factory | Secret[str] input via ++@<(...) or nf.sdk |
Salted digest only (in saved plans / deployment inputs) |
| Generate a password, hex token, UUID, or TLS CA + cert with no external provider | GeneratedValue (and write_only_params for CA keys) |
Generated value yes (marked sensitive); write_only_params never |
| Pass a secret to a provider attribute without ever storing it in plans or state | Provider write_only attribute (value_wo + value_wo_version) + EphemeralResource |
Never (null in plans and state) |
| Supply a PostgreSQL state backend password | --postgresql-password-file <(...) or password_source= callable |
Never |
| Export a secret output safely | Output(..., sensitive=True) |
Yes (masked as [secret] unless --show-secrets) |
1. Passing secrets into an app (Secret[T])
Annotate sensitive factory parameters with nf.core.Secret[T]:
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Output, Provider, Resource, Secret, Stack
def identity(client_secret: Secret[str], url: str = "https://sso.example.com") -> App:
with App(nf_id="identity") as app, Stack() as sso, BindContext:
keycloak: Bind = Provider(
nf_type="keycloak",
url=url,
client_id="nf-admin",
client_secret=client_secret,
)
realm: Bind = Resource(nf_type="keycloak_realm", nf_provider=keycloak, realm="acme", enabled=True)
realm_id: Bind = Output(value=realm.output.id)
return app
- Refused on CLI argv:
nf plan --app identity ++client_secret=oopsfails immediately so secrets never land in shell history orpsoutput. - Pass via process substitution or file:
nf apply --app identity ++@<(printf '{"client_secret": "%s"}' "$KEYCLOAK_SECRET") - Pass from Python (
nf.sdk):Project().apply(app="identity", inputs={"client_secret": secret})accepts secrets directly in memory without touching disk. - Saved plans & state: Saved plans and recorded deployment inputs store only a salted
HMAC digest of
Secret[T]inputs, never plaintext; when applying--plan-file, supply the secret again and Netherframe verifies the digest matches.
2. Generating passwords and TLS certs in-process (GeneratedValue)
GeneratedValue runs inside Netherframe's built-in provider—no hashicorp/random or
hashicorp/tls binary to install or cache:
# coding: nf_autoid
from nf.core import App, Bind, BindContext, GeneratedValue, Output, Stack
def credentials(rotation: str = "2026-11") -> App:
with App(nf_id="credentials") as app, Stack() as pki, BindContext:
db_password: Bind = GeneratedValue(
generator="password",
params={"length": 32, "min_special": 2, "override_special": "-_!"},
keepers={"rotation": rotation},
)
ca: Bind = GeneratedValue(
generator="tls_ca",
params={"common_name": "Internal CA", "validity_period_hours": 87600, "early_renewal_hours": 720},
)
cert: Bind = GeneratedValue(
generator="tls_cert",
params={"ca_cert_pem": ca.value("cert_pem"), "common_name": "api.internal", "dns_names": ["api.internal"]},
# Write-only: used during signing, never persisted in cert's state entry
write_only_params={"ca_private_key_pem": ca.value("private_key_pem")},
keepers={"rotation": rotation},
)
password_out: Bind = Output(value=db_password.result, sensitive=True)
cert_pem: Bind = Output(value=cert.value("cert_pem"))
return app
See Generated Values and the runnable
zero-cloud example examples/generated_secrets.
3. Write-only attributes and ephemeral resources (zero-state secrets)
When a provider schema marks an argument write_only (for example,
aws_ssm_parameter.value_wo or aws_secretsmanager_secret_version.secret_string_wo):
- Netherframe sends the value only in the provider configuration request and records
nullin saved plans and state. - Pair it with the companion version argument (
value_wo_version=2) to rotate the value explicitly. - Values produced by
EphemeralResourceconstructs (opened during a run and closed at the end) may flow only intowrite_onlyarguments or other ephemeral resources—never into plans, outputs, or state.
4. PostgreSQL backend passwords
PostgreSQLGraphBackend never accepts a password as a CLI flag or constructor string. Pass
it through either:
- A mounted secret file or process substitution:
nf --postgresql-password-file /run/secrets/pg-password apply --app parameters nf --postgresql-password-file <(vault kv get -field=password secret/nf) apply --app parameters - A Python callable (
password_source=):from nf.backends.postgresql import PostgreSQLGraphBackend def fetch_password() -> str: # In production, call AWS Secrets Manager, Vault, or GCP Secret Manager here return "fetched-at-runtime" backend = PostgreSQLGraphBackend( state_id="parameters", host="db.internal", database="netherframe", username="nf_apply", ssl_mode="verify-full", password_source=fetch_password, )
5. Masking in diffs, JSON, logs, and TUI recordings
nf plan --diffand--json: Attributes marked sensitive in the provider schema render as(sensitive). If no cached schema is available to determine sensitivity, values render as(hidden: sensitivity unknown)by default so logs stay safe. Pass--show-secretsonly in trusted local terminals.nf apply/Outputs:: Sensitive outputs print as[secret]unless--show-secretsis given.- Provider diagnostics: Registered sensitive values and
Bearertokens are scrubbed from provider error messages before display. nf tuiandnf tui --record: Sensitive attributes remain masked in the TUI until explicitly revealed, and session recordings mask values from state automatically.
6. Protect state files, checkpoints, and saved plans
Just like Terraform, any non-write-only sensitive resource attribute (such as a generated password or RDS master password) is stored in plaintext inside state, checkpoints, and saved plans. Always:
- Enable server-side encryption (KMS/SSE) and strict IAM/RBAC on remote state buckets and PostgreSQL databases.
- Keep
.nf.out/and*.plan.jsonout of Git (add to.gitignore). - Give CI plan artifacts tight permissions and short retention windows.