Skip to content

engine: extend CatalogHandler with provider-supplied field transforms #1680

Open

Description

@jfallows

Describe the desired outcome from the user's perspective

As a Zilla operator, I want a catalog to be able to supply a compiled transform for a resolved schema, so that behaviour derived from the schema registry can be installed without the engine or the models containing any of it.

Open scope question, not a staleness fix: does anything still need this? The composition pattern this issue was designed for — a registry-mode catalog resolving its own vendor rule set into a transform the model composes with — is achievable a different way with what's already shipped: an installed per-codec extension (AvroModelExtFactorySpi and peers, #1681–#1684) can reach a live CatalogHandler directly (via the model's own already-resolved catalog reference) and drive whatever it needs from there, rather than the catalog handing a value back through a new CatalogHandler method. No known current consumer needs a catalog-supplied ModelTransform via the mechanism below. Worth deciding whether to keep this open on the strength of the capability being generically useful on its own, or close it until a real need reappears.

Acceptance criteria

  • Add to CatalogHandler:

    default ModelTransform supplyTransform(long traceId, long bindingId, int schemaId)
    {
        return ModelTransform.NONE;
    }

    Return type is ModelTransform directly — no Class kind token. The token's only purpose was avoiding a licensing dependency from engine (Apache-licensed) onto the Aklivity-Community-Licensed common-avro/common-json/common-protobuf modules; ModelTransform (Add a pluggable per-field ModelTransform hook to the model pipeline (decode + encode) #2325→feat(engine): add pluggable per-field ModelTransform hook to the model pipeline #2326, merged) is engine-native, so that dependency never arises. A catalog implementation still resolves the schema's format internally to build the right transform — it already has the schema id and determines format from what it resolves; it never needed the caller to supply which kind to build.

  • Catalog-supplied and model-owned transforms compose — they are not alternatives. A deployment can legitimately want a catalog purely for schema validation while using a model-owned transform for something else on the same schema — composition has to work per-field, not just per-deployment, since either seam may claim a disjoint subset of fields on the very same message.

  • Default returns ModelTransform.NONE, unconditionally. The model's own composed transform (built from whatever extensions are installed against its ModelExtFactorySpi, per Declare AvroModelExtFactorySpi and wire provider-supplied pipeline stages in avro model #1681–Add bytes and string models and declare their ModelExtFactorySpi to wire provider-supplied pipeline stages #1684) runs regardless of what the catalog returns, and ModelTransform.NONE composes for free (the same cheap-elision behavior already established for ModelTransform.NONE elsewhere). There is only one state — no null-vs-sentinel distinction to maintain. A fail-closed concern ("capability absent, reject at startup if something was configured expecting it") is each catalog implementation's own startup-validation responsibility, not something a generic caller infers from the return value.

  • Composition order: catalogTransform.andThen(modelOwnedTransform) on encode, reversed on decode — the standard last-applied-first-stripped ordering for any layered composition, the same shape every multi-stage transform chain in this design follows. For disjoint fields (the expected case) order doesn't matter at all, since each layer only touches what it claims. Order matters only when the same field is claimed by both, which composes as one more position in whatever chain-composition mechanism the model-owned transform already uses, not a new mechanism.

  • Caching this composed transform by schema id depends on one required property: a schema id is immutable once assigned. Any catalog implementation this SPI supports must guarantee that resolving the same schema id always yields the same schema definition and any attached rule/metadata — never a mutated one in place — and that a rule change mints a new schema id rather than altering the existing one's registration. Given that, a catalog-supplied transform resolved once per schema id, and its composition with the model-owned transform, never needs re-resolving for the lifetime of that id.

  • model-avro builds its own concrete ModelTransform implementation — AvroModelTransform — distinct from the AvroModelDecoderTransform/AvroModelEncoderTransform adapters that bridge AvroEvent↔ModelEvent; this is model-avro's own internal composition root, and is not itself tracked by any GitHub issue in this epic — Declare AvroModelExtFactorySpi and wire provider-supplied pipeline stages in avro model #1681–Add bytes and string models and declare their ModelExtFactorySpi to wire provider-supplied pipeline stages #1684 declare the generic extension-point SPI (AvroModelExtFactorySpi and its siblings) that installed providers plug into, which is a distinct piece of scope from the model's own base ModelTransform implementation that those providers plug into. model-json/model-protobuf get the analogous JsonModelTransform/ProtobufModelTransform.

  • Default returns ModelTransform.NONE, so existing catalog implementations are unaffected — same guarantee the old default-null gave, restated for the new type.

  • Javadoc stays protocol-neutral per runtime/engine/AGENTS.md — no mention of encryption or Kafka

  • Unit coverage: the default returning ModelTransform.NONE; a test catalog whose supplied transform composes correctly with a model-supplied transform on the same schema, covering both the disjoint-field case and the same-field chain case; encode/decode ordering (catalog transform outermost on encode, innermost on decode)

