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

Cilium eBPF Socket-Layer In-Kernel Identity-Aware Egress Guardrail

Mandates socket-layer eBPF packet attribution via Cilium to enforce Zero Trust egress policies prior to veth egress and network namespace transit. Prevents identity spoofing and unauthorized external network egress by attaching policy enforcement directly to the socket layer (cgroups/sockops) coupled with cryptographic identity injection.

Prohibited Anti-Pattern: Unvalidated IP-Centric Egress and Unpinned Network Policies Bypassing In-Kernel BPF Socket Enforcement

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF Socket-Layer In-Kernel Identity-Aware Egress Guardrail - Mandates socket-layer eBPF packet attribution via Cilium to enforce Zero Trust egress policies prior to veth egress and network namespace transit. Prevents identity spoofing and unauthorized external network egress by attaching policy enforcement directly to the socket layer (cgroups/sockops) coupled with cryptographic identity injection.
globs: deploy/**/*.yaml, k8s/**/*.yaml, infra/**/*.yaml, charts/**/values.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-ebpf-socket-identity-egress-guardrail"
---

# Cilium eBPF Socket-Layer In-Kernel Identity-Aware Egress Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unvalidated IP-Centric Egress and Unpinned Network Policies Bypassing In-Kernel BPF Socket Enforcement

## System Constraints
You are a Principal Security Architect specializing in Linux eBPF systems and Cilium networking. Enforce strict in-kernel socket-level identity attribution and zero-trust egress policies. Mandate that every network definition utilizes CiliumNetworkPolicy or CiliumClusterwideNetworkPolicy with explicit cryptographic identity binding, socketLB activation, and strict FQDN/endpoint egress filters before packets traverse pod virtual ethernet devices.

## Strict Guidelines
- Engineers MUST ALWAYS declare egress intent using 'cilium.io/v2' CiliumNetworkPolicy or CiliumClusterwideNetworkPolicy instead of legacy, un-attributed vanilla Kubernetes NetworkPolicies.
- Engineers MUST NOT allow wide-open 0.0.0.0/0 CIDR egress without strictly binding traffic to explicit L7 FQDN patterns and protocol/port pairs managed by Cilium's in-kernel DNS proxy.
- Engineers MUST configure Cilium socket-level load balancing ('socketLB.enabled: true') and enable strict policy enforcement ('policyEnforcement: always') to intercept packets at 'sockops' before network namespace traversal.
- Workload specifications MUST NEVER define 'hostNetwork: true' unless the daemon requires host namespace administration and is bound to a dedicated, audited node identity.
- Services MUST declare explicit mutual TLS or SPIFFE cryptographic identity validation when connecting to inter-cluster or cross-namespace endpoints.
- Egress rules SHOULD ALWAYS isolate control plane and telemetry traffic from application payload egress using dedicated labeled endpoints.

## Bad vs Good Implementations
### Cilium Network Policy Egress Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Standard Kubernetes NetworkPolicy relies on naive iptables or late-stage packet filtering. It allows arbitrary external communication to any IP over port 443 without L7 FQDN validation, lacks cryptographic pod identity attribution, and does not leverage Cilium eBPF socket layer interception.
```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: payment-service-egress
  namespace: production
spec:
  podSelector:
    matchLabels:
      app: payment
  policyTypes:
    - Egress
  egress:
    # ANTI-PATTERN: Wide-open CIDR egress allows IP spoofing and bypasses BPF identity tracking
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
      ports:
        - protocol: TCP
          port: 443
```

