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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -0
  3. data/README.md +16 -2
  4. data/lib/vault/encrypted_model.rb +30 -8
  5. data/lib/vault/rails/configurable.rb +3 -0
  6. data/lib/vault/rails/errors.rb +3 -0
  7. data/lib/vault/rails/json_serializer.rb +3 -0
  8. data/lib/vault/rails/version.rb +4 -1
  9. data/lib/vault/rails.rb +3 -0
  10. data/spec/dummy/app/models/lazy_person.rb +3 -0
  11. data/spec/dummy/app/models/lazy_single_person.rb +3 -0
  12. data/spec/dummy/app/models/person.rb +3 -0
  13. data/spec/dummy/config/application.rb +3 -0
  14. data/spec/dummy/config/boot.rb +3 -0
  15. data/spec/dummy/config/database.yml +7 -5
  16. data/spec/dummy/config/environment.rb +3 -0
  17. data/spec/dummy/config/environments/development.rb +3 -0
  18. data/spec/dummy/config/environments/test.rb +3 -0
  19. data/spec/dummy/config/initializers/assets.rb +3 -0
  20. data/spec/dummy/config/initializers/backtrace_silencers.rb +3 -0
  21. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
  23. data/spec/dummy/config/initializers/inflections.rb +3 -0
  24. data/spec/dummy/config/initializers/mime_types.rb +3 -0
  25. data/spec/dummy/config/initializers/session_store.rb +3 -0
  26. data/spec/dummy/config/initializers/vault.rb +3 -0
  27. data/spec/dummy/config/initializers/wrap_parameters.rb +3 -0
  28. data/spec/dummy/config/locales/en.yml +3 -0
  29. data/spec/dummy/config/routes.rb +3 -0
  30. data/spec/dummy/config/secrets.yml +3 -0
  31. data/spec/dummy/config.ru +3 -0
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/migrate/20150428220101_create_people.rb +3 -0
  34. data/spec/dummy/db/schema.rb +3 -0
  35. data/spec/dummy/db/test.sqlite3 +0 -0
  36. data/spec/dummy/lib/binary_serializer.rb +3 -0
  37. data/spec/dummy/log/development.log +18379 -0
  38. data/spec/dummy/public/404.html +5 -0
  39. data/spec/dummy/public/422.html +5 -0
  40. data/spec/dummy/public/500.html +5 -0
  41. data/spec/integration/rails_spec.rb +42 -2
  42. data/spec/lib/vault/rails/json_serializer_spec.rb +3 -0
  43. data/spec/spec_helper.rb +3 -0
  44. data/spec/support/vault_server.rb +38 -10
  45. data/spec/unit/encrypted_model_spec.rb +3 -0
  46. data/spec/unit/rails/configurable_spec.rb +3 -0
  47. data/spec/unit/rails_spec.rb +3 -0
  48. data/spec/unit/vault/rails_spec.rb +3 -0
  49. metadata +15 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d1495e96fb575962f54ab1046322ba914262ccd1c6510608969098910b26722
4
- data.tar.gz: 0a8c14b4e9b9657c8c3d8d69130a7ffd322ee12110df6f19058b612e7951c547
3
+ metadata.gz: 2cb9b608c70662fc9e761cbed5eaf27dd34382e502ffdc9fbf8a2d847309b65d
4
+ data.tar.gz: c7d1746c9807cb13771757a55e2c06077dca2a376d497c145194f57ca27a34c9
5
5
  SHA512:
6
- metadata.gz: a4864910f4373d375b1950b98f97fab013b4954939fabdb0cadede4fc1e22d082c5e6658621c03b163964b64de7d33695f02538bd4f6ac89bd2c37f228a0b0f5
7
- data.tar.gz: 3484a4c69580aeb6095b3b488ef8f8ed40fc0bb892f33104ad4dd8d852b8d403b6a0c70240264b9347fde8fbe1065e97d51d1b344c0972bc0407b7ef235c046b
6
+ metadata.gz: 8e2bb2b378c2707f7e2a2d14f68b16522e0817afbaa3f0c4850a595e4b1cec07abe6a9ae351347a334c9fe7455b9860c7f3870b8fa85ddfc62636d752420f67e
7
+ data.tar.gz: 79e817496fc0b5a30a281ecbdc4f9b86d2b575d091dde48f62380a4d80812c7af8409400f5155d84cba13477c7c9c3a0e317970dea79ab1038c81b00d87855e5
data/LICENSE CHANGED
@@ -1,3 +1,5 @@
1
+ Copyright (c) 2015 HashiCorp, Inc.
2
+
1
3
  Mozilla Public License, version 2.0
2
4
 
3
5
  1. Definitions
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}_#{column}`. This is customizable by setting the `:key` option when declaring the attribute:
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
- key = options[:key]
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
- # Return the updated column so we can save
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
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  module Vault
2
5
  module Rails
3
6
  module Configurable
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  module Vault
2
5
  module Rails
3
6
  class VaultRailsError < RuntimeError; end
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  module Vault
2
5
  module Rails
3
6
  module JSONSerializer
@@ -1,5 +1,8 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  module Vault
2
5
  module Rails
3
- VERSION = "0.8.0"
6
+ VERSION = "0.10.0"
4
7
  end
5
8
  end
data/lib/vault/rails.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "vault"
2
5
 
3
6
  require "base64"
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "binary_serializer"
2
5
 
3
6
  class LazyPerson < ActiveRecord::Base
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
 
2
5
  class LazySinglePerson < ActiveRecord::Base
3
6
  include Vault::EncryptedModel
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "binary_serializer"
2
5
 
3
6
  class Person < ActiveRecord::Base
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require File.expand_path('../boot', __FILE__)
2
5
 
3
6
  # Pick the frameworks you want:
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Set up gems listed in the Gemfile.
2
5
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
6
 
@@ -1,12 +1,14 @@
1
- default: &default
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
- <<: *default
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
  # Load the Rails application.
2
5
  require File.expand_path('../application', __FILE__)
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  Rails.application.configure do
2
5
  # Settings specified here will take precedence over those in config/application.rb.
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  Rails.application.configure do
2
5
  # Settings specified here will take precedence over those in config/application.rb.
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # Version of your assets, change this if you want to expire all your assets.
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # Configure sensitive parameters which will be filtered from the log file.
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # Add new inflection rules using the following format. Inflections
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # Add new mime types for use in respond_to blocks:
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  Rails.application.config.session_store :cookie_store, key: '_dummy_session'
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "vault/rails"
2
5
 
3
6
  require_relative "../../../support/vault_server"
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # This file contains settings for ActionController::ParamsWrapper which
@@ -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.
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  Rails.application.routes.draw do
2
5
 
3
6
  end
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Be sure to restart your server when you modify this file.
2
5
 
3
6
  # Your secret key is used for verifying the integrity of signed cookies.
data/spec/dummy/config.ru CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # This file is used by Rack-based servers to start the application.
2
5
 
3
6
  require ::File.expand_path('../config/environment', __FILE__)
Binary file
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  class CreatePeople < ActiveRecord::Migration[4.2]
2
5
  def change
3
6
  create_table :people do |t|
@@ -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
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  # Encodes and decodes binary data.
2
5
  module BinarySerializer
3
6
  def self.encode(raw)