vault-rails 0.8.0 → 0.10.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/LICENSE +2 -0
- data/README.md +16 -2
- data/lib/vault/encrypted_model.rb +30 -8
- data/lib/vault/rails/configurable.rb +3 -0
- data/lib/vault/rails/errors.rb +3 -0
- data/lib/vault/rails/json_serializer.rb +3 -0
- data/lib/vault/rails/version.rb +4 -1
- data/lib/vault/rails.rb +3 -0
- data/spec/dummy/app/models/lazy_person.rb +3 -0
- data/spec/dummy/app/models/lazy_single_person.rb +3 -0
- data/spec/dummy/app/models/person.rb +3 -0
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/boot.rb +3 -0
- data/spec/dummy/config/database.yml +7 -5
- data/spec/dummy/config/environment.rb +3 -0
- data/spec/dummy/config/environments/development.rb +3 -0
- data/spec/dummy/config/environments/test.rb +3 -0
- data/spec/dummy/config/initializers/assets.rb +3 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +3 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
- data/spec/dummy/config/initializers/inflections.rb +3 -0
- data/spec/dummy/config/initializers/mime_types.rb +3 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/vault.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +3 -0
- data/spec/dummy/config/locales/en.yml +3 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +3 -0
- data/spec/dummy/config.ru +3 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150428220101_create_people.rb +3 -0
- data/spec/dummy/db/schema.rb +3 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/binary_serializer.rb +3 -0
- data/spec/dummy/log/development.log +18379 -0
- data/spec/dummy/public/404.html +5 -0
- data/spec/dummy/public/422.html +5 -0
- data/spec/dummy/public/500.html +5 -0
- data/spec/integration/rails_spec.rb +42 -2
- data/spec/lib/vault/rails/json_serializer_spec.rb +3 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/vault_server.rb +38 -10
- data/spec/unit/encrypted_model_spec.rb +3 -0
- data/spec/unit/rails/configurable_spec.rb +3 -0
- data/spec/unit/rails_spec.rb +3 -0
- data/spec/unit/vault/rails_spec.rb +3 -0
- metadata +15 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cb9b608c70662fc9e761cbed5eaf27dd34382e502ffdc9fbf8a2d847309b65d
|
|
4
|
+
data.tar.gz: c7d1746c9807cb13771757a55e2c06077dca2a376d497c145194f57ca27a34c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e2bb2b378c2707f7e2a2d14f68b16522e0817afbaa3f0c4850a595e4b1cec07abe6a9ae351347a334c9fe7455b9860c7f3870b8fa85ddfc62636d752420f67e
|
|
7
|
+
data.tar.gz: 79e817496fc0b5a30a281ecbdc4f9b86d2b575d091dde48f62380a4d80812c7af8409400f5155d84cba13477c7c9c3a0e317970dea79ab1038c81b00d87855e5
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -104,7 +104,7 @@ vault_attribute :credit_card,
|
|
|
104
104
|
- **Note** This value **cannot** be the same name as the vault attribute!
|
|
105
105
|
|
|
106
106
|
#### Specifying a custom key
|
|
107
|
-
By default, the name of the key in Vault is `#{app}_#{table}_#{
|
|
107
|
+
By default, the name of the key in Vault is `#{app}_#{table}_#{attribute}`. This is customizable by setting the `:key` option when declaring the attribute:
|
|
108
108
|
|
|
109
109
|
```ruby
|
|
110
110
|
vault_attribute :credit_card,
|
|
@@ -332,6 +332,21 @@ So for the example above, the key would be:
|
|
|
332
332
|
|
|
333
333
|
my_app_people_ssn
|
|
334
334
|
|
|
335
|
+
### Encrypting without Saving
|
|
336
|
+
Normally, vault-rails will wait until the after_save callback to encrypt changed
|
|
337
|
+
values before updating them. If you'd like to encrypt changed attributes without
|
|
338
|
+
saving, call `vault_encrypt_attributes!`
|
|
339
|
+
|
|
340
|
+
```ruby
|
|
341
|
+
p = Person.new(ssn: "123-45-6789")
|
|
342
|
+
p.ssn_encrypted
|
|
343
|
+
=> nil
|
|
344
|
+
p.vault_encrypt_attributes!
|
|
345
|
+
p.ssn_encrypted
|
|
346
|
+
=> "vault:dev:flu/yp9oeYYFgjcZH2hVBA=="
|
|
347
|
+
p.persisted?
|
|
348
|
+
=> false
|
|
349
|
+
```
|
|
335
350
|
|
|
336
351
|
### Searching Encrypted Attributes
|
|
337
352
|
Because each column is uniquely encrypted, it is not possible to search for a
|
|
@@ -345,7 +360,6 @@ Person.where(ssn: "123-45-6789")
|
|
|
345
360
|
This is because the database is unaware of the plain-text data (which is part of
|
|
346
361
|
the security model).
|
|
347
362
|
|
|
348
|
-
|
|
349
363
|
Development
|
|
350
364
|
-----------
|
|
351
365
|
↥ [back to top](#table-of-contents)
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) HashiCorp, Inc.
|
|
2
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
|
|
1
4
|
require "active_support/concern"
|
|
2
5
|
|
|
3
6
|
module Vault
|
|
@@ -322,12 +325,7 @@ module Vault
|
|
|
322
325
|
# Encrypt a single attribute using Vault and persist back onto the
|
|
323
326
|
# encrypted attribute value.
|
|
324
327
|
def __vault_persist_attribute!(attribute, options)
|
|
325
|
-
|
|
326
|
-
path = options[:path]
|
|
327
|
-
serializer = options[:serializer]
|
|
328
|
-
column = options[:encrypted_column]
|
|
329
|
-
context = options[:context]
|
|
330
|
-
transform = options[:transform_secret]
|
|
328
|
+
column = options[:encrypted_column]
|
|
331
329
|
|
|
332
330
|
# Only persist changed attributes to minimize requests - this helps
|
|
333
331
|
# minimize the number of requests to Vault.
|
|
@@ -343,6 +341,19 @@ module Vault
|
|
|
343
341
|
|
|
344
342
|
# Get the current value of the plaintext attribute
|
|
345
343
|
plaintext = attributes[attribute.to_s]
|
|
344
|
+
ciphertext = __vault_write_encrypted_attribute!(plaintext, options)
|
|
345
|
+
|
|
346
|
+
# Return the updated column so we can save
|
|
347
|
+
{ column => ciphertext }
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def __vault_write_encrypted_attribute!(plaintext, options)
|
|
351
|
+
column = options[:encrypted_column]
|
|
352
|
+
key = options[:key]
|
|
353
|
+
path = options[:path]
|
|
354
|
+
serializer = options[:serializer]
|
|
355
|
+
context = options[:context]
|
|
356
|
+
transform = options[:transform_secret]
|
|
346
357
|
|
|
347
358
|
# Apply the serialize to the plaintext value, if one exists
|
|
348
359
|
if serializer
|
|
@@ -369,8 +380,7 @@ module Vault
|
|
|
369
380
|
# to get the ciphertext
|
|
370
381
|
write_attribute(column, ciphertext)
|
|
371
382
|
|
|
372
|
-
|
|
373
|
-
{ column => ciphertext }
|
|
383
|
+
ciphertext
|
|
374
384
|
end
|
|
375
385
|
|
|
376
386
|
# Generates an Vault Transit encryption context for use on derived keys.
|
|
@@ -402,6 +412,18 @@ module Vault
|
|
|
402
412
|
self.__vault_initialize_attributes!
|
|
403
413
|
end
|
|
404
414
|
end
|
|
415
|
+
|
|
416
|
+
def vault_encrypt_attributes!
|
|
417
|
+
self.class.__vault_attributes.each do |attribute, options|
|
|
418
|
+
next if !attribute_changed?(attribute) && options[:default].nil?
|
|
419
|
+
|
|
420
|
+
# Get the current value of the plaintext attribute
|
|
421
|
+
plaintext = attributes[attribute.to_s]
|
|
422
|
+
|
|
423
|
+
__vault_write_encrypted_attribute!(plaintext, options)
|
|
424
|
+
end
|
|
425
|
+
self
|
|
426
|
+
end
|
|
405
427
|
end
|
|
406
428
|
end
|
|
407
429
|
end
|
data/lib/vault/rails/errors.rb
CHANGED
data/lib/vault/rails/version.rb
CHANGED
data/lib/vault/rails.rb
CHANGED
data/spec/dummy/config/boot.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright (c) HashiCorp, Inc.
|
|
2
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
|
|
4
|
+
development:
|
|
2
5
|
adapter: sqlite3
|
|
3
6
|
pool: 5
|
|
4
7
|
timeout: 5000
|
|
5
|
-
|
|
6
|
-
development:
|
|
7
|
-
<<: *default
|
|
8
8
|
database: db/development.sqlite3
|
|
9
9
|
|
|
10
10
|
test:
|
|
11
|
-
|
|
11
|
+
adapter: sqlite3
|
|
12
|
+
pool: 5
|
|
13
|
+
timeout: 5000
|
|
12
14
|
database: db/test.sqlite3
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) HashiCorp, Inc.
|
|
2
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
|
|
1
4
|
# Files in the config/locales directory are used for internationalization
|
|
2
5
|
# and are automatically loaded by Rails. If you want to use locales other
|
|
3
6
|
# than English, add the necessary files in this directory.
|
data/spec/dummy/config/routes.rb
CHANGED
data/spec/dummy/config.ru
CHANGED
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) HashiCorp, Inc.
|
|
2
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
|
|
1
4
|
# This file is auto-generated from the current state of the database. Instead
|
|
2
5
|
# of editing this file, please use the migrations feature of Active Record to
|
|
3
6
|
# incrementally modify your database, and then regenerate this schema definition.
|
|
Binary file
|