This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: ebpf-tc-microsegmentation-pod-identity-guardrail

eBPF TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation

Mandates verified kernel-level tenant identity injection and boundary validation at the Traffic Control (TC) layer via eBPF. Forbids unauthenticated IP-to-identity mappings and missing verifier bounds checks on custom encapsulation headers, ensuring line-rate lateral movement isolation without userspace proxy latency.

Prohibited Anti-Pattern: Trusting Plaintext L3/L4 Metadata Without Cryptographic Authentication and Missing Packet Boundary Validation in TC Filters

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation - Mandates verified kernel-level tenant identity injection and boundary validation at the Traffic Control (TC) layer via eBPF. Forbids unauthenticated IP-to-identity mappings and missing verifier bounds checks on custom encapsulation headers, ensuring line-rate lateral movement isolation without userspace proxy latency.
globs: bpf/**/*.{c,h}, **/*.bpf.c, pkg/bpf/**/*.{go,c,h}, src/bpf/**/*.{c,h}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tc-microsegmentation-pod-identity-guardrail"
---

# eBPF TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Trusting Plaintext L3/L4 Metadata Without Cryptographic Authentication and Missing Packet Boundary Validation in TC Filters

## System Constraints
You are a Principal Systems & Kernel Security Architect enforcing eBPF Traffic Control (TC) Microsegmentation Pod-Identity Tagging invariants. Enforce strict direct packet access verifier compliance, cryptographic identity validation on packet metadata headers (Geneve/VXLAN options or eBBR authentication tags), fail-closed packet handling with TC_ACT_SHOT, and mandatory incremental checksum updates across all TC ingress/egress hooks.

## Strict Guidelines
- Engineers MUST ALWAYS validate packet buffer boundaries (`data + sizeof(struct) > data_end`) immediately before dereferencing any network or custom identity header.
- Engineers MUST NOT trust raw IPv4/IPv6 source addresses for tenant authorization; identity must be derived from cryptographically verified encapsulation tokens, security context labels in Geneve/VXLAN TLVs, or IPsec/WireGuard SPI bindings.
- Code MUST return `TC_ACT_SHOT` on authentication failure, malformed identity options, or unexpected identity spoofing attempts.
- Services MUST invoke `bpf_l3_csum_replace` and `bpf_l4_csum_replace` when modifying IP/TCP/UDP headers or prepending custom microsegmentation identity shims to preserve transport layer packet integrity.
- Components NEVER fall back to userspace daemons for synchronous per-packet identity verification in hot ingress TC paths.

## Bad vs Good Implementations
### TC BPF Ingress Identity Parsing & Verification

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly dereferences packet pointers without verifier-mandated boundary checks against `data_end`, which causes eBPF verifier rejection or memory faults. It also unsafely relies on unauthenticated plaintext source IP addresses for pod identity, allowing spoofing.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <bpf/bpf_helpers.h>

