This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-gateway-v1-2-gamma-mtls-san-validation

Kubernetes Gateway API v1.2 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard

Enforces zero-trust cryptographic workload identity verification across cross-namespace east-west service routing using Kubernetes Gateway API v1.2 Gamma specifications. Mandates explicit BackendTLSPolicy definitions with strict SPIFFE Subject Alternative Name (SAN) validation and ReferenceGrant controls to prevent identity spoofing without incurring per-pod sidecar latency overhead.

Prohibited Anti-Pattern: Unvalidated Backend TLS and Wildcard SAN Matching in Cross-Namespace Gateway Mesh Routing

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API v1.2 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard - Enforces zero-trust cryptographic workload identity verification across cross-namespace east-west service routing using Kubernetes Gateway API v1.2 Gamma specifications. Mandates explicit BackendTLSPolicy definitions with strict SPIFFE Subject Alternative Name (SAN) validation and ReferenceGrant controls to prevent identity spoofing without incurring per-pod sidecar latency overhead.
globs: k8s/**/*.yaml, k8s/**/*.yml, deploy/**/*.yaml, deploy/**/*.yml, manifests/**/*.yaml, helm/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-v1-2-gamma-mtls-san-validation"
---

# Kubernetes Gateway API v1.2 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unvalidated Backend TLS and Wildcard SAN Matching in Cross-Namespace Gateway Mesh Routing

## System Constraints
You are a Principal Cloud-Native Security Architect and Rules Author enforcing Gateway API v1.2 Gamma standards. Mandate zero-trust cross-namespace east-west routing via sidecarless ambient mesh architectures (eBPF/waypoint). You must enforce strict cryptographically bound SPIFFE identities via BackendTLSPolicy and ReferenceGrant resources, explicitly rejecting wildcard SANs, unauthenticated plaintext fallbacks, and legacy sidecar injection.

