#vault #credentials #environment-variables #inject #fetch #secrets #environment

vault-credentials

Rust Library that fetch secrets from Vault and load them as environment variables

8 releases (3 stable)

1.0.2 Jan 5, 2022
1.0.0 Jan 4, 2022
0.4.1 Oct 11, 2021
0.4.0 May 14, 2021
0.1.0 Mar 14, 2021

#131 in Authentication

Download history 4/week @ 2021-09-28 13/week @ 2021-10-05 14/week @ 2021-10-12 1/week @ 2021-10-19 2/week @ 2021-11-02 5/week @ 2021-11-09 1/week @ 2021-11-16 2/week @ 2021-11-23 7/week @ 2021-11-30 1/week @ 2021-12-07 1/week @ 2021-12-14 6/week @ 2021-12-28 88/week @ 2022-01-04 9/week @ 2022-01-11

103 downloads per month

MIT/Apache

11KB
187 lines

Vault Credentials

Rust Library that fetch secrets from Vault and load them as environment variables. Inspired by Spring Cloud Vault.

Getting started

We will assume that you want to retrieve some secrets from your local Vault Server.

This is the json secret located in secret/hello (from Vault perspective, either by using the Vault UI or Vault CLI)

{
  "my-key": "my-value",
  "github.com": {
    "api-key": "123456",
    "base-url": "http://localhost:8080"
  }
}

In your program you must provide the environment variables required to make a connection to the Vault Server and retrieve the token. You can use the .dotenv crate and put the variables in a .env file.

VAULT_ADDR=http://127.0.0.1:8200
VAULT_PATH=hello
VAULT_TYPE=approle
VAULT_ROLE_ID=9bf0581f-[...]-533ba207ec80
VAULT_SECRET_ID=55473ff2-[...]-0ab9ae6e499b

To use the vault_credentials crate in your program, import it and call the initialize method.

use dotenv::dotenv;

#[tokio::main]
async fn main() {
    dotenv().ok();
    vault_credentials::initialize().await;

    println!("{}", std::env::var("github.com.api-key").unwrap());
    // Output: 123456
}

Authentication types

You can use other types of authentication by using VAULT_TYPE. (default is set to token)

Vault Type Required environment variables
token VAULT_TOKEN
approle VAULT_ROLE_ID,VAULT_SECRET_ID
kubernetes VAULT_K8S_AUTH_PATH,VAULT_ROLE_NAME
userpass,ldap VAULT_USERNAME, VAULT_PASSWORD

Namespace

If you use a namespace, you can define it using the environment variable VAULT_NAMESPACE. This will add a header in the requests.

Dependencies

~5–8.5MB
~184K SLoC

da