Project

sekreto

0.02
No commit activity in last 3 years
No release in over 3 years
Manage AWS Secrets from Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.4.2
~> 1.16
~> 0.12.0
~> 13.0
~> 3.0
~> 0.17.0
~> 1.0
~> 0.9.11

Runtime

 Project Readme

Sekreto

Gem Version Build Status Maintainability Test Coverage Dependabot Status

Use AWS Secrets Manager from Ruby, with rails support

Installation

Add this line to your application's Gemfile:

gem 'sekreto'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sekreto

Usage

Configuration

Configuration will happen automatically in a Rails environment to set defaults that make integrating easy. The defaults look like

Sekreto.setup do |setup|
  # Default secrets manager is a new client
  setup.secrets_manager = Aws::SecretsManager::Client.new

  # Prefix of secrets set to Rails app name and RAILS_ENV
  setup.prefix = 'railsappname-staging'

  # Allowed environments to use secrets is set to production/staging
  # Any block can be given that responds to #call and returns a true or false
  # that will use secrets calls if allowed and use the fallback if not
  setup.is_allowed_env = -> { %w[production staging].include?(::Rails.env) }

  # Default fallback is to look up the secret in the ENV if it is not an
  # allowed env to use the secret manager
  setup.fallback_lookup = ->(secret_id) { ENV[secret_id] }
end

You can use an initializer to customize any of the defaults

config/initializers/sekreto.rb

Sekreto.setup do |setup|
  setup.secrets_manager = Aws::SecretsManager::Client.new
  setup.prefix = 'some/other/prefix'
  setup.is_allowed_env = -> { ENV.fetch('USE_SECRETS', false) }
  setup.fallback_lookup = ->(secret_id) { Secrets.where(name: secret_id).pluck(:value).first }
end

Retrieving Secrets

Getting plain text secrets:

# Will query for "#{prefix}/my-secret"
secret = Sekreto.get_value('my-secret')
puts secret
# Output: asdf124asdf134asdf1243asdf

Getting JSON secrets will return the parsed value

# Will query for "#{prefix}/my-secret-config"
secret = Sekreto.get_json_value('my-secret-config')
puts secret
# Output: { some: 'json', data: 'here' }

Getting secrets with a custom prefix. Useful for shared secrets or secrets across apps, namespaces, etc.

# Will query for "shared-secrets/MY-SECRET-CONFIG"
secret = Sekreto.get_json_value('MY-SECRET-CONFIG', 'shared-secrets')
puts secret
# Output: { some: 'json', data: 'here' }

If you want to skip prefixes all together you can pas false to either get value methods. Not recommended

# Will query for "MY-SECRET-CONFIG"
secret = Sekreto.get_json_value('MY-SECRET-CONFIG', false)
puts secret
# Output: { some: 'json', data: 'here' }

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

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/autolist/sekreto. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Sekreto project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.