Expand description
Monosecret - A declarative secrets manager for development workflows
This library provides a type-safe, declarative way to manage secrets and environment variables across different environments and storage backends.
§Features
- Declarative Configuration: Define secrets in
monosecret.toml - Rust-first Declarations: Build a
Specdirectly in Rust (0.20+) - Multiple Providers: Keyring, dotenv, environment variables, Keeper Secrets Manager (0.18+)
- Profile Support: Different configurations for development, staging, production
- Type Safety: Optional compile-time code generation for strongly-typed access
- Validation: Ensure all required secrets are present before running applications
§Example
ⓘ
// Generate typed structs from monosecret.toml
monosecret_derive::declare_secrets!("monosecret.toml");
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load secrets and configure provider/profile
let mut spec = Secrets::load()?;
spec.set_provider("keyring"); // Can use provider name or URI like "dotenv:/path/to/.env"
spec.set_profile("development");
// Validate and get secrets
let secrets = match spec.validate()? {
Ok(validated) => validated,
Err(errors) => return Err(format!("Missing secrets: {}", errors).into()),
};
// Access secrets (field names are lowercased)
println!("Database: {}", secrets.resolved.secrets.get("DATABASE_URL").unwrap());
// Access profile and provider information
println!("Using profile: {}", secrets.resolved.profile);
println!("Using provider: {}", secrets.resolved.provider);
Ok(())
}Modules§
Structs§
- Caller
Context - Describes the software integration that requested secret access.
- Constraint
Violation - A failed cross-secret presence constraint.
- Credential
Source - Where one credential required by a provider comes from.
- Discovery
Context - Context supplied when a provider discovers secret declarations.
- External
Provider - A core provider backed by one
monosecret.provider/1endpoint. - Manifest
- Secret-value-free manifest for SDK code generation.
- Manifest
Profile - Effective profile metadata included in a
Manifest. - Manifest
Project - Project metadata included in a
Manifest. - Manifest
Secret - Effective secret metadata included in a
Manifest. - Native
Address - Native coordinates of one externally managed secret: the value of a
secret’s
reffield. - Native
Address Template - A provider-alias template for native secret coordinates (0.19+).
- Platform
Endpoint Security - Profile
- One profile in a Rust-built
Spec. - Project
Defaults - Project-wide defaults for provider-backed secrets (0.4.0+).
- Provider
Alias - A provider alias: either a leaf provider or, in Monosecret 0.17+, a cached fallback route.
- Provider
Cache - Cache policy for a cached provider alias. Available since Monosecret 0.17.
- Provider
Config Structured - Structured project provider configuration.
- Provider
Credential Principal - The host-selected provider instance a credential request belongs to (0.4.0+).
- Provider
Credential Request - Semantic credential request made by an external endpoint (0.4.0+). One semantic provider credential requested while an endpoint is initializing or refreshing its authentication (0.4.0+).
- Provider
Dependency - A secret needed to construct a provider.
- Provider
Discovery - Explicit inputs to external-provider discovery.
- Provider
Endpoint - A resolved provider endpoint and its fixed executable identity.
- Provider
RefDetail - Detailed provider reference with relative location hints.
- Provider
Value - A provider value with optional authoritative validity and revision metadata.
- Resolution
Report - A complete, value-free snapshot of one resolution pass over a profile.
- Resolve
Response - A complete value-carrying resolution result for one profile.
The default
Stringpayload is the JSON wire format; Rust byte resolution usesResolveResponse<SecretBytes>(0.4.0+) without a Serde representation. - Resolved
- Container for resolved secrets with their context.
- Resolved
Secret - One resolved secret. Exactly one of
valueorpathis set:pathwhen the secret is materialized to a temp file (as_path),valueotherwise. The default inline type isStringfor text/JSON APIs. Byte resolution APIs usecrate::SecretBytesstarting with 0.21. - Revision
- A provider-defined identity and generation token, or a resolver-derived token for the logical value. Equality is meaningful; ordering is not.
- Secret
- One secret declaration in a Rust-built
Spec. - Secret
Bytes - An owned, zeroizing secret byte sequence.
- Secret
Extract - Selects one logical secret from a structured stored value.
- Secret
Request - Provider-relative lookup hints derived from a
ProviderRef. - Secret
Resolution - The resolution outcome for one declared secret. Never carries the value.
- Secrets
- The main entry point for the monosecret library
- Spec
- A validated, format-independent description of a Monosecret project.
- Spec
Builder - Rust-first construction of a
Spec. - Validated
Secrets - Container for validated secrets with metadata
- Validation
Errors - Container for validation errors
Enums§
- Address
- How a provider operation addresses a secret.
- Constraint
Kind - The kind of cross-secret presence constraint that failed.
- Export
Format - Output format for
Secrets::export - Extract
Format - A structured-data format from which one logical secret can be extracted.
- Generation
- A typed secret-generation strategy.
- Monosecret
Error - The main error type for monosecret operations
- Named
Resolution - The outcome of resolving one secret by name with
crate::Secrets::resolve_named. - Password
Charset - Character set used by
Generation::Password. - Produced
Value Persistence - Whether a value Monosecret produces after a provider miss is written back to the primary provider.
- Provider
Config - A single entry in a project’s
[providers]table. - Provider
Ref - A provider entry on a secret or profile default.
- Registration
Scope - Scope used by the injectable endpoint security policy.
- Require
Reason - When monosecret requires a reason for secret access.
- Resolution
Status - How a single declared secret resolved.
- Resolved
Source - Where a resolved value came from.
- Secret
Encoding - Text encoding used for a secret’s stored representation.
Constants§
- BASE_
ENDPOINT_ ENVIRONMENT - Parent environment variables every endpoint receives: what a process
needs to find programs, locale, temporary and user directories, proxies,
certificate stores, and desktop or agent sessions for native
authentication. Anything else, including other providers’ tokens, reaches
an endpoint only when its registration names it. Entries ending in
*are prefixes. - INLINE_
SPEC_ SCHEMA_ VERSION - The version of the JSON inline-declaration document understood by this library.
- MIN_
INLINE_ SPEC_ SCHEMA_ VERSION - The oldest inline-declaration document version this library still accepts.
- NATIVE_
CALL_ REQUEST_ VERSION - The version of the native call envelope understood by this library.
- RESOLUTION_
REPORT_ SCHEMA_ VERSION - Version of the
ResolutionReportwire format. - RESOLVE_
SCHEMA_ VERSION - Version of the
ResolveResponsewire format.
Traits§
- Endpoint
Security - Platform security seam used by discovery tests and embedders with a stronger host-specific ACL policy.
- Provider
- Trait defining the interface for secret storage providers.
- Provider
Credential Broker - Resolves credentials requested by one already-discovered external provider.
Functions§
- call_
json - Process a versioned native request and return its JSON response envelope.
- resolve_
json - Resolve secrets from a JSON request string and return the JSON response
envelope:
{"ok": true, "response": <ResolveResponse | ResolutionReport>}or{"ok": false, "error": {"kind", "message"}}. - set_
provider_ discovery - Replaces the process-wide discovery inputs used by ordinary provider URI construction. Embedders can use this to supply trusted direct endpoints or to opt into PATH discovery. Available since Monosecret 0.21.
Type Aliases§
- Result
- A type alias for
Result<T, MonosecretError>