This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: envoy-gateway-spiffe-spire-svid-ratchet-standard

Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard

Enforces seamless zero-downtime X.509 SVID rotation across Envoy Gateway managed ingress clusters integrated with SPIFFE/SPIRE. Mandates dynamic Secret Discovery Service (SDS) socket streaming, dual-bundle trust validation windows, and TLS listener drain coordination to eliminate transient connection reset bursts (ECONNRESET) during short-lived certificate lifecycles.

Prohibited Anti-Pattern: Hard certificate swapping via static volume remounts or single-trust SDS pushes lacking graceful TLS drain intervals

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard - Enforces seamless zero-downtime X.509 SVID rotation across Envoy Gateway managed ingress clusters integrated with SPIFFE/SPIRE. Mandates dynamic Secret Discovery Service (SDS) socket streaming, dual-bundle trust validation windows, and TLS listener drain coordination to eliminate transient connection reset bursts (ECONNRESET) during short-lived certificate lifecycles.
globs: k8s/**/*.yaml, helm/**/*.yaml, infrastructure/**/*.ts, deploy/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/envoy-gateway-spiffe-spire-svid-ratchet-standard"
---

# Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Hard certificate swapping via static volume remounts or single-trust SDS pushes lacking graceful TLS drain intervals

## System Constraints
You are a Principal Infrastructure Architect enforcing zero-downtime mTLS SVID rotations for Envoy Gateway backed by SPIFFE/SPIRE. You must strictly forbid static Secret mounts, manual SIGHUP proxy restarts, and non-overlapping trust bundle configurations. Ensure all manifests and dynamic control plane extensions implement gRPC SDS over UNIX domain sockets, certificate ratcheting with overlapping validity, and strict SPIFFE ID SAN validation.

## Strict Guidelines
- Engineers MUST ALWAYS configure Envoy Gateway to consume X.509 SVIDs and SPIFFE trust bundles dynamically via gRPC Secret Discovery Service (SDS) over a local SPIRE Agent UNIX domain socket.
- Engineers MUST NOT rely on Kubernetes Secrets or file-projected volumes with atomic symlink swaps for high-frequency mTLS credential rotations.
- SDS configurations MUST maintain dual-bundle overlap during trust root rotations, ensuring inbound handshakes accept both expiring and newly issued authority certificates.
- Envoy ClientTrafficPolicy and listener settings MUST configure a non-zero `drain_timeout` (minimum 30 seconds) and set `delayed_close_timeout` to prevent abrupt TCP FIN resets during TLS context updates.
- SecurityPolicy resources MUST enforce explicit SPIFFE ID SAN matching patterns (`spiffe://<trust-domain>/...`) on downstream and upstream validation contexts rather than legacy generic DNS/CommonName checks.

## Bad vs Good Implementations
### Pulumi/TypeScript: Envoy Gateway Dynamic SPIRE SDS vs Static Secret Mount

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Static Kubernetes Secrets require volume updates or pod restarts. When certificates rotate rapidly (e.g., every 15-60 minutes in dynamic meshes), active TLS handshakes abort and client sockets drop abruptly.
```typescript
import * as k8s from "@pulumi/kubernetes";

// ANTI-PATTERN: Consuming static mounted Kubernetes Secret certificates.
// Rotating this secret triggers atomic file swaps that Envoy cannot drain gracefully,
// causing immediate downstream TLS handshake failures and ECONNRESET bursts.
export const badSecurityPolicy = new k8s.apiextensions.CustomResource("insecure-policy", {
  apiVersion: "gateway.envoyproxy.io/v1alpha1",
  kind: "SecurityPolicy",
  metadata: { name: "ingress-mtls-policy", namespace: "envoy-gateway-system" },
  spec: {
    targetRef: {
      group: "gateway.networking.k8s.io",
      kind: "Gateway",
      name: "edge-gateway"
    },
    tls: {
      // Hard-coded static secret without dynamic SPIFFE/SPIRE SDS streaming
      certificateRefs: [{
        name: "static-workload-svid-secret",
        kind: "Secret"
      }]
    }
  }
});
```

