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

SPIFFE/SPIRE Ephemeral X.509 SVID Dynamic In-Memory Auto-Rotation Standard

Enforces dynamic consumption of SPIFFE X.509 SVIDs directly from SPIRE Workload API domain sockets without persisting secrets to disk or caching stale TLS contexts. Requires streaming Workload API listeners and dynamic TLS certificate reloading to guarantee uninterrupted mutual TLS during sub-hour identity rotation across heterogeneous multi-cloud topologies.

Prohibited Anti-Pattern: Caching Static X.509 SVIDs or Persisting Ephemeral Keys to Filesystem Without Dynamic TLS Context Reloading

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SPIFFE/SPIRE Ephemeral X.509 SVID Dynamic In-Memory Auto-Rotation Standard - Enforces dynamic consumption of SPIFFE X.509 SVIDs directly from SPIRE Workload API domain sockets without persisting secrets to disk or caching stale TLS contexts. Requires streaming Workload API listeners and dynamic TLS certificate reloading to guarantee uninterrupted mutual TLS during sub-hour identity rotation across heterogeneous multi-cloud topologies.
globs: src/**/*.{ts,js,go,rs,py}, pkg/**/*.{go,rs}, infra/**/*.tf, k8s/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spiffe-spire-x509-svid-rotation-standard"
---

# SPIFFE/SPIRE Ephemeral X.509 SVID Dynamic In-Memory Auto-Rotation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Caching Static X.509 SVIDs or Persisting Ephemeral Keys to Filesystem Without Dynamic TLS Context Reloading

## System Constraints
You are a Principal Security Architect enforcing the SPIFFE/SPIRE Workload Identity Ephemeral X.509 SVID Auto-Rotation Standard. Mandate that all inter-service communications, cloud API federations, and mTLS transports dynamically bind to SPIRE Workload API UNIX domain sockets. Prohibit static disk persistence of private keys, eliminate long-lived cloud credentials, and mandate dynamic in-memory TLS context reloads before cryptographic material expires.

