This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: cilium-ebpf-encryption-host-routing-invariants

Cilium eBPF Socket Encryption & Host-Routing Wire Invariants

Enforces strict kernel-level eBPF host-routing and transparent encryption (WireGuard/IPsec) configuration invariants across Kubernetes clusters without sidecar overhead. Mandates that Cilium eBPF map limits, MTU encap calculations, Node-to-Node encryption boundaries, and Envoy L7 egress redirects preserve cryptographic pod-identity verification at the socket layer.

Prohibited Anti-Pattern: Bypassing Kernel eBPF Data-Path via Misconfigured Host-Routing Fallback and Unencrypted Overlay Leaks

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF Socket Encryption & Host-Routing Wire Invariants - Enforces strict kernel-level eBPF host-routing and transparent encryption (WireGuard/IPsec) configuration invariants across Kubernetes clusters without sidecar overhead. Mandates that Cilium eBPF map limits, MTU encap calculations, Node-to-Node encryption boundaries, and Envoy L7 egress redirects preserve cryptographic pod-identity verification at the socket layer.
globs: deploy/helm/**/*.yaml, infra/k8s/**/*.yaml, charts/**/cilium*.yaml, clusters/**/cilium-values.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-ebpf-encryption-host-routing-invariants"
---

# Cilium eBPF Socket Encryption & Host-Routing Wire Invariants

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Bypassing Kernel eBPF Data-Path via Misconfigured Host-Routing Fallback and Unencrypted Overlay Leaks

## System Constraints
You are a Principal Platform Engineer enforcing Cilium eBPF Transparent Socket Encryption, BPF Host-Routing, and Wire Invariants. You must ensure all Cilium Helm values, CiliumNetworkPolicies, and kernel sysctls eliminate iptables/sidecar overhead while maintaining strict cryptographically signed WireGuard or IPsec pod-to-pod identity across node boundaries, L7 egress visibility, and preventing MTU fragmentation.

## Strict Guidelines
- Engineers MUST ALWAYS configure `bpf.masquerade=true` and `bpf.hostRouting=true` when enabling Cilium transparent encryption to bypass legacy iptables processing completely.
- Engineers MUST ALWAYS set explicit MTU accounting (`encryption.wireguard.persistentKeepalive` and adjusted `mtu`) accounting for the 60-byte WireGuard or 72-byte IPsec header overhead relative to host network interface MTU.
- Engineers MUST NOT disable `encryption.nodeEncryption` when enabling WireGuard or IPsec; pod-to-node and node-to-node traffic must both traverse cryptographic validation.
- Configurations MUST define `endpointRoutes.enabled=true` when paired with BPF host-routing to prevent cross-node socket-to-socket hairpin leaks that bypass tc/eBPF egress hooks.
- CiliumNetworkPolicy L7 egress rules MUST enforce strict `toPorts` rules pointing explicitly to Envoy proxy redirection without relying on mutating sidecar injection.

## Bad vs Good Implementations
### Cilium Helm Values: Insecure iptables fallback vs Strict eBPF WireGuard Routing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Disabling bpf.hostRouting forces packet traversing to iptables/legacy netfilter, increasing pod-to-pod latency and CPU usage. Omitting nodeEncryption leaks node-to-node metadata, while neglecting bpfMasquerade breaks transparent socket-level attribution.
```yaml
# INSECURE: Relies on legacy iptables masquerading, disabled node encryption, unadjusted MTU
enablement:
  encryption:
    enabled: true
    type: wireguard
routing:
  bpf:
    hostRouting: false
  tunnel: vxlan
trafficMasquerade:
  masquerade: true
  bpfMasquerade: false
```

#### Production Standard (Correct)
> **Standard**: Directs all pod-to-pod and node-to-node traffic through the eBPF data-path, bypassing netfilter via native BPF host routing, transparently encrypting at the socket boundary, and precisely compensating for Jumbo Frame MTU delta.
```yaml
# HARDENED: Full kernel-space eBPF host-routing, transparent WireGuard socket encryption, strict MTU
routingMode: native
ipv4NativeRoutingCIDR: 10.244.0.0/16
autoDirectNodeRoutes: true
bpf:
  hostRouting: true
  masquerade: true
  tproxy: true
enpointRoutes:
  enabled: true
enctyption:
  enabled: true
  type: wireguard
  nodeEncryption: true
  wireguard:
    persistentKeepalive: 25s
mtu: 8940 # Host MTU 9000 minus 60 bytes WireGuard header overhead
```

