ReferenceGrant checks ignore to.name, and revoked grants can keep authorizing access
Description
The controller's ReferenceGrant check (referenceGrantValidator in internal/controller/referencegrant.go) ignores the optional to.name field. In Gateway API, name limits a grant to that one object. Here, a grant for one object authorizes every object of that kind in the namespace.
Affected
- Released, v0.4.0 through v1.1.0: AIGatewayRoute → AIServiceBackend cross-namespace backendRefs. A route in namespace A that is granted backend
xin namespace B can reference any AIServiceBackend in B. Its traffic then goes through that backend with that backend's BackendSecurityPolicy credential. - main, unreleased (#2746): BackendSecurityPolicy → Secret references (AzureCredentials.clientSecretRef, GCPCredentials.credentialsFile, OIDC client secrets).
- I've opened #2783 for #2778, which adds the same check to the static credential types (APIKey, AzureAPIKey, AnthropicAPIKey, AWS credentialsFile). Those Secret values are sent as-is to an upstream the policy owner configures. With
to.nameignored, a grant for one Secret would let that owner send any Secret in the namespace with anapiKeyorcredentialskey to a host they control. I've kept this out of the public PR. Please fixto.namebefore or together with it.
Reproduction
Namespace shared has Secrets granted and other, and a ReferenceGrant from BackendSecurityPolicy in namespace app to Secret with name: granted. On main, validateSecretReference(ctx, "app", "shared", "other") returns nil. It should return the "not permitted" error.
Suggested fix
Pass the target name from validateReference into isReferenceGrantValid/matchesTo, and match only when to.Name == nil || string(*to.Name) == targetName. No existing test or YAML fixture sets to.name.
Related revocation gaps
- On main: a ReferenceGrant that is being deleted still validates;
isReferenceGrantValiddoesn't checkDeletionTimestamp. The ReferenceGrant finalizer added in #2750 triggers downstream reconciles before it is removed (handleFinalizer, controller.go), so those reconciles can still see the grant. Once the grant is gone nothing reconciles again, so the old access can stay in the generated config. If the finalizer removal fails, the error is only logged and the grant stays valid. - Narrowing a grant (editing or removing a
fromentry) only requeues the objects that match the new spec (getAffectedAIGatewayRoutes/getAffectedBackendSecurityPolicies). Objects that lost access keep it until something else reconciles them. - BackendSecurityPolicy changes for InferencePool targets never reach the Gateway:
syncInferencePooldoesn't notify Gateways. So a revoked grant, or a rotated Secret, isn't applied to the filter config for those backends.