msakrejda / attr_vault

Simple at-rest encryption with key rotation for Sequel models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Silent failures when key_id column is missing

msakrejda opened this issue · comments

If the key_id column does not exist, attr_vault will still happily save the object, but will always read out nil, which is pretty bogus.

There are two ways to fix this:

  • make the key_id column optional, and just try every key in the keyring
  • fail to write the record if the key_id column does not exist

The first option is preferable, but the second may be somewhat simpler.

/cc @rhyselsmore

I think the thing to do is ensure that the key_id column exists if it is set, default to having it key_id (as it is now), but accept nil as a valid key_field value, which will not attempt to write out a key id, and support reading in encrypted fields with no key id by iterating over the keyring. This is probably the best combination of flexibility and sensible defaults.