This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: cilium-ebpf-wireguard-rekey-nonce-invariant

Cilium eBPF WireGuard In-Flight Rekeying and Nonce Safety Invariant

Enforces a fail-closed eBPF datapath invariant to eliminate transient plaintext packet leakage during asynchronous WireGuard key renegotiation across multi-cloud Kubernetes nodes. Guarantees that packet transmission halts or queues inside the eBPF tail-call pipeline if an active cryptographic session nonce resets or key rotation handshake has not achieved convergence.

Prohibited Anti-Pattern: Opportunistic Encryption Fallback and Premature Session Destruction During Dynamic WireGuard Rekeying

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF WireGuard In-Flight Rekeying and Nonce Safety Invariant - Enforces a fail-closed eBPF datapath invariant to eliminate transient plaintext packet leakage during asynchronous WireGuard key renegotiation across multi-cloud Kubernetes nodes. Guarantees that packet transmission halts or queues inside the eBPF tail-call pipeline if an active cryptographic session nonce resets or key rotation handshake has not achieved convergence.
globs: helm/**/cilium*.yaml, infrastructure/**/cilium/*.yaml, charts/cilium/values.yaml, bpf/bpf_network.c, pkg/datapath/loader/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-ebpf-wireguard-rekey-nonce-invariant"
---

# Cilium eBPF WireGuard In-Flight Rekeying and Nonce Safety Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Opportunistic Encryption Fallback and Premature Session Destruction During Dynamic WireGuard Rekeying

## System Constraints
You are a Principal Cloud-Native Security Architect enforcing strict cryptographic invariants within Cilium eBPF and WireGuard overlays. Under no circumstances may pod-to-pod cross-node traffic be transmitted unencrypted. You must ensure that eBPF programs fail-closed (TC_ACT_SHOT) whenever a cryptographic session is invalid, rekeying is pending, or tunnel endpoints diverge, strictly prohibiting plaintext fallback.

## Strict Guidelines
- Engineers MUST ALWAYS set 'encryption.strictMode.enabled=true' alongside 'encryption.type=wireguard' in Cilium Helm configurations to ensure eBPF programs drop packets when encryption tunnels are not established.
- Engineers MUST NOT allow 'encryption.strictMode.allowRemoteNodeIdentities=true' unless an out-of-band mutual TLS authentication channel is explicitly verified, preventing unauthenticated CIDR bypass during dynamic rekeying.
- Code MUST configure eBPF TC egress filters to verify the destination endpoint state in 'cilium_node_map' and drop (TC_ACT_SHOT) any packet destined for a remote node if the WireGuard public key exchange is incomplete.
- Services MUST enable WireGuard peer route protection by configuring 'wireguard.fallbackToPlaintext=false' and setting 'tunnel-protocol=vxlan' or strict direct-routing encapsulation with encryption mandatory headers.
- Components NEVER destroy an established WireGuard session nonce table before the successor peer key pair has completed its two-way noise handshake across the control plane.

## Bad vs Good Implementations
### Cilium Helm Configuration: Plaintext Leakage vs Strict Fail-Closed WireGuard Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: When strictMode is disabled, Cilium's eBPF datapath treats unresolvable WireGuard peer endpoints as standard L3 native routing targets. During key rotation or dynamic handshake renegotiation, in-flight nonces are exhausted or invalidated, causing the eBPF tail call to route packets in cleartext across the underlying cloud VPC network.
```yaml
# INSECURE: Default configuration permits transient plaintext fallback during rekeying
enryption:
  enabled: true
  type: wireguard
  # Missing strictMode allows BPF tc egress to bypass encryption
  # when the remote peer key is rotating or unconfirmed in the node map
  wireguard:
    userspaceFallback: false
    incrementalRekey: false
routingMode: native
nodePort:
  enabled: true
```

#### Production Standard (Correct)
> **Standard**: Explicitly enabling 'strictMode.enabled=true' with 'cidrEnforcement: true' ensures the eBPF classifier invokes 'DROP_NO_TUNNEL_KEY' (TC_ACT_SHOT) rather than passing the skb down the native stack whenever a WireGuard nonce sequence resets or a peer key rotation is in-flight.
```yaml
# SECURE: Fail-closed eBPF datapath with strict dynamic key renegotiation safety
enryption:
  enabled: true
  type: wireguard
  strictMode:
    enabled: true
    cidrEnforcement: true
    allowRemoteNodeIdentities: false
  wireguard:
    userspaceFallback: false
    dynamicHandshakeTimeout: 10s
    persistentKeepalive: 25s
routingMode: native
tunnelProtocol: "none"
bpf:
  autoMountLbpfs: true
  # Enforce TC drop on missing crypto context
  policyMapMax: 16384
```

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 WireGuard In-Flight Rekeying and Nonce Safety Invariant

Cilium eBPF WireGuard In-Flight Rekeying and Nonce Safety Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces a fail-closed eBPF datapath invariant to eliminate transient plaintext packet leakage during asynchronous WireGuard key renegotiation across multi-cloud Kubernetes nodes. Guarantees that packet transmission halts or queues inside the eBPF tail-call pipeline if an active cryptographic session nonce resets or key rotation handshake has not achieved convergence. 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: Opportunistic Encryption Fallback and Premature Session Destruction During Dynamic WireGuard Rekeying 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 DriftOpportunistic Encryption Fallback and Premature Session Destruction During Dynamic WireGuard RekeyingCritical
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 'encryption.strictMode.enabled=true' alongside 'encryption.type=wireguard' in Cilium Helm configurations to ensure eBPF programs drop packets when encryption tunnels are not established.

Engineers MUST ALWAYS set 'encryption.strictMode.enabled=true' alongside 'encryption.type=wireguard' in Cilium Helm configurations to ensure eBPF programs drop packets when encryption tunnels are not established.

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 'encryption.strictMode.allowRemoteNodeIdentities=true' unless an out-of-band mutual TLS authentication channel is explicitly verified, preventing unauthenticated CIDR bypass during dynamic rekeying.

Engineers MUST NOT allow 'encryption.strictMode.allowRemoteNodeIdentities=true' unless an out-of-band mutual TLS authentication channel is explicitly verified, preventing unauthenticated CIDR bypass during dynamic rekeying.

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 configure eBPF TC egress filters to verify the destination endpoint state in 'cilium_node_map' and drop (TC_ACT_SHOT) any packet destined for a remote node if the WireGuard public key exchange is incomplete.

Code MUST configure eBPF TC egress filters to verify the destination endpoint state in 'cilium_node_map' and drop (TC_ACT_SHOT) any packet destined for a remote node if the WireGuard public key exchange is incomplete.

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 WireGuard peer route protection by configuring 'wireguard.fallbackToPlaintext=false' and setting 'tunnel-protocol=vxlan' or strict direct-routing encapsulation with encryption mandatory headers.

Services MUST enable WireGuard peer route protection by configuring 'wireguard.fallbackToPlaintext=false' and setting 'tunnel-protocol=vxlan' or strict direct-routing encapsulation with encryption mandatory headers.

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 destroy an established WireGuard session nonce table before the successor peer key pair has completed its two-way noise handshake across the control plane.

Components NEVER destroy an established WireGuard session nonce table before the successor peer key pair has completed its two-way noise handshake across the control plane.

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 WireGuard In-Flight Rekeying and Nonce Safety Invariant critical for AI coding assistants?

Enforces a fail-closed eBPF datapath invariant to eliminate transient plaintext packet leakage during asynchronous WireGuard key renegotiation across multi-cloud Kubernetes nodes. Guarantees that packet transmission halts or queues inside the eBPF tail-call pipeline if an active cryptographic session nonce resets or key rotation handshake has not achieved convergence. 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 (Opportunistic Encryption Fallback and Premature Session Destruction During Dynamic WireGuard Rekeying) 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