GithubHelp home page GithubHelp logo

zihaoyu / node-vault Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodevault/node-vault

0.0 1.0 0.0 573 KB

Client for HashiCorp's Vault

Home Page: https://vaultproject.io/

License: MIT License

HCL 0.13% JavaScript 99.73% Dockerfile 0.13%

node-vault's Introduction

node-vault

Build Status Coverage Status Download Status Dependency Status Open Collective backers and sponsors

A client for the HTTP API of HashiCorp's Vault written for Node.js.

install

make sure to use node.js version >= 6

npm install node-vault

test

Run tests inside docker to do also nice integration testing:

docker-compose up --force-recreate test

This will create containers for vault, postgres and running the tests inside docker.

usage

init and unseal

var options = {
  apiVersion: 'v1', // default
  endpoint: 'http://127.0.0.1:8200', // default
  token: '1234' // optional client token; can be fetched after valid initialization of the server
};

// get new instance of the client
var vault = require("node-vault")(options);

// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then( (result) => {
  var keys = result.keys;
  // set token for all following requests
  vault.token = result.root_token;
  // unseal vault server
  return vault.unseal({ secret_shares: 1, key: keys[0] })
})
.catch(console.error);

write, read and delete secrets

vault.write('secret/hello', { value: 'world', lease: '1s' })
.then( () => vault.read('secret/hello'))
.then( () => vault.delete('secret/hello'))
.catch(console.error);

docs

Just generate docco docs via npm run docs.

examples

Please have a look at the examples and the generated feature list to see what is already implemented.

Instead of installing all the dependencies like vault itself, postgres and other stuff you can use docker and docker-compose to link and run multiple docker containers with all of its dependencies.

git clone [email protected]:kr1sp1n/node-vault.git
cd node-vault
docker-compose up vault

Now you can run the examples from another terminal window.

First of all you should initialize and unseal the vault:

node example/init.js

You should see root_token: followed by a long key in the response. Please copy that long key and export it as environment variable:

export VAULT_TOKEN=<insert long key here>

Now you are able to run all of the other examples:

node example/policies.js

Connecting to vault through a bastion host

To connect to a vault server in a private network with a bastion host, you'll need to first open a connection:

ssh -D <socks4Port> bastion.example.com
const SocksProxyAgent = require('socks-proxy-agent');
const agent = new SocksProxyAgent(`socks://127.0.0.1:${socks4Port}`, true);
const options = {
  apiVersion: 'v1',
  rpOptions: {
    agent,
  },
};

const vault = require('node-vault')(options);

Backers

node-vault's People

Contributors

0xn3bs avatar aearly avatar at88mph avatar brandonros avatar dependabot[bot] avatar doublerebel avatar expeddrewery avatar fearphage avatar firefoxnx avatar frostmar avatar guilt avatar kakoc avatar kr1sp1n avatar kstiehl avatar mikeboan avatar mpareja avatar owenfarrell avatar raphcal avatar ryanlewis avatar saranrapjs avatar seangallavan avatar seyfert avatar siboulet avatar sjparkinson avatar snyk-bot avatar tavogel avatar timjrobinson avatar trevorr avatar ulan08 avatar zioproto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.