## Strict Guidelines
- Services MUST interact with SPIRE agents solely via UNIX domain sockets (e.g., unix:///run/spire/sockets/agent.sock) using the SPIFFE Workload API client library.
- Services MUST NEVER write received X.509 SVID certificates, bundle chains, or private keys to non-volatile disk storage or shared volumes.
- Engineers MUST configure continuous streaming listeners (X509Source / WatchX509Context) to receive automated SVID updates prior to sub-hour expirations.
- TLS servers and HTTP clients MUST implement dynamic SNI/certificate resolution callbacks (e.g., tls.Config.GetCertificate and tls.Config.GetClientCertificate) that query active in-memory X509Source instances rather than using static tls.Certificate slices.
- Services MUST validate SPIFFE IDs against an explicit trust bundle whitelist using strictly typed spiffeid.ID parsers; regex parsing or wildcard string matching is strictly forbidden.
- Components MUST treat SVID refresh failures as transient and retry with exponential backoff while retaining the unexpired in-memory SVID until valid renewal occurs.
- Services operating across multi-cloud boundaries MUST federate trust domains using SPIFFE Workload Identity without injecting long-lived IAM service account keys.

## Bad vs Good Implementations
### Go SPIRE Workload API Dynamic TLS Listener Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fetches the X.509 SVID once at startup and assigns it to a static tls.Config.Certificates array. Sub-hour rotated SVIDs from SPIRE will expire, breaking active client connections due to stale certificates and missing dynamic reload hooks.
```go
package main

import (
	"context"
	"crypto/tls"
	"net/http"
	"os"
	"github.com/spiffe/go-spiffe/v2/workloadapi"
)

func startBadServer(ctx context.Context) error {
	// ANTI-PATTERN: Fetching SVID once and writing to static TLS config without rotation watch
	client, err := workloadapi.New(ctx, workloadapi.WithAddress("unix:///run/spire/sockets/agent.sock"))
	if err != nil {
		return err
	}
	defer client.Close()

	svid, err := client.FetchX509SVID(ctx)
	if err != nil {
		return err
	}

	// Flaw: Statically binding certs causes service disruption when the sub-hour SVID expires
	cert, err := tls.X509KeyPair(svid.Certificates[0].Raw, []byte(os.Getenv("STATIC_KEY")))
	if err != nil {
		return err
	}

	server := &http.Server{
		Addr: ":8443",
		TLSConfig: &tls.Config{
			Certificates: []tls.Certificate{cert},
		},
	}
	return server.ListenAndServeTLS("", "")
}
```

#### Production Standard (Correct)
> **Standard**: Leverages workloadapi.NewX509Source to maintain an active in-memory stream from SPIRE. The tlsconfig.MTLSServerConfig dynamically supplies rotated certificates and validates peer SPIFFE IDs on every TLS handshake without server restarts or disk leaks.
```go
package main

import (
	"context"
	"crypto/tls"
	"net/http"
	"github.com/spiffe/go-spiffe/v2/spiffeid"
	"github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
	"github.com/spiffe/go-spiffe/v2/workloadapi"
)

func startSecureServer(ctx context.Context) error {
	// PRODUCTION INVARIANT: Stream SVID updates via X509Source dynamic in-memory supplier
	source, err := workloadapi.NewX509Source(
		ctx,
		workloadapi.WithAddress("unix:///run/spire/sockets/agent.sock"),
	)
	if err != nil {
		return err
	}
	defer source.Close()

	// Enforce dynamic authorization using explicit SPIFFE ID matching
	allowedClient := spiffeid.RequireTrustDomainID(
		spiffeid.RequireTrustDomainFromString("prod.internal"),
		"billing-service",
	)

	tlsConfig := tlsconfig.MTLSServerConfig(
		source,
		source,
		tlsconfig.AuthorizeID(allowedClient),
	)

	server := &http.Server{
		Addr:      ":8443",
		TLSConfig: tlsConfig,
	}

	return server.ListenAndServeTLS("", "")
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: SPIFFE/SPIRE Ephemeral X.509 SVID Dynamic In-Memory Auto-Rotation Standard

SPIFFE/SPIRE Ephemeral X.509 SVID Dynamic In-Memory Auto-Rotation Standard defines an industrial-grade behavioral standard for security engineering. Enforces dynamic consumption of SPIFFE X.509 SVIDs directly from SPIRE Workload API domain sockets without persisting secrets to disk or caching stale TLS contexts. Requires streaming Workload API listeners and dynamic TLS certificate reloading to guarantee uninterrupted mutual TLS during sub-hour identity rotation across heterogeneous multi-cloud topologies. 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: Caching Static X.509 SVIDs or Persisting Ephemeral Keys to Filesystem Without Dynamic TLS Context Reloading 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 DriftCaching Static X.509 SVIDs or Persisting Ephemeral Keys to Filesystem Without Dynamic TLS Context ReloadingCritical
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

Services MUST interact with SPIRE agents solely via UNIX domain sockets (e.g., unix

Services MUST interact with SPIRE agents solely via UNIX domain sockets (e.g., unix:///run/spire/sockets/agent.sock) using the SPIFFE Workload API client library.

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

Services MUST NEVER write received X.509 SVID certificates, bundle chains, or private keys to non-volatile disk storage or shared volumes.

Services MUST NEVER write received X.509 SVID certificates, bundle chains, or private keys to non-volatile disk storage or shared volumes.

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

Engineers MUST configure continuous streaming listeners (X509Source / WatchX509Context) to receive automated SVID updates prior to sub-hour expirations.

Engineers MUST configure continuous streaming listeners (X509Source / WatchX509Context) to receive automated SVID updates prior to sub-hour expirations.

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

TLS servers and HTTP clients MUST implement dynamic SNI/certificate resolution callbacks (e.g., tls.Config.GetCertificate and tls.Config.GetClientCertificate) that query active in-memory X509Source instances rather than using static tls.Certificate slices.

TLS servers and HTTP clients MUST implement dynamic SNI/certificate resolution callbacks (e.g., tls.Config.GetCertificate and tls.Config.GetClientCertificate) that query active in-memory X509Source instances rather than using static tls.Certificate slices.

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

Services MUST validate SPIFFE IDs against an explicit trust bundle whitelist using strictly typed spiffeid.ID parsers

Services MUST validate SPIFFE IDs against an explicit trust bundle whitelist using strictly typed spiffeid.ID parsers; regex parsing or wildcard string matching is strictly forbidden.

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.
6

Components MUST treat SVID refresh failures as transient and retry with exponential backoff while retaining the unexpired in-memory SVID until valid renewal occurs.

Components MUST treat SVID refresh failures as transient and retry with exponential backoff while retaining the unexpired in-memory SVID until valid renewal occurs.

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.
7

Services operating across multi-cloud boundaries MUST federate trust domains using SPIFFE Workload Identity without injecting long-lived IAM service account keys.

Services operating across multi-cloud boundaries MUST federate trust domains using SPIFFE Workload Identity without injecting long-lived IAM service account keys.

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 X.509 SVID Dynamic In-Memory Auto-Rotation Standard critical for AI coding assistants?

Enforces dynamic consumption of SPIFFE X.509 SVIDs directly from SPIRE Workload API domain sockets without persisting secrets to disk or caching stale TLS contexts. Requires streaming Workload API listeners and dynamic TLS certificate reloading to guarantee uninterrupted mutual TLS during sub-hour identity rotation across heterogeneous multi-cloud topologies. 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 (Caching Static X.509 SVIDs or Persisting Ephemeral Keys to Filesystem Without Dynamic TLS Context Reloading) 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