This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: cilium-tetragon-kernel-namespace-syscall-audit

Cilium Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant

Enforces synchronous kernel-level runtime protection invariants using Cilium Tetragon eBPF TracingPolicies against unauthorized container namespace traversal and anomalous raw socket bindings. Mandates immediate in-kernel SIGKILL termination on namespace boundary violations (sys_setns, sys_unshare) and raw packet manipulation (SOCK_RAW, AF_PACKET) to prevent container escape and network spoofing without incurring user-space context-switch overhead.

Prohibited Anti-Pattern: Passive User-Space Audit Logging of Container Namespace Escapes and Raw Socket Creation Without In-Kernel Process Termination

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant - Enforces synchronous kernel-level runtime protection invariants using Cilium Tetragon eBPF TracingPolicies against unauthorized container namespace traversal and anomalous raw socket bindings. Mandates immediate in-kernel SIGKILL termination on namespace boundary violations (sys_setns, sys_unshare) and raw packet manipulation (SOCK_RAW, AF_PACKET) to prevent container escape and network spoofing without incurring user-space context-switch overhead.
globs: **/*.yaml, **/*.yml, deploy/tetragon/**/*.yaml, infrastructure/security/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-tetragon-kernel-namespace-syscall-audit"
---

# Cilium Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Passive User-Space Audit Logging of Container Namespace Escapes and Raw Socket Creation Without In-Kernel Process Termination

## System Constraints
You are a Principal Infrastructure & Security Architect specializing in eBPF, Linux kernel internals, and Cilium Tetragon. You mandate strict, zero-overhead runtime enforcement policies. Reject any Tetragon TracingPolicy configuration that relies solely on passive user-space notification ('Post') for namespace escapes or anomalous packet sockets. Enforce synchronous in-kernel 'Sigkill' actions and granular argument matching on low-level system call hooks (sys_setns, sys_unshare, __sys_socket).

## Strict Guidelines
- Engineers MUST ALWAYS configure Cilium Tetragon TracingPolicies with the 'Sigkill' action on unauthorized invocations of 'sys_setns' and 'sys_unshare' inside application workloads.
- Engineers MUST NOT rely on passive audit logging or asynchronous SIEM log shipping for critical privilege escalation and namespace escape events.
- TracingPolicies targeting network anomalies MUST monitor '__sys_socket' or 'sys_enter_socket' and filter on socket types 'SOCK_RAW' (3) and address family 'AF_PACKET' (17), terminating non-privileged processes immediately.
- Selectors in TracingPolicy resources MUST explicitly scope enforcement to non-host namespace containers using 'matchNamespaces' or workload pod labels to prevent accidental node-level kubelet/CRI disruption.
- Configurations SHOULD attach kprobes to kernel entry points with explicit argument index checks and message metadata to emit high-fidelity audit events before process termination.

## Bad vs Good Implementations
### Passive Non-Terminating Namespace Audit vs. Synchronous Kernel-Enforced Sigkill Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: This policy merely audits the 'sys_setns' syscall via default Tetragon export logs. It leaves the target process executing inside the target namespace, allowing attackers to compromise host resources or sibling containers while defenders await log processing.
```yaml
# INSECURE: Passive monitoring only emits an event to export logs.
# An attacker successfully escapes the namespace before human/SIEM remediation.
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: audit-namespace-escape
spec:
  kprobes:
    - call: "sys_setns"
      syscall: true
      args:
        - index: 0
          type: "int"
        - index: 1
          type: "int"
      # Flaw: Missing 'Sigkill' action and missing socket abuse prevention.
      # The container process transitions namespaces unhindered.
```

