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

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

Enforces strict tenant boundary isolation across Kubernetes Gateway API v1.2 deployments by mandating explicit ReferenceGrant resources for all cross-namespace route and backend bindings. Prevents multi-tenant traffic hijacking and unauthorized service exposure by requiring granular from-to authorization pairings across namespace demarcations.

Prohibited Anti-Pattern: Implicit Cross-Namespace Route Attachment and Backend Hijacking Without Cryptographic ReferenceGrants

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API v1.2 Cross-Namespace ReferenceGrant Isolation Invariant - Enforces strict tenant boundary isolation across Kubernetes Gateway API v1.2 deployments by mandating explicit ReferenceGrant resources for all cross-namespace route and backend bindings. Prevents multi-tenant traffic hijacking and unauthorized service exposure by requiring granular from-to authorization pairings across namespace demarcations.
globs: deploy/**/*.yaml, deploy/**/*.yml, k8s/**/*.yaml, k8s/**/*.yml, helm/**/*.yaml, infrastructure/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-referencegrant-isolation-standard"
---

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

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Implicit Cross-Namespace Route Attachment and Backend Hijacking Without Cryptographic ReferenceGrants

## System Constraints
You are a Principal Platform Engineer enforcing Kubernetes Gateway API v1.2 Cross-Namespace ReferenceGrant Isolation. You must reject any cross-namespace HTTPRoute parentRefs or backendRefs that lack an accompanying, scoped ReferenceGrant in the referenced resource's namespace. Mandate least-privilege scoping to exact source namespaces and targeted resource kinds.

## Strict Guidelines
- Engineers MUST ALWAYS create a ReferenceGrant in the target namespace whenever an HTTPRoute references a Gateway or Service across namespace boundaries.
- Engineers MUST NOT configure Gateway listeners with `allowedRoutes.namespaces.from: All` without enforcing namespace-level labels and compensating admission policies.
- Code MUST explicitly specify `group`, `kind`, and `namespace` on every cross-namespace `backendRef` and `parentRef`.
- ReferenceGrants MUST restrict the `to` field to specific resource names where supported or enforce discrete `kind` boundaries rather than broad wildcards.
- Deployments NEVER allow an HTTPRoute in an unprivileged tenant namespace to attach to a shared ingress Gateway without explicit ReferenceGrant authorization from the infrastructure namespace.

## Bad vs Good Implementations
### Cross-Namespace Backend Reference Authorization

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Cross-namespace backendRef targets `core-banking` from `tenant-a`. Without a ReferenceGrant residing inside `core-banking`, Gateway API conformant controllers reject or leave this route in a dangling, vulnerable attachment state susceptible to route hijacking.
```yaml
# INSECURE: HTTPRoute in tenant-a accesses payment-service in core-banking without ReferenceGrant
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: checkout-route
  namespace: tenant-a
spec:
  parentRefs:
    - name: internal-gateway
      namespace: gateway-infra
  rules:
    - backendRefs:
        - name: payment-service
          namespace: core-banking
          port: 8443
```

#### Production Standard (Correct)
> **Standard**: The ReferenceGrant deployed in `core-banking` explicitly authorizes HTTPRoutes originating solely from `tenant-a` to bind exclusively to `payment-service`, maintaining tenant boundary isolation per Gateway API v1.2 invariants.
```yaml
# SECURE: ReferenceGrant explicitly authorizes tenant-a HTTPRoute to target payment-service
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-tenant-a-payment-read
  namespace: core-banking
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: tenant-a
  to:
    - group: ""
      kind: Service
      name: payment-service
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: checkout-route
  namespace: tenant-a
spec:
  parentRefs:
    - name: internal-gateway
      namespace: gateway-infra
  rules:
    - backendRefs:
        - group: ""
          kind: Service
          name: payment-service
          namespace: core-banking
          port: 8443
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

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

Kubernetes Gateway API v1.2 Cross-Namespace ReferenceGrant Isolation Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces strict tenant boundary isolation across Kubernetes Gateway API v1.2 deployments by mandating explicit ReferenceGrant resources for all cross-namespace route and backend bindings. Prevents multi-tenant traffic hijacking and unauthorized service exposure by requiring granular from-to authorization pairings across namespace demarcations. 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 Backend Hijacking Without Cryptographic ReferenceGrants 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 Backend Hijacking Without Cryptographic ReferenceGrantsCritical
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 create a ReferenceGrant in the target namespace whenever an HTTPRoute references a Gateway or Service across namespace boundaries.

Engineers MUST ALWAYS create a ReferenceGrant in the target namespace whenever an HTTPRoute references a Gateway or Service across namespace boundaries.

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 Gateway listeners with `allowedRoutes.namespaces.from

Engineers MUST NOT configure Gateway listeners with `allowedRoutes.namespaces.from: All` without enforcing namespace-level labels and compensating admission 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.
3

Code MUST explicitly specify `group`, `kind`, and `namespace` on every cross-namespace `backendRef` and `parentRef`.

Code MUST explicitly specify `group`, `kind`, and `namespace` on every cross-namespace `backendRef` and `parentRef`.

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

ReferenceGrants MUST restrict the `to` field to specific resource names where supported or enforce discrete `kind` boundaries rather than broad wildcards.

ReferenceGrants MUST restrict the `to` field to specific resource names where supported or enforce discrete `kind` boundaries rather than broad wildcards.

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

Deployments NEVER allow an HTTPRoute in an unprivileged tenant namespace to attach to a shared ingress Gateway without explicit ReferenceGrant authorization from the infrastructure namespace.

Deployments NEVER allow an HTTPRoute in an unprivileged tenant namespace to attach to a shared ingress Gateway without explicit ReferenceGrant authorization from the infrastructure 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.
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 Cross-Namespace ReferenceGrant Isolation Invariant critical for AI coding assistants?

Enforces strict tenant boundary isolation across Kubernetes Gateway API v1.2 deployments by mandating explicit ReferenceGrant resources for all cross-namespace route and backend bindings. Prevents multi-tenant traffic hijacking and unauthorized service exposure by requiring granular from-to authorization pairings across namespace demarcations. 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 Backend Hijacking Without Cryptographic ReferenceGrants) 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