This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-gateway-envoy-ebpf-socket-acceleration-guardrail

Kubernetes Gateway API Envoy eBPF Socket Redirection Invariants

Enforces strict architectural and resource invariants when pairing Kubernetes Gateway API implementations (such as Cilium or Envoy Gateway) with eBPF sockops and sockmap socket acceleration. Bypasses the standard host TCP/IP stack safely for node-local L7 proxying while guaranteeing socket lookup continuity, mTLS SPIFFE validation, and cgroup namespace compatibility.

Prohibited Anti-Pattern: Bypassing Host TCP/IP Without Node-Local Topology Constraints and Sockmap Socket Preservation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API Envoy eBPF Socket Redirection Invariants - Enforces strict architectural and resource invariants when pairing Kubernetes Gateway API implementations (such as Cilium or Envoy Gateway) with eBPF sockops and sockmap socket acceleration. Bypasses the standard host TCP/IP stack safely for node-local L7 proxying while guaranteeing socket lookup continuity, mTLS SPIFFE validation, and cgroup namespace compatibility.
globs: deploy/**/*.yaml, k8s/**/*.yaml, helm/**/*.yaml, config/**/*.yaml, infra/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-envoy-ebpf-socket-acceleration-guardrail"
---

# Kubernetes Gateway API Envoy eBPF Socket Redirection Invariants

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Bypassing Host TCP/IP Without Node-Local Topology Constraints and Sockmap Socket Preservation

## System Constraints
You are a Principal Systems and Infrastructure Architect enforcing strict configurations for Kubernetes Gateway API with Envoy eBPF socket acceleration (sockops/sockmap). You mandate that any configuration enabling socket bypass between Envoy ingress listeners and upstream workloads must ensure cgroup v2 mount availability, enforce strict topology-aware routing, configure downstream/upstream mutual TLS with SPIFFE verification, and safeguard against sockmap-induced connection dropouts during pod lifecycle transitions.

## Strict Guidelines
- Engineers MUST ALWAYS enforce strict node-local topology routing (e.g., service.kubernetes.io/topology-mode: Auto or topologySpreadConstraints) when Envoy socket acceleration is active, ensuring eBPF sockmap redirection only triggers on co-located container sockets.
- Engineers MUST NOT allow Envoy eBPF sockmap redirection without pinning BPF filesystem paths and validating cgroup v2 mounts in privileged or ambient capability containers (CAP_BPF, CAP_NET_ADMIN).
- Deployments MUST configure explicit connection termination grace periods and pre-stop hooks to remove dead sockets from eBPF maps before pods enter Terminating state, preventing TCP reset storms.
- Envoy configurations MUST NEVER disable downstream or upstream TLS validation when sockops redirection is active; mTLS handshake state machines must complete inside Envoy before payload socket splicing occurs.
- Gateway API manifests MUST bind EnvoyProxy parameters explicitly through GatewayClass or Gateway infrastructure parameters, forbidding ad-hoc or unmanaged hostNetwork daemonset overrides.

## Bad vs Good Implementations
### Configuring Gateway API with EnvoyProxy and eBPF Sockmap Acceleration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Enabling hostNetwork without eBPF socket map pinning and lacking node-local topology controls causes Envoy to attempt eBPF socket redirection to non-local endpoints, leading to silent connection blackholing and TCP RST floods when traffic crosses physical host boundaries.
```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: edge-gateway
  namespace: ingress-infra
spec:
  gatewayClassName: eg
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    tls:
      mode: Terminate
      certificateRefs:
      - kind: Secret
        name: edge-tls-wildcard
---
# BAD: Using generic Envoy configuration with hostNetwork
# and no topology control, causing eBPF socket-splicing failures across nodes
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: default-proxy-config
  namespace: ingress-infra
spec:
  telemetry:
    accessLog:
      disable: false
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        hostNetwork: true
```

