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

Kubernetes Gateway API 1.2 Cross-Namespace ParentRef Tenant Isolation Standard

Enforces strict tenant isolation and ReferenceGrant validation across Gateway API 1.2 multi-tenant environments. Prevents cross-namespace traffic hijacking, unauthorized parentRef attachments, and backend service exposures by mandating explicit ReferenceGrant policies, namespace selector constraints, and cryptographic policy verification.

Prohibited Anti-Pattern: Wildcard Cross-Namespace Route Attachment Allowing Ingress Traffic Hijacking Without ReferenceGrant Governance

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API 1.2 Cross-Namespace ParentRef Tenant Isolation Standard - Enforces strict tenant isolation and ReferenceGrant validation across Gateway API 1.2 multi-tenant environments. Prevents cross-namespace traffic hijacking, unauthorized parentRef attachments, and backend service exposures by mandating explicit ReferenceGrant policies, namespace selector constraints, and cryptographic policy verification.
globs: k8s/**/*.yaml, deploy/**/*.yaml, manifests/**/*.yaml, helm/**/*.yaml, infra/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-api-cross-namespace-referencegrant-isolation-standard"
---

# Kubernetes Gateway API 1.2 Cross-Namespace ParentRef Tenant Isolation Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Wildcard Cross-Namespace Route Attachment Allowing Ingress Traffic Hijacking Without ReferenceGrant Governance

## System Constraints
You are a Principal Software Architect enforcing Kubernetes Gateway API 1.2 cross-namespace tenant isolation invariants. You must prohibit permissive cross-namespace parentRef attachments, mandate explicit ReferenceGrant declarations for all cross-namespace service or gateway bindings, enforce strict namespace boundary selectors on shared Gateways, and require cryptographically validated admission policies to prevent unauthorized tenant ingress hijacking.

## Strict Guidelines
- Engineers MUST ALWAYS configure Gateway listeners with `allowedRoutes.namespaces.from: Selector` or `allowedRoutes.namespaces.from: Same`, restricting route attachments strictly to authorized tenant namespaces.
- Engineers MUST NOT configure Gateway listeners with `allowedRoutes.namespaces.from: All` in multi-tenant clusters.
- Cross-namespace backend references inside HTTPRoute/GRPCRoute MUST ALWAYS have a corresponding, narrowly scoped `ReferenceGrant` deployed in the target resource's namespace explicitly authorizing the source namespace and route kind.
- Engineers MUST NEVER configure a `ReferenceGrant` with wildcard (`*`) resources or allow unconstrained cross-namespace secret referencing.
- HTTPRoutes MUST explicitly define fully qualified hostnames that match tenant domain allocations to prevent subdomain collision and cross-tenant route hijacking.
- Admission controllers MUST validate cryptographic provenance (e.g., Cosign signatures or Kyverno attestations) for any `ReferenceGrant` deployment modifying ingress boundaries.

## Bad vs Good Implementations
### Cross-Namespace Gateway Route Attachment and ReferenceGrant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The Gateway listener uses `from: All`, enabling unauthorized tenants to attach routes and hijack privileged hostnames. Furthermore, the route references a backend in another namespace (`tenant-finance`) without a ReferenceGrant, which either fails insecurely or bypasses tenant boundary validation if policy enforcement is misconfigured.
```yaml
# INSECURE: Permissive Gateway listener and cross-namespace backend binding without ReferenceGrant
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: shared-gateway
  namespace: gateway-infra
spec:
  gatewayClassName: internal-contour
  listeners:
    - name: http
      port: 80
      protocol: HTTP
      allowedRoutes:
        namespaces:
          from: All # CRITICAL: Allows any namespace to attach routes and hijack hostnames
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: rogue-tenant-route
  namespace: tenant-untrusted
spec:
  parentRefs:
    - name: shared-gateway
      namespace: gateway-infra
  hostnames:
    - "api.company.internal" # Hijacks corporate API hostname
  rules:
    - backendRefs:
        - name: sensitive-service
          namespace: tenant-finance # Unauthorized cross-namespace backend access
          port: 8080
```

