• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enhances Rails credentials for multiple environments

Gem Version Ruby

RailsEnvCredentials

It enhances the Credentials feature introduced by Rails v5.2.0.

Installation

Add this line to your Rails application's Gemfile:

group :development, :test do
  gem 'rails-env-credentials'
end

And then execute:

$ bundle

Usage

RailsEnvCredentials manages credentials and key pairs with the following:

config/credentials-development.yml.enc
config/credentials-test.yml.enc
config/credentials.yml.enc
master-development.key
master-test.key
master.key

It also manages environment variables for each env.

RAILS_MASTER_KEY_DEVELOPMENT
RAILS_MASTER_KEY_TEST
RAILS_MASTER_KEY

You can use appropriate credentials depending on Rails.env.

$ rails env_credentials:show -e development
# config/credentials-development.yml.enc
aws:
  bucket: foo-dev

$ rails env_credentials:show -e production
# config/credentials.yml.enc
aws:
  bucket: foo-prod

$ rails runner -e development 'pp Rails.application.credentials.aws.bucket'
"foo-dev"
$ rails runner -e production 'pp Rails.application.credentials.aws.bucket'
"foo-prod"

Generating secrets and a master key

It automatically generate encrypted file and the master key when you starts editing credentials at first:

$ rails env_credentials:edit -e development

Show secrets

You want to see decrypted contents, use env_credentials:show:

$ rails env_credentials:show -e development

Additional information

Other environments support

For example, if the config/environments/staging.rb exists, you will generate config/credentials-staging.yml.enc.

$ rails env_credentials:edit -e staging

Display a diff

You canโ€™t directly compare encrypted files between two versions, but it turns out you can see a diff using Git attributes.

Put the following line in your .gitattributes file:

config/credentials*.yml.enc diff=env_credentials

Then configure Git to use env_credentials:show:

$ git config diff.env_credentials.textconv 'rails env_credentials:show --file'

This tells Git that encrypted files should decrypt by the env_credentials:show task when you try to display a diff.

Why make this gem?

Credentials is a good feature, but we cannot use it on development and test environment.

DHH wrote as follow in the pull request for initial implementation:

It's only in production (and derivative environments, like exposed betas) where the secret actually needs to be secret.

refs: rails/rails#30067

However, I have to manage secrets and a master key different from production for testing in the staging environment.

I do not have the confidence to explain explicit use cases to Rails team, so I implemented as a gem.

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/sinsoku/rails-env-credentials. 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 Rails::Env::Credentials projectโ€™s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

More Repositories

1

clairvoyance

Clairvoyance provides a way to measure code coverage for CSS
JavaScript
60
star
2

bundler-diff

Bundler Diff show changes with GitHub compare view urls
Ruby
57
star
3

pretty_validation

PrettyValidation generate validation modules from database schema
Ruby
17
star
4

tachikoma_ai

Give a comparing function on GitHub to tachikoma
Ruby
13
star
5

banana

Ruby
12
star
6

rails_credentials_custom_key

Ruby
11
star
7

gems_comparator

GemsComparator generates GitHub's compare view urls from Gemfile.lock
Ruby
9
star
8

jewel_seed

Ruby
8
star
9

dotfiles

dotfiles
Shell
7
star
10

ecs_oneshot

A CLI tool that simply executes tasks on AWS Fargate.
Ruby
7
star
11

study

Ruby
7
star
12

rusty_rails

This app is a sample that uses wasabi which is a Rust-based Ruby extension.
Ruby
6
star
13

miteras-cli

A command-line tool for MITERAS.
HTML
6
star
14

pickel

A plugin that make it easy to build a search form
Ruby
6
star
15

amazon-ecs-run-task-definition

Run an Amazon ECS task definition on the same configuration as the existing ECS service.
JavaScript
6
star
16

ghost_pictures

A library to wait for Ajax requests with Capybara
Ruby
4
star
17

active_record_in_cache

Provides a method to execute SQL while automatically caching.
Ruby
4
star
18

ponytail

Ruby
4
star
19

rails_assetsless_container

Ruby
3
star
20

steep-app-example

Ruby
3
star
21

wasabi

Ruby
3
star
22

action_prefixer

Ruby
2
star
23

OAuthSample

Swift
2
star
24

circleci_latest_artifact

Ruby
2
star
25

unofficial-forkwell-api

Ruby
2
star
26

workfloweditorplus

JavaScript
2
star
27

active_record_lazy_find_by

It provides a simple method to make SQL execution lazy.
Ruby
2
star
28

cacoon

C++
2
star
29

git-pair

2
star
30

rb_pipe_operator

Ruby
2
star
31

tracreportmail

1
star
32

sinon-with-time

JavaScript
1
star
33

pyredmine

1
star
34

felicapy

1
star
35

git_proj

1
star
36

sphinx_sample

Python
1
star
37

sample

Python
1
star
38

numa08_stalker

Ruby
1
star
39

mfa

Shell
1
star
40

omiai-bot

Python
1
star
41

twitterbot

Python
1
star
42

mm-crss

Python
1
star
43

rust_web

Web app for personal study
Rust
1
star
44

terraform-provider-esa

Go
1
star
45

multi_merge_test

1
star
46

git-jp-test

1
star
47

rails-ui-br

1
star