Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support blind indexes #18

Closed
kdawgwilk opened this issue Mar 11, 2021 · 1 comment
Closed

Support blind indexes #18

kdawgwilk opened this issue Mar 11, 2021 · 1 comment

Comments

@kdawgwilk
Copy link

I realize the readme calls out the ability to use cloak_ecto to create hashed searchable columns but it would be nice to offer more of a first-class option for this similar to this ruby lib https://github.com/ankane/blind_index

They reference this article which breaks down what this would look like https://www.sitepoint.com/how-to-search-on-securely-encrypted-database-fields

@danielberkompas
Copy link
Owner

@kdawgwilk Cloak.Ecto already supports blind indexes. The differences from blind_index are mainly due to Elixir / Ecto doing things differently than ActiveRecord.

As you noted, you can already use this library to create fields for blind indexes and keep them up to date, like so:

schema "table" do
  field :field_name, MyApp.Encrypted.Binary
  field :field_name_hash, MyApp.Hashed.HMAC
end

def changeset(struct, attrs \\ %{}) do
  struct
  |> cast(attrs, [:field_name, :field_name_hash])
  |> put_hashed_fields()
end

defp put_hashed_fields(changeset) do
  changeset
  |> put_change(:field_name_hash, get_field(changeset, :field_name))
end

This is functionally the same as the blind_index gem, and I don't currently see any way to make it simpler within the constraints of Ecto's design. If you have any specific suggestions, let me know!

@danielberkompas danielberkompas closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants