#vault #api #client #hashicorp


An asynchronous Rust client library for the Hashicorp Vault API

13 releases (5 breaking)

new 0.6.2 May 13, 2022
0.6.1 May 13, 2022
0.6.0 Mar 15, 2022
0.5.4 Sep 22, 2021
0.1.1 Aug 22, 2021

#7 in Authentication

Download history 111/week @ 2022-01-27 95/week @ 2022-02-03 177/week @ 2022-02-10 102/week @ 2022-02-17 124/week @ 2022-02-24 177/week @ 2022-03-03 179/week @ 2022-03-10 292/week @ 2022-03-17 204/week @ 2022-03-24 141/week @ 2022-03-31 200/week @ 2022-04-07 199/week @ 2022-04-14 483/week @ 2022-04-21 767/week @ 2022-04-28 839/week @ 2022-05-05 1008/week @ 2022-05-12

3,169 downloads per month
Used in 2 crates

MIT license



An asynchronous Rust client library for the Hashicorp Vault API

The following features are currently supported:

See something missing? Open an issue.


Add vaultrs as a dependency to your cargo.toml:

vaultrs = "0.6.2"



The client is used to configure the connection to Vault and is required to be passed to all API calls for execution. Behind the scenes it uses an asynchronous client from Reqwest for communicating to Vault.

use vaultrs::client::{VaultClient, VaultClientSettingsBuilder};

// Create a client
let client = VaultClient::new(


The library currently supports all operations available for version 2 of the key/value store.

use serde::{Deserialize, Serialize};
use vaultrs::kv2;

// Create and read secrets
#[derive(Debug, Deserialize, Serialize)]
struct MySecret {
    key: String,
    password: String,

let secret = MySecret {
    key: "super".to_string(),
    password: "secret".to_string(),

let secret: MySecret = kv2::read(&client, "secret", "mysecret").await.unwrap();
println!("{}", secret.password) // "secret"


The library currently supports all operations available for the PKI secrets engine.

use vaultrs::api::pki::requests::GenerateCertificateRequest;
use vaultrs::pki::cert;

// Generate a certificate using the PKI backend
let cert = cert::generate(
println!("{}", cert.certificate) // "{PEM encoded certificate}"


All requests implement the ability to be wrapped. These can be passed in your application internally before being unwrapped.

use vaultrs::api::ResponseWrapper;
use vaultrs::api::sys::requests::ListMountsRequest;

let endpoint = ListMountsRequest::builder().build().unwrap();
let wrap_resp = endpoint.wrap(&client).await; // Wrapped response

let wrap_resp = wrap_resp.unwrap(); // Unwrap Result<>
let info = wrap_resp.lookup(&client).await; // Check status of this wrapped response

let unwrap_resp = wrap_resp.unwrap(&client).await; // Unwrap the response

let info = wrap_resp.lookup(&client).await; // Error: response already unwrapped

Error Handling and Tracing

All errors generated by this crate are wrapped in the ClientError enum provided by the crate. API warnings are automatically captured via tracing and API errors are captured and returned as their own variant. Connection related errors from rustify are wrapped and returned as a single variant.

All top level API operations are instrumented with tracing's #[instrument] attribute.


See the the tests directory for tests. Run tests with cargo test.

Note: All tests rely on bringing up a local Vault development server using Docker. In order to run tests Docker must be running locally (Docker Desktop works).


Check out the issues for items needing attention or submit your own and then:

  1. Fork the repo (https://github.com/jmgilman/vaultrs/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

See CONTRIBUTING for extensive documentation on the architecture of this library and how to add additional functionality to it.


~296K SLoC