This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: gateway-api-v1-2-referencegrant-isolation-fence

Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence

Enforces deterministic, bidirectional trust boundaries across multi-tenant Kubernetes clusters utilizing Gateway API v1.2. Cross-namespace references—including backendRefs, Gateway-to-Secret TLS references, and Route-to-Gateway attachments—MUST be validated by an explicit, least-privilege ReferenceGrant resource residing in the target resource's namespace before any routing or binding reconciles.

Prohibited Anti-Pattern: Implicit Cross-Namespace Route Attachment and Unchecked Service Bridging Without Cryptographic ReferenceGrant Handshakes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence - Enforces deterministic, bidirectional trust boundaries across multi-tenant Kubernetes clusters utilizing Gateway API v1.2. Cross-namespace references—including backendRefs, Gateway-to-Secret TLS references, and Route-to-Gateway attachments—MUST be validated by an explicit, least-privilege ReferenceGrant resource residing in the target resource's namespace before any routing or binding reconciles.
globs: k8s/**/*.yaml, deploy/**/*.yaml, helm/**/*.yaml, infra/**/*.yaml, manifests/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/gateway-api-v1-2-referencegrant-isolation-fence"
---

# Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Implicit Cross-Namespace Route Attachment and Unchecked Service Bridging Without Cryptographic ReferenceGrant Handshakes

## System Constraints
You are a Principal Infrastructure & Security Architect enforcing strict Kubernetes Gateway API v1.2 cross-namespace boundary isolation. Gateway API prohibits implicit cross-namespace references; any resource referencing a Secret, Service, or Route residing in an external namespace is strictly quarantined and rejected by compliant Gateway controllers unless an explicit ReferenceGrant exists in the target namespace. You must reject any manifest, Helm chart, or Kustomize overlay that attempts cross-namespace linking without emitting an adjacent, least-privilege ReferenceGrant specifying exact group, kind, namespace, and optional resource name.

## Strict Guidelines
- Engineers MUST ALWAYS define a `ReferenceGrant` (group: `gateway.networking.k8s.io/v1beta1`) in the target namespace whenever an `HTTPRoute`, `GRPCRoute`, `TCPRoute`, or `Gateway` references a backend Service or Secret located in a different namespace.
- Engineers MUST NOT configure cross-namespace `backendRefs` in Route manifests without deploying the corresponding `ReferenceGrant` within the target namespace in the same deployment atomic unit.
- Engineers MUST NOT omit the `name` field in `to` blocks of `ReferenceGrant` resources unless routing to all services of that kind in the target namespace is explicitly approved by security policies.
- Gateway listeners configuring `allowedRoutes.namespaces.from: All` MUST be gated by upstream namespace selectors (`from: Selector`) to prevent unauthorized tenant route hijacking.
- Code SHOULD validate the status conditions of both the `Gateway` (`Accepted=True`) and child `HTTPRoute` (`ResolvedRefs=True`) using CI/CD integration tests to confirm the controller validated the `ReferenceGrant` handshake.
- Services MUST remain private to their source namespace; cross-namespace service mesh or ingress access MUST NEVER rely on cluster-wide implicit visibility or deprecated ingress annotations.

## Bad vs Good Implementations
### Cross-Namespace Ingress Routing with Missing vs. Validated ReferenceGrant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The HTTPRoute attempts cross-namespace access to 'payment-processor-svc' located in 'secure-payments' without an authorizing ReferenceGrant in the destination namespace. Compliant Gateway API v1.2 controllers will set ResolvedRefs=False with Reason=RefNotPermitted, causing runtime blackholing.
```yaml
# INSECURE: HTTPRoute in tenant-frontend attempts to route cross-namespace to backend in secure-payments
# Gateway controller marks this route as ResolvedRefs: False and drops traffic.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: checkout-route
  namespace: tenant-frontend
spec:
  parentRefs:
    - name: shared-edge-gateway
      namespace: ingress-infra
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api/v1/checkout
      backendRefs:
        - name: payment-processor-svc
          namespace: secure-payments
          port: 8443
# Violation: No ReferenceGrant exists in 'secure-payments', leading to silent route rejection or multi-tenant boundary compromise.
```