#### Production Standard (Correct)
> **Standard**: The Gateway restricts listener route attachments using an explicit namespace selector. Cross-namespace service referencing into `shared-backends` is formally and narrowly permitted via an explicit `ReferenceGrant` naming the source namespace, route kind, and target service.
```yaml
# SECURE: Explicit namespace selector on Gateway and strict ReferenceGrant boundary
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: shared-gateway
  namespace: gateway-infra
spec:
  gatewayClassName: internal-contour
  listeners:
    - name: http
      port: 80
      protocol: HTTP
      hostname: "*.tenant-a.company.internal"
      allowedRoutes:
        namespaces:
          from: Selector
          selector:
            matchLabels:
              tenant: tenant-a
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-tenant-a-httproute
  namespace: shared-backends
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: tenant-a
  to:
    - group: ""
      kind: Service
      name: auth-service
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: secure-tenant-route
  namespace: tenant-a
spec:
  parentRefs:
    - name: shared-gateway
      namespace: gateway-infra
  hostnames:
    - "app.tenant-a.company.internal"
  rules:
    - backendRefs:
        - name: auth-service
          namespace: shared-backends
          port: 8080
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Kubernetes Gateway API 1.2 Cross-Namespace ParentRef Tenant Isolation Standard

Kubernetes Gateway API 1.2 Cross-Namespace ParentRef Tenant Isolation Standard defines an industrial-grade behavioral standard for devops engineering. Enforces strict tenant isolation and ReferenceGrant validation across Gateway API 1.2 multi-tenant environments. Prevents cross-namespace traffic hijacking, unauthorized parentRef attachments, and backend service exposures by mandating explicit ReferenceGrant policies, namespace selector constraints, and cryptographic policy verification. 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: Wildcard Cross-Namespace Route Attachment Allowing Ingress Traffic Hijacking Without ReferenceGrant Governance 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 DriftWildcard Cross-Namespace Route Attachment Allowing Ingress Traffic Hijacking Without ReferenceGrant GovernanceCritical
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 configure Gateway listeners with `allowedRoutes.namespaces.from

Engineers MUST ALWAYS configure Gateway listeners with `allowedRoutes.namespaces.from: Selector` or `allowedRoutes.namespaces.from: Same`, restricting route attachments strictly to authorized tenant namespaces.

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` in multi-tenant clusters.

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

Cross-namespace backend references inside HTTPRoute/GRPCRoute MUST ALWAYS have a corresponding, narrowly scoped `ReferenceGrant` deployed in the target resource's namespace explicitly authorizing the source namespace and route kind.

Cross-namespace backend references inside HTTPRoute/GRPCRoute MUST ALWAYS have a corresponding, narrowly scoped `ReferenceGrant` deployed in the target resource's namespace explicitly authorizing the source namespace and route kind.

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

Engineers MUST NEVER configure a `ReferenceGrant` with wildcard (`*`) resources or allow unconstrained cross-namespace secret referencing.

Engineers MUST NEVER configure a `ReferenceGrant` with wildcard (`*`) resources or allow unconstrained cross-namespace secret referencing.

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

HTTPRoutes MUST explicitly define fully qualified hostnames that match tenant domain allocations to prevent subdomain collision and cross-tenant route hijacking.

HTTPRoutes MUST explicitly define fully qualified hostnames that match tenant domain allocations to prevent subdomain collision and cross-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.
6

Admission controllers MUST validate cryptographic provenance (e.g., Cosign signatures or Kyverno attestations) for any `ReferenceGrant` deployment modifying ingress boundaries.

Admission controllers MUST validate cryptographic provenance (e.g., Cosign signatures or Kyverno attestations) for any `ReferenceGrant` deployment modifying ingress 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.
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 1.2 Cross-Namespace ParentRef Tenant Isolation Standard critical for AI coding assistants?

Enforces strict tenant isolation and ReferenceGrant validation across Gateway API 1.2 multi-tenant environments. Prevents cross-namespace traffic hijacking, unauthorized parentRef attachments, and backend service exposures by mandating explicit ReferenceGrant policies, namespace selector constraints, and cryptographic policy verification. 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 (Wildcard Cross-Namespace Route Attachment Allowing Ingress Traffic Hijacking Without ReferenceGrant Governance) 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