Temporary credential leases
fnox leases provide short-lived credentials for tools that need access to cloud or service APIs. A lease backend obtains credentials from an external system, fnox records the lease and its expiry in a project-scoped ledger, and fnox exec or fnox get makes the resulting values available to a consumer. This model keeps long-lived credentials at the boundary of lease creation and limits the lifetime of the credentials used by downstream commands.
Lease model
Credential issuance
A lease is the result of asking one configured backend to vend credentials for a requested period. The result has three important parts: credential values mapped to their consumer names, a lease ID for later operations, and an optional expiry time.
The backend owns the rules for obtaining the credential and the service owns its actual lifetime. fnox checks the requested duration against the backend limit, then records the expiry returned by the backend rather than treating the request alone as proof of validity.
flowchart LR
A[Lease configuration] --> B[Backend]
C[Master credentials] --> B
B --> D[Short-lived credentials]
D --> E[Project lease ledger]
D --> F[fnox exec or fnox get]
F --> G[Tool or process]
References: crates/…/mod.rs• L17-50 crates/…/lease.rs• L408-439 crates/…/lease.rs• L642-738
Credential delivery
Lease credentials are delivered as named values. fnox exec gives them to the child process and ensures they take precedence over a long-lived secret with the same name. fnox get can return a value when a configured lease backend produces the requested name.
The master credentials used to create a lease are made available only while fnox talks to the backend. fnox removes those temporary values before it starts the child process, so the child receives the lease credentials rather than the credentials that created them.
References: src/…/exec.rs• L91-105 src/…/exec.rs• L147-216 src/…/get.rs• L29-47 src/…/get.rs• L115-230
Lease state
Project lease ledger
The lease ledger is fnox’s local record of leases for one project. It lets later commands find a usable lease without contacting the backend again, while keeping records from different projects separate.
Each record links a lease ID to its backend, label, creation time, expiry, and local status. The record can also hold cached credentials and the name of the encryption provider used to protect them. It keeps a backend configuration identity so a later configuration change cannot reuse credentials issued for a different target. A file lock guards updates, and writes are made in a way that avoids exposing a partial ledger.
The ledger is stored below the fnox state directory. Its file name is derived from the project directory, so the ledger follows the configuration scope instead of the current shell alone.
References: crates/…/lease.rs• L17-41 crates/…/lease.rs• L48-119 crates/…/lease.rs• L122-183
Cached credential reuse
When a command needs a lease, fnox first looks for a cached record for the same backend and backend configuration. It reuses a record only when it is not revoked, has cached credentials, and has enough time left before expiry. The five-minute reuse buffer avoids handing a process credentials that may expire during its work.
Changes to security-relevant backend settings invalidate the match. A change such as a new role target therefore causes a fresh lease, while a duration-only change does not discard still-valid credentials. If cached values are encrypted, fnox must be able to use the same configured encryption provider; otherwise it creates a new lease.
References: crates/…/lease.rs• L226-260 crates/…/mod.rs• L416-434 crates/…/lease.rs• L540-639
Credential cache protection
The ledger may cache the short-lived values so that normal command runs do not repeat a network or login step. If the active default provider supports encryption, fnox encrypts each cached value and records which provider can decrypt it. If no encryption provider is configured, fnox stores the values without that extra protection; if a configured provider is unavailable or encryption fails, fnox skips the cache instead of saving an unusable entry.
This cache is separate from the master credentials. Interactive creation and normal lease resolution use master credentials only to obtain the short-lived result, and the temporary environment is cleared after that work.
References: crates/…/lease.rs• L263-277 crates/…/lease.rs• L471-537 src/…/exec.rs• L95-105 src/…/exec.rs• L213-216
Lease lifecycle
Creation and resolution
Lease creation is available for one named backend or for all configured backends. A duration supplied on the command line overrides the backend setting; otherwise fnox uses the backend setting or a fifteen-minute default. The create command resolves shared secrets before it starts backend work, fails when a required secret cannot be resolved, and can collect missing values interactively for the current operation.
The normal resolution path follows this order:
- Load the project ledger and look for a reusable cached lease.
- Decrypt the cached values when needed.
- If no usable cache exists, check backend prerequisites and create a new lease.
- Cache and record the result.
- Return the short-lived values to the caller.
fnox lease create prints the result in shell, JSON, or environment-export form. Running fnox lease without a subcommand creates leases for all configured backends. fnox exec performs the same resolution as part of starting a command, so most users do not need to create leases by hand. Detailed backend choices and lifecycle rules are in Lease lifecycle and backends.
References: src/…/lease.rs• L83-163 src/…/lease.rs• L216-312 crates/…/lease.rs• L645-740
Listing and status
fnox lease list reads the ledger and reports each tracked lease as active, expired, or revoked. Active means that the record is not revoked and its expiry has not passed. A lease without an expiry is treated as active until it is revoked or becomes stale in ledger maintenance.
Listing is a view of local tracking state. It does not prove that a remote service still accepts a credential, nor does it renew or revoke a lease.
References: src/…/lease.rs• L375-421 crates/…/lease.rs• L203-219
Revocation and cleanup
Explicit revocation targets one lease ID. fnox restores cached credentials when needed so a backend can use them for remote revocation, then asks the configured backend to revoke the lease when that backend supports the action. It marks the local record revoked even when the remote attempt fails, and it removes cached credential values from the ledger.
Cleanup targets all locally tracked leases that have passed their expiry. It makes a best-effort backend call without cached credentials, then marks each expired record revoked so stale local entries do not remain. Some services rely on native credential TTLs and have no separate revoke action; those leases become unusable through expiry even when cleanup has no remote work to perform.
Ledger saves also remove revoked or expired records older than twenty-four hours. This keeps recent history visible while preventing the project state from growing without limit.
References: src/…/lease.rs• L425-517 src/…/lease.rs• L520-579 crates/…/lease.rs• L122-151 crates/…/lease.rs• L190-201
Backend integrations
Backend contract
Every lease backend presents the same high-level contract: create a credential for a duration and label, report the maximum supported duration, and optionally revoke a previously issued lease. The shared contract lets command resolution and ledger tracking stay the same while the backend handles service-specific authentication and response formats.
The configured backend name selects one of the following service patterns:
| Backend family | Credential purpose | Expiry or revocation model |
|---|---|---|
| AWS STS | Assumed-role AWS credentials | Service-issued TTL; revocation is not needed for normal expiry |
| GCP IAM | Impersonated service-account access token | Service-issued TTL; revocation is not needed for normal expiry |
| Azure token | Access token for a configured scope | Azure controls the token lifetime |
| Vault | Values from a Vault secret endpoint | Can use Vault lease revocation when the service provides it |
| Cloudflare | User- or account-scoped API token | Creates a token with an expiry and supports token deletion |
| GitHub App or OAuth | Installation or user access token | GitHub controls the token lifetime; OAuth may use a separate refresh flow |
| Command | Credentials supplied by a local command | The command defines the values and may define its own revoke action |
The detailed service rules and configuration choices belong on Lease lifecycle and backends. This page uses the contract to explain how all backends fit the same lease system.
References: crates/…/mod.rs• L28-50 crates/…/mod.rs• L107-227 docs/…/leases.md• L289-300
Backend boundaries
Backends consume master credentials from the environment or from their service’s normal login path. The lease layer does not need to know whether those credentials came from an encrypted file, a password manager, a keychain, a hardware device, or an interactive prompt.
Each backend declares which environment names it can produce and consume. That relationship allows fnox exec to route lease values to the correct child process and allows fnox get to resolve only when a backend owns the requested name. A backend that cannot satisfy its prerequisites can use a cached lease when one remains reusable; a failed fresh creation is reported instead of silently running without credentials when the lease was expected.
References: crates/…/mod.rs• L229-302 src/…/exec.rs• L107-146 src/…/get.rs• L124-228 src/…/lease.rs• L227-277
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the lease record fields, cache validity rules, and status filters aligned. A mismatch can make a credential appear active while resolution will not reuse it.
- When adding or renaming a produced environment name, update backend routing and the child-process precedence rules together. Otherwise a lease can be created but not reach the intended tool.
- When changing backend configuration fields, preserve the distinction between security-relevant settings and duration-only settings in cache invalidation.
- When changing revoke behavior, keep local marking separate from remote best-effort cleanup. Native-TTL backends and service-backed revocation have different guarantees.
- When changing cached credential protection, keep the recorded encryption-provider identity compatible with later decryption and explicit revocation.
- When changing required backend inputs, keep batch secret resolution, interactive prompting, and prerequisite checks consistent. Otherwise creation can fail before the prompt or report the wrong missing input.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Backend configuration changes after a lease is cached | Old credentials are not reused for the changed backend target | The cache match includes a security-relevant configuration hash |
| Cached lease is within five minutes of expiry | fnox creates or requests a fresh lease instead of risking near-expiry credentials | The reuse check applies an expiry buffer |
| A required master secret cannot be resolved | Lease creation stops before backend work instead of producing a misleading backend error | The create command checks required inputs after batch resolution |
| Backend prerequisites are missing and no usable cache exists | Creation fails, or exec skips that lease with a setup hint when prerequisites are absent | Prerequisite checks run before fresh creation |
| Remote revocation fails | The service credential may remain until its native expiry, while local tracking says revoked | Revoke and cleanup still mark the local record and emit a warning |
| Encryption provider for a cached lease is unavailable | Cached credentials cannot be used, so fnox needs a fresh lease | Decryption failure falls back to fresh creation |
| Lease ledger save fails after remote creation | The credential exists but local tracking cannot revoke or reuse it | fnox warns that the lease is untracked and requires manual attention |
Key files
| File | Why to read it |
|---|---|
| crates/…/lease.rs | Defines the lease record, project ledger, cache rules, credential cache handling, and shared resolution path. |
| crates/…/mod.rs | Defines the common backend contract and the set of supported backend configurations. |
| src/…/lease.rs | Shows the user-facing create, list, revoke, and cleanup lifecycle. |
| src/…/exec.rs | Shows how lease credentials join ordinary secret resolution and reach a child process. |
| src/…/get.rs | Shows how a requested secret name can resolve from a lease backend. |
crates/fnox-core/src/lease_backends/ | Contains the service-specific lease integrations that implement the shared contract. |
| docs/…/leases.md | Provides the user-level lease model, supported backend summary, and operational examples. |