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

SPIFFE/SPIRE 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail

Enforces continuous in-memory rotation of short-lived X.509 SVIDs directly from the SPIFFE Workload API via Unix domain sockets. Eliminates static filesystem credential persistence, avoids process restarts upon identity rotation, and mandates strict peer SPIFFE ID authorizers for zero-trust cross-cluster mTLS.

Prohibited Anti-Pattern: Persisting SVIDs to Disk or Caching Static TLS Configurations Leading to SVID Expiry Outages and Key Leakage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SPIFFE/SPIRE 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail - Enforces continuous in-memory rotation of short-lived X.509 SVIDs directly from the SPIFFE Workload API via Unix domain sockets. Eliminates static filesystem credential persistence, avoids process restarts upon identity rotation, and mandates strict peer SPIFFE ID authorizers for zero-trust cross-cluster mTLS.
globs: **/*.go, src/**/*.go, pkg/**/*.go, cmd/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spiffe-spire-dynamic-x509-svid-rotation"
---

# SPIFFE/SPIRE 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Persisting SVIDs to Disk or Caching Static TLS Configurations Leading to SVID Expiry Outages and Key Leakage

## System Constraints
You are a Principal Security Architect enforcing SPIFFE/SPIRE 1.10 workload identity standards. You must mandate dynamic, zero-downtime X.509 SVID rotation directly from the SPIFFE Workload API. Disallow reading certificates/keys from disk or environment variables, prohibit restarting processes for certificate updates, and strictly enforce cryptographic SPIFFE ID authorizers for peer verification.

## Strict Guidelines
- Engineers MUST ALWAYS initialize dynamic TLS configurations using an in-memory SPIFFE Workload API source (e.g., `workloadapi.NewX509Source`) that auto-refreshes sub-hour SVIDs and trust bundles.
- Engineers MUST NOT persist X.509 SVID private keys, certificates, or intermediate bundles to ephemeral disks, config maps, or environment variables.
- Services MUST bind to SPIFFE Workload API sockets (`spiffe-workload-api.sock`) and use TLS callbacks (`GetCertificate`, `GetClientCertificate`) rather than static `tls.Config{Certificates: ...}`.
- Code MUST validate remote peer identities using SPIFFE ID Authorizers (such as `tlsconfig.AuthorizeID` or `tlsconfig.AuthorizeOneOf`) instead of raw Subject Alternative Name (SAN) string matching or Common Name (CN) checks.
- Components NEVER terminate or restart server listeners or worker processes upon certificate rotation; the dynamic X509Source must update cryptographic material transparently.
- Clients and servers MUST configure resilient reconnect backoff routines when communicating with the SPIRE Agent socket to absorb local agent restarts without dropping active TLS listeners.

## Bad vs Good Implementations
### Dynamic SPIFFE/SPIRE X.509 SVID mTLS Server Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Loading certificates from disk into a static tls.Config breaks sub-hour SVID rotation, requiring process restarts or cron reloads when certificates expire. Furthermore, writing raw private keys to filesystem volumes introduces token leakage risks, and omitting SPIFFE ID authorizers bypasses zero-trust identity validation.
```go
package main

import (
	"crypto/tls"
	"crypto/x509"
	"net/http"
	"os"
)

func startMTLSServer() error {
	// ANTI-PATTERN: Loading static certs from disk (dumped by sidecar or init container)
	// Fails to rotate automatically when SPIRE issues sub-hour SVIDs (causing 1h outages).
	// Also risks key compromise by persisting private keys to local disk.
	crt, err := os.ReadFile("/tmp/spiffe/svid.crt")
	if err != nil { return err }
	key, err := os.ReadFile("/tmp/spiffe/svid.key")
	if err != nil { return err }
	cert, err := tls.X509KeyPair(crt, key)
	if err != nil { return err }

	caCert, err := os.ReadFile("/tmp/spiffe/bundle.crt")
	if err != nil { return err }
	caPool := x509.NewCertPool()
	caPool.AppendCertsFromPEM(caCert)

	tlsConfig := &tls.Config{
		Certificates: []tls.Certificate{cert},
		ClientCAs:    caPool,
		ClientAuth:   tls.RequireAndVerifyClientCert,
		// Flaw: No SPIFFE ID authorization; any cert signed by CA is accepted
	}

	server := &http.Server{Addr: ":8443", TLSConfig: tlsConfig}
	return server.ListenAndServeTLS("", "")
}
```

#### Production Standard (Correct)
> **Standard**: The X509Source hooks directly into the SPIRE Agent UNIX domain socket. Private keys remain exclusively in-memory, TLS handshakes dynamically invoke GetCertificate/GetClientCertificate to retrieve current SVIDs without service downtime or process restarts, and peer identities are strictly verified using SPIFFE ID authorizers.
```go
package main

import (
	"context"
	"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 startMTLSServer(ctx context.Context) error {
	// PRODUCTION INVARIANT: Connect directly to SPIRE Agent Workload API socket.
	// SVIDs and trust bundles are managed entirely in memory and rotated automatically.
	source, err := workloadapi.NewX509Source(ctx, workloadapi.WithClientOptions(
		workloadapi.WithAddress("unix:///run/spire/sockets/spiffe-workload-api.sock"),
	))
	if err != nil {
		return err
	}
	defer source.Close()

	// Define authorized peer identity
	clientClientID := spiffeid.MustFromString("spiffe://prod.domain/ns/finance/sa/payment-worker")

	// Create dynamic mTLS server config wired directly to the rotating X509Source
	tlsConfig := tlsconfig.MTLSServerConfig(source, source, tlsconfig.AuthorizeID(clientClientID))

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

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

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: SPIFFE/SPIRE 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail

SPIFFE/SPIRE 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces continuous in-memory rotation of short-lived X.509 SVIDs directly from the SPIFFE Workload API via Unix domain sockets. Eliminates static filesystem credential persistence, avoids process restarts upon identity rotation, and mandates strict peer SPIFFE ID authorizers for zero-trust cross-cluster mTLS. 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: Persisting SVIDs to Disk or Caching Static TLS Configurations Leading to SVID Expiry Outages and Key Leakage 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 DriftPersisting SVIDs to Disk or Caching Static TLS Configurations Leading to SVID Expiry Outages and Key LeakageCritical
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 initialize dynamic TLS configurations using an in-memory SPIFFE Workload API source (e.g., `workloadapi.NewX509Source`) that auto-refreshes sub-hour SVIDs and trust bundles.

Engineers MUST ALWAYS initialize dynamic TLS configurations using an in-memory SPIFFE Workload API source (e.g., `workloadapi.NewX509Source`) that auto-refreshes sub-hour SVIDs and trust bundles.

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 persist X.509 SVID private keys, certificates, or intermediate bundles to ephemeral disks, config maps, or environment variables.

Engineers MUST NOT persist X.509 SVID private keys, certificates, or intermediate bundles to ephemeral disks, config maps, or environment variables.

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

Services MUST bind to SPIFFE Workload API sockets (`spiffe-workload-api.sock`) and use TLS callbacks (`GetCertificate`, `GetClientCertificate`) rather than static `tls.Config{Certificates

Services MUST bind to SPIFFE Workload API sockets (`spiffe-workload-api.sock`) and use TLS callbacks (`GetCertificate`, `GetClientCertificate`) rather than static `tls.Config{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

Code MUST validate remote peer identities using SPIFFE ID Authorizers (such as `tlsconfig.AuthorizeID` or `tlsconfig.AuthorizeOneOf`) instead of raw Subject Alternative Name (SAN) string matching or Common Name (CN) checks.

Code MUST validate remote peer identities using SPIFFE ID Authorizers (such as `tlsconfig.AuthorizeID` or `tlsconfig.AuthorizeOneOf`) instead of raw Subject Alternative Name (SAN) string matching or Common Name (CN) 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.
5

Components NEVER terminate or restart server listeners or worker processes upon certificate rotation

Components NEVER terminate or restart server listeners or worker processes upon certificate rotation; the dynamic X509Source must update cryptographic material transparently.

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

Clients and servers MUST configure resilient reconnect backoff routines when communicating with the SPIRE Agent socket to absorb local agent restarts without dropping active TLS listeners.

Clients and servers MUST configure resilient reconnect backoff routines when communicating with the SPIRE Agent socket to absorb local agent restarts without dropping active TLS listeners.

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 1.10 Dynamic X.509 SVID Rotation and In-Memory mTLS Guardrail critical for AI coding assistants?

Enforces continuous in-memory rotation of short-lived X.509 SVIDs directly from the SPIFFE Workload API via Unix domain sockets. Eliminates static filesystem credential persistence, avoids process restarts upon identity rotation, and mandates strict peer SPIFFE ID authorizers for zero-trust cross-cluster mTLS. 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 (Persisting SVIDs to Disk or Caching Static TLS Configurations Leading to SVID Expiry Outages and Key Leakage) 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