| Crates.io | corteq-onepassword |
| lib.rs | corteq-onepassword |
| version | 0.1.5 |
| created_at | 2025-12-15 11:39:17.635817+00 |
| updated_at | 2025-12-17 09:43:41.31966+00 |
| description | Secure 1Password SDK wrapper with FFI bindings for Rust applications |
| homepage | |
| repository | https://github.com/trendium-labs/corteq-onepassword |
| max_upload_size | |
| id | 1985879 |
| size | 314,331 |
This is a 1Password SDK wrapper for Rust applications. This does NOT use the 1Password CLI! Providing a safe interface to 1Password secrets using FFI bindings for the official 1Password SDK Core library.
SecretString with automatic memory zeroizationSend + Sync for use in async applicationsuse corteq_onepassword::{OnePassword, ExposeSecret};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client from OP_SERVICE_ACCOUNT_TOKEN environment variable
let client = OnePassword::from_env()?
.integration("my-app", "1.0.0") // Name of your app for audit purposes on 1password side
.connect()
.await?;
// Resolve a secret
let api_key = client.secret("op://vault/item/api-key").await?;
// Use the secret (expose only when needed)
println!("API key length: {}", api_key.expose_secret().len());
Ok(())
}
Refer to the Implementation Guide for detailed instructions.
Add to your Cargo.toml:
[dependencies]
corteq-onepassword = "0.1"
When you install this crate from crates.io, the native library is not included
(due to crates.io's 10MB size limit). The library is automatically downloaded during
cargo build:
pypi.org (package metadata)files.pythonhosted.org (library download)For environments without network access:
Download the library on a connected machine:
# Download for your platform (example for Linux x86_64)
curl -L "https://pypi.org/pypi/onepassword-sdk/json" | \
jq -r '.urls[] | select(.filename | contains("manylinux")) | .url' | \
head -1 | xargs curl -L -o sdk.whl
unzip sdk.whl "onepassword/*.so" -d extracted/
Set the library path before building:
export ONEPASSWORD_LIB_PATH="/path/to/libop_uniffi_core.so"
cargo build
This crate uses 1Password service account tokens. Personal account tokens are not supported.
export OP_SERVICE_ACCOUNT_TOKEN="ops_..."
let client = OnePassword::from_env()?.connect().await?;
or use dotenvy
dotenvy::dotenv().ok();
let client = OnePassword::from_token("ops_...").connect().await?;
Secrets are referenced using the op://vault/item/field format:
op://Production/Database/password - Simple referenceop://Production/Database/admin/password - Section-scoped referenceSee https://developer.1password.com/docs/cli/secret-reference-syntax/
let api_key = client.secret("op://prod/stripe/api-key").await?;
let secrets = client.secrets(&[
"op://prod/db/host",
"op://prod/db/user",
"op://prod/db/pass",
]).await?;
let host = secrets[0].expose_secret();
let user = secrets[1].expose_secret();
let pass = secrets[2].expose_secret();
let secrets = client.secrets_named(&[
("host", "op://prod/db/host"),
("user", "op://prod/db/user"),
("pass", "op://prod/db/pass"),
]).await?;
let host = secrets.get("host").unwrap().expose_secret();
The client is thread-safe and can be shared via Arc:
use std::sync::Arc;
let client = Arc::new(OnePassword::from_env()?.connect().await?);
let client1 = Arc::clone(&client);
let client2 = Arc::clone(&client);
tokio::join!(
async move { client1.secret("op://vault/item/field1").await },
async move { client2.secret("op://vault/item/field2").await },
);
blocking - Enable synchronous API via connect_blocking()tracing - Enable tracing spans for observability[dependencies]
corteq-onepassword = { version = "0.1", features = ["blocking"] }
| Platform | Architecture | Status |
|---|---|---|
| Linux | x86_64 | ✅ Supported |
| Linux | aarch64 | ✅ Supported |
| macOS | x86_64 | ✅ Supported |
| macOS | aarch64 | ✅ Supported |
| Windows | - | ❌ Not supported |
| Alpine | - | ❌ Not supported (musl) |
The build script looks for the 1Password SDK native library in this order:
ONEPASSWORD_LIB_PATH - Custom path via environment variablesrc/libs/{platform}/This repository includes pre-downloaded libraries for all supported platforms in src/libs/:
src/libs/
├── linux-x86_64/libop_uniffi_core.so (~18MB)
├── linux-aarch64/libop_uniffi_core.so (~17MB)
├── macos-x86_64/libop_uniffi_core.dylib (~16MB)
└── macos-aarch64/libop_uniffi_core.dylib (~15MB)
These files are tracked with Git LFS due to their size. After cloning:
git lfs pull # Download the actual library files
Why bundle libraries?
To update the bundled libraries (e.g., for a new SDK version):
./scripts/download-libs.sh
This script fetches all 4 platform libraries from PyPI with SHA256 verification.
If bundled libraries are not found, the build script downloads from PyPI:
When downloading from PyPI, network access is required to:
pypi.org - Package metadata and checksumsfiles.pythonhosted.org - Library downloadsFor custom library locations:
export ONEPASSWORD_LIB_PATH="/path/to/libop_uniffi_core.so"
SecretString and zeroized on dropAll errors are typed and implement std::error::Error:
use corteq_onepassword::Error;
match client.secret("op://vault/item/field").await {
Ok(secret) => { /* use secret */ },
Err(Error::SecretNotFound { reference }) => {
eprintln!("Secret not found: {}", reference);
},
Err(Error::AccessDenied { vault }) => {
eprintln!("Access denied to vault: {}", vault);
},
Err(e) => {
eprintln!("Error: {}", e);
}
}
This error occurs when the native library cannot be located at runtime.
Solutions:
Rebuild the crate - The build script downloads the library automatically:
cargo clean && cargo build
Check network access - The build script needs to reach PyPI:
curl -I https://pypi.org/pypi/onepassword-sdk/json
Set custom path - If you have the library elsewhere:
export ONEPASSWORD_LIB_PATH="/path/to/libop_uniffi_core.so"
If the automatic download fails during build:
curl https://pypi.orgONEPASSWORD_SKIP_DOWNLOAD=1 and provide the library manually via ONEPASSWORD_LIB_PATH