figment-keyring
A Figment2 provider that fetches secrets from system keyrings.
Overview
figment-keyring provides a Figment2 provider that fetches secrets from system keyrings (macOS Keychain, Windows Credential Manager, Linux Secret Service). It uses late binding to configure keyring access via any Figment source (files, environment, custom providers).
Features
- Late binding: Provider holds a Figment reference and extracts configuration at
.data()time - Multi-keyring support: Search user, system, and custom named keyrings in priority order
- Flexible configuration: Configure via TOML, JSON, environment variables, or any Figment provider
- Optional secrets: Gracefully handle missing secrets without errors
- Profile support: Target specific Figment profiles
- Key mapping: Map credential names to different config keys
Installation
[]
= "0.1"
= { = "0.11", = ["env"] }
Platform Support
The provider uses the keyring crate which supports multiple platforms:
| Platform | Backend (keyring crate) | Status |
|---|---|---|
| macOS | Keychain Services | Supported |
| Windows | Credential Manager | Supported |
| Linux | Secret Service / Keyutils | Supported |
| iOS | Keychain Services | Supported |
| FreeBSD | Secret Service | Supported |
| OpenBSD | Secret Service | Supported |
Usage
Quick Start
use ;
use KeyringProvider;
// Simple: user keyring with defaults
let provider = new;
let config: MyConfig = new
.merge
.extract
.unwrap;
Configuration File
Configure keyring behavior via any Figment source:
# config.toml
= "myapp"
= ["user", "team-secrets", "system"]
= false
use ;
use KeyringProvider;
let config_figment = new
.merge;
let api_key_provider = configured_by;
Multiple Secrets
use Figment;
use KeyringProvider;
let config_figment = new
.merge;
let config = new
.merge
.merge
.merge
.extract
.unwrap;
Nested Configuration
For more flexible configuration, the provider can work with a focused Figment that contains keyring configuration in a nested path:
use Figment;
use KeyringProvider;
let config_figment = new
.merge;
let provider = configured_by;
Example TOML configuration:
[]
= "myapp"
= ["user", "system"]
= false
[]
= "localhost"
Optional Secrets
use Figment;
use KeyringProvider;
let config = KeyringConfig ;
let provider = configured_by;
Key Mapping
Map keyring entries to different config keys:
use Figment;
use KeyringProvider;
let provider = configured_by
.as_key; // Maps to "credentials.password" in config
Key Mapping
Map keyring entries to different config keys:
use Figment;
use KeyringProvider;
let provider = configured_by
.as_key; // Maps to "credentials.password" in config
Configuration
KeyringConfig
use ;
use ;
Keyring Types
use Keyring;
Platform Support
| Keyring | macOS | Linux | Windows |
|---|---|---|---|
| User | Login Keychain | User Secret Service | User Credential Manager |
| System | System Keychain | System Secret Service | Local Machine credentials |
| Named(x) | Keychain x.keychain-db |
Collection x |
Target x |
API
KeyringProvider
License
Licensed under either of
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0
at your option.