Replaces each encrypted attribute with a private ciphertext attribute plus a decrypt calculation, and rewrites the actions that used to accept it.
Ordering is load-bearing
This transformer runs after Ash.Resource.Transformers.DefaultAccept, which is what
expands :*/nil accept lists into concrete attribute names. Running before it would
make attr.name in action.accept false everywhere and rewrite zero actions — a silent,
total failure in which nothing is ever encrypted.
Per field
- remove the plaintext attribute entity — this is the non-persistence mechanism.
There is no plaintext column, so no data layer can write one.
private?and scrubbing are not relied on for that. - add
encrypted_<name>as a:binaryattribute,public?: false,sensitive?: true,allow_nil?: true - add a calculation of the original name, type and constraints backed by
AshVault.Calculations.Decrypt - for every create/update/destroy action that accepted the attribute: add an
argument of the original type, prepend
AshVault.Changes.Encrypt, and drop the attribute fromaccept
Per searchable field, additionally
add
<name>_lookupas a:binaryattribute —public?: false,sensitive?: true,allow_nil?: true,filterable?: true, and out of the default select wherever the data layer can selectfor
unique?: true, an identity named<name>_lookup_uniqueon[<name>_lookup]. The multitenancy attribute is deliberately NOT listed: Ash adds it itself, both to the generated unique index and to the eager/pre-check query, wheneverall_tenants?is false. See the comment onadd_lookup_identity/3.On a data layer that cannot enforce an identity natively — ETS, Mnesia — this is a DSL error unless the field also carries
pre_check_with:. Seeverify_uniqueness_enforceable!/2.a
:by_<name>read action taking the plaintext as asensitive?: trueargument, backed byAshVault.Preparations.FilterByLookup
Deviation from ash_cloak: allow_nil? on the backing attribute
ash_cloak copies the original attribute.allow_nil? onto the ciphertext column. That is
wrong whenever encrypt_nil?: false, because a nil value then legitimately stores SQL
NULL in an allow_nil?: false column and the write fails. AshVault always sets the
backing attribute to allow_nil?: true and enforces real nullability through the
calculation's allow_nil? and the action argument's allow_nil? instead.
Summary
Functions
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Functions
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.