Skip to content

Follow-up: consolidate remaining options.* abstraction leaks in openapi/asyncapi #2113

Closed

Description

@jfallows

Follow-up to #2079. That PR unified options.specs.<label>.security (scheme→guard mapping) across binding-openapi, binding-asyncapi, binding-mcp-openapi, and binding-openapi-asyncapi, and removed options.tcp / options.specs.<label>.paths/.names as internal-composite-shaped escape hatches. An audit of what's left in the same spirit turned up four items, captured here before the design discussion evaporates.

1. Authorization: derive from security, don't inline a separate authorization field

binding-kafka's KafkaOptionsConfig already has both sasl (legacy) and authorization (KafkaAuthorizationConfig{name, credentials}, mirroring HttpAuthorizationConfig/MqttAuthorizationConfig exactly) — but AsyncapiClientGenerator still only reads options.kafka.sasl (AsyncapiClientGenerator.java:421-427), never authorization. Fixing that is the immediate trigger for this item, but the better fix is broader: don't add a third per-transport authorization field (http.authorization, mqtt.authorization, kafka.authorization) — associate authorization with guards via security schemes, the same mechanism security already established, rather than inlining a standalone config section. This is the same shape as what binding-mcp-openapi already does.

Two different trust directions, two different sources:

  • Inbound (caller → Zilla): HTTP/MQTT server-side default authorization context. Should derive from the spec's declared security schemes → guard mapping (security), not a separate field.
  • Outbound (Zilla → Kafka): Kafka client credentials. Genuinely different — this is Zilla authenticating itself to the broker, not validating a caller. Should be informed by the shape/mechanism the AsyncAPI doc's own security declaration implies (e.g. "this needs SASL/SCRAM" vs "this needs OAuth2 client-credentials"), used only to know how to generate the Kafka client's authorization section in the composite — never to source actual credentials from the spec (that's a secrets-in-config anti-pattern). The credential material still flows through the operator's own guard config, exactly like every other guard reference in this codebase. Where the spec doesn't declare this, an overlay (see Mockito test failure only on GitHub Actions #3 below) would be the fallback source for the shape.

Open design question — server-side default authorization and guard multiplicity:

Today OpenapiServerGenerator/AsyncapiServerGenerator only ever generate one http_server0 regardless of how many servers the doc declares (confirmed: injectTcpRoutes/injectTlsRoutes route by port only, all converging on the single shared http_server0 binding, OpenapiServerGenerator.java:156-220). HttpOptionsConfig.authorization/MqttOptionsConfig.authorization are each a single config value — so today there is no way to express "different guard for different parts of this spec."

But security already explicitly allows different operations in the same spec to resolve to different guards (the resolver only denies AND-of-distinct-guards within one operation, not variety across operations) — so if authorization is meant to derive from security, guard multiplicity needs a real target to land on.

Resolution: guard divergence should map onto server divergence — the same multiplicity unit Workstream A (#2079) already made the axis for path dispatch and port binding. Concretely:

  • Generate one http_server0-equivalent binding per distinct-guard server-group (instead of always exactly one).
  • Dispatch to the right one via the mechanisms already available at the TCP/TLS layer:
    • Port — already works today (TcpConditionConfig.port/TlsConditionConfig.port), just needs to route to N server bindings instead of always one.
    • TLS authority/SNI — for servers sharing a port but differing by hostname. TlsConditionConfig already has an authority field (TlsConditionConfig.java:25), used elsewhere in the codebase for SNI-based routing — it's just unpopulated in injectTlsRoutes today (OpenapiServerGenerator.java:205-219). This is wiring up an existing capability, not inventing a new one.

This is real, bounded implementation work — not just a field relocation — but it's a natural extension of what Workstream A already built, not a new architectural axis.

2. mqtt.store → specs.<label>.store (ignored where not applicable)

store (a reference to an operator's own top-level store binding, currently used for MQTT session/retained-message persistence) is a general concept that happens to only be consumed today by the MQTT code path, but could become relevant to other AsyncAPI-mapped protocols later. Move it under specs.<label>.store, consistent with the per-spec-not-per-transport pattern security/catalogs already use. Where a given spec's protocol doesn't use it, ignore it silently — consistent with the fail-open, no-event-on-unmapped-value philosophy security already established.

3. mqttKafka.channels.{sessions,messages,retained} → AsyncAPI x- extension / overlay

Today options.mqttKafka.channels.{sessions,messages,retained} maps operator-supplied channel names onto the three internal topic roles the generated mqtt_kafka_proxy0 binding's own MqttKafkaOptionsConfig.topics model expects (AsyncapiProxyGenerator.java:297-317). The values are document-facing (real channel names), but the shape (three named roles) is a verbatim mirror of an internal composite's own model — AsyncAPI has no native "MQTT session topic" vocabulary, this is a pure Zilla mqtt-kafka binding-type concept expressed through options.

This binding already expresses other Zilla-specific per-operation directives as spec-embedded vendor extensions (x-zilla-http-kafka, x-zilla-sse-kafka), so options.mqttKafka.channels is the outlier, not the norm. Preferred direction: drive this from an x-zilla-mqtt-kafka-style extension on the AsyncAPI channels themselves, with an overlay mechanism (specs.<label>.overlay) as the escape hatch for docs the operator doesn't own/can't edit directly (e.g. fetched from a schema registry). Bigger lift than #1/#2 — needs both the new extension schema and the overlay indirection itself, not just a field move.

4. resolveIdentity()'s hardcoded '<namespace>:jwt0' guard reference

Not an options field, but the same design smell one layer down. resolveIdentity() (OpenapiCompositeGenerator.java:214-223, AsyncapiCompositeGenerator.java:263-272, OpenapiAsyncapiCompositeGenerator.java:144-153) rewrites any {identity} placeholder in a Kafka key/header/filter template into ${guarded['<namespace>:jwt0'].identity} — a hardcoded literal guard name, completely independent of whatever guard security actually resolved for that operation. Two real consequences, not just style:

  • The security mechanism this PR built doesn't cover {identity} substitution at all — it's a silent, separate path.
  • Any operator whose guard isn't literally named jwt0 gets a template that resolves to nothing, with no schema validation or generation-time error to catch it. This is a correctness bug shape (silent failure), not just an abstraction-leak nitpick.

Fix: thread the actual resolved GuardedRef.qname for that operation (already computed by OpenapiGuardResolver/AsyncapiGuardResolver per #2079's Workstream B) into the {identity} substitution site, instead of the hardcoded literal. Once #1's security-scheme→guard resolution is the single source of truth end to end, this becomes close to a mechanical fix — same resolved reference, two consumption sites (route guarded: block and {identity} template) instead of one.

Sequencing note

If the overlay mechanism from #3 gets scoped generally enough (not narrowly for mqttKafka.channels alone), it could plausibly also carry the security-scheme-shape hint used for #1's Kafka-auth-mechanism sourcing, and even the guard reference for #4 — worth designing the overlay's extension surface generally rather than single-purpose, so it isn't revisited three separate times.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions