Home

Awesome

Vaulted

No Longer Being Maintained

Use node-vault for future support of Vault features!


Vaulted is a nodejs-based wrapper for the Vault HTTP API.

Installation

$ npm install vaulted

Getting Started

Documentation

Read the documentation

New Vault

var Vaulted = require('vaulted');

var myVault = new Vaulted({
  vault_host: '127.0.0.1',
  vault_port: 8200,
  vault_ssl: false
});

var keys;

myVault.prepare()
  .bind(myVault)
  .then(function () {
    return myVault.init();
  }).then(function (data) {
    myVault.setToken(data.root_token);
    keys = data.keys;
  })
  .then(function () {
    return myVault.unSeal({
      body: {
        key: keys[0]
      }
    });
  })
  .then(function () {
    return myVault.unSeal({
      body: {
        key: keys[1]
      }
    });
  })
  .then(function () {
    console.log('Vault is now ready!');
  })
  .catch(function onError(err) {
    console.error('Could not initialize or unseal vault:', err.message, err.error);
  });

Existing Vault - set token globally

var Vaulted = require('vaulted');

var myVault = new Vaulted({
  vault_host: '127.0.0.1',
  vault_port: 8200,
  vault_ssl: false
});

myVault.setToken('mytoken');

myVault.prepare()
  .then(function () {
    console.log('Vault is now ready!');
  });

Existing Vault - set token per-call

var Vaulted = require('vaulted');

var myVault = new Vaulted({
  vault_host: '127.0.0.1',
  vault_port: 8200,
  vault_ssl: false
});

myVault.prepare('mytoken')
  .then(function () {
    console.log('Vault is now ready!');
  });

Configuring

The available options below can either be passed to the Vaulted constructor, using environment variables, or configuration files.

Constructor

var Vaulted = require('vaulted');

var myVault = new Vaulted({
  vault_host: '127.0.0.1',
  vault_port: 8200,
  vault_ssl: false,
  timeout: 5000
});

Environment Variables

$ export VAULT_HOST=127.0.0.1
$ export VAULT_PORT=8200
$ export VAULT_SSL=false
$ export VAULT_TIMEOUT=5000
var Vaulted = require('vaulted');

var myVault = new Vaulted();

Configuration File

File: config/default.yml

vault_host: 127.0.0.1
vault_port: 8200
vault_ssl: true
var Vaulted = require('vaulted');

var myVault = new Vaulted();

Available Options

AttributeEnvironment VariableDefault ValueDescription
vault_hostVAULT_HOST127.0.0.1Vault server hostname
vault_portVAULT_PORT8200Vault server port
vault_sslVAULT_SSLtrue (enabled)Use SSL?
vault_tokenVAULT_TOKENToken to use to access the vault
ssl_ciphersVAULT_SSL_CIPHERSTLSv1.2The ciphers that will be used when communicating with vault over ssl
ssl_cert_fileVAULT_SSL_CERTPath to custom SSL cert file
ssl_pem_fileVAULT_SSL_CERT_KEYPath of SSL cert PEM file to use with custom SSL verification
ssl_pem_passphraseVAULT_SSL_CERT_PASSPHRASEPassphrase associated SSL cert PEM file to use with custom SSL verification
ssl_ca_certVAULT_CACERTCA cert path used for certification verification
ssl_verifyVAULT_SSL_VERIFYtruevalidate SSL requests?
timeoutVAULT_TIMEOUTmilliseconds to wait for response headers
proxy_addressVAULT_PROXY_ADDRESSHTTP Proxy server address
proxy_passwordVAULT_PROXY_PASSWORDHTTP Proxy user password
proxy_portVAULT_PROXY_PORTHTTP Proxy server port
proxy_usernameVAULT_PROXY_USERNAMEHTTP Proxy server username
debugDEBUGfalseShow verbose messages, network requests?
secret_sharesSECRET_SHARES3Number of shared secret keys to generate
secret_thresholdSECRET_THRESHOLD2Threshold at which to unseal vault (must be <= SECRET_SHARES)

Example - An Express Application

In order to run the example, you will need to install:

$ make run-local

After starting the servers, you can point a tool like POSTman at http://$(boot2docker ip):3000. You can perform read/write/delete operations on secrets:

curl \
  -X PUT \
  -H "Content-Type: application/json" \
  -d '{ "hashicorp": "amazeballs", "value": "s3cr37" }' \
  'http://$(boot2docker ip):3000/secret/value'
{"success":true}
curl \
  -X GET \
  'http://$(boot2docker ip):3000/secret/value'
{
  "lease_id": "secret/value/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
  "renewable": false,
  "lease_duration": 2592000,
  "data": {
    "hashicorp": "amazeballs",
    "value": "s3cr37"
  },
  "auth": null
}

Development

Use the docker-compose-test.yml to aid development. PRs are very, very welcome. Please add tests when including new functionality.

Running Tests

$ docker-compose -f docker-compose-test.yml up -d consul vault
$ docker-compose -f docker-compose-test.yml run vaulted

License

The MIT License (MIT)

Copyright (c) 2015-2016 Christopher "Chief" Najewicz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.