### CiliumNetworkPolicy: Non-isolated vs Cryptographic L7 Identity Egress Enforcement

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Allows arbitrary TLS egress without verifying application identity invariants or routing through Cilium's kernel-integrated Envoy daemonset, making it vulnerable to egress exfiltration from compromised workloads.
```yaml
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: payment-egress
spec:
  endpointSelector:
    matchLabels:
      app: payment
  egress:
  - toEntities:
    - world
    toPorts:
    - ports:
      - port: "443"
        protocol: TCP
```

#### Production Standard (Correct)
> **Standard**: Binds pod socket egress directly to cryptographic FQDN/L7 validation rules and specific internal cryptographic identities via Cilium eBPF, without running sidecars, while dropping unmapped outbound flows.
```yaml
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: payment-egress-secure
spec:
  endpointSelector:
    matchLabels:
      app: payment
  egress:
  - toFQDNs:
    - matchName: "api.stripe.com"
    toPorts:
    - ports:
      - port: "443"
        protocol: TCP
      rules:
        http:
        - method: "POST"
          path: "/v1/charges"
  - toEndpoints:
    - matchLabels:
      "k8s:io.kubernetes.pod.namespace": vault
      app: vault
    toPorts:
    - ports:
      - port: "8200"
        protocol: TCP
```

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: Cilium eBPF Socket Encryption & Host-Routing Wire Invariants

Cilium eBPF Socket Encryption & Host-Routing Wire Invariants defines an industrial-grade behavioral standard for devops engineering. Enforces strict kernel-level eBPF host-routing and transparent encryption (WireGuard/IPsec) configuration invariants across Kubernetes clusters without sidecar overhead. Mandates that Cilium eBPF map limits, MTU encap calculations, Node-to-Node encryption boundaries, and Envoy L7 egress redirects preserve cryptographic pod-identity verification at the socket layer. 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 Kernel eBPF Data-Path via Misconfigured Host-Routing Fallback and Unencrypted Overlay Leaks 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 Kernel eBPF Data-Path via Misconfigured Host-Routing Fallback and Unencrypted Overlay LeaksCritical
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 `bpf.masquerade=true` and `bpf.hostRouting=true` when enabling Cilium transparent encryption to bypass legacy iptables processing completely.

Engineers MUST ALWAYS configure `bpf.masquerade=true` and `bpf.hostRouting=true` when enabling Cilium transparent encryption to bypass legacy iptables processing completely.

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 ALWAYS set explicit MTU accounting (`encryption.wireguard.persistentKeepalive` and adjusted `mtu`) accounting for the 60-byte WireGuard or 72-byte IPsec header overhead relative to host network interface MTU.

Engineers MUST ALWAYS set explicit MTU accounting (`encryption.wireguard.persistentKeepalive` and adjusted `mtu`) accounting for the 60-byte WireGuard or 72-byte IPsec header overhead relative to host network interface MTU.

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 disable `encryption.nodeEncryption` when enabling WireGuard or IPsec

Engineers MUST NOT disable `encryption.nodeEncryption` when enabling WireGuard or IPsec; pod-to-node and node-to-node traffic must both traverse cryptographic validation.

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

Configurations MUST define `endpointRoutes.enabled=true` when paired with BPF host-routing to prevent cross-node socket-to-socket hairpin leaks that bypass tc/eBPF egress hooks.

Configurations MUST define `endpointRoutes.enabled=true` when paired with BPF host-routing to prevent cross-node socket-to-socket hairpin leaks that bypass tc/eBPF egress hooks.

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

CiliumNetworkPolicy L7 egress rules MUST enforce strict `toPorts` rules pointing explicitly to Envoy proxy redirection without relying on mutating sidecar injection.

CiliumNetworkPolicy L7 egress rules MUST enforce strict `toPorts` rules pointing explicitly to Envoy proxy redirection without relying on mutating sidecar injection.

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 Cilium eBPF Socket Encryption & Host-Routing Wire Invariants critical for AI coding assistants?

Enforces strict kernel-level eBPF host-routing and transparent encryption (WireGuard/IPsec) configuration invariants across Kubernetes clusters without sidecar overhead. Mandates that Cilium eBPF map limits, MTU encap calculations, Node-to-Node encryption boundaries, and Envoy L7 egress redirects preserve cryptographic pod-identity verification at the socket layer. 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 Kernel eBPF Data-Path via Misconfigured Host-Routing Fallback and Unencrypted Overlay Leaks) 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

Cilium