eyaml 0.3.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +92 -53
- data/README.md +72 -4
- data/eyaml.gemspec +1 -0
- data/lib/eyaml/railtie.rb +26 -7
- data/lib/eyaml/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db8844c2bbddc8461708c26243e51830e6caabb0863b51a255dcef05f762842
|
4
|
+
data.tar.gz: bc1103be88e0418663ce58bfc7f4b497466a9fe98a08b5ddddafae76d18667ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b6f9ebcae7c5a2b7920abb7ec5e75e06c1ac2e51eff9b8ea7f61a00305c80e06b60bcc3219a5b94700a6d4af6ba6915f92c646573d00a4fb1a43732aa331ec1
|
7
|
+
data.tar.gz: 4d6359cad8b3514dd4fdc8ecfe9ccfed07bd9e18a5d5bd6033633696111754e522001a18cc8c9746da0f065ee14bc8a2f6a7b009bd2bd7926293e2b658a9ccdc
|
data/.github/workflows/test.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.2
|
data/Gemfile.lock
CHANGED
@@ -1,89 +1,127 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eyaml (0.
|
4
|
+
eyaml (0.4.0)
|
5
5
|
rbnacl (~> 7.1)
|
6
6
|
thor (~> 1.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (7.
|
12
|
-
actionview (= 7.
|
13
|
-
activesupport (= 7.
|
14
|
-
|
11
|
+
actionpack (7.1.3)
|
12
|
+
actionview (= 7.1.3)
|
13
|
+
activesupport (= 7.1.3)
|
14
|
+
nokogiri (>= 1.8.5)
|
15
|
+
racc
|
16
|
+
rack (>= 2.2.4)
|
17
|
+
rack-session (>= 1.0.1)
|
15
18
|
rack-test (>= 0.6.3)
|
16
|
-
rails-dom-testing (~> 2.
|
17
|
-
rails-html-sanitizer (~> 1.
|
18
|
-
actionview (7.
|
19
|
-
activesupport (= 7.
|
19
|
+
rails-dom-testing (~> 2.2)
|
20
|
+
rails-html-sanitizer (~> 1.6)
|
21
|
+
actionview (7.1.3)
|
22
|
+
activesupport (= 7.1.3)
|
20
23
|
builder (~> 3.1)
|
21
|
-
erubi (~> 1.
|
22
|
-
rails-dom-testing (~> 2.
|
23
|
-
rails-html-sanitizer (~> 1.
|
24
|
-
activesupport (7.
|
24
|
+
erubi (~> 1.11)
|
25
|
+
rails-dom-testing (~> 2.2)
|
26
|
+
rails-html-sanitizer (~> 1.6)
|
27
|
+
activesupport (7.1.3)
|
28
|
+
base64
|
29
|
+
bigdecimal
|
25
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
connection_pool (>= 2.2.5)
|
32
|
+
drb
|
26
33
|
i18n (>= 1.6, < 2)
|
27
34
|
minitest (>= 5.1)
|
35
|
+
mutex_m
|
28
36
|
tzinfo (~> 2.0)
|
37
|
+
base64 (0.2.0)
|
38
|
+
bigdecimal (3.1.6)
|
29
39
|
builder (3.2.4)
|
30
40
|
coderay (1.1.3)
|
31
|
-
concurrent-ruby (1.
|
41
|
+
concurrent-ruby (1.2.3)
|
42
|
+
connection_pool (2.4.1)
|
32
43
|
crass (1.0.6)
|
33
|
-
|
34
|
-
|
35
|
-
|
44
|
+
debug (1.9.2)
|
45
|
+
irb (~> 1.10)
|
46
|
+
reline (>= 0.3.8)
|
47
|
+
diff-lcs (1.5.1)
|
48
|
+
drb (2.2.0)
|
49
|
+
ruby2_keywords
|
50
|
+
erubi (1.12.0)
|
51
|
+
fakefs (1.8.0)
|
36
52
|
ffi (1.15.5)
|
37
|
-
i18n (1.
|
53
|
+
i18n (1.14.1)
|
38
54
|
concurrent-ruby (~> 1.0)
|
39
|
-
|
55
|
+
io-console (0.7.2)
|
56
|
+
irb (1.11.1)
|
57
|
+
rdoc
|
58
|
+
reline (>= 0.4.2)
|
59
|
+
loofah (2.22.0)
|
40
60
|
crass (~> 1.0.2)
|
41
|
-
nokogiri (>= 1.
|
61
|
+
nokogiri (>= 1.12.0)
|
42
62
|
method_source (1.0.0)
|
43
|
-
minitest (5.
|
44
|
-
|
63
|
+
minitest (5.21.2)
|
64
|
+
mutex_m (0.2.0)
|
65
|
+
nokogiri (1.16.0-arm64-darwin)
|
45
66
|
racc (~> 1.4)
|
46
|
-
nokogiri (1.
|
67
|
+
nokogiri (1.16.0-x86_64-linux)
|
47
68
|
racc (~> 1.4)
|
48
|
-
pry (0.14.
|
69
|
+
pry (0.14.2)
|
49
70
|
coderay (~> 1.1)
|
50
71
|
method_source (~> 1.0)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
72
|
+
psych (5.1.2)
|
73
|
+
stringio
|
74
|
+
racc (1.7.3)
|
75
|
+
rack (3.0.8)
|
76
|
+
rack-session (2.0.0)
|
77
|
+
rack (>= 3.0.0)
|
78
|
+
rack-test (2.1.0)
|
79
|
+
rack (>= 1.3)
|
80
|
+
rackup (2.1.0)
|
81
|
+
rack (>= 3)
|
82
|
+
webrick (~> 1.8)
|
83
|
+
rails-dom-testing (2.2.0)
|
84
|
+
activesupport (>= 5.0.0)
|
85
|
+
minitest
|
57
86
|
nokogiri (>= 1.6)
|
58
|
-
rails-html-sanitizer (1.
|
59
|
-
loofah (~> 2.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
87
|
+
rails-html-sanitizer (1.6.0)
|
88
|
+
loofah (~> 2.21)
|
89
|
+
nokogiri (~> 1.14)
|
90
|
+
railties (7.1.3)
|
91
|
+
actionpack (= 7.1.3)
|
92
|
+
activesupport (= 7.1.3)
|
93
|
+
irb
|
94
|
+
rackup (>= 1.0.0)
|
64
95
|
rake (>= 12.2)
|
65
|
-
thor (~> 1.0)
|
66
|
-
zeitwerk (~> 2.
|
67
|
-
rake (13.0
|
96
|
+
thor (~> 1.0, >= 1.2.2)
|
97
|
+
zeitwerk (~> 2.6)
|
98
|
+
rake (13.1.0)
|
68
99
|
rbnacl (7.1.1)
|
69
100
|
ffi
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rspec
|
75
|
-
rspec-
|
76
|
-
|
101
|
+
rdoc (6.6.2)
|
102
|
+
psych (>= 4.0.0)
|
103
|
+
reline (0.4.2)
|
104
|
+
io-console (~> 0.5)
|
105
|
+
rspec (3.13.0)
|
106
|
+
rspec-core (~> 3.13.0)
|
107
|
+
rspec-expectations (~> 3.13.0)
|
108
|
+
rspec-mocks (~> 3.13.0)
|
109
|
+
rspec-core (3.13.0)
|
110
|
+
rspec-support (~> 3.13.0)
|
111
|
+
rspec-expectations (3.13.0)
|
77
112
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-mocks (3.
|
113
|
+
rspec-support (~> 3.13.0)
|
114
|
+
rspec-mocks (3.13.1)
|
80
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.
|
82
|
-
rspec-support (3.
|
83
|
-
|
84
|
-
|
116
|
+
rspec-support (~> 3.13.0)
|
117
|
+
rspec-support (3.13.1)
|
118
|
+
ruby2_keywords (0.0.5)
|
119
|
+
stringio (3.1.0)
|
120
|
+
thor (1.3.0)
|
121
|
+
tzinfo (2.0.6)
|
85
122
|
concurrent-ruby (~> 1.0)
|
86
|
-
|
123
|
+
webrick (1.8.1)
|
124
|
+
zeitwerk (2.6.12)
|
87
125
|
|
88
126
|
PLATFORMS
|
89
127
|
arm64-darwin-20
|
@@ -91,6 +129,7 @@ PLATFORMS
|
|
91
129
|
x86_64-linux
|
92
130
|
|
93
131
|
DEPENDENCIES
|
132
|
+
debug
|
94
133
|
eyaml!
|
95
134
|
fakefs
|
96
135
|
ffi (~> 1.15.5)
|
data/README.md
CHANGED
@@ -55,12 +55,13 @@ Options:
|
|
55
55
|
```shell
|
56
56
|
-> % eyaml encrypt config/secrets.production.eyaml
|
57
57
|
Wrote 517 bytes to config/secrets.production.eyaml.
|
58
|
-
```
|
59
58
|
|
59
|
+
Note: entries starting with an `_` won't be encrypted. This has to be the case for the `_public_key`, but can be handy if you want to add keys in there that you dont't want to encrypt. Like a public key for ex.
|
60
|
+
```
|
60
61
|
|
61
62
|
#### `eyaml decrypt`
|
62
63
|
|
63
|
-
Decrypts the provided EYAML file.
|
64
|
+
Decrypts the whole provided EYAML file.
|
64
65
|
|
65
66
|
```shell
|
66
67
|
-> % eyaml decrypt config/secrets.production.eyaml
|
@@ -70,7 +71,15 @@ secret: password
|
|
70
71
|
|
71
72
|
#### `eyaml keygen`
|
72
73
|
|
73
|
-
Generates the keypair for the encryption flow to work. The public key must be placed into the file at `_public_key`
|
74
|
+
Generates the keypair for the encryption flow to work. The public key must be placed into the file at `_public_key` like this:
|
75
|
+
e.g.
|
76
|
+
```shell
|
77
|
+
-> % cat config/credentials.development.eyaml
|
78
|
+
_public_key: a3dbdef9efd1e52a34588de56a6cf9b03bbc2aaf0edda145cfbd9a6370a0a849
|
79
|
+
my_secret: 85d1fca99d98c4e7b83b868f75f809e1e33346317b0c354b593cdcdc8793ad4e
|
80
|
+
```
|
81
|
+
|
82
|
+
The private key must be saved in the default key directory (`/opt/ejson/keys`) or the `EJSON_PRIVATE_KEY` must point to the right directory, with the filename being the public key and the contents, the private key, a key directory you'll provide later, or just pass the `--write` flag for `eyaml` to handle it for you.
|
74
83
|
|
75
84
|
```shell
|
76
85
|
-> % eyaml keygen
|
@@ -88,11 +97,70 @@ b01592942ba10f152bcf7c6b6734f6392554c578ff24cebcc62f9e3da6fcf302
|
|
88
97
|
|
89
98
|
### Rails
|
90
99
|
|
91
|
-
`eyaml` comes with baked in Rails support.
|
100
|
+
`eyaml` comes with baked in Rails support.
|
101
|
+
It will search for a rails secrets or credentials file in `config/`, decrypt, and load the first valid one it finds.
|
102
|
+
|
103
|
+
For this a public-private keyfile needs to be present, which you can generate with `eyaml keygen`. For a development/test environment you can keep this in your
|
104
|
+
version control, but on production you want to take the proper precautions since this can contain your rails master key as well.
|
105
|
+
|
106
|
+
Credential files have priority over secrets before rails 7.2:
|
107
|
+
`credentials.{eyaml|eyml|ejson}` (e.g. `config/credentials.eyaml`) then `credentials.$env.{eyaml|eyml|ejson}` (e.g. `credentials.production.eyml`).
|
108
|
+
Then if no credentials are found it will look for a secrets file:
|
92
109
|
`secrets.{eyaml|eyml|ejson}` (e.g. `config/secrets.eyaml`) then `secrets.$env.{eyaml|eyml|ejson}` (e.g. `secrets.production.eyml`).
|
93
110
|
|
111
|
+
Note: From rails 7.2 onwards secrets are deprecated and eyaml will only look for credential files.
|
112
|
+
|
94
113
|
Instead of needing a private key locally, you can provide it to EYAML by setting `EJSON_PRIVATE_KEY` and it'll be automatically used for decrypting the secrets file.
|
95
114
|
|
115
|
+
If you put your rails master key encrypted in the eyaml file, make sure you don't have another `master.key` file somewhere, since that can interfere.
|
116
|
+
|
117
|
+
### Example setup
|
118
|
+
|
119
|
+
To add encryption + credentials to a rails project do the following things:
|
120
|
+
|
121
|
+
- Generate a private-public keypair with (or add the --write flag and a keypair file will be written to `/opt/ejson/keys/`):
|
122
|
+
```shell
|
123
|
+
eyaml keygen
|
124
|
+
|
125
|
+
Public Key: a3dbdef9efd1e52a34588de56a6cf9b03bbc2aaf0edda145cfbd9a6370a0a849
|
126
|
+
Private Key: b01592942ba10f152bcf7c6b6734f6392554c578ff24cebcc62f9e3da6fcf302
|
127
|
+
```
|
128
|
+
|
129
|
+
For this example I show you a dev setup, but for test, production etc. it works the same.
|
130
|
+
|
131
|
+
- Create a file with the name of the public key that contains the private key.
|
132
|
+
If you don't want to add the file to the `/opt/ejson/keys/` (for for example a dev/test environment) so you can check it in with your version management you can set the `EJSON_KEYDIR` to the keypair file
|
133
|
+
in rails `application.rb` like so:
|
134
|
+
```ruby
|
135
|
+
ENV["EJSON_KEYDIR"] = File.expand_path("../dev/ejson-keys", __dir__) unless Rails.env.production?
|
136
|
+
```
|
137
|
+
and rails will look there for the file decryption when the environment loads.
|
138
|
+
You can test this by calling
|
139
|
+
```ruby
|
140
|
+
Rails.application.credentials.secret_key_base
|
141
|
+
```
|
142
|
+
in a rails console and it should give you back the unencrypted key.
|
143
|
+
|
144
|
+
Note that you should not have a `config/master.key` file present (created by rails when using it's credentials management like for ex when calling `rails credentials:edit`) when using eyaml.
|
145
|
+
Eyaml is a replacement for rails's credentials management and currently conflicts with it. Eyaml will raise when a master.key is present.
|
146
|
+
|
147
|
+
- Create a `config/credentials.development.eyaml` file
|
148
|
+
- In the credentials file add:
|
149
|
+
```yaml
|
150
|
+
_public_key: a3dbdef9efd1e52a34588de56a6cf9b03bbc2aaf0edda145cfbd9a6370a0a849
|
151
|
+
```
|
152
|
+
on top
|
153
|
+
- You can then add your rails `secret_key_base` like so:
|
154
|
+
```yaml
|
155
|
+
secret_key_base: <secret>
|
156
|
+
```
|
157
|
+
And any other key you need in there.
|
158
|
+
- Then every time you edit your eyaml file(s) run (for ex for development):
|
159
|
+
```shell
|
160
|
+
eyaml encrypt config/credentials.development.eyaml
|
161
|
+
```
|
162
|
+
And you can see that the key put in there is encrypted afterwards (except the ones starting with an `_`).
|
163
|
+
|
96
164
|
### Apple M1 Support
|
97
165
|
|
98
166
|
If you're using the new Apple M1, you need to ensure that you're using a `ffi` that is working. We've temporarily been including a fork with a fix in any `Gemfile` where we've included `eyaml`:
|
data/eyaml.gemspec
CHANGED
data/lib/eyaml/railtie.rb
CHANGED
@@ -8,8 +8,27 @@ module EYAML
|
|
8
8
|
class Railtie < Rails::Railtie
|
9
9
|
PRIVATE_KEY_ENV_VAR = "EJSON_PRIVATE_KEY"
|
10
10
|
|
11
|
+
class ConflictError < StandardError
|
12
|
+
end
|
13
|
+
|
11
14
|
config.before_configuration do
|
12
|
-
|
15
|
+
if File.exist?(Rails.root.join("config", "master.key"))
|
16
|
+
raise ConflictError, "A config/master.key has been found. The rails credentials lookup conflicts with eyaml. Please remove rails credentials management by removing the master.key file to keep using eyaml."
|
17
|
+
end
|
18
|
+
secret_files_present = Dir.glob(auth_files(:secrets)).any?
|
19
|
+
credential_files_present = Dir.glob(auth_files(:credentials)).any?
|
20
|
+
|
21
|
+
secrets_or_credentials = if Rails.version >= "7.2"
|
22
|
+
:credentials
|
23
|
+
else
|
24
|
+
if credential_files_present
|
25
|
+
:credentials
|
26
|
+
elsif secret_files_present
|
27
|
+
:secrets
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
auth_files(secrets_or_credentials).each do |file|
|
13
32
|
next unless valid?(file)
|
14
33
|
|
15
34
|
# If private_key is nil (i.e. when $EJSON_PRIVATE_KEY is not set), EYAML will search
|
@@ -19,7 +38,7 @@ module EYAML
|
|
19
38
|
.deep_symbolize_keys
|
20
39
|
.except(:_public_key)
|
21
40
|
|
22
|
-
break Rails.application.
|
41
|
+
break Rails.application.send(secrets_or_credentials).deep_merge!(secrets)
|
23
42
|
end
|
24
43
|
end
|
25
44
|
|
@@ -30,13 +49,13 @@ module EYAML
|
|
30
49
|
pathname.exist?
|
31
50
|
end
|
32
51
|
|
33
|
-
def
|
34
|
-
EYAML::SUPPORTED_EXTENSIONS.
|
52
|
+
def auth_files(secrets_or_credentials)
|
53
|
+
EYAML::SUPPORTED_EXTENSIONS.flat_map do |ext|
|
35
54
|
[
|
36
|
-
Rails.root.join("config", "
|
37
|
-
Rails.root.join("config", "
|
55
|
+
Rails.root.join("config", "#{secrets_or_credentials}.#{ext}"),
|
56
|
+
Rails.root.join("config", "#{secrets_or_credentials}.#{Rails.env}.#{ext}")
|
38
57
|
]
|
39
|
-
end
|
58
|
+
end
|
40
59
|
end
|
41
60
|
end
|
42
61
|
end
|
data/lib/eyaml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eyaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Stolarsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Secret management by encrypting values in a YAML file with a public/private
|
70
84
|
keypair
|
71
85
|
email:
|
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '0'
|
117
131
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.4.21
|
119
133
|
signing_key:
|
120
134
|
specification_version: 4
|
121
135
|
summary: Asymmetric keywise encryption for YAML
|