Skip to content

binding-openapi-asyncapi: options.specs.asyncapi.<name>.security is accepted but never consumed #2133

Closed

Description

@jfallows

Problem

OpenapiAsyncapiOptionsConfigAdapter fully round-trips options.specs.asyncapi.<name>.security (a scheme-name → guard-name map, same shape as the openapi side) into AsyncapiSpecificationConfig.security. The schema (openapi.asyncapi.schema.patch.json) declares it as a legitimate operator-facing property.

However, nothing in binding-openapi-asyncapi ever reads it:

  • OpenapiAsyncapiCompositeGenerator.generate() now threads asyncapiSpec.security into AsyncapiSchemaConfig (fixed alongside Follow-up: consolidate remaining options.* abstraction leaks in openapi/asyncapi #2113 as parity with the sibling security plumbing), but that's as far as it goes.
  • OpenapiAsyncapiProxyGenerator.resolveGuarded() — the only place that resolves a route's guard — only ever combines operation.security (the OpenAPI operation) with schema.security (the OpenAPI spec's scheme map). It never looks at the AsyncAPI/Kafka side's security or AsyncapiOperationView.security at all.

So an operator can configure options.specs.asyncapi.<name>.security, see it validate against the schema, and it will silently do nothing — the same "declared but inert" pattern the #2113 cleanup targeted elsewhere.

Why this isn't a small wiring fix

Unlike the other #2113 findings, there's no direct place to "just wire it in": OpenapiGuardResolver.resolve() explicitly rejects combining more than one distinct guard on a single route —

"operation "%s" in spec "%s" requires multiple distinct guards (...) simultaneously, which is not supported because Zilla guards cannot be combined with AND semantics"

binding-openapi-asyncapi's http-kafka proxy route only has one guarded() attachment point (governing the inbound HTTP side). There's no internally-generated Kafka client/server binding in this proxy (unlike plain binding-asyncapi, which generates its own Kafka client and can attach Kafka-side security to it directly) — so there's no natural second attachment point for a Kafka-side guard either.

Options worth discussing:

  1. Treat the asyncapi-side security as a fallback/default only when the OpenAPI operation itself declares no security (mirroring how OpenAPI's own spec-level security is a fallback for operations that don't declare their own) — same guard, no AND-combination.
  2. Deny the route at generation time if the openapi-resolved guard and the asyncapi-resolved guard disagree, surfacing a clear config error instead of silently ignoring one side.
  3. Remove security support for asyncapi specs from this binding's schema/adapter entirely, since there's currently no coherent semantics for it in a proxy binding with a single guard attachment point.

Scope note

Filed separately from #2113 / PR #2128 (which fixes the openapi-asyncapi overlay-bypass and the parity gap in AsyncapiSchemaConfig construction) since this needs a design decision, not a mechanical fix.

Activity

  1. changed the title [-]binding-openapi-asyncapi: options.specs.asyncapi.&lt;name&gt;.security is accepted but never consumed[/-] [+]binding-openapi-asyncapi: options.specs.asyncapi.<name>.security is accepted but never consumed[/+] on Jul 12, 2026
  2. jfallows commented on Jul 13, 2026

    @jfallows
    ContributorAuthor

    Traced the code to ground the three options before picking one:

    • OpenapiAsyncapiProxyGenerator.resolveGuarded() (HttpKafkaBindingsHelper) only ever calls OpenapiGuardResolver.resolve(operation.id, schema.specLabel, operation.security, schema.security, ...) — openapi operation + openapi spec map. The kafkaOp (AsyncapiOperationView, whose .security is populated but never fed anywhere) is already in scope at the injectHttpKafkaRoute() call site, so no new lookup/threading is needed to get at it — just two more parameters through resolveGuarded/allowed.
    • The "operation security falls back to spec-level security" pattern cited as a mirror for option 1 already exists, but it lives in OpenapiOperationView's constructor (model.security != null ? ... : specification.security), not in OpenapiGuardResolver. OpenapiGuardResolver itself has no fallback logic — it just consumes whatever operation.security already resolved to.
    • binding-asyncapi already has a structurally identical AsyncapiGuardResolver (same "multiple distinct guards ... AND semantics" denial, same GuardedResolution/GuardedRef shape) with its own full unit test suite (AsyncapiGuardResolverTest). It's unused by binding-openapi-asyncapi today but is a ready-made tool for resolving kafkaOp.security against AsyncapiSchemaConfig.security.

    Given that, option 1 seems like the right call:

    • It composes with the existing openapi-side fallback rather than adding a new kind of precedence rule: openapi operation security (which may itself already be an openapi-spec-level fallback) wins when present; asyncapi spec-level security only applies when the openapi side declares none at all. No AND-combination, no new denial path.
    • It's cheap given what already exists: resolve via AsyncapiGuardResolver.resolve(kafkaOp.name, ..., kafkaOp.security, asyncapiSchema.security, ...) when OpenapiGuardResolver.resolve(...) on the openapi side yields no guard, and use whichever result is non-empty. Both resolvers already share the same denied/multiple distinct guards semantics, so the combination logic doesn't need to invent anything new.
    • Option 2 (deny on disagreement) requires resolving both sides on every route just to compare, and penalizes operators who legitimately declare the same guard on both the openapi and asyncapi spec for documentation/clarity — that's a plausible, not malformed, config.
    • Option 3 (remove the property) throws away a real use case: proxies whose openapi spec has no security block at all but whose backing asyncapi/kafka spec does declare one, which is exactly what the schema was added to support.

    If that direction sounds right, I can follow up with a test-first PR: extend OpenapiAsyncapiProxyGeneratorTest with an asyncapi-side-security case (today none of its AsyncapiSpecificationConfig.builder() calls populate .security(...)), add a paired config/proxy.guarded.asyncapi.yaml + streams/asyncapi/<scenario>/{client,server}.rpt mirroring the existing proxy.guarded.yaml / shouldCreatePetWhenAuthorized scaffolding, then wire kafkaOp/AsyncapiSchemaConfig.security into resolveGuarded() as the fallback. Let me know if you'd rather go a different direction first.


    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

No one assigned

    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