This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-sockops-zerocopy-transit-guardrail

eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation

Enforces deterministic socket redirection via eBPF sockops (BPF_PROG_TYPE_SOCK_OPS) and sockhash (BPF_MAP_TYPE_SOCKHASH) for co-located intra-node Kubernetes pod networking. Mandates that local TCP/IP stack bypass maintains mutual identity attestation, SPIFFE/SPIRE SVID contextual integrity, and fallback egress telemetry without short-circuiting network security policies.

Prohibited Anti-Pattern: Unconditional BPF sk_msg Redirect Bypassing Netfilter Without Cryptographic Identity and Socket Policy Attestation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation - Enforces deterministic socket redirection via eBPF sockops (BPF_PROG_TYPE_SOCK_OPS) and sockhash (BPF_MAP_TYPE_SOCKHASH) for co-located intra-node Kubernetes pod networking. Mandates that local TCP/IP stack bypass maintains mutual identity attestation, SPIFFE/SPIRE SVID contextual integrity, and fallback egress telemetry without short-circuiting network security policies.
globs: bpf/**/*.c, bpf/**/*.h, src/network/**/*.ts, deploy/daemonsets/**/*.yaml, deploy/helm/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-sockops-zerocopy-transit-guardrail"
---

# eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unconditional BPF sk_msg Redirect Bypassing Netfilter Without Cryptographic Identity and Socket Policy Attestation

## System Constraints
You are a Principal Systems Engineer and Kernel Security Architect enforcing eBPF Sockops Zero-Copy Kernel Bypass for intra-node pod transit. You must ensure that local socket redirection via sk_msg and sockhash maintains strict SPIFFE/mTLS identity verification, prevents cross-tenant socket hijacking via namespace collision, logs non-repudiable audit events, and maintains seamless fallback to veth/tc when identity attestations fail.

## Strict Guidelines
- Engineers MUST ALWAYS key the sockhash BPF map using a deterministic 5-tuple along with the network namespace inode (`netns_cookie`) to prevent cross-pod collision or socket hijacking.
- Engineers MUST NOT redirect traffic via `bpf_msg_redirect_hash` before verifying the identity context and cryptographically attested pod labels in user-space or via helper BPF maps.
- Programs MUST verify `skops->family == AF_INET` or `AF_INET6` and restrict zero-copy bypass strictly to loopback or node-local CIDR allocations.
- Code MUST handle `BPF_SOCK_OPS_STATE_CHK` and `BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB` cleanly, pruning sockhash table entries synchronously upon `BPF_SOCK_OPS_STATE_CLOSE`.
- Services MUST preserve a non-bypassable fallback path via `tc` (Traffic Control) BPF egress filters whenever pod-to-pod mTLS handshakes or SPIFFE SVID validation is in flight.

## Bad vs Good Implementations
### eBPF Sockops Registration and Inode Namespace Scoping in Node Agent

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Attaching raw sockops without validating the netns cookie or checking identity context allows co-located pods to bypass network policy filters and creates multi-tenant socket poisoning vectors in shared sockhash tables.
```typescript
import { execSync } from 'child_process';

// Flawed: Global socket bypass without verifying network namespace isolation or identity attestation
export function attachSockopsBypass(podPid: number, podIp: string, targetPort: number): void {
  // Insecure: Bypasses Netfilter/eBPF host policy indiscriminately for any connection to port
  execSync(`bpftool cgroup attach /sys/fs/cgroup/unified/kubepods.slice sock_ops pinned /sys/fs/bpf/sockops_hook`);
  console.log(`Attached raw sockops bypass directly targeting IP ${podIp}:${targetPort}`);
}
```

