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

Kubernetes Gateway API v1.2 Cross-Namespace L7 Route Delegation & Canary Invariants

Enforces strict RBAC boundary separation between platform teams and multi-tenant application developers using Gateway API v1.2 route delegation. Mandates that root Gateway listeners delegate path-prefixes via explicit ReferenceGrants, prohibiting application teams from binding directly to root gateways while preserving zero-trust canary weights and fallback routing.

Prohibited Anti-Pattern: Direct Gateway-to-Service Binding and Unscoped Cross-Namespace Route Hijacking

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API v1.2 Cross-Namespace L7 Route Delegation & Canary Invariants - Enforces strict RBAC boundary separation between platform teams and multi-tenant application developers using Gateway API v1.2 route delegation. Mandates that root Gateway listeners delegate path-prefixes via explicit ReferenceGrants, prohibiting application teams from binding directly to root gateways while preserving zero-trust canary weights and fallback routing.
globs: infra/**/*.yaml, deploy/**/*.yaml, k8s/**/*.yaml, helm/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-api-v1-2-cross-namespace-delegation"
---

# Kubernetes Gateway API v1.2 Cross-Namespace L7 Route Delegation & Canary Invariants

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Direct Gateway-to-Service Binding and Unscoped Cross-Namespace Route Hijacking

## System Constraints
You are a Principal Infrastructure Architect enforcing Kubernetes Gateway API v1.2 standards across multi-tenant clusters. You must ensure platform engineers manage the root Gateway and root HTTPRoutes in central infrastructure namespaces, while application developers control leaf HTTPRoutes within tenant namespaces. Every cross-namespace delegation must be backed by an explicit ReferenceGrant. Never allow HTTPRoutes in application namespaces to attach directly to platform Gateways without route delegation hierarchies.

## Strict Guidelines
- Platform engineers MUST manage the root Gateway and root HTTPRoutes inside dedicated infrastructure namespaces (e.g., gateway-system).
- Application teams MUST NOT attach HTTPRoutes directly to root Gateways using Gateway parentRefs; they MUST attach exclusively to root HTTPRoutes via route delegation.
- Root HTTPRoutes MUST specify path prefixes and forward to child HTTPRoutes using backendRefs with group 'gateway.networking.k8s.io' and kind 'HTTPRoute'.
- Tenant namespaces MUST define a ReferenceGrant allowing the gateway-system HTTPRoute to bind to tenant HTTPRoutes across namespace boundaries.
- Canary deployments MUST be declared within child HTTPRoutes using weight-based backendRefs with non-zero fallback routes and explicit request timeouts.
- Engineers MUST NEVER configure wildcard cross-namespace permissions in ReferenceGrants; from.namespace and to.resource must be strictly enumerated.

## Bad vs Good Implementations
### Cross-Namespace Route Delegation with Explicit ReferenceGrant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Direct attachment of tenant HTTPRoute to the platform Gateway breaches team boundaries, permits path hijacking across namespaces, and lacks mandatory route delegation hierarchy and explicit ReferenceGrant authorization.
```yaml
# INSECURE: Tenant bypasses delegation and binds directly to platform Gateway
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: payments-service-route
  namespace: payments-team
spec:
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: edge-gateway
      namespace: gateway-system
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api/v1/payments
      backendRefs:
        - name: payments-v1
          port: 8080
          weight: 90
        - name: payments-v2
          port: 8080
          weight: 10
```

#### Production Standard (Correct)
> **Standard**: Platform operations govern the root listener and path allocation. Route delegation transfers control of /api/v1/payments to payments-team, sanctioned by a scoped ReferenceGrant. Canary weighting is encapsulated within tenant boundaries.
```yaml
# SECURE: Explicit delegation from platform root to tenant child HTTPRoute
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: platform-root-route
  namespace: gateway-system
spec:
  parentRefs:
    - name: edge-gateway
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /api/v1/payments
      backendRefs:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
          name: payments-route
          namespace: payments-team
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-gateway-system-route-delegation
  namespace: payments-team
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: gateway-system
  to:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: payments-route
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: payments-route
  namespace: payments-team
spec:
  rules:
    - timeouts:
        request: 3s
      backendRefs:
        - name: payments-v1
          port: 8080
          weight: 90
        - name: payments-canary
          port: 8080
          weight: 10
```

Recommended MCP Servers (mcp-serverlist.com)

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Kubernetes Gateway API v1.2 Cross-Namespace L7 Route Delegation & Canary Invariants

Kubernetes Gateway API v1.2 Cross-Namespace L7 Route Delegation & Canary Invariants defines an industrial-grade behavioral standard for devops engineering. Enforces strict RBAC boundary separation between platform teams and multi-tenant application developers using Gateway API v1.2 route delegation. Mandates that root Gateway listeners delegate path-prefixes via explicit ReferenceGrants, prohibiting application teams from binding directly to root gateways while preserving zero-trust canary weights and fallback routing. 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: Direct Gateway-to-Service Binding and Unscoped Cross-Namespace Route Hijacking 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 DriftDirect Gateway-to-Service Binding and Unscoped Cross-Namespace Route HijackingCritical
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

Platform engineers MUST manage the root Gateway and root HTTPRoutes inside dedicated infrastructure namespaces (e.g., gateway-system).

Platform engineers MUST manage the root Gateway and root HTTPRoutes inside dedicated infrastructure namespaces (e.g., gateway-system).

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

Application teams MUST NOT attach HTTPRoutes directly to root Gateways using Gateway parentRefs

Application teams MUST NOT attach HTTPRoutes directly to root Gateways using Gateway parentRefs; they MUST attach exclusively to root HTTPRoutes via route delegation.

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

Root HTTPRoutes MUST specify path prefixes and forward to child HTTPRoutes using backendRefs with group 'gateway.networking.k8s.io' and kind 'HTTPRoute'.

Root HTTPRoutes MUST specify path prefixes and forward to child HTTPRoutes using backendRefs with group 'gateway.networking.k8s.io' and kind 'HTTPRoute'.

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

Tenant namespaces MUST define a ReferenceGrant allowing the gateway-system HTTPRoute to bind to tenant HTTPRoutes across namespace boundaries.

Tenant namespaces MUST define a ReferenceGrant allowing the gateway-system HTTPRoute to bind to tenant HTTPRoutes 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.
5

Canary deployments MUST be declared within child HTTPRoutes using weight-based backendRefs with non-zero fallback routes and explicit request timeouts.

Canary deployments MUST be declared within child HTTPRoutes using weight-based backendRefs with non-zero fallback routes and explicit request timeouts.

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

Engineers MUST NEVER configure wildcard cross-namespace permissions in ReferenceGrants

Engineers MUST NEVER configure wildcard cross-namespace permissions in ReferenceGrants; from.namespace and to.resource must be strictly enumerated.

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 L7 Route Delegation & Canary Invariants critical for AI coding assistants?

Enforces strict RBAC boundary separation between platform teams and multi-tenant application developers using Gateway API v1.2 route delegation. Mandates that root Gateway listeners delegate path-prefixes via explicit ReferenceGrants, prohibiting application teams from binding directly to root gateways while preserving zero-trust canary weights and fallback routing. 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 (Direct Gateway-to-Service Binding and Unscoped Cross-Namespace Route Hijacking) 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