#### Production Standard (Correct)
> **Standard**: Routes certificate and trust bundle ingestion through the SPIRE Agent UNIX socket via Envoy SDS. Introduces a 60-second listener drain timeout and 10-second delayed close timeout to allow in-flight TLS handshakes to complete cleanly during SVID ratchet transitions.
```typescript
import * as k8s from "@pulumi/kubernetes";

// PRODUCTION STANDARD: Dynamic EnvoyExtensionPolicy with SPIRE SDS Unix Socket,
// overlapping trust bundles, and Envoy ClientTrafficPolicy configured for graceful TLS context draining.
export const spireClientTrafficPolicy = new k8s.apiextensions.CustomResource("spire-traffic-policy", {
  apiVersion: "gateway.envoyproxy.io/v1alpha1",
  kind: "ClientTrafficPolicy",
  metadata: { name: "edge-gateway-ratchet-policy", namespace: "envoy-gateway-system" },
  spec: {
    targetRef: {
      group: "gateway.networking.k8s.io",
      kind: "Gateway",
      name: "edge-gateway"
    },
    tcp: {
      connectionBufferLimits: 32768
    },
    connection: {
      delayedCloseTimeout: "10s",
      drainTimeout: "60s"
    },
    tls: {
      minVersion: "1.3",
      alpnProtocols: ["h2", "http/1.1"]
    }
  }
});

export const spireSecurityPolicy = new k8s.apiextensions.CustomResource("spire-security-policy", {
  apiVersion: "gateway.envoyproxy.io/v1alpha1",
  kind: "SecurityPolicy",
  metadata: { name: "edge-gateway-spiffe-mtls", namespace: "envoy-gateway-system" },
  spec: {
    targetRef: {
      group: "gateway.networking.k8s.io",
      kind: "Gateway",
      name: "edge-gateway"
    },
    downstreamValidationContext: {
      sds: {
        agentSocketPath: "/run/spire/sockets/agent.sock",
        certificateValidationContext: {
          trustedCa: {
            spiffeDomain: "cluster.local"
          },
          matchTypedSubjectAltNames: [{
            sanType: "URI",
            matcher: {
              prefix: "spiffe://cluster.local/ns/workloads/sa/"
            }
          }]
        }
      }
    }
  }
});
```

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: Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard

Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard defines an industrial-grade behavioral standard for devops engineering. Enforces seamless zero-downtime X.509 SVID rotation across Envoy Gateway managed ingress clusters integrated with SPIFFE/SPIRE. Mandates dynamic Secret Discovery Service (SDS) socket streaming, dual-bundle trust validation windows, and TLS listener drain coordination to eliminate transient connection reset bursts (ECONNRESET) during short-lived certificate lifecycles. 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: Hard certificate swapping via static volume remounts or single-trust SDS pushes lacking graceful TLS drain intervals 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 DriftHard certificate swapping via static volume remounts or single-trust SDS pushes lacking graceful TLS drain intervalsCritical
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 Envoy Gateway to consume X.509 SVIDs and SPIFFE trust bundles dynamically via gRPC Secret Discovery Service (SDS) over a local SPIRE Agent UNIX domain socket.

Engineers MUST ALWAYS configure Envoy Gateway to consume X.509 SVIDs and SPIFFE trust bundles dynamically via gRPC Secret Discovery Service (SDS) over a local SPIRE Agent UNIX domain socket.

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 Kubernetes Secrets or file-projected volumes with atomic symlink swaps for high-frequency mTLS credential rotations.

Engineers MUST NOT rely on Kubernetes Secrets or file-projected volumes with atomic symlink swaps for high-frequency mTLS credential rotations.

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

SDS configurations MUST maintain dual-bundle overlap during trust root rotations, ensuring inbound handshakes accept both expiring and newly issued authority certificates.

SDS configurations MUST maintain dual-bundle overlap during trust root rotations, ensuring inbound handshakes accept both expiring and newly issued authority certificates.

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

Envoy ClientTrafficPolicy and listener settings MUST configure a non-zero `drain_timeout` (minimum 30 seconds) and set `delayed_close_timeout` to prevent abrupt TCP FIN resets during TLS context updates.

Envoy ClientTrafficPolicy and listener settings MUST configure a non-zero `drain_timeout` (minimum 30 seconds) and set `delayed_close_timeout` to prevent abrupt TCP FIN resets during TLS context updates.

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

SecurityPolicy resources MUST enforce explicit SPIFFE ID SAN matching patterns (`spiffe

SecurityPolicy resources MUST enforce explicit SPIFFE ID SAN matching patterns (`spiffe://<trust-domain>/...`) on downstream and upstream validation contexts rather than legacy generic DNS/CommonName checks.

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 Envoy Gateway SPIFFE/SPIRE Zero-Downtime mTLS SVID Ratchet Standard critical for AI coding assistants?

Enforces seamless zero-downtime X.509 SVID rotation across Envoy Gateway managed ingress clusters integrated with SPIFFE/SPIRE. Mandates dynamic Secret Discovery Service (SDS) socket streaming, dual-bundle trust validation windows, and TLS listener drain coordination to eliminate transient connection reset bursts (ECONNRESET) during short-lived certificate lifecycles. 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 (Hard certificate swapping via static volume remounts or single-trust SDS pushes lacking graceful TLS drain intervals) 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

Envoy