yaml_vault 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/exe/yaml_vault +10 -3
- data/lib/yaml_vault/version.rb +1 -1
- data/lib/yaml_vault.rb +40 -1
- data/yaml_vault.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d513c736945058b14e097674eb7f2a4743718a0b
|
4
|
+
data.tar.gz: 417af775003ec2105570ef50ce819303a2561d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fce2b4f85b47332badef4c03882d86fb83cfac33ee9da92b376512de571272b5bf4580dfccee0bcbe42e359c98356a282197c1b0466e9bee1fdb39a358ba2b35
|
7
|
+
data.tar.gz: 8e8abd2ec36cb12797f110d95043f5a8947f1ebf74246da0b967779252ccfb781aa80128a9a91716f6455f26fa2debb4acfe176cfe874955c8e5f09942089016
|
data/README.md
CHANGED
@@ -109,7 +109,19 @@ Max encryptable size is 4096 bytes. (value size as encoded by Base64)
|
|
109
109
|
--aws-secret-access-key=<AWS_SECRET_ACCESS_KEY>
|
110
110
|
```
|
111
111
|
|
112
|
-
If region, access_key_id, secret_access_key is not set, use `ENV["AWS_REGION"]`, `ENV["AWS_ACCESS_KEY_ID"]`, `ENV["AWS_SECRET_ACCESS_KEY"]
|
112
|
+
If region, access_key_id, secret_access_key is not set, use `ENV["AWS_REGION"]`, `ENV["AWS_ACCESS_KEY_ID"]`, `ENV["AWS_SECRET_ACCESS_KEY"]` or default credentials or Instance Profile.
|
113
|
+
|
114
|
+
#### GCP KMS Encryption
|
115
|
+
|
116
|
+
```
|
117
|
+
% yaml_vault encrypt secrets.yml -o encrypted_secrets.yml --cryptor=gcp-kms \
|
118
|
+
--gcp-kms-resource-id=<kms-resource-id> \
|
119
|
+
--gcp-credential-file=<credential-json-file-path>
|
120
|
+
```
|
121
|
+
|
122
|
+
ex. `--gcp-kms-resource-id=projects/<PROJECT_ID>/locations/global/keyRings/<KEYRING_ID>/cryptoKeys/<KEY_ID>`
|
123
|
+
|
124
|
+
If gcp_credential_file is not set, use Google Application Default Credentials flow (https://developers.google.com/identity/protocols/application-default-credentials)
|
113
125
|
|
114
126
|
### Decrypt
|
115
127
|
|
@@ -129,6 +141,14 @@ If `ENV["YAML_VAULT_PASSPHRASE"]`, use it as passphrase
|
|
129
141
|
--aws-secret-access-key=<AWS_SECRET_ACCESS_KEY>
|
130
142
|
```
|
131
143
|
|
144
|
+
#### GCP KMS Decryption
|
145
|
+
|
146
|
+
```
|
147
|
+
% yaml_vault decrypt encrypted_secrets.yml -o secrets.yml --cryptor=gcp-kms \
|
148
|
+
--gcp-kms-resource-id=<kms-resource-id> \
|
149
|
+
--gcp-credential-file=<credential-json-file-path>
|
150
|
+
```
|
151
|
+
|
132
152
|
### Direct Assignment
|
133
153
|
|
134
154
|
```ruby
|
@@ -141,7 +161,7 @@ configs = YamlVault::Main.from_file(
|
|
141
161
|
passphrase: ENV["YAML_VAULT_PASSPHRASE"], sign_passphrase: ENV["YAML_VAULT_SIGN_PASSPHRASE"]
|
142
162
|
).decrypt
|
143
163
|
|
144
|
-
# KMS
|
164
|
+
# AWS KMS
|
145
165
|
configs = YamlVault::Main.from_file(
|
146
166
|
File.expand_path("../encrypted_sample.yml", __FILE__),
|
147
167
|
[["vault"], ["production", "password"]],
|
@@ -151,6 +171,15 @@ configs = YamlVault::Main.from_file(
|
|
151
171
|
aws_access_key_id: "xxxxxxx", # optional
|
152
172
|
aws_secret_access_key: "xxxxxxx", # optional
|
153
173
|
).decrypt
|
174
|
+
|
175
|
+
# GCP KMS
|
176
|
+
configs = YamlVault::Main.from_file(
|
177
|
+
File.expand_path("../encrypted_sample.yml", __FILE__),
|
178
|
+
[["vault"], ["production", "password"]],
|
179
|
+
"gcp-kms",
|
180
|
+
gcp_kms_resource_id: "xxxxxxx",
|
181
|
+
gcp_credential_file: File.expand_path("../credential.json", __FILE__)
|
182
|
+
).decrypt
|
154
183
|
```
|
155
184
|
|
156
185
|
## How to use with docker
|
data/exe/yaml_vault
CHANGED
@@ -8,7 +8,7 @@ class YamlVault::Cli < Thor
|
|
8
8
|
include Thor::Actions
|
9
9
|
|
10
10
|
class_option :key, aliases: "-k", type: :string, banner: "KEYNAME (format: \"KEY1.INNER_KEY,KEY2\")", desc: "target key", default: "vault"
|
11
|
-
class_option :cryptor, type: :string, enum: %w(simple aws-kms), default: "simple"
|
11
|
+
class_option :cryptor, type: :string, enum: %w(simple aws-kms gcp-kms), default: "simple"
|
12
12
|
|
13
13
|
class_option :salt, aliases: "-s", type: :string
|
14
14
|
class_option :cipher, type: :string, desc: "Encrypt cipher (see. OpenSSL::Cipher.ciphers)", default: "aes-256-cbc"
|
@@ -22,6 +22,9 @@ class YamlVault::Cli < Thor
|
|
22
22
|
class_option :aws_access_key_id, type: :string
|
23
23
|
class_option :aws_secret_access_key, type: :string
|
24
24
|
|
25
|
+
class_option :gcp_kms_resource_id, type: :string
|
26
|
+
class_option :gcp_credential_file, type: :string
|
27
|
+
|
25
28
|
desc "encrypt YAML_FILE", "Encrypt yaml file"
|
26
29
|
method_option :output, aliases: "-o", type: :string, required: true
|
27
30
|
def encrypt(yaml_file)
|
@@ -37,7 +40,9 @@ class YamlVault::Cli < Thor
|
|
37
40
|
aws_kms_key_id: options[:aws_kms_key_id],
|
38
41
|
aws_region: options[:aws_region],
|
39
42
|
aws_access_key_id: options[:aws_access_key_id],
|
40
|
-
aws_secret_access_key: options[:aws_secret_access_key]
|
43
|
+
aws_secret_access_key: options[:aws_secret_access_key],
|
44
|
+
gcp_kms_resource_id: options[:gcp_kms_resource_id],
|
45
|
+
gcp_credential_file: options[:gcp_credential_file]
|
41
46
|
).encrypt_yaml
|
42
47
|
puts "encrypted #{yaml_file} -> #{options[:output]}"
|
43
48
|
File.open(options[:output], "w") { |f| f.write encrypted_yaml }
|
@@ -57,7 +62,9 @@ class YamlVault::Cli < Thor
|
|
57
62
|
aws_kms_key_id: options[:aws_kms_key_id],
|
58
63
|
aws_region: options[:aws_region],
|
59
64
|
aws_access_key_id: options[:aws_access_key_id],
|
60
|
-
aws_secret_access_key: options[:aws_secret_access_key]
|
65
|
+
aws_secret_access_key: options[:aws_secret_access_key],
|
66
|
+
gcp_kms_resource_id: options[:gcp_kms_resource_id],
|
67
|
+
gcp_credential_file: options[:gcp_credential_file]
|
61
68
|
).decrypt_yaml
|
62
69
|
puts "decrypted #{yaml_file} -> #{options[:output]}"
|
63
70
|
File.open(options[:output], "w") { |f| f.write decrypted_yaml }
|
data/lib/yaml_vault/version.rb
CHANGED
data/lib/yaml_vault.rb
CHANGED
@@ -18,7 +18,8 @@ module YamlVault
|
|
18
18
|
def initialize(
|
19
19
|
yaml_content, keys, cryptor_name = nil,
|
20
20
|
passphrase: nil, sign_passphrase: nil, salt: nil, cipher: "aes-256-cbc", key_len: 32, signature_key_len: 64, digest: "SHA256",
|
21
|
-
aws_kms_key_id: nil, aws_region: nil, aws_access_key_id: nil, aws_secret_access_key: nil
|
21
|
+
aws_kms_key_id: nil, aws_region: nil, aws_access_key_id: nil, aws_secret_access_key: nil,
|
22
|
+
gcp_kms_resource_id: nil, gcp_credential_file: nil
|
22
23
|
)
|
23
24
|
@data = YAML.load(yaml_content)
|
24
25
|
@keys = keys
|
@@ -36,6 +37,9 @@ module YamlVault
|
|
36
37
|
@aws_access_key_id = aws_access_key_id
|
37
38
|
@aws_secret_access_key = aws_secret_access_key
|
38
39
|
|
40
|
+
@gcp_kms_resource_id = gcp_kms_resource_id
|
41
|
+
@gcp_credential_file = gcp_credential_file
|
42
|
+
|
39
43
|
@cryptor = get_cryptor(cryptor_name)
|
40
44
|
end
|
41
45
|
|
@@ -67,6 +71,8 @@ module YamlVault
|
|
67
71
|
ValueCryptor::Simple.new(@passphrase, @sign_passphrase, @salt, @cipher, @digest, @key_len, @signature_key_len)
|
68
72
|
when "aws-kms", "kms"
|
69
73
|
ValueCryptor::KMS.new(@aws_kms_key_id, region: @aws_region, aws_access_key_id: @aws_access_key_id, aws_secret_access_key: @aws_secret_access_key)
|
74
|
+
when "gcp-kms"
|
75
|
+
ValueCryptor::GCPKMS.new(@gcp_kms_resource_id, @gcp_credential_file)
|
70
76
|
else
|
71
77
|
ValueCryptor::Simple.new(@passphrase, @sign_passphrase, @salt, @cipher, @digest, @key_len, @signature_key_len)
|
72
78
|
end
|
@@ -154,6 +160,39 @@ module YamlVault
|
|
154
160
|
YAML.load(resp.plaintext)
|
155
161
|
end
|
156
162
|
end
|
163
|
+
|
164
|
+
class GCPKMS
|
165
|
+
def initialize(resource_id, credential_file)
|
166
|
+
raise "Need key resource id" unless resource_id
|
167
|
+
require 'googleauth'
|
168
|
+
require 'google/apis/cloudkms_v1'
|
169
|
+
|
170
|
+
scope = [
|
171
|
+
'https://www.googleapis.com/auth/cloud-platform'
|
172
|
+
]
|
173
|
+
|
174
|
+
@resource_id = resource_id
|
175
|
+
@client = Google::Apis::CloudkmsV1::CloudKMSService.new
|
176
|
+
if credential_file
|
177
|
+
@client.authorization = Google::Auth::DefaultCredentials.make_creds(
|
178
|
+
json_key_io: File.open(credential_file),
|
179
|
+
scope: scope
|
180
|
+
)
|
181
|
+
else
|
182
|
+
@client.authorization = Google::Auth.get_application_default(scope)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def encrypt(value)
|
187
|
+
response = @client.encrypt_crypto_key(@resource_id, {plaintext: YAML.dump(value)}, {})
|
188
|
+
Base64.strict_encode64(response.ciphertext)
|
189
|
+
end
|
190
|
+
|
191
|
+
def decrypt(value)
|
192
|
+
response = @client.decrypt_crypto_key(@resource_id, {ciphertext: Base64.strict_decode64(value)}, {})
|
193
|
+
YAML.load(response.plaintext)
|
194
|
+
end
|
195
|
+
end
|
157
196
|
end
|
158
197
|
|
159
198
|
private_constant :ValueCryptor
|
data/yaml_vault.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "activesupport", ">= 4"
|
22
22
|
spec.add_runtime_dependency "aws-sdk", "~> 2.0"
|
23
|
+
spec.add_runtime_dependency "google-api-client", "~> 0.11"
|
24
|
+
spec.add_runtime_dependency "googleauth", "~> 0.4"
|
23
25
|
spec.add_runtime_dependency "thor"
|
24
26
|
|
25
27
|
spec.add_development_dependency "bundler", "~> 1.11"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_vault
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google-api-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.11'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: googleauth
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: thor
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|