dev_secrets 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +61 -0
- data/Rakefile +23 -0
- data/lib/dev_secrets/version.rb +3 -0
- data/lib/dev_secrets.rb +52 -0
- data/lib/tasks/dev_secrets_tasks.rake +4 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 750bb9e189e74ed2362a9701a49efba7802f9b1b
|
4
|
+
data.tar.gz: 98f5333713e03b22f4da788826bb61305fc47544
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4e2751f6cba44ee744c96b0359e1a2826d6d0148f61092f80281ce44a647c68046b0ed692a1f1d3f6222c1f5af4b4aafca37f19b43f40d1ad0355905c1d8008
|
7
|
+
data.tar.gz: c28d2d7208978b3142f11ebb4646c836273a7624afaddc20e7827e918470af990d57d077cf02d2a15aac2d3bc0335b91da9cd96a85f64d291d5746c961c0a980
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Jesse Kipp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# DevSecrets
|
2
|
+
|
3
|
+
Rails 5.1 introduced encrypted secrets, a way of keeping your applciation's
|
4
|
+
secret tokens safely in the repository where they belong, without actually
|
5
|
+
committing them in a readable form.
|
6
|
+
|
7
|
+
This gem allows your app to have multiple secrets files matching the
|
8
|
+
file glob `secrets*.yml{,.enc}`, so you can store encrypted secrets for
|
9
|
+
different environments.
|
10
|
+
|
11
|
+
### But aren't the secrets YML files already formatted to support multiple environments?
|
12
|
+
|
13
|
+
The problem this solves is individual developers using encrypted secrets locally.
|
14
|
+
The local Rails server may rely on accessing a remote resource, but even for throwaway
|
15
|
+
dev accounts, you might not want to commit those secrets in plaintext. So you use
|
16
|
+
encrypted secrets.
|
17
|
+
|
18
|
+
But you also have production secrets stored in the same encrypted file. Even if
|
19
|
+
you trust the people running the app locally in dev, you shouldn't need to give
|
20
|
+
them all the keys to, say, the S3 bucket containing your production client data.
|
21
|
+
|
22
|
+
This lets you drop multiple secrets files into the same app and then hand out the
|
23
|
+
appropriate decryption key.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
Add it to any Gemfile that also includes Rails >= 5.1. Commit your encrypted
|
27
|
+
secrets to any file matching the pattern `secrets*.yml.enc`. Your app's master
|
28
|
+
key (either in `ENV['RAILS_MASTER_KEY']` or the file `secrets.yml.key`) need
|
29
|
+
only decrypt one of them. When your app's secrets are loaded for the first time,
|
30
|
+
Rails will attempt to read all encrypted secrets, merging only the ones that
|
31
|
+
decrypt correctly.
|
32
|
+
|
33
|
+
Rails normally raises `ActiveSupport::MessageEncryptor::InvalidMessage` when
|
34
|
+
it attempts and fails to decrypt secrets. Because the expected behavior of
|
35
|
+
DevSecrets is to naturally fail to decrypt secrets that are for the wrong
|
36
|
+
environment, Rails will now swallow that error if at least one encrypted secrets
|
37
|
+
file was successfully parsed. If all parses fail, it will raise the exception as
|
38
|
+
expected.
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
Add this line to your application's Gemfile:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'dev_secrets'
|
45
|
+
```
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
```bash
|
49
|
+
$ bundle
|
50
|
+
```
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
```bash
|
54
|
+
$ gem install dev_secrets
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
lol
|
59
|
+
|
60
|
+
## License
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'DevSecrets'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
data/lib/dev_secrets.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module DevSecrets
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "dev_secrets.set_secrets_glob_pattern" do |app|
|
4
|
+
app.config.paths["config/secrets"].glob = "secrets*.yml{,.enc}"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
Secrets.instance_eval do
|
11
|
+
require "active_support/message_encryptor"
|
12
|
+
|
13
|
+
def _dev_secrets_parse(paths, env:)
|
14
|
+
all_secrets = Hash.new
|
15
|
+
valid_encrypted_secrets_file = false
|
16
|
+
invalid_message = false
|
17
|
+
|
18
|
+
paths_enc, paths_plain = paths.partition { |path| path.end_with?(".enc") }
|
19
|
+
|
20
|
+
paths_plain.each do |path|
|
21
|
+
_dev_secrets_parse_file(path, env, all_secrets)
|
22
|
+
end
|
23
|
+
|
24
|
+
paths_enc.each do |path|
|
25
|
+
begin
|
26
|
+
_dev_secrets_parse_file(path, env, all_secrets)
|
27
|
+
valid_encrypted_secrets_file = true
|
28
|
+
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
29
|
+
invalid_message = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# If at least one encrypted secrets file was loaded, then ignore the
|
34
|
+
# exceptions from any failures.
|
35
|
+
raise ActiveSupport::MessageEncryptor::InvalidMessage if invalid_message && !valid_encrypted_secrets_file
|
36
|
+
all_secrets
|
37
|
+
end
|
38
|
+
|
39
|
+
alias parse_original parse
|
40
|
+
alias parse _dev_secrets_parse
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def _dev_secrets_parse_file(path, env, all_secrets)
|
45
|
+
require "erb"
|
46
|
+
secrets = YAML.load(ERB.new(preprocess(path)).result) || {}
|
47
|
+
all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"]
|
48
|
+
all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dev_secrets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesse Kipp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.0
|
27
|
+
description: |
|
28
|
+
Commit multiple encrypted secrets files and decrypt only the one
|
29
|
+
appropriate for the current environment.
|
30
|
+
email:
|
31
|
+
- jesse@toomanybees.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/dev_secrets.rb
|
40
|
+
- lib/dev_secrets/version.rb
|
41
|
+
- lib/tasks/dev_secrets_tasks.rake
|
42
|
+
homepage: https://github.com/TooManyBees/dev_secrets
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.5.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Rails 5.1 encrypted secrets in dev
|
66
|
+
test_files: []
|