Gaia Client Library (Rust)
A Rust client library for interacting with the Gaia secret management daemon.
Features
- 🔒 Secure mTLS Communication - All communication is encrypted and authenticated using mutual TLS
- 🚀 Async/Await Support - Built on Tokio for high-performance async operations
- 📦 Easy to Use - Simple, idiomatic Rust API
- 🔑 Secret Management - Read secrets from your application's namespaces
- 🌐 Common Secrets - Access shared secrets available to all clients
- ⚡ gRPC Based - Fast, efficient communication protocol
- 🛠️ No Build Tools Required - Ships with pre-generated protobuf code, no need for
protoc
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
No additional build tools required! The library ships with pre-generated protobuf code, so you don't need to install protoc or any other external dependencies.
Quick Start
use ;
async
Configuration
From Code
use GaiaClientConfig;
let config = new;
From Environment Variables
use GaiaClientConfig;
// Reads from:
// - GAIA_SERVER_ADDRESS (default: "localhost:50051")
// - GAIA_CA_CERT (default: "/etc/gaia/certs/ca.crt")
// - GAIA_CLIENT_CERT (default: "/etc/gaia/certs/client.crt")
// - GAIA_CLIENT_KEY (default: "/etc/gaia/certs/client.key")
let config = from_env;
Custom Domain Name
let config = new.with_domain_name;
API Reference
Client Methods
connect(config: GaiaClientConfig) -> Result<GaiaClient>
Connects to the Gaia daemon using the provided configuration.
let mut client = connect.await?;
get_status() -> Result<StatusResponse>
Retrieves the daemon status ("locked" or "unlocked").
let status = client.get_status.await?;
println!;
is_unlocked() -> Result<bool>
Checks if the daemon is unlocked and ready to serve secrets.
if client.is_unlocked.await?
get_secret(namespace: &str, id: &str) -> Result<Secret>
Retrieves a specific secret from a namespace.
let secret = client.get_secret.await?;
println!;
get_namespaces() -> Result<NamespaceResponse>
Lists all namespaces accessible to this client.
let namespaces = client.get_namespaces.await?;
for ns in namespaces.namespaces
get_common_secrets(namespace: Option<String>) -> Result<Vec<Namespace>>
Retrieves all secrets from the common area, optionally filtered by namespace.
// Get all common secrets
let all_common = client.get_common_secrets.await?;
// Get common secrets from specific namespace
let production_common = client.get_common_secrets.await?;
get_common_namespace_secrets(namespace: &str) -> Result<Vec<Secret>>
Retrieves secrets from a specific namespace in the common area.
let secrets = client.get_common_namespace_secrets.await?;
for secret in secrets
list_secrets(namespace: Option<String>) -> Result<Vec<Namespace>> ⭐ NEW
Lists all secrets for the authenticated client, including both the client's own namespaces and the common namespace.
// Get all secrets (client's own + common)
let all_secrets = client.list_secrets.await?;
for namespace in &all_secrets
// Get secrets from specific namespace only
let prod_secrets = client.list_secrets.await?;
Note: This is the recommended method for fetching all secrets at once, as it's more efficient than making multiple individual requests.
load_env(options: Option<LoadEnvOptions>) -> Result<()> ⭐ NEW
Fetches all accessible secrets and loads them into the current process's environment.
By default, environment variables are named directly after the secret key, converted to uppercase with hyphens replaced by underscores.
You can optionally configure a custom prefix or include the namespace via LoadEnvOptions.
use LoadEnvOptions;
// Load with default behavior (key only)
client.load_env.await?;
// The secret "database_url" from any accessible namespace is now available as:
let db = var?;
// To load with a custom prefix and namespace:
// client.load_env(Some(LoadEnvOptions::new().with_prefix("GAIA").with_namespace(true))).await?;
// let db = std::env::var("GAIA_PRODUCTION_DATABASE_URL")?;
Examples
The library includes several examples in the examples/ directory:
Simple Client
Demonstrates basic connection and status checking:
Fetch Secrets
Shows how to retrieve secrets from different namespaces:
Error Handling
The library provides a comprehensive error type:
use GaiaError;
match client.get_secret.await
Certificate Setup
Before using the client, you need to:
- Generate or obtain certificates from your Gaia administrator
- Place certificates in the appropriate directory (e.g.,
/etc/gaia/certs/) - Ensure permissions are correct (certificates should be readable by your application)
Example certificate structure:
/etc/gaia/certs/
├── ca.crt # CA certificate (verifies server)
├── client.crt # Client certificate (authenticates your app)
└── client.key # Client private key
Platform Support
The library works on:
- ✅ Linux
- ✅ macOS
- ✅ Windows
Requirements
- Rust 1.70 or later
- Tokio runtime
- Valid mTLS certificates from Gaia
No external build tools required! The library ships with pre-generated protobuf code.
Building from Source
The library uses Protocol Buffers for gRPC communication. The proto files are compiled automatically at build time.
Quick Build
Using Makefile
A Makefile is provided for common tasks:
# See all available commands
# Build the library
# Run tests
# Run all quality checks (format, clippy, test)
# Format code
# Run clippy lints
# Generate documentation
# Clean build artifacts
Proto Files
The library uses gRPC with Protocol Buffers. The proto definitions are located in ../../proto/gaia-client.proto (root of the repository).
At build time, the build.rs script automatically:
- Reads the proto file from
../../proto/gaia-client.proto - Compiles it using
tonic-build
Development
Protocol Buffers
This library uses pre-generated protobuf code checked into src/proto.rs, eliminating the need for protoc at build time. This makes the library easy to use as a dependency - users don't need to install any external tools.
For Library Users
Just add the dependency to your Cargo.toml and start using it. No protoc installation required!
For Library Developers
If you need to regenerate the protobuf code (e.g., after updating the proto files):
-
Install
protoc(Protocol Buffers compiler):# macOS # Ubuntu/Debian # Or download from: https://github.com/protocolbuffers/protobuf/releases -
Regenerate the proto code:
REGENERATE_PROTO=1 -
Copy the generated code to source:
-
Commit the updated
src/proto.rsfile
Note: The proto files are kept in sync with the main Gaia repository at ../../proto/gaia-client.proto during development, and copied to proto/ when publishing.
Development Workflow
# Check if everything is set up correctly
# Development cycle
# Before committing
# Run examples (requires running Gaia daemon)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- Gaia - The main Gaia secret management daemon
- Gaia Go Client - Go client library
- Gaia JS Client - JavaScript/TypeScript client library
Support
For issues, questions, or contributions, please visit the GitHub repository.