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

Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation

Enforces cryptographic workload identity in distributed multi-cloud service meshes using SPIFFE Workload API streams instead of static credentials. Demands zero filesystem-cached secret retention, sub-hour x509-SVID validity lifecycles, and in-memory non-disruptive TLS handshake context refreshment via dynamic watchers.

Prohibited Anti-Pattern: Persisting static cloud API keys or caching static x509 certificates without dynamic Workload API watchers

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation - Enforces cryptographic workload identity in distributed multi-cloud service meshes using SPIFFE Workload API streams instead of static credentials. Demands zero filesystem-cached secret retention, sub-hour x509-SVID validity lifecycles, and in-memory non-disruptive TLS handshake context refreshment via dynamic watchers.
globs: src/**/identity/**/*.{ts,js,go}, src/**/transport/**/*.{ts,js,go}, src/**/security/**/*.{ts,js,go}, src/**/mesh/**/*.{ts,js,go}, deploy/spire/**/*.{yaml,json}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spiffe-spire-dynamic-workload-attestation-mesh-standard"
---

# Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Persisting static cloud API keys or caching static x509 certificates without dynamic Workload API watchers

## System Constraints
You are a Principal Security Architect enforcing zero-trust dynamic workload attestation using SPIFFE/SPIRE across multi-cloud service mesh environments. You must enforce runtime streaming from the local SPIRE Workload API agent via standard Unix domain sockets, mandating strict sub-hour x509-SVID lifecycles and strictly forbidding long-lived tokens, disk persistence of private keys, or non-reloading TLS contexts.