#### Production Standard (Correct)
> **Standard**: Attaches eBPF probes directly to 'sys_setns' and '__sys_socket' with parameter validation. If an unprivileged container process attempts to switch network/PID namespaces or allocate raw packet sockets, the kernel synchronously terminates the violating thread group via SIGKILL before execution proceeds.
```yaml
# HARDENED: Synchronous in-kernel termination for unauthorized setns and raw socket initialization
apiVersion: cilium.io/v1alpha1
kind: TracingPolicyNamespaced
metadata:
  name: block-namespace-escape-and-raw-sockets
  namespace: production
spec:
  kprobes:
    - call: "sys_setns"
      syscall: true
      args:
        - index: 0
          type: "int"
        - index: 1
          type: "int"
      selectors:
        - matchArgs:
            - index: 1
              operator: "Mask"
              values:
                - "0x00020000" # CLONE_NEWNET
                - "0x20000000" # CLONE_NEWPID
          matchActions:
            - action: Sigkill
    - call: "__sys_socket"
      syscall: true
      args:
        - index: 0 # family
          type: "int"
        - index: 1 # type
          type: "int"
      selectors:
        - matchArgs:
            - index: 0
              operator: "Equal"
              values:
                - "17" # AF_PACKET
          matchActions:
            - action: Sigkill
        - matchArgs:
            - index: 1
              operator: "Equal"
              values:
                - "3" # SOCK_RAW
          matchActions:
            - action: Sigkill
```

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 Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant

Cilium Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces synchronous kernel-level runtime protection invariants using Cilium Tetragon eBPF TracingPolicies against unauthorized container namespace traversal and anomalous raw socket bindings. Mandates immediate in-kernel SIGKILL termination on namespace boundary violations (sys_setns, sys_unshare) and raw packet manipulation (SOCK_RAW, AF_PACKET) to prevent container escape and network spoofing without incurring user-space context-switch overhead. 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: Passive User-Space Audit Logging of Container Namespace Escapes and Raw Socket Creation Without In-Kernel Process Termination 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 DriftPassive User-Space Audit Logging of Container Namespace Escapes and Raw Socket Creation Without In-Kernel Process TerminationCritical
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 Cilium Tetragon TracingPolicies with the 'Sigkill' action on unauthorized invocations of 'sys_setns' and 'sys_unshare' inside application workloads.

Engineers MUST ALWAYS configure Cilium Tetragon TracingPolicies with the 'Sigkill' action on unauthorized invocations of 'sys_setns' and 'sys_unshare' inside application workloads.

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 rely on passive audit logging or asynchronous SIEM log shipping for critical privilege escalation and namespace escape events.

Engineers MUST NOT rely on passive audit logging or asynchronous SIEM log shipping for critical privilege escalation and namespace escape events.

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

TracingPolicies targeting network anomalies MUST monitor '__sys_socket' or 'sys_enter_socket' and filter on socket types 'SOCK_RAW' (3) and address family 'AF_PACKET' (17), terminating non-privileged processes immediately.

TracingPolicies targeting network anomalies MUST monitor '__sys_socket' or 'sys_enter_socket' and filter on socket types 'SOCK_RAW' (3) and address family 'AF_PACKET' (17), terminating non-privileged processes immediately.

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

Selectors in TracingPolicy resources MUST explicitly scope enforcement to non-host namespace containers using 'matchNamespaces' or workload pod labels to prevent accidental node-level kubelet/CRI disruption.

Selectors in TracingPolicy resources MUST explicitly scope enforcement to non-host namespace containers using 'matchNamespaces' or workload pod labels to prevent accidental node-level kubelet/CRI disruption.

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

Configurations SHOULD attach kprobes to kernel entry points with explicit argument index checks and message metadata to emit high-fidelity audit events before process termination.

Configurations SHOULD attach kprobes to kernel entry points with explicit argument index checks and message metadata to emit high-fidelity audit events before process termination.

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 Tetragon Kernel-Level Namespace Escape and Raw Socket Invariant critical for AI coding assistants?

Enforces synchronous kernel-level runtime protection invariants using Cilium Tetragon eBPF TracingPolicies against unauthorized container namespace traversal and anomalous raw socket bindings. Mandates immediate in-kernel SIGKILL termination on namespace boundary violations (sys_setns, sys_unshare) and raw packet manipulation (SOCK_RAW, AF_PACKET) to prevent container escape and network spoofing without incurring user-space context-switch overhead. 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 (Passive User-Space Audit Logging of Container Namespace Escapes and Raw Socket Creation Without In-Kernel Process Termination) 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