Post-compile checks on the ash_vault section.
Verifiers run after the resource module is compiled, so cross-module checks — such as "does the configured vault actually implement the callbacks?" — cost no compile-time dependency on the vault.
Checks:
a plain-module
vaultexportsencrypt!/2,decrypt!/2,rotate!/1anddestroy!/1(thefun/2and MFA forms are resolved at runtime, so they are skipped)the resource's key
scopeagrees with the vault's own scope module. The effective encryption scope is the vault's —AshVault.Vault.Runtimeresolves it from the vault's:scopeoption — while the resource'sscopeis what thekey_lifecycleactions rotate and destroy. Letting the two disagree would act on a different scope than the one the data was encrypted under.This is deliberately stricter than EXTENSION_SPEC §1: spark materializes schema defaults into the DSL state, so
Spark.Dsl.Extension.fetch_opt/3cannot tell a writtenscope :tenantfrom the default one. Rather than let a silent mismatch through, AshVault requires a resource to restate a non-default scope. Both defaults areAshVault.Scopes.AshTenant, so the common case never trips; a vault built withscope: MyApp.CustomScopeneedsscope MyApp.CustomScopeon the resource too.decrypt_by_defaultnames only encrypted fieldsbackfill_fromnames an attribute that still existskey_lifecycleis only configured on ascope_owner? trueresourceno duplicate
encryptentriesnothing else on the resource still points at the plaintext attribute in a way that the encrypted form cannot honour — see
Constructs an encrypted attribute voidsbelow
use Spark.Dsl.Extension auto-prepends Spark.Dsl.Verifiers.VerifyEntityUniqueness and
VerifySectionSingletonEntities to the verifier list, so entity-level uniqueness is
already covered; the duplicate check here catches sugar/entity collisions.
Constructs an encrypted attribute voids
AshVault.Transformers.SetupEncryption removes the plaintext attribute and replaces
it with a filterable?: false, sortable?: false calculation. Anything elsewhere on the
resource that was declared against that attribute is therefore now declared against
something that is not a column, and most of those constructs fail silently rather
than loudly.
Ash and AshPostgres already catch most of them, and this verifier deliberately does not duplicate their errors:
- a relationship's
source_attribute—deps/ash/lib/ash/resource/verifiers/validate_relationship_attributes.ex:33-40raises "expects source attributeemailto be defined"; the other side is caught on the other resource at:75-83of the same file. - a
postgrescheck_constraintsentry —deps/ash_postgres/lib/verifiers/validate_check_constraints.ex:17-30raises.
The multitenancy attribute is rejected earlier by
AshVault.Transformers.SetupEncryption, before removing any attributes. AshPostgres
needs that column while persisting key metadata, before Ash's multitenancy verifier runs.
Two do not, and this verifier covers them:
an identity whose
keysinclude the encrypted field. Ash's owndeps/ash/lib/ash/resource/verifiers/verify_identities.ex:16accepts a key that is either an attribute or a calculation — and the encrypted field is now exactly that, a calculation. Soidentity :unique_email, [:email]compiles with no complaint whatsoever on a Postgres-backed resource, the migration generator has no column to index, and duplicates start landing while the developer believes the field is unique. (ETS-backed resources happen to fail viaAsh.DataLayer.Verifiers.RequirePreCheckWith, but that is an ETS-only accident: Postgres enforces identities with a real index and needs no pre-check, so the realistic configuration is the unguarded one.)a
postgrescustom_indexesentry naming the encrypted field. Nothing in AshPostgres validates those field names —AshPostgres.DataLayer.Info.custom_indexes/1hands them straight to the migration generator — so the index is generated against a column that does not exist.