## Strict Guidelines
- Services MUST interact exclusively with the SPIFFE Workload API via local Unix Domain Socket (UDS) streaming (e.g., /run/spire/sockets/agent.sock), never via remote unauthenticated TCP.
- Engineers MUST NOT persist private keys, SVID certificates, or intermediate bundles to local persistent volumes, ephemeral disk storage, or environment variables.
- Workload TLS configurations MUST implement non-disruptive, in-memory dynamic keypair reloaders via active X509Source watchers rather than restarting process daemons upon cert rotation.
- x509-SVID TTLs MUST NOT exceed 60 minutes, ensuring high-frequency cryptographic refresh and strict forward secrecy across multi-cloud boundaries.
- Peer verification MUST explicitly evaluate the SPIFFE ID scheme, trust domain, and workload path against exact authorization policies (e.g., spiffe://prod.domain/ns/prod/sa/order-service) rather than naive SAN regex matches.
- Mesh client and server transports MUST reject any connection when the underlying SPIFFE trust bundle cannot validate the peer's root of trust during federation handshakes.

## Bad vs Good Implementations
### Anti-Pattern: Static Cert Caching vs Production Invariant: Streaming SPIFFE Workload API Watcher

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Persisting static certificates and keys to disk exposes long-lived secrets to file-system inspection and requires disruptive process restarts for rotation. It fails to stream ephemeral SVIDs from the SPIRE Workload API and bypasses strict SPIFFE ID SAN validation.
```typescript
import * as tls from 'node:tls';
import * as fs from 'node:fs';

// ANTI-PATTERN: Loading long-lived certificates from disk or static env vars.
// Does not rotate when SVID expires; leaves unencrypted key material on disk.
export function createMeshServer(): tls.Server {
  const options: tls.TlsOptions = {
    key: fs.readFileSync(process.env.TLS_KEY_PATH || '/etc/certs/tls.key'),
    cert: fs.readFileSync(process.env.TLS_CERT_PATH || '/etc/certs/tls.crt'),
    ca: fs.readFileSync(process.env.CA_BUNDLE_PATH || '/etc/certs/bundle.crt'),
    requestCert: true,
    rejectUnauthorized: true
  };
  
  return tls.createServer(options, (socket) => {
    // Naive verification lacking SPIFFE trust domain policy checks
    const cert = (socket as tls.TLSSocket).getPeerCertificate();
    console.log(`Accepted connection from: ${cert.subject.CN}`);
  });
}
```

#### Production Standard (Correct)
> **Standard**: Consumes the SPIRE Agent Workload API via Unix Domain Socket, rotating the TLS SecureContext in-memory without downtime or disk persistence, and strictly validates the client's SPIFFE ID URI against zero-trust policy.
```typescript
import * as tls from 'node:tls';
import { createSecureContext } from 'node:tls';

interface SpiffeX509Context {
  certChainPem: string;
  privateKeyPem: string;
  bundlePem: string;
  spiffeId: string;
}

interface WorkloadWatcher {
  on(event: 'update', listener: (context: SpiffeX509Context) => void): void;
  getCurrentContext(): SpiffeX509Context;
}

declare function connectSpiffeWorkloadApi(socketPath: string): Promise<WorkloadWatcher>;

const EXPECTED_CLIENT_ID = 'spiffe://corp.mesh/ns/checkout/sa/payment-worker';

export async function createAttestedMeshServer(): Promise<tls.Server> {
  // Invariant: Bind directly to SPIRE Agent UDS for dynamic attestation
  const agentWatcher = await connectSpiffeWorkloadApi('unix:///run/spire/sockets/agent.sock');
  
  let currentSecureContext = createSecureContext({
    cert: agentWatcher.getCurrentContext().certChainPem,
    key: agentWatcher.getCurrentContext().privateKeyPem,
    ca: agentWatcher.getCurrentContext().bundlePem
  });

  // Non-disruptive in-memory rotation on sub-hour SVID delivery
  agentWatcher.on('update', (updatedContext: SpiffeX509Context) => {
    currentSecureContext = createSecureContext({
      cert: updatedContext.certChainPem,
      key: updatedContext.privateKeyPem,
      ca: updatedContext.bundlePem
    });
  });

  const server = tls.createServer({
    requestCert: true,
    rejectUnauthorized: true,
    SNICallback: (_serverName, cb) => cb(null, currentSecureContext)
  }, (socket) => {
    const peerCert = (socket as tls.TLSSocket).getPeerCertificate();
    const sanUri = peerCert.subjectaltname?.split(', ').find(s => s.startsWith('URI:spiffe://'))?.replace('URI:', '');

    if (sanUri !== EXPECTED_CLIENT_ID) {
      socket.destroy(new Error(`Unauthorized SPIFFE ID: ${sanUri}`));
    }
  });

  return server;
}
```

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: Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation

Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation defines an industrial-grade behavioral standard for security engineering. Enforces cryptographic workload identity in distributed multi-cloud service meshes using SPIFFE Workload API streams instead of static credentials. Demands zero filesystem-cached secret retention, sub-hour x509-SVID validity lifecycles, and in-memory non-disruptive TLS handshake context refreshment via dynamic watchers. 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 static cloud API keys or caching static x509 certificates without dynamic Workload API watchers 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 static cloud API keys or caching static x509 certificates without dynamic Workload API watchersCritical
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 exclusively with the SPIFFE Workload API via local Unix Domain Socket (UDS) streaming (e.g., /run/spire/sockets/agent.sock), never via remote unauthenticated TCP.

Services MUST interact exclusively with the SPIFFE Workload API via local Unix Domain Socket (UDS) streaming (e.g., /run/spire/sockets/agent.sock), never via remote unauthenticated TCP.

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

Engineers MUST NOT persist private keys, SVID certificates, or intermediate bundles to local persistent volumes, ephemeral disk storage, 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

Workload TLS configurations MUST implement non-disruptive, in-memory dynamic keypair reloaders via active X509Source watchers rather than restarting process daemons upon cert rotation.

Workload TLS configurations MUST implement non-disruptive, in-memory dynamic keypair reloaders via active X509Source watchers rather than restarting process daemons upon cert rotation.

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

x509-SVID TTLs MUST NOT exceed 60 minutes, ensuring high-frequency cryptographic refresh and strict forward secrecy across multi-cloud boundaries.

x509-SVID TTLs MUST NOT exceed 60 minutes, ensuring high-frequency cryptographic refresh and strict forward secrecy across multi-cloud boundaries.

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

Peer verification MUST explicitly evaluate the SPIFFE ID scheme, trust domain, and workload path against exact authorization policies (e.g., spiffe

Peer verification MUST explicitly evaluate the SPIFFE ID scheme, trust domain, and workload path against exact authorization policies (e.g., spiffe://prod.domain/ns/prod/sa/order-service) rather than naive SAN regex matches.

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

Mesh client and server transports MUST reject any connection when the underlying SPIFFE trust bundle cannot validate the peer's root of trust during federation handshakes.

Mesh client and server transports MUST reject any connection when the underlying SPIFFE trust bundle cannot validate the peer's root of trust during federation handshakes.

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 Enforce Dynamic SPIFFE/SPIRE x509-SVID Attestation & Ephemeral Rotation critical for AI coding assistants?

Enforces cryptographic workload identity in distributed multi-cloud service meshes using SPIFFE Workload API streams instead of static credentials. Demands zero filesystem-cached secret retention, sub-hour x509-SVID validity lifecycles, and in-memory non-disruptive TLS handshake context refreshment via dynamic watchers. 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 static cloud API keys or caching static x509 certificates without dynamic Workload API watchers) 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

Enforce