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

SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail

Enforces zero-trust authentication across heterogeneous container runtimes by obtaining ephemeral X.509 SPIFFE Verifiable Identity Documents (X509-SVIDs) directly from the SPIRE Workload API. Prohibits persistent static credentials, requiring sub-hour certificate lifetimes and dynamic in-memory TLS context updates via active Workload API socket streaming.

Prohibited Anti-Pattern: Mounting Long-Lived Static Secrets or Statically Loading Ephemeral Certificates Without Watch Loops

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail - Enforces zero-trust authentication across heterogeneous container runtimes by obtaining ephemeral X.509 SPIFFE Verifiable Identity Documents (X509-SVIDs) directly from the SPIRE Workload API. Prohibits persistent static credentials, requiring sub-hour certificate lifetimes and dynamic in-memory TLS context updates via active Workload API socket streaming.
globs: src/**/*.{ts,tsx,js,jsx}, src/**/*.{go,rs,py}, deploy/**/*.{yaml,yml}, infra/**/*.{tf,json}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spire-workload-identity-x509-svid-rotation"
---

# SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Mounting Long-Lived Static Secrets or Statically Loading Ephemeral Certificates Without Watch Loops

## System Constraints
You are a Principal Software Architect enforcing zero-trust workload attestation using SPIRE and SPIFFE standards. Reject all pull requests and code modifications that introduce static cloud credentials (such as AWS IAM user keys, GCP service account JSON files, or Azure client secrets) or that statically cache ephemeral X509-SVID certificates. Mandate runtime attestation via the local SPIRE Agent Unix Domain Socket, requiring memory-only certificate handling and continuous watch-stream rotation with a certificate time-to-live (TTL) of 60 minutes or less.

## Strict Guidelines
- Engineers MUST ALWAYS interface with the SPIRE Agent exclusively via the local Unix Domain Socket (default: unix:///run/spire/sockets/agent.sock) for workload attestation.
- Engineers MUST NOT write SVID private keys, certificates, or trust bundles to local disk, persistent volumes, environment variables, or external storage.
- Services MUST implement continuous event-driven watch loops (e.g., SPIFFE Workload API X509-SVID stream) that reload TLS SecureContexts in-memory prior to expiration without restarting the container.
- Applications MUST enforce maximum X509-SVID TTLs of 60 minutes or less, configuring automated rotation thresholds at 50% of the active certificate lifespan.
- Components NEVER fall back to static API keys, unauthenticated transport, or permissive trust stores when the SPIRE Workload API is unreachable; workloads MUST fail closed.

## Bad vs Good Implementations
### SPIRE Workload API Dynamic TLS Rotation vs Static Secret Loading

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Reading TLS certificates from static files at boot fails to accommodate short-lived SVIDs (< 60 minutes). When SPIRE rotates the certificate, the running process retains the expired credentials, leading to authentication outages or forcing insecurely long TTLs.
```typescript
import * as https from 'https';
import * as fs from 'fs';

// ANTI-PATTERN: Loading long-lived certificates or static cloud keys from filesystem/env
// If the certificate expires or is rotated by SPIRE, this server holds stale credentials
const options: https.ServerOptions = {
  key: fs.readFileSync(process.env.TLS_KEY_PATH || '/etc/ssl/certs/server.key'),
  cert: fs.readFileSync(process.env.TLS_CERT_PATH || '/etc/ssl/certs/server.crt'),
  ca: fs.readFileSync(process.env.TLS_CA_PATH || '/etc/ssl/certs/bundle.crt'),
  requestCert: true,
  rejectUnauthorized: true
};

export const server = https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('Authenticated via static keys');
}).listen(8443);
```

#### Production Standard (Correct)
> **Standard**: Establishes a non-blocking watch on the SPIRE Workload API Unix socket. It updates an in-memory TLS SecureContext on every SVID rotation cycle, keeping certificate lifetime short (sub-hour) without container restarts and without persisting secrets to disk.
```typescript
import * as https from 'https';
import * as tls from 'tls';
import { SpiffeWorkloadClient } from '@spiffe/spiffe-client';

// PRODUCTION INVARIANT: Stream ephemeral X509-SVIDs from the SPIRE Workload API socket
let currentSecureContext: tls.SecureContext | null = null;
const spireSocketPath = process.env.SPIFFE_ENDPOINT_SOCKET || 'unix:///run/spire/sockets/agent.sock';
const client = new SpiffeWorkloadClient({ address: spireSocketPath });

// Watch stream automatically pushes rotated X509-SVIDs before the sub-hour TTL expires
client.watchX509Context((err, x509Context) => {
  if (err || !x509Context) {
    // Fail closed: Do not fall back to unencrypted or unauthenticated transport
    throw new Error(`SPIRE attestation failed: ${err?.message}`);
  }

  const svid = x509Context.defaultSvid();
  const trustBundle = x509Context.bundleForTrustDomain(svid.spiffeId.trustDomain);

  // Ephemeral in-memory context update without restarting the process
  currentSecureContext = tls.createSecureContext({
    key: svid.privateKey,
    cert: svid.certificateChain,
    ca: trustBundle.certificates,
    minVersion: 'TLSv1.3'
  });
});

export const server = https.createServer({
  SNICallback: (_servername, callback) => {
    if (!currentSecureContext) {
      return callback(new Error('SPIRE SVID not yet attested'), null);
    }
    callback(null, currentSecureContext);
  },
  requestCert: true,
  rejectUnauthorized: true
}, (req, res) => {
  res.writeHead(200);
  res.end('Authenticated via dynamic sub-hour SPIFFE X509-SVID');
}).listen(8443);
```

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: SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail

SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces zero-trust authentication across heterogeneous container runtimes by obtaining ephemeral X.509 SPIFFE Verifiable Identity Documents (X509-SVIDs) directly from the SPIRE Workload API. Prohibits persistent static credentials, requiring sub-hour certificate lifetimes and dynamic in-memory TLS context updates via active Workload API socket streaming. 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: Mounting Long-Lived Static Secrets or Statically Loading Ephemeral Certificates Without Watch Loops 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 DriftMounting Long-Lived Static Secrets or Statically Loading Ephemeral Certificates Without Watch LoopsCritical
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 interface with the SPIRE Agent exclusively via the local Unix Domain Socket (default

Engineers MUST ALWAYS interface with the SPIRE Agent exclusively via the local Unix Domain Socket (default: unix:///run/spire/sockets/agent.sock) for workload attestation.

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 write SVID private keys, certificates, or trust bundles to local disk, persistent volumes, environment variables, or external storage.

Engineers MUST NOT write SVID private keys, certificates, or trust bundles to local disk, persistent volumes, environment variables, or external storage.

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 implement continuous event-driven watch loops (e.g., SPIFFE Workload API X509-SVID stream) that reload TLS SecureContexts in-memory prior to expiration without restarting the container.

Services MUST implement continuous event-driven watch loops (e.g., SPIFFE Workload API X509-SVID stream) that reload TLS SecureContexts in-memory prior to expiration without restarting the container.

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

Applications MUST enforce maximum X509-SVID TTLs of 60 minutes or less, configuring automated rotation thresholds at 50% of the active certificate lifespan.

Applications MUST enforce maximum X509-SVID TTLs of 60 minutes or less, configuring automated rotation thresholds at 50% of the active certificate lifespan.

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 API keys, unauthenticated transport, or permissive trust stores when the SPIRE Workload API is unreachable

Components NEVER fall back to static API keys, unauthenticated transport, or permissive trust stores when the SPIRE Workload API is unreachable; workloads MUST fail closed.

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 SPIRE Workload Identity X.509 SVID Sub-Hour Rotation and Attestation Guardrail critical for AI coding assistants?

Enforces zero-trust authentication across heterogeneous container runtimes by obtaining ephemeral X.509 SPIFFE Verifiable Identity Documents (X509-SVIDs) directly from the SPIRE Workload API. Prohibits persistent static credentials, requiring sub-hour certificate lifetimes and dynamic in-memory TLS context updates via active Workload API socket streaming. 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 (Mounting Long-Lived Static Secrets or Statically Loading Ephemeral Certificates Without Watch Loops) 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

SPIRE