kura_encryption (kura v2.31.3)

View Source

Equality lookups on deterministic encrypted fields ({encrypted, Inner, #{mode => deterministic}}, see kura_types:encryption/1).

kura_query:where/2 and having/2 turn {Field, Value}, {Field, '=', Value} and {Field, in, Values} on a deterministic field into a lookup that compares the column to ciphertexts, and {Field, '!=', Value} and {Field, not_in, Values} into its negation. A value is cast and normalised as a write of it would be, then encrypted under the keyring's deterministic_active/0 key and every id of its deterministic_key_ids/0, so the plaintext never enters the query.

lookup_params/3 returns the same ciphertexts for a {fragment, SQL, Params} condition, which where/2 does not inspect:

Params = kura_encryption:lookup_params(my_user, email, ~"ada@example.com"),
Marks = lists:join(~", ", [~"?" || _ <- Params]),
SQL = iolist_to_binary([~"email IN (", Marks, ~")"]),
Q = kura_query:where(kura_query:from(my_user), {fragment, SQL, Params}).

The number of ciphertexts is the number of lookup keys in the keyring (one to eight), so build the placeholders from the list rather than assuming one. On SQLite, which binds a binary as text, write each placeholder as CAST(? AS BLOB).

A lookup reveals which rows hold the looked-up value, and its ciphertexts are a stable pseudonym of the value wherever the query's parameters are recorded, such as telemetry and logs.

Summary

Functions

The ciphertexts a lookup of Value in the deterministic field Field of Schema compares the column against, one per lookup key. Raises {kura, {not_a_deterministic_field, Field}} when Field is not a deterministic field of Schema, {kura, {invalid_lookup_value, Field}} when Value does not cast to a non-null value of the field, and {kura_crypto, Reason} on a keyring failure.

Functions

lookup_params(Schema, Field, Value)

-spec lookup_params(module(), atom(), term()) -> [binary()].

The ciphertexts a lookup of Value in the deterministic field Field of Schema compares the column against, one per lookup key. Raises {kura, {not_a_deterministic_field, Field}} when Field is not a deterministic field of Schema, {kura, {invalid_lookup_value, Field}} when Value does not cast to a non-null value of the field, and {kura_crypto, Reason} on a keyring failure.