Skip to content

Wire ModelEnvelope into kafka cache storage's read and write paths #1689

Closed

Description

@jfallows

Describe the desired outcome from the user's perspective

As a ModelTransform (#2325/#2326) that needs message metadata carried outside the value itself, I want the kafka cache storage layer to give my transform a real ModelEnvelope (#2384) backed by the cached record's actual headers, so that I can read metadata that was present on produce and write metadata that a consumer needs on fetch, without knowing anything about Kafka myself.

Acceptance criteria

0. Implementation layer

This lives in the shared kafka cache storage implementation, not in any single binding's factory. The binding resolves the model (catalog + schema id) and supplies the per-message long authorization; the storage read and write paths — populating and draining the envelope — are the storage layer's own behavior, invoked identically regardless of which binding reads or writes through it. Any future binding built on this storage layer inherits identical behavior with no separate implementation of its own.

1. Produce path: materializing envelope writes as real headers

When a value pipeline's composed transform calls ModelEnvelope.set(name, value) during encode, the storage write path collects every named value written during that encode pass and, once encode completes, writes each as a real Kafka header on the produced record — repeated set calls under one name become repeated headers with that name, in call order. A transform that writes nothing leaves the record's header set untouched.

2. Fetch path: populating envelope reads from real headers

Before invoking the value pipeline's decode, the storage read path constructs a ModelEnvelope backed by the cached record's actual headers, so that envelope.count(name)/envelope.get(name, index) reflect exactly what is present on that record — no headers means an empty envelope, not an error. A composed transform that never calls envelope() incurs no cost from this — the envelope is materialized lazily, only when a transform actually asks for it.

3. Symmetry with existing conversion

This mirrors, at the metadata level, the same principle the existing JSON↔Avro view: json conversion already establishes at the value level: the storage layer provides a real, general mechanism (there, format conversion; here, an out-of-value metadata channel) that any composed transform can use, with the storage layer itself carrying no opinion about what a transform does with it.

Coverage

Unit and k3po coverage for: a transform that writes one named value on encode and a corresponding fetch reading it back correctly; a transform writing the same name more than once producing that many headers in order; a fetched record with no headers presenting an empty envelope with no error; a transform that never touches the envelope incurring no observable behavior change from before this issue.

Additional context

Depends on #2384 (ModelEnvelope, shipped) and #2310 (the authorization parameter on ModelPipeline.transform, shipped).

Per-message authorization on the fetch path is a separate issue, not this one's scope: #2423. That issue exists because there is currently nowhere on the per-consumer fetch path to plug a live authorization value into at all — the fetch stream constructs no model pipeline of its own today. This issue's envelope wiring is orthogonal to that and doesn't depend on it landing first.

Activity

  1. added theissue type on Mar 30, 2026
  2. changed the title [-]Implement consume-path decryption with per-consumer authorization in kafka-cache-client[/-] [+]Implement consume-path per-consumer field authorization in kafka-cache-client[/+] on Aug 4, 2026
  3. jfallows commented on Aug 4, 2026

    @jfallows
    ContributorAuthor

    Three additions from the validation-ordering discussion.

    1. Pipeline ordering is fixed, not configurable

    produce (encode):  parse → validate → encrypt → sink
    consume (decode):  parse → decrypt  → validate → sink
    

    Validation always operates on plaintext — base64 ciphertext will not satisfy a pattern, maxLength, enum, or numeric range on the plaintext value, so validate-before-decrypt would fail every encrypted message. Encryption is therefore the outermost transform on both paths.

    This ordering must be baked into pipeline composition rather than exposed as configuration. Conduktor treats interceptor ordering as operator-configurable priority except for its integrity interceptor, which it hardcodes as outermost precisely because getting it wrong is a correctness bug rather than a preference. Same reasoning applies here.

    Useful property of this order: AES-GCM is authenticated, so decryption is an integrity check and it runs before schema validation. A tampered payload fails tag verification and never reaches the validator — two layers in the right sequence for the poison-pill case.

    2. Two new startup checks, because the validator sees redacted and omitted output

    decrypt/redact/omit are branches of one per-field decision in a single traversal, so the validator downstream sees whatever the transform produced.

    • redact must be rejected where the field's own constraints exclude the zero value. "Schema-compatible" means compatible with the type, not the constraints: string with minLength: 1 redacted to "" fails validation; pattern requiring an email fails; enum without an empty member fails. Extends the existing requirement to reject redact where no zero value exists at all.
    • omit must be rejected on a required or non-nullable field. Removing a required field makes the message structurally invalid. omit is only safe on optional or nullable fields.

    Both are config-validation failures at startup, consistent with every other unsatisfiable combination in this design. The alternative — validating decrypted plaintext in one pass and applying redaction in a second — costs an extra traversal and delivers unvalidated output, which is worse.

    Consequence worth recording: validate: on the model and the encryption policy are no longer independent settings. They constrain each other, and the constraint is checked at startup.

    3. Open — a third otherwise: value?

    Conduktor's unauthorized outcome is neither redact nor omit: "if the interceptor is unable to decrypt a message, the encrypted message will be returned to the client." The consumer receives ciphertext.

    An otherwise: passthrough would be worth having for the strategy: encoded path specifically, where Zilla already passes ciphertext through untouched and is not in the key chain — and it is what a CS-FLE-capable client expects, since it can decrypt independently. It also cannot fail a type check, though a constrained field would still reject it.

    Not proposing it for v1 unless there is a use case; noting it so the otherwise: enum is not treated as closed at two values.


    Generated by Claude Code

  4. changed the title [-]Implement consume-path per-consumer field authorization in kafka-cache-client[/-] [+]Implement egress disclosure control in kafka-cache-client[/+] on Aug 4, 2026
  5. self-assigned this
    on Aug 5, 2026
  6. changed the title [-]Implement egress disclosure control in kafka-cache-client[/-] [+]Implement egress disclosure control in kafka cache storage[/+] on Aug 6, 2026
  7. changed the title [-]Implement egress disclosure control in kafka cache storage[/-] [+]Wire ModelEnvelope into kafka cache storage's read and write paths[/+] on Aug 15, 2026
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