SEC("tc/ingress")
int tc_ingress_identity(struct __sk_buff *skb) {
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;
    
    // ANTI-PATTERN: Blind cast without verifier bounds check
    struct ethhdr *eth = data;
    struct iphdr *ip = (struct iphdr *)(eth + 1);
    
    // ANTI-PATTERN: Relying purely on plaintext source IP for identity
    __u32 src_ip = ip->saddr;
    if (src_ip == 0x0A000002) { // 10.0.0.2
        return TC_ACT_OK; // Vulnerable to IP spoofing
    }
    
    return TC_ACT_SHOT;
}
```

#### Production Standard (Correct)
> **Standard**: Enforces strict bounds verification before accessing packet structures, parsing an explicit pod authentication header and validating security tokens in-kernel with fail-closed execution (TC_ACT_SHOT).
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <bpf/bpf_helpers.h>

struct pod_auth_hdr {
    __u32 security_identity;
    __u32 auth_tag;
} __attribute__((packed));

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 1024);
    __type(key, __u32);   // security_identity
    __type(value, __u32); // expected_shared_key
} identity_keys_map SEC(".maps");

SEC("tc/ingress")
int tc_ingress_identity(struct __sk_buff *skb) {
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;

    // 1. Strict Ethernet header bounds validation
    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end)
        return TC_ACT_SHOT;

    if (eth->h_proto != __constant_htons(ETH_P_IP))
        return TC_ACT_OK;

    // 2. Strict IPv4 header bounds validation
    struct iphdr *ip = (void *)(eth + 1);
    if ((void *)(ip + 1) > data_end)
        return TC_ACT_SHOT;

    // 3. Strict Pod Identity shim boundary check
    struct pod_auth_hdr *auth = (void *)(ip + 1);
    if ((void *)(auth + 1) > data_end)
        return TC_ACT_SHOT;

    // 4. In-kernel cryptographic identity validation against map
    __u32 sec_id = auth->security_identity;
    __u32 *expected_key = bpf_map_lookup_elem(&identity_keys_map, &sec_id);
    if (!expected_key || (*expected_key ^ sec_id) != auth->auth_tag)
        return TC_ACT_SHOT; // Fail-closed on identity mismatch

    return TC_ACT_OK;
}
```

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 TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation

eBPF TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation defines an industrial-grade behavioral standard for security engineering. Mandates verified kernel-level tenant identity injection and boundary validation at the Traffic Control (TC) layer via eBPF. Forbids unauthenticated IP-to-identity mappings and missing verifier bounds checks on custom encapsulation headers, ensuring line-rate lateral movement isolation without userspace proxy latency. 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: Trusting Plaintext L3/L4 Metadata Without Cryptographic Authentication and Missing Packet Boundary Validation in TC Filters 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 DriftTrusting Plaintext L3/L4 Metadata Without Cryptographic Authentication and Missing Packet Boundary Validation in TC FiltersCritical
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 validate packet buffer boundaries (`data + sizeof(struct) > data_end`) immediately before dereferencing any network or custom identity header.

Engineers MUST ALWAYS validate packet buffer boundaries (`data + sizeof(struct) > data_end`) immediately before dereferencing any network or custom identity header.

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 trust raw IPv4/IPv6 source addresses for tenant authorization

Engineers MUST NOT trust raw IPv4/IPv6 source addresses for tenant authorization; identity must be derived from cryptographically verified encapsulation tokens, security context labels in Geneve/VXLAN TLVs, or IPsec/WireGuard SPI bindings.

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

Code MUST return `TC_ACT_SHOT` on authentication failure, malformed identity options, or unexpected identity spoofing attempts.

Code MUST return `TC_ACT_SHOT` on authentication failure, malformed identity options, or unexpected identity spoofing attempts.

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

Services MUST invoke `bpf_l3_csum_replace` and `bpf_l4_csum_replace` when modifying IP/TCP/UDP headers or prepending custom microsegmentation identity shims to preserve transport layer packet integrity.

Services MUST invoke `bpf_l3_csum_replace` and `bpf_l4_csum_replace` when modifying IP/TCP/UDP headers or prepending custom microsegmentation identity shims to preserve transport layer packet integrity.

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

Components NEVER fall back to userspace daemons for synchronous per-packet identity verification in hot ingress TC paths.

Components NEVER fall back to userspace daemons for synchronous per-packet identity verification in hot ingress TC paths.

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 TC Ingress/Egress Pod-Identity Cryptographic Tagging and In-Kernel Microsegmentation critical for AI coding assistants?

Mandates verified kernel-level tenant identity injection and boundary validation at the Traffic Control (TC) layer via eBPF. Forbids unauthenticated IP-to-identity mappings and missing verifier bounds checks on custom encapsulation headers, ensuring line-rate lateral movement isolation without userspace proxy latency. 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 (Trusting Plaintext L3/L4 Metadata Without Cryptographic Authentication and Missing Packet Boundary Validation in TC Filters) 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