## Strict Guidelines
- Engineers MUST ALWAYS configure BackendTLSPolicy (gateway.networking.k8s.io/v1alpha3 or v1alpha2) for any east-west Service target receiving cross-namespace traffic.
- Engineers MUST specify the exact fully qualified SPIFFE ID or precise host validation (spiffe://<trust-domain>/ns/<namespace>/sa/<service-account>) within BackendTLSPolicy `validation.hostname` or SAN fields.
- Engineers MUST NOT use wildcard certificates, insecureSkipVerify, or empty hostname validation in TLS target specifications.
- Cross-namespace routes MUST define a reciprocal ReferenceGrant in the target namespace explicitly permitting `from.group: gateway.networking.k8s.io` to reference target Services.
- Workload manifests MUST NOT configure sidecar injection annotations (e.g., `sidecar.istio.io/inject: 'true'`); identity verification MUST occur at the node/eBPF or designated waypoint layer.
- Services consumed via Gamma mesh routing MUST declare `appProtocol: https` or `appProtocol: tls` on their respective Service port definitions.

## Bad vs Good Implementations
### Cross-Namespace Gateway Gamma Routing with Strict BackendTLSPolicy & ReferenceGrant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omits BackendTLSPolicy and ReferenceGrant, creating a security hole where any client pod can spoof service identities. Relies on legacy sidecar injection which introduces memory bloat and latency hops instead of sidecarless node-level/waypoint transport encryption.
```yaml
# ANTI-PATTERN: Cross-namespace route targeting a service without BackendTLSPolicy or SAN validation.
# Relies on implicit trust, lacks ReferenceGrant, and injects heavy sidecars.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: billing-route
  namespace: frontend
spec:
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: internal-gateway
  rules:
    - backendRefs:
        - name: billing-svc
          namespace: payments
          port: 8443
---
apiVersion: v1
kind: Service
metadata:
  name: billing-svc
  namespace: payments
  annotations:
    sidecar.istio.io/inject: "true" # Causes 2-3ms latency overhead per hop
spec:
  ports:
    - name: https
      port: 8443
      targetPort: 8443 # Missing appProtocol; no mTLS cryptographic SAN validation configured
```

#### Production Standard (Correct)
> **Standard**: Implements zero-trust isolation using Gateway API v1.2 standards. ReferenceGrant explicitly authorizes cross-namespace access from the frontend namespace. BackendTLSPolicy binds cryptographic trust to a specific SPIFFE identity, preventing man-in-the-middle attacks without sidecar overhead.
```yaml
# PRODUCTION STANDARD: Gateway API v1.2 Gamma with ReferenceGrant and BackendTLSPolicy
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-frontend-to-payments
  namespace: payments
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: frontend
  to:
    - group: ""
      kind: Service
      name: billing-svc
---
apiVersion: gateway.networking.k8s.io/v1alpha3
kind: BackendTLSPolicy
metadata:
  name: billing-svc-tls
  namespace: payments
spec:
  targetRefs:
    - group: ""
      kind: Service
      name: billing-svc
  validation:
    caCertificateRefs:
      - group: ""
        kind: ConfigMap
        name: mesh-ca-bundle
    hostname: "spiffe://prod.cluster.local/ns/payments/sa/billing-service-account"
    wellKnownCACertificates: System
---
apiVersion: v1
kind: Service
metadata:
  name: billing-svc
  namespace: payments
  labels:
    istio.io/use-waypoint: cross-ns-waypoint # Utilizes sidecarless L7 gateway proxy
spec:
  ports:
    - name: https
      port: 8443
      protocol: TCP
      appProtocol: https
      targetPort: 8443
  selector:
    app: billing
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Kubernetes Gateway API v1.2 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard

Kubernetes Gateway API v1.2 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard defines an industrial-grade behavioral standard for devops engineering. Enforces zero-trust cryptographic workload identity verification across cross-namespace east-west service routing using Kubernetes Gateway API v1.2 Gamma specifications. Mandates explicit BackendTLSPolicy definitions with strict SPIFFE Subject Alternative Name (SAN) validation and ReferenceGrant controls to prevent identity spoofing without incurring per-pod sidecar latency overhead. 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: Unvalidated Backend TLS and Wildcard SAN Matching in Cross-Namespace Gateway Mesh Routing 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 DriftUnvalidated Backend TLS and Wildcard SAN Matching in Cross-Namespace Gateway Mesh RoutingCritical
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 BackendTLSPolicy (gateway.networking.k8s.io/v1alpha3 or v1alpha2) for any east-west Service target receiving cross-namespace traffic.

Engineers MUST ALWAYS configure BackendTLSPolicy (gateway.networking.k8s.io/v1alpha3 or v1alpha2) for any east-west Service target receiving cross-namespace traffic.

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 specify the exact fully qualified SPIFFE ID or precise host validation (spiffe

Engineers MUST specify the exact fully qualified SPIFFE ID or precise host validation (spiffe://<trust-domain>/ns/<namespace>/sa/<service-account>) within BackendTLSPolicy `validation.hostname` or SAN fields.

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 use wildcard certificates, insecureSkipVerify, or empty hostname validation in TLS target specifications.

Engineers MUST NOT use wildcard certificates, insecureSkipVerify, or empty hostname validation in TLS target specifications.

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

Cross-namespace routes MUST define a reciprocal ReferenceGrant in the target namespace explicitly permitting `from.group

Cross-namespace routes MUST define a reciprocal ReferenceGrant in the target namespace explicitly permitting `from.group: gateway.networking.k8s.io` to reference target Services.

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

Workload manifests MUST NOT configure sidecar injection annotations (e.g., `sidecar.istio.io/inject

Workload manifests MUST NOT configure sidecar injection annotations (e.g., `sidecar.istio.io/inject: 'true'`); identity verification MUST occur at the node/eBPF or designated waypoint layer.

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 consumed via Gamma mesh routing MUST declare `appProtocol

Services consumed via Gamma mesh routing MUST declare `appProtocol: https` or `appProtocol: tls` on their respective Service port definitions.

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 Gamma Sidecarless Cross-Namespace mTLS SAN Validation Standard critical for AI coding assistants?

Enforces zero-trust cryptographic workload identity verification across cross-namespace east-west service routing using Kubernetes Gateway API v1.2 Gamma specifications. Mandates explicit BackendTLSPolicy definitions with strict SPIFFE Subject Alternative Name (SAN) validation and ReferenceGrant controls to prevent identity spoofing without incurring per-pod sidecar latency overhead. 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 (Unvalidated Backend TLS and Wildcard SAN Matching in Cross-Namespace Gateway Mesh Routing) 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