#### Production Standard (Correct)
> **Standard**: A ReferenceGrant is explicitly placed in the target 'secure-payments' namespace. It strictly permits only HTTPRoute resources from 'tenant-frontend' to reference the explicit core Service 'payment-processor-svc', guaranteeing cryptographic isolation and policy compliance.
```yaml
# SECURE: Atomic declaration of HTTPRoute and granting ReferenceGrant with least-privilege
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: checkout-route
  namespace: tenant-frontend
spec:
  parentRefs:
    - name: shared-edge-gateway
      namespace: ingress-infra
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api/v1/checkout
      backendRefs:
        - name: payment-processor-svc
          namespace: secure-payments
          port: 8443
---
# Explicit, least-privilege handshake in target namespace
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-checkout-route-to-payment
  namespace: secure-payments
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: tenant-frontend
  to:
    - group: ""
      kind: Service
      name: payment-processor-svc
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence

Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic, bidirectional trust boundaries across multi-tenant Kubernetes clusters utilizing Gateway API v1.2. Cross-namespace references—including backendRefs, Gateway-to-Secret TLS references, and Route-to-Gateway attachments—MUST be validated by an explicit, least-privilege ReferenceGrant resource residing in the target resource's namespace before any routing or binding reconciles. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Implicit Cross-Namespace Route Attachment and Unchecked Service Bridging Without Cryptographic ReferenceGrant Handshakes Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftImplicit Cross-Namespace Route Attachment and Unchecked Service Bridging Without Cryptographic ReferenceGrant HandshakesCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS define a `ReferenceGrant` (group

Engineers MUST ALWAYS define a `ReferenceGrant` (group: `gateway.networking.k8s.io/v1beta1`) in the target namespace whenever an `HTTPRoute`, `GRPCRoute`, `TCPRoute`, or `Gateway` references a backend Service or Secret located in a different namespace.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT configure cross-namespace `backendRefs` in Route manifests without deploying the corresponding `ReferenceGrant` within the target namespace in the same deployment atomic unit.

Engineers MUST NOT configure cross-namespace `backendRefs` in Route manifests without deploying the corresponding `ReferenceGrant` within the target namespace in the same deployment atomic unit.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT omit the `name` field in `to` blocks of `ReferenceGrant` resources unless routing to all services of that kind in the target namespace is explicitly approved by security policies.

Engineers MUST NOT omit the `name` field in `to` blocks of `ReferenceGrant` resources unless routing to all services of that kind in the target namespace is explicitly approved by security policies.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Gateway listeners configuring `allowedRoutes.namespaces.from

Gateway listeners configuring `allowedRoutes.namespaces.from: All` MUST be gated by upstream namespace selectors (`from: Selector`) to prevent unauthorized tenant route hijacking.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Code SHOULD validate the status conditions of both the `Gateway` (`Accepted=True`) and child `HTTPRoute` (`ResolvedRefs=True`) using CI/CD integration tests to confirm the controller validated the `ReferenceGrant` handshake.

Code SHOULD validate the status conditions of both the `Gateway` (`Accepted=True`) and child `HTTPRoute` (`ResolvedRefs=True`) using CI/CD integration tests to confirm the controller validated the `ReferenceGrant` handshake.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Services MUST remain private to their source namespace

Services MUST remain private to their source namespace; cross-namespace service mesh or ingress access MUST NEVER rely on cluster-wide implicit visibility or deprecated ingress annotations.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Kubernetes Gateway API v1.2 ReferenceGrant Cross-Namespace Isolation Fence critical for AI coding assistants?

Enforces deterministic, bidirectional trust boundaries across multi-tenant Kubernetes clusters utilizing Gateway API v1.2. Cross-namespace references—including backendRefs, Gateway-to-Secret TLS references, and Route-to-Gateway attachments—MUST be validated by an explicit, least-privilege ReferenceGrant resource residing in the target resource's namespace before any routing or binding reconciles. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Implicit Cross-Namespace Route Attachment and Unchecked Service Bridging Without Cryptographic ReferenceGrant Handshakes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Kubernetes