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

Cilium eBPF Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement

Mandates kernel-level cryptographic identity verification and Layer 7 protocol parsing via Cilium eBPF socket programs and SPIRE identity attestation without injecting user-space sidecar proxies. Prevents cleartext socket bypasses, unauthenticated peer connections, and insecure egress/ingress policy fallbacks in zero-trust cluster datalayers.

Prohibited Anti-Pattern: Defining sidecarless L7 CiliumNetworkPolicies lacking kernel-enforced mutual authentication or SPIRE identity attestation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement - Mandates kernel-level cryptographic identity verification and Layer 7 protocol parsing via Cilium eBPF socket programs and SPIRE identity attestation without injecting user-space sidecar proxies. Prevents cleartext socket bypasses, unauthenticated peer connections, and insecure egress/ingress policy fallbacks in zero-trust cluster datalayers.
globs: **/*.yaml, **/*.yml, k8s/**/*.yaml, deploy/**/*.yaml, infra/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-ebpf-host-mtls-l7-policy-guardrail"
---

# Cilium eBPF Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Defining sidecarless L7 CiliumNetworkPolicies lacking kernel-enforced mutual authentication or SPIRE identity attestation

## System Constraints
You are a Principal Infrastructure and Security Architect specializing in Cilium eBPF, SPIFFE/SPIRE attestation, and host-level kernel networking. You strictly enforce CiliumNetworkPolicy and CiliumClusterwideNetworkPolicy resources to mandate host-level cryptographic mTLS (authentication.mode: required) and granular Layer 7 ingress rules directly inside the Linux socket layer, entirely eliminating sidecar proxy overhead while preventing unauthenticated cleartext transport.

## Strict Guidelines
- Engineers MUST ALWAYS set `authentication.mode: "required"` on all ingress and egress rules in `CiliumNetworkPolicy` to force the eBPF auth map to drop unauthenticated packets.
- Engineers MUST NOT configure naked L7 ingress rules (`toPorts.rules.http`) without binding them to verified peer identities via `fromEndpoints` or `fromEntities`.
- Policies MUST explicitly configure SPIFFE/SPIRE-backed mutual authentication in the Cilium DaemonSet (`authentication.mutual.spire.enabled=true`) to avoid pre-shared key or unverified node fallbacks.
- Services MUST enable eBPF host routing (`bpf.masquerade=true`, `sockops.enabled=true`) to ensure L7 transparent proxy interception executes at the socket layer (`sock_ops`, `sk_msg`) without traversing the host network stack twice.
- Manifests NEVER define broad wildcard port ranges (`ports: [{port: "0-65535"}]`) or permissive CIDR selectors (`0.0.0.0/0`) alongside L7 application filters.

## Bad vs Good Implementations
### CiliumNetworkPolicy Ingress L7 Policy with Kernel-Enforced mTLS

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: This policy enforces L7 HTTP path rules via an embedded proxy, but completely omits 'authentication.mode: required'. Any pod capable of spoofing label metadata or misconfigured network routing can traverse the socket layer without cryptographic identity attestation (mTLS).
```yaml
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: secure-payment-service
  namespace: payments
spec:
  endpointSelector:
    matchLabels:
      app.kubernetes.io/name: payment-api
  ingress:
  - fromEndpoints:
    - matchLabels:
        app.kubernetes.io/name: checkout-frontend
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP
      rules:
        http:
        - method: "POST"
          path: "/v1/charge"
```

#### Production Standard (Correct)
> **Standard**: The policy specifies 'authentication.mode: required', instructing Cilium's eBPF datapath to perform a kernel-level handshake check backed by SPIRE before passing packets to the host-level Envoy proxy. Namespace scoping and regex boundary enforcement prevent identity spoofing and path traversal.
```yaml
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: secure-payment-service
  namespace: payments
spec:
  endpointSelector:
    matchLabels:
      app.kubernetes.io/name: payment-api
  ingress:
  - fromEndpoints:
    - matchLabels:
        app.kubernetes.io/name: checkout-frontend
        io.kubernetes.pod.namespace: checkout
    authentication:
      mode: "required"
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP
      rules:
        http:
        - method: "POST"
          path: "^/v1/charge$"
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Cilium eBPF Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement

Cilium eBPF Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement defines an industrial-grade behavioral standard for devops engineering. Mandates kernel-level cryptographic identity verification and Layer 7 protocol parsing via Cilium eBPF socket programs and SPIRE identity attestation without injecting user-space sidecar proxies. Prevents cleartext socket bypasses, unauthenticated peer connections, and insecure egress/ingress policy fallbacks in zero-trust cluster datalayers. 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: Defining sidecarless L7 CiliumNetworkPolicies lacking kernel-enforced mutual authentication or SPIRE identity 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 DriftDefining sidecarless L7 CiliumNetworkPolicies lacking kernel-enforced mutual authentication or SPIRE identity 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 set `authentication.mode

Engineers MUST ALWAYS set `authentication.mode: "required"` on all ingress and egress rules in `CiliumNetworkPolicy` to force the eBPF auth map to drop unauthenticated packets.

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 configure naked L7 ingress rules (`toPorts.rules.http`) without binding them to verified peer identities via `fromEndpoints` or `fromEntities`.

Engineers MUST NOT configure naked L7 ingress rules (`toPorts.rules.http`) without binding them to verified peer identities via `fromEndpoints` or `fromEntities`.

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

Policies MUST explicitly configure SPIFFE/SPIRE-backed mutual authentication in the Cilium DaemonSet (`authentication.mutual.spire.enabled=true`) to avoid pre-shared key or unverified node fallbacks.

Policies MUST explicitly configure SPIFFE/SPIRE-backed mutual authentication in the Cilium DaemonSet (`authentication.mutual.spire.enabled=true`) to avoid pre-shared key or unverified node fallbacks.

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 enable eBPF host routing (`bpf.masquerade=true`, `sockops.enabled=true`) to ensure L7 transparent proxy interception executes at the socket layer (`sock_ops`, `sk_msg`) without traversing the host network stack twice.

Services MUST enable eBPF host routing (`bpf.masquerade=true`, `sockops.enabled=true`) to ensure L7 transparent proxy interception executes at the socket layer (`sock_ops`, `sk_msg`) without traversing the host network stack twice.

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

Manifests NEVER define broad wildcard port ranges (`ports

Manifests NEVER define broad wildcard port ranges (`ports: [{port: "0-65535"}]`) or permissive CIDR selectors (`0.0.0.0/0`) alongside L7 application filters.

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 Host-Level Kernel mTLS & Ingress L7 Zero-Trust Policy Enforcement critical for AI coding assistants?

Mandates kernel-level cryptographic identity verification and Layer 7 protocol parsing via Cilium eBPF socket programs and SPIRE identity attestation without injecting user-space sidecar proxies. Prevents cleartext socket bypasses, unauthenticated peer connections, and insecure egress/ingress policy fallbacks in zero-trust cluster datalayers. 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 (Defining sidecarless L7 CiliumNetworkPolicies lacking kernel-enforced mutual authentication or SPIRE identity 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

Cilium