#### Production Standard (Correct)
> **Standard**: Properly specifies the EnvoyProxy CRD with the required kernel capabilities (NET_ADMIN, BPF) for sockops manipulation, sets node-level topologySpreadConstraints to ensure co-location, and strictly binds the custom Envoy proxy profile to the Gateway API listener.
```yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: accelerated-envoy-config
  namespace: ingress-infra
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        container:
          securityContext:
            capabilities:
              add: ["NET_ADMIN", "BPF", "PERFMON"]
              drop: ["ALL"]
            readOnlyRootFilesystem: true
            allowPrivilegeEscalation: false
        topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: kubernetes.io/hostname
          whenUnsatisfiable: DoNotSchedule
          labelSelector:
            matchLabels:
              gateway.envoyproxy.io/owning-gateway-name: edge-gateway
  bootstrap:
    type: Merge
    value: |
      node:
        cluster: edge-ingress
      cluster_manager:
        outlier_detection:
          event_log_path: /dev/stdout
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: edge-gateway
  namespace: ingress-infra
  annotations:
    gateway.envoyproxy.io/envoyproxy: accelerated-envoy-config
spec:
  gatewayClassName: eg-accelerated
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    tls:
      mode: Terminate
      certificateRefs:
      - kind: Secret
        name: edge-tls-cert
    allowedRoutes:
      namespaces:
        from: Selector
        selector:
          matchLabels:
            network-routing: accelerated-mesh
```

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 Envoy eBPF Socket Redirection Invariants

Kubernetes Gateway API Envoy eBPF Socket Redirection Invariants defines an industrial-grade behavioral standard for devops engineering. Enforces strict architectural and resource invariants when pairing Kubernetes Gateway API implementations (such as Cilium or Envoy Gateway) with eBPF sockops and sockmap socket acceleration. Bypasses the standard host TCP/IP stack safely for node-local L7 proxying while guaranteeing socket lookup continuity, mTLS SPIFFE validation, and cgroup namespace compatibility. 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: Bypassing Host TCP/IP Without Node-Local Topology Constraints and Sockmap Socket Preservation 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 DriftBypassing Host TCP/IP Without Node-Local Topology Constraints and Sockmap Socket PreservationCritical
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 enforce strict node-local topology routing (e.g., service.kubernetes.io/topology-mode

Engineers MUST ALWAYS enforce strict node-local topology routing (e.g., service.kubernetes.io/topology-mode: Auto or topologySpreadConstraints) when Envoy socket acceleration is active, ensuring eBPF sockmap redirection only triggers on co-located container sockets.

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 allow Envoy eBPF sockmap redirection without pinning BPF filesystem paths and validating cgroup v2 mounts in privileged or ambient capability containers (CAP_BPF, CAP_NET_ADMIN).

Engineers MUST NOT allow Envoy eBPF sockmap redirection without pinning BPF filesystem paths and validating cgroup v2 mounts in privileged or ambient capability containers (CAP_BPF, CAP_NET_ADMIN).

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

Deployments MUST configure explicit connection termination grace periods and pre-stop hooks to remove dead sockets from eBPF maps before pods enter Terminating state, preventing TCP reset storms.

Deployments MUST configure explicit connection termination grace periods and pre-stop hooks to remove dead sockets from eBPF maps before pods enter Terminating state, preventing TCP reset storms.

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

Envoy configurations MUST NEVER disable downstream or upstream TLS validation when sockops redirection is active

Envoy configurations MUST NEVER disable downstream or upstream TLS validation when sockops redirection is active; mTLS handshake state machines must complete inside Envoy before payload socket splicing occurs.

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

Gateway API manifests MUST bind EnvoyProxy parameters explicitly through GatewayClass or Gateway infrastructure parameters, forbidding ad-hoc or unmanaged hostNetwork daemonset overrides.

Gateway API manifests MUST bind EnvoyProxy parameters explicitly through GatewayClass or Gateway infrastructure parameters, forbidding ad-hoc or unmanaged hostNetwork daemonset overrides.

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 Envoy eBPF Socket Redirection Invariants critical for AI coding assistants?

Enforces strict architectural and resource invariants when pairing Kubernetes Gateway API implementations (such as Cilium or Envoy Gateway) with eBPF sockops and sockmap socket acceleration. Bypasses the standard host TCP/IP stack safely for node-local L7 proxying while guaranteeing socket lookup continuity, mTLS SPIFFE validation, and cgroup namespace compatibility. 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 (Bypassing Host TCP/IP Without Node-Local Topology Constraints and Sockmap Socket Preservation) 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