Additional context

This replaces the March 2026 draft's Appendix A — FieldEncryption, TaggedFieldConsumer, DekConsumer, NO_DEK_VERSION, NO_FIELD_ENCRYPTION, and newFieldEncryption(...) are all withdrawn.

Rationale: an earlier draft had two separate cipher implementations, one model-side and one catalog-side. This design has one, model-side, with catalogs and vaults only parameterizing it. A provider returns a compiled transform which the model composes through the existing stream.transform(t).into(sink) — inheriting Status, resume(...), reset(), SUSPENDED/STARVED, and identity() for free.

Scope note: this issue was previously four separable engine changes and has been split so each is independently reviewable and landable:

Alternative considered: per-codec capability interfaces declared in the codec libraries with instanceof on the handler. More conventional typing, but it makes catalog capabilities implicit at the call site.

Activity

  1. added theissue type on Mar 30, 2026
  2. self-assigned this
    on Apr 1, 2026
  3. changed the title [-]Extend CatalogHandler SPI with FieldEncryption strategy[/-] [+]Extend engine SPI for provider-supplied field transforms[/+] on Aug 4, 2026
  4. changed the title [-]Extend engine SPI for provider-supplied field transforms[/-] [+]engine: extend CatalogHandler with provider-supplied field transforms[/+] on Aug 4, 2026
  5. jfallows commented on Aug 4, 2026

    @jfallows
    ContributorAuthor

    Correcting the Framing description. The body above describes TINK framing as "Confluent magic byte + key-version prefix." That is wrong, verified against confluentinc/schema-registry and by executing Tink 1.16 directly.

    There is no Tink output prefix. Cryptor obtains its AEAD primitive via Registry.getPrimitive(dekTemplate.getTypeUrl(), dek, Aead.class) — a bare key-manager primitive rather than a KeysetHandle — so Tink's output-prefix variant declared on the key template is never applied. Confirmed empirically: the template reports outputPrefixType=TINK, but the primitive is com.google.crypto.tink.subtle.AesGcmJce, and an 11-byte plaintext yields exactly 39 bytes = 12 + 11 + 16, with a random first byte rather than 0x01.

    Actual layouts:

    ZILLA:                          IV(12) | ciphertext | tag(16)
    TINK:   [ 0x00 | version:int32BE ]?  IV(12) | ciphertext | tag(16)
    
    • The 5-byte prefix is MAGIC_BYTE = 0x00 followed by a big-endian int32 DEK version, and it is present only when encrypt.dek.expiry.days > 0 — i.e. only when DEK rotation is enabled. Otherwise the two framings are byte-identical.
    • For a string field the prefix sits inside the base64 encoding, not outside it.

    This actually validates keeping two framings, for a better reason than the one recorded. The version prefix exists because registry mode resolves the DEK from the DEK Registry by (kekName, subject, version, dekFormat) and so must carry the version in the payload. Embedded mode does not need it, because zilla:edek carries the EDEK per message. So the distinction is "does the payload need to identify which DEK", not "which vendor's format".

    One more variant to be aware of, relevant to strategy: encoded verification. AES256_SIV is a supported Confluent DEK format with a different layout — SIV(16) | ciphertext, length = plaintext + 16, also unprefixed. A verifier that assumes GCM framing would misjudge a SIV-encrypted field. Out of scope for v1 encryption, since we specify AES128_GCM and AES256_GCM, but the verification path in aklivity/zilla-plus#1162 should either handle it or reject it explicitly rather than silently misread it.

    Not fully verified: no Confluent test asserts an exact byte layout — their CryptorTest only round-trips — so this rests on source reading plus independent execution. Only the Java and Go clients were inspected.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions