Ruby Config Vault Source
This gem is provided to support vault sources in rubyconfig/config installations. Further documentation can be found at rubydoc.info.
Installation
Add this line to your application's Gemfile:
gem 'config'
gem 'rubyconfig-vault'And then execute:
$ bundle install
Or install it yourself as:
$ gem install rubyconfig-vault
Usage
For more vault authentication methods see ruby documentation for https://github.com/hashicorp/vault-ruby and for additional rubyconfig configuration options see https://github.com/rubyconfig/config.
require 'config'
require 'config/vault'
auth_secret = Vault.auth.approle('roleid', 'secret id')
source = Config::Sources::VaultSource.new(address: ENV['VAULT_ADDR'],
token: auth_secret.auth.client_token,
paths: ['kvp/secret'],
flatten: false)
# The * operator retrieves values at kvp/ and the values of immediate child keys
source.add_path('kvp/*')
# The ** operator scans all child keys of kvp/ for sub-keys containing 'test'
source.add_path('kvp/**/test')
# Or combine the two...
source.add_path('kvp/**/some/keys/*')
# Or mount path to custom root...
source.add_path('kvp/custom', 'vault')
Config.load_and_set_settings(source)
# Alternatively to reload after loading yaml configuration...
# Settings.add_source!(source)
# Settings.reload!
# 'kvp/secret'
puts Settings.kvp.secret
# 'kvp/*'
puts Settings.kvp.some_value
puts Settings.kvp.rando.some_value
# 'kvp/**/test'
puts Settings.kvp.rando.test.some_value
puts Settings.kvp.rando2.test.some_value
# 'kvp/custom'
puts Settings.vault.custom
# 'kvp/**/some/keys/*'
puts Settings.kvp.rando3.some.keys.some_value
puts Settings.kvp.rando4.some.keys.test2.some_valueValid options for Config::Sources::VaultSource.new include all the configuration options provided by Vault::Client.new and the following:
-
:rootset a root key under which all keys from this source will be located -
:kvset the mount point -
:pathsa list of valid paths for keys -
:attemptsnumber of attempts to recover from Vault::HTTPError -
:baseinitial backoff for attempts -
:max_waitmaximum backoff for attempts -
:flattenflatten hash and mount on root(s) if provided
Development
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
Follow https://www.vaultproject.io/docs/install to install vault as development dependency and then run rake. Alternatively leverage the provided Dockerfile using rake docker:build and rake docker:spec to run tests.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/CrunchwrapSupreme/rubyconfig-vault.