Skip to content

ExtensionServerPolicy: targetRef.kind: GatewayClass is silently ignored, not just under mergeGateways #10060

Closed

Description

@zirain

Description:

ProcessExtensionServerPolicies (internal/gatewayapi/extensionserverpolicy.go) does not support an ExtensionServerPolicy with targetRef.kind: GatewayClass. Such a policy is silently ignored — it produces no status, is not attached to any listener/gateway, and is dropped entirely from the output — regardless of whether mergeGateways is enabled or not.

This is not a mergeGateways-specific regression: GatewayClass was never a supported target kind for this policy type in the first place, in any mode.

Root cause, tracing what happens to targetRef.kind: GatewayClass:

  1. isGateway/isListener (internal/gatewayapi/helpers.go) only match Kind == "Gateway", so the policy never reaches processExtensionServerPolicyForGateway — the mergeGateways-aware getIRKey/IRKey logic (internal/gatewayapi/translator.go) is never invoked at all.
  2. isRoute/isRouteRule only check Kind != "Gateway" (too broad — they don't verify the kind is actually a route type), so a GatewayClass target is misrouted into processExtensionServerPolicyForRoute.
  3. There, resolveExtServerPolicyRouteTargetRef looks the target up in routeMap, which is keyed only by actual route kinds (HTTPRoute/GRPCRoute/etc). Nothing matches, so it returns (nil, nil) and the function returns early with no status set.
  4. Back in ProcessExtensionServerPolicies, the policy ends up with zero ancestor statuses, so it's filtered out of the returned slice — a completely silent no-op.

For comparison, EnvoyPatchPolicy handles this correctly (internal/gatewayapi/envoypatchpolicy.go): it explicitly branches on t.MergeGateways, requiring targetRef.kind == GatewayClass when merged (using the GatewayClass name directly as the IR key) and Gateway otherwise. ExtensionServerPolicy has no equivalent branch.

The extension-server docs (site/content/en/latest/tasks/extensibility/extension-server.md) only document Gateway and HTTPRoute/GRPCRoute as supported target kinds, and describe "target not found" as a silent skip with no condition written — which is technically what happens here, but a GatewayClass target is a reasonable, discoverable configuration that currently fails with zero feedback to the user.

Expected behavior:

Either:

  • ExtensionServerPolicy should support targetRef.kind: GatewayClass when mergeGateways is enabled (mirroring EnvoyPatchPolicy's pattern), attaching the policy to all listeners under the merged Gateway set, or
  • If GatewayClass targeting is intentionally unsupported, the policy should receive an explicit Accepted: False / unsupported-kind status condition instead of being silently dropped (matching how an unsupported route kind like TCPRoute is already handled with an explicit rejection status).

Repro steps:

  1. Enable mergeGateways for a GatewayClass.
  2. Create an ExtensionServerPolicy with targetRef: {group: gateway.networking.k8s.io, kind: GatewayClass, name: <gatewayclass-name>}.
  3. Observe that the policy's extension hooks (e.g. PostTranslateModifyHook) are never invoked for any Gateway/listener under that class, and the policy receives no status/condition of any kind.

Environment:

N/A — code-inspection finding in internal/gatewayapi/extensionserverpolicy.go (current main, commit 3ec9a0156).

Logs:

N/A — the failure is silent (no error, no status, no log output).

Activity

  1. added
    kind/bug
    and removed on Sep 21, 2026
  2. vishals-3 commented on Sep 26, 2026

    @vishals-3
    Contributor

    I traced this against current main and can confirm every step.

    func isRoute(target policyTargetReferenceWithSectionName) bool {
    	// If the target is not a gateway and the section name is nil, then it's a route.
    	return target.Kind != resource.KindGateway && target.SectionName == nil
    }

    Kind != Gateway is the whole problem: a GatewayClass target satisfies it, gets dispatched into processExtensionServerPolicyForRoute, misses routeMap (keyed only by real route kinds), and returns early without setting status. The policy then never reaches the gateway pass either, since isGateway requires Kind == Gateway. So it is dropped with no condition, exactly as described.

    One thing worth flagging that widens the change beyond what the issue implies: isRoute and isRouteRule are shared by four policy types, not just this one —

    • securitypolicy.go (L162, L186)
    • envoyextensionpolicy.go (L149, L175)
    • backendtrafficpolicy.go (L354, L380)
    • extensionserverpolicy.go (L106, L127)

    So tightening them to match actual route kinds changes dispatch for SecurityPolicy, EnvoyExtensionPolicy and BackendTrafficPolicy too. That is arguably the correct fix — the same misrouting presumably affects an unsupported target kind on any of them — but it is a wider blast radius than a one-file change, and each of those has its own status-setting behaviour to keep consistent.

    Which leaves a direction question I would rather have answered than guess at:

    1. Reject — tighten the predicates so an unsupported target kind falls through to an explicit Accepted: False / Invalid condition naming the kind. Matches the issue's point that GatewayClass was never supported, and fixes the silence without changing what is supported.
    2. Support — make GatewayClass a real target kind for ExtensionServerPolicy, attaching to every Gateway of that class.

    1 is the smaller change and addresses the actual complaint. 2 is a feature and would need its own design. Happy to implement either — and if 1, happy to scope it to ExtensionServerPolicy only, or fix the shared predicates across all four, whichever you prefer.

    @arkodg @zirain

  3. zirain commented on Sep 28, 2026

    @zirain
    MemberAuthor

    @vishals-3 we need to support target to GatewayClass unless we deprecated merge gateways mode. I have sent out a fix in #10062.

  4. self-assigned this
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions