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

SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard

Enforces proactive, asynchronous rotation of X.509 SVIDs prior to cryptographic expiry using deterministic grace overlap margins. Eliminates in-flight mTLS handshake failures and transport-layer downtime by decoupling the Workload API fetch loop from TLS context creation and socket-level negotiation.

Prohibited Anti-Pattern: Synchronous or Lazy SVID Refresh Triggering Handshake Drops and TLS Expiry Invalidation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard - Enforces proactive, asynchronous rotation of X.509 SVIDs prior to cryptographic expiry using deterministic grace overlap margins. Eliminates in-flight mTLS handshake failures and transport-layer downtime by decoupling the Workload API fetch loop from TLS context creation and socket-level negotiation.
globs: src/**/*.{ts,js,go,rs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spiffe-spire-svid-nonblocking-rotation-standard"
---

# SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Synchronous or Lazy SVID Refresh Triggering Handshake Drops and TLS Expiry Invalidation

## System Constraints
You are a Principal Engineer enforcing SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation Standard. Mandate that all microsegmentation handshakes use double-buffered, non-blocking X.509 SVID rotation with a strict overlap grace window (typically 50% of total TTL). Never allow synchronous blocking fetches against the Workload API during TLS client/server handshakes.

## Strict Guidelines
- Engineers MUST ALWAYS implement an asynchronous background watcher against the SPIFFE Workload API that updates an in-memory atomic reference to the current X.509 SVID.
- Engineers MUST NOT block TLS handshakes with synchronous network calls to the SPIFFE Workload API daemon/socket.
- Code SHOULD calculate proactive rotation triggers using an invariant overlap margin (defaulting to max(0.5 * TTL, 30 seconds)) to absorb temporary SPIRE agent downtime.
- Services MUST retain the outgoing SVID in memory alongside the incoming SVID during the overlap window to maintain validation continuity for in-flight sessions.
- Components NEVER fall back to static or hardcoded certificates when the Workload API is temporarily unreachable; cached valid SVIDs must be served until hard expiration.

## Bad vs Good Implementations
### Asynchronous SVID Store vs Synchronous Dynamic Lookup

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fetching SVIDs synchronously inside SNICallback or per-handshake introduces massive latency, locks the event loop, and immediately drops active microsegmentation handshakes if the SPIRE Agent undergoes maintenance or transient socket stalls.
```typescript
import * as tls from 'node:tls';

interface SpireClient {
  fetchX509SVIDSync(): { cert: string; key: string };
}

declare const spireClient: SpireClient;

// ANTI-PATTERN: Blocking fetch or on-demand fetch on SNI / handshake
export function createTLSServer() {
  return tls.createServer({
    SNICallback: (servername, cb) => {
      try {
        // Synchronous RPC blocks event loop and drops connections on SPIRE latency
        const svid = spireClient.fetchX509SVIDSync();
        const ctx = tls.createSecureContext({
          cert: svid.cert,
          key: svid.key
        });
        cb(null, ctx);
      } catch (err) {
        cb(err as Error);
      }
    }
  });
}
```

#### Production Standard (Correct)
> **Standard**: Maintains an in-memory atomic reference to the pre-computed tls.SecureContext. SVID rotation is driven by an asynchronous process with an invariant 50% overlap margin, ensuring TLS handshakes execute in sub-millisecond time without network stalls.
```typescript
import * as tls from 'node:tls';
import { EventEmitter } from 'node:events';

interface X509SVID {
  cert: string;
  key: string;
  expiresAt: Date;
}

export class SvidStore extends EventEmitter {
  private currentContext: tls.SecureContext | null = null;
  private activeSvid: X509SVID | null = null;

  constructor(initialSvid: X509SVID) {
    super();
    this.updateSvid(initialSvid);
  }

  public updateSvid(svid: X509SVID): void {
    // Atomic swap of secure context without blocking handshakes
    this.activeSvid = svid;
    this.currentContext = tls.createSecureContext({
      cert: svid.cert,
      key: svid.key
    });
    this.emit('rotated', svid.expiresAt);
  }

  public getSecureContext(): tls.SecureContext {
    if (!this.currentContext) {
      throw new Error('SVID secure context uninitialized');
    }
    return this.currentContext;
  }

  public calculateRotationDelay(svid: X509SVID): number {
    const now = Date.now();
    const expiry = svid.expiresAt.getTime();
    const ttl = Math.max(0, expiry - now);
    // Deterministic 50% overlap margin to guarantee non-blocking pre-expiry rotation
    return Math.floor(ttl * 0.5);
  }
}

export function createResilientTLSServer(store: SvidStore): tls.Server {
  return tls.createServer({
    SNICallback: (_servername, cb) => {
      // Non-blocking retrieval of pre-computed atomic secure context
      cb(null, store.getSecureContext());
    }
  });
}
```

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: SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard

SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard defines an industrial-grade behavioral standard for security engineering. Enforces proactive, asynchronous rotation of X.509 SVIDs prior to cryptographic expiry using deterministic grace overlap margins. Eliminates in-flight mTLS handshake failures and transport-layer downtime by decoupling the Workload API fetch loop from TLS context creation and socket-level negotiation. 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: Synchronous or Lazy SVID Refresh Triggering Handshake Drops and TLS Expiry Invalidation 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 DriftSynchronous or Lazy SVID Refresh Triggering Handshake Drops and TLS Expiry InvalidationCritical
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 implement an asynchronous background watcher against the SPIFFE Workload API that updates an in-memory atomic reference to the current X.509 SVID.

Engineers MUST ALWAYS implement an asynchronous background watcher against the SPIFFE Workload API that updates an in-memory atomic reference to the current X.509 SVID.

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 block TLS handshakes with synchronous network calls to the SPIFFE Workload API daemon/socket.

Engineers MUST NOT block TLS handshakes with synchronous network calls to the SPIFFE Workload API daemon/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.
3

Code SHOULD calculate proactive rotation triggers using an invariant overlap margin (defaulting to max(0.5 * TTL, 30 seconds)) to absorb temporary SPIRE agent downtime.

Code SHOULD calculate proactive rotation triggers using an invariant overlap margin (defaulting to max(0.5 * TTL, 30 seconds)) to absorb temporary SPIRE agent downtime.

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 retain the outgoing SVID in memory alongside the incoming SVID during the overlap window to maintain validation continuity for in-flight sessions.

Services MUST retain the outgoing SVID in memory alongside the incoming SVID during the overlap window to maintain validation continuity for in-flight sessions.

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 fall back to static or hardcoded certificates when the Workload API is temporarily unreachable

Components NEVER fall back to static or hardcoded certificates when the Workload API is temporarily unreachable; cached valid SVIDs must be served until hard expiration.

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 SPIFFE/SPIRE Ephemeral SVID Non-Blocking Rotation and Overlap Margin Standard critical for AI coding assistants?

Enforces proactive, asynchronous rotation of X.509 SVIDs prior to cryptographic expiry using deterministic grace overlap margins. Eliminates in-flight mTLS handshake failures and transport-layer downtime by decoupling the Workload API fetch loop from TLS context creation and socket-level negotiation. 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 (Synchronous or Lazy SVID Refresh Triggering Handshake Drops and TLS Expiry Invalidation) 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

SPIFFE/SPIRE