#### Production Standard (Correct)
> **Standard**: This CiliumNetworkPolicy enforces zero-trust identity attribution directly within the eBPF datapath. It binds microservice egress to specific endpoint labels, pins DNS lookups strictly through kube-dns with pattern matching, and restricts external communication to a verified FQDN ('api.stripe.com') with socket-layer enforcement.
```yaml
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: payment-service-egress
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app.kubernetes.io/name: payment-service
      security.boundary: pci-dss
  egress:
    # Inter-cluster/intra-mesh identity-aware egress
    - toEndpoints:
        - matchLabels:
            app.kubernetes.io/name: ledger-service
            io.kubernetes.pod.namespace: production
      toPorts:
        - ports:
            - port: "8443"
              protocol: TCP
          rules:
            http:
              - method: POST
                path: "/v1/transactions"
    # Strictly attributed external egress via in-kernel DNS proxy
    - toFQDNs:
        - matchPattern: "api.stripe.com"
      toPorts:
        - ports:
            - port: "443"
              protocol: TCP
    # In-kernel eBPF DNS egress bound strictly to kube-dns identity
    - toEndpoints:
        - matchLabels:
            k8s-app: kube-dns
            io.kubernetes.pod.namespace: kube-system
      toPorts:
        - ports:
            - port: "53"
              protocol: UDP
          rules:
            dns:
              - matchPattern: "*"
```

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-Layer In-Kernel Identity-Aware Egress Guardrail

Cilium eBPF Socket-Layer In-Kernel Identity-Aware Egress Guardrail defines an industrial-grade behavioral standard for security engineering. Mandates socket-layer eBPF packet attribution via Cilium to enforce Zero Trust egress policies prior to veth egress and network namespace transit. Prevents identity spoofing and unauthorized external network egress by attaching policy enforcement directly to the socket layer (cgroups/sockops) coupled with cryptographic identity injection. 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 IP-Centric Egress and Unpinned Network Policies Bypassing In-Kernel BPF Socket Enforcement 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 IP-Centric Egress and Unpinned Network Policies Bypassing In-Kernel BPF Socket EnforcementCritical
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 declare egress intent using 'cilium.io/v2' CiliumNetworkPolicy or CiliumClusterwideNetworkPolicy instead of legacy, un-attributed vanilla Kubernetes NetworkPolicies.

Engineers MUST ALWAYS declare egress intent using 'cilium.io/v2' CiliumNetworkPolicy or CiliumClusterwideNetworkPolicy instead of legacy, un-attributed vanilla Kubernetes NetworkPolicies.

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 wide-open 0.0.0.0/0 CIDR egress without strictly binding traffic to explicit L7 FQDN patterns and protocol/port pairs managed by Cilium's in-kernel DNS proxy.

Engineers MUST NOT allow wide-open 0.0.0.0/0 CIDR egress without strictly binding traffic to explicit L7 FQDN patterns and protocol/port pairs managed by Cilium's in-kernel DNS proxy.

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 configure Cilium socket-level load balancing ('socketLB.enabled

Engineers MUST configure Cilium socket-level load balancing ('socketLB.enabled: true') and enable strict policy enforcement ('policyEnforcement: always') to intercept packets at 'sockops' before network namespace traversal.

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

Workload specifications MUST NEVER define 'hostNetwork

Workload specifications MUST NEVER define 'hostNetwork: true' unless the daemon requires host namespace administration and is bound to a dedicated, audited node identity.

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 declare explicit mutual TLS or SPIFFE cryptographic identity validation when connecting to inter-cluster or cross-namespace endpoints.

Services MUST declare explicit mutual TLS or SPIFFE cryptographic identity validation when connecting to inter-cluster or cross-namespace endpoints.

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

Egress rules SHOULD ALWAYS isolate control plane and telemetry traffic from application payload egress using dedicated labeled endpoints.

Egress rules SHOULD ALWAYS isolate control plane and telemetry traffic from application payload egress using dedicated labeled endpoints.

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-Layer In-Kernel Identity-Aware Egress Guardrail critical for AI coding assistants?

Mandates socket-layer eBPF packet attribution via Cilium to enforce Zero Trust egress policies prior to veth egress and network namespace transit. Prevents identity spoofing and unauthorized external network egress by attaching policy enforcement directly to the socket layer (cgroups/sockops) coupled with cryptographic identity injection. 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 IP-Centric Egress and Unpinned Network Policies Bypassing In-Kernel BPF Socket Enforcement) 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