#### Production Standard (Correct)
> **Standard**: Validates the SPIFFE identity context, verifies the pod cgroup path, and ensures sockops bypass is scoped to verified network namespaces with proper credentials.
```typescript
import { execFileSync } from 'child_process';
import * as fs from 'fs';

interface SockopsSecurityContext {
  podUid: string;
  netnsCookie: bigint;
  spiffeId: string;
  nodeLocalIp: string;
  authorizedPort: number;
}

export function configureAttestedSockopsBypass(ctx: SockopsSecurityContext): void {
  // Enforce validation of node-local IP and cryptographic identity context before map registration
  if (!ctx.spiffeId.startsWith('spiffe://cluster.local/ns/')) {
    throw new Error(`Unauthorized SPIFFE identity for socket bypass: ${ctx.spiffeId}`);
  }

  const cgroupPath = `/sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/pod${ctx.podUid}`;
  if (!fs.existsSync(cgroupPath)) {
    throw new Error(`Invalid cgroup path for targeted pod container: ${cgroupPath}`);
  }

  // Pin and map with composite key: [IP + Port + NetnsCookie] to ensure strict kernel-space tenant separation
  execFileSync('bpftool', [
    'cgroup', 'attach',
    cgroupPath,
    'sock_ops',
    'pinned', '/sys/fs/bpf/cilium_sockops_attested'
  ], { stdio: 'pipe' });
}
```

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: eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation

eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic socket redirection via eBPF sockops (BPF_PROG_TYPE_SOCK_OPS) and sockhash (BPF_MAP_TYPE_SOCKHASH) for co-located intra-node Kubernetes pod networking. Mandates that local TCP/IP stack bypass maintains mutual identity attestation, SPIFFE/SPIRE SVID contextual integrity, and fallback egress telemetry without short-circuiting network security policies. 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: Unconditional BPF sk_msg Redirect Bypassing Netfilter Without Cryptographic Identity and Socket Policy Attestation 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 DriftUnconditional BPF sk_msg Redirect Bypassing Netfilter Without Cryptographic Identity and Socket Policy AttestationCritical
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 key the sockhash BPF map using a deterministic 5-tuple along with the network namespace inode (`netns_cookie`) to prevent cross-pod collision or socket hijacking.

Engineers MUST ALWAYS key the sockhash BPF map using a deterministic 5-tuple along with the network namespace inode (`netns_cookie`) to prevent cross-pod collision or socket 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.
2

Engineers MUST NOT redirect traffic via `bpf_msg_redirect_hash` before verifying the identity context and cryptographically attested pod labels in user-space or via helper BPF maps.

Engineers MUST NOT redirect traffic via `bpf_msg_redirect_hash` before verifying the identity context and cryptographically attested pod labels in user-space or via helper BPF maps.

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

Programs MUST verify `skops->family == AF_INET` or `AF_INET6` and restrict zero-copy bypass strictly to loopback or node-local CIDR allocations.

Programs MUST verify `skops->family == AF_INET` or `AF_INET6` and restrict zero-copy bypass strictly to loopback or node-local CIDR allocations.

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

Code MUST handle `BPF_SOCK_OPS_STATE_CHK` and `BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB` cleanly, pruning sockhash table entries synchronously upon `BPF_SOCK_OPS_STATE_CLOSE`.

Code MUST handle `BPF_SOCK_OPS_STATE_CHK` and `BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB` cleanly, pruning sockhash table entries synchronously upon `BPF_SOCK_OPS_STATE_CLOSE`.

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

Services MUST preserve a non-bypassable fallback path via `tc` (Traffic Control) BPF egress filters whenever pod-to-pod mTLS handshakes or SPIFFE SVID validation is in flight.

Services MUST preserve a non-bypassable fallback path via `tc` (Traffic Control) BPF egress filters whenever pod-to-pod mTLS handshakes or SPIFFE SVID validation is in flight.

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 eBPF Sockops Zero-Copy Inter-Pod Transit & Identity Attestation critical for AI coding assistants?

Enforces deterministic socket redirection via eBPF sockops (BPF_PROG_TYPE_SOCK_OPS) and sockhash (BPF_MAP_TYPE_SOCKHASH) for co-located intra-node Kubernetes pod networking. Mandates that local TCP/IP stack bypass maintains mutual identity attestation, SPIFFE/SPIRE SVID contextual integrity, and fallback egress telemetry without short-circuiting network security policies. 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 (Unconditional BPF sk_msg Redirect Bypassing Netfilter Without Cryptographic Identity and Socket Policy Attestation) 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

eBPF