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

SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail

Eliminates long-lived static credentials, baked-in certificates, and persistent tokens across hybrid cloud services by enforcing dynamic workload attestation via the local SPIRE Agent Workload API. Demands zero-trust mutual TLS (mTLS) with automated short-lived X.509 SVID rotation and deterministic SPIFFE ID authorization at kernel-attested process boundaries.

Prohibited Anti-Pattern: Persisting Long-Lived Static Private Keys and Bypassing SPIRE Workload Attestation Sockets

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail - Eliminates long-lived static credentials, baked-in certificates, and persistent tokens across hybrid cloud services by enforcing dynamic workload attestation via the local SPIRE Agent Workload API. Demands zero-trust mutual TLS (mTLS) with automated short-lived X.509 SVID rotation and deterministic SPIFFE ID authorization at kernel-attested process boundaries.
globs: src/**/*.{ts,tsx,js}, services/**/*.{ts,js,go}, infra/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/spiffe-spire-dynamic-mtls-workload-attestation"
---

# SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Persisting Long-Lived Static Private Keys and Bypassing SPIRE Workload Attestation Sockets

## System Constraints
You are a Principal Security Architect enforcing the SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail. You must prohibit long-lived static secrets, disk-persisted credentials, and hardcoded trust stores. Require workloads to dynamically obtain ephemeral X.509 SVIDs and federated trust bundles directly from the local SPIRE Agent UNIX domain socket. Ensure streaming SVID rotation without process restart, and enforce strict SAN URI validation matching expected SPIFFE IDs across all service-to-service communication.

## Strict Guidelines
- Services MUST NOT read static private keys or long-lived certificates from disk, environment variables, or config volumes.
- Workloads MUST connect to the local SPIRE Agent Workload API over a secure UNIX domain socket (default: unix:///tmp/spire-agent/public/api.sock).
- Services MUST subscribe to real-time X.509 SVID rotation streams and update their in-memory TLS SecureContext without terminating connections or restarting processes.
- Engineers MUST explicitly authorize peer SPIFFE IDs during TLS handshake verification by checking the SAN URI against an exact trust domain and workload path pattern.
- Services MUST configure automated fallback backoff and circuit-breaking when the Workload API socket becomes temporarily unavailable.
- Infrastructure configurations MUST enable kernel-level attestation (e.g., k8s-bundle, docker-cgroup, or unix-uid/gid) in SPIRE Agent registration entries instead of static token attestation.

## Bad vs Good Implementations
### Dynamic SPIRE Workload API X.509 SVID Stream vs Static Disk Certificates

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Loads static, long-lived certificates from disk without kernel-level attestation. Certificates cannot rotate dynamically without dropping traffic or restarting the process, and peer identity is not strictly bound to verified SPIFFE IDs.
```typescript
import * as https from 'https';
import * as fs from 'fs';

// ANTI-PATTERN: Baking long-lived static certificates and private keys
// Bypasses workload attestation and requires process restarts for credential rotation
const serverOptions: https.ServerOptions = {
  key: fs.readFileSync('/etc/ssl/certs/service-key.pem'),
  cert: fs.readFileSync('/etc/ssl/certs/service-cert.pem'),
  ca: fs.readFileSync('/etc/ssl/certs/ca-bundle.pem'),
  requestCert: true,
  rejectUnauthorized: true
};

export const server = https.createServer(serverOptions, (req, res) => {
  res.writeHead(200);
  res.end('Authenticated with static cert');
});
```

#### Production Standard (Correct)
> **Standard**: Connects directly to the SPIRE Agent UNIX domain socket for kernel-level attestation. Automatically streams rotated ephemeral X.509 SVIDs into an in-memory SecureContext via SNICallback without restarting the server, and explicitly validates the peer SPIFFE ID SAN URI during the mTLS handshake.
```typescript
import * as https from 'https';
import * as tls from 'tls';
import { WorkloadApiClient } from '@spiffe/spiffe-client';

const EXPECTED_CLIENT_SPIFFE_ID = 'spiffe://acme.internal/ns/prod/sa/order-service';
let activeSecureContext: tls.SecureContext | null = null;

// Establish dynamic X.509 SVID watcher via SPIRE Workload API UNIX Domain Socket
const spiffeClient = new WorkloadApiClient({
  spiffeSocketPath: 'unix:///tmp/spire-agent/public/api.sock'
});

async function initializeSpireTls(): Promise<https.Server> {
  // Continuously listen for attested short-lived SVID rotations
  spiffeClient.watchX509Context({
    onX509Context: (x509Context) => {
      const defaultSvid = x509Context.defaultSvid;
      const trustBundle = x509Context.bundle;

      activeSecureContext = tls.createSecureContext({
        cert: defaultSvid.cert,
        key: defaultSvid.privateKey,
        ca: trustBundle.x509Authorities,
        ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384',
        minVersion: 'TLSv1.3'
      });
    },
    onError: (err) => {
      console.error('Critical: SPIRE Workload API attestation error:', err);
    }
  });

  const server = https.createServer({
    SNICallback: (_hostname, cb) => {
      if (!activeSecureContext) {
        return cb(new Error('SVID not yet attested by SPIRE'), null);
      }
      cb(null, activeSecureContext);
    },
    requestCert: true,
    rejectUnauthorized: true
  }, (req, res) => {
    const peerCert = (req.socket as tls.TLSSocket).getPeerCertificate(true);
    const sanUri = peerCert.subjectaltname?.split(', ').find(s => s.startsWith('URI:spiffe://'));
    const clientSpiffeId = sanUri ? sanUri.replace('URI:', '') : null;

    if (clientSpiffeId !== EXPECTED_CLIENT_SPIFFE_ID) {
      res.writeHead(403, { 'Content-Type': 'application/json' });
      return res.end(JSON.stringify({ error: 'Unauthorized SPIFFE Workload Identity' }));
    }

    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ status: 'Attested & Authorized via SPIFFE mTLS' }));
  });

  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: SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail

SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail defines an industrial-grade behavioral standard for security engineering. Eliminates long-lived static credentials, baked-in certificates, and persistent tokens across hybrid cloud services by enforcing dynamic workload attestation via the local SPIRE Agent Workload API. Demands zero-trust mutual TLS (mTLS) with automated short-lived X.509 SVID rotation and deterministic SPIFFE ID authorization at kernel-attested process boundaries. 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 Long-Lived Static Private Keys and Bypassing SPIRE Workload Attestation Sockets 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 Long-Lived Static Private Keys and Bypassing SPIRE Workload Attestation SocketsCritical
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 NOT read static private keys or long-lived certificates from disk, environment variables, or config volumes.

Services MUST NOT read static private keys or long-lived certificates from disk, environment variables, or config 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.
2

Workloads MUST connect to the local SPIRE Agent Workload API over a secure UNIX domain socket (default

Workloads MUST connect to the local SPIRE Agent Workload API over a secure UNIX domain socket (default: unix:///tmp/spire-agent/public/api.sock).

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 subscribe to real-time X.509 SVID rotation streams and update their in-memory TLS SecureContext without terminating connections or restarting processes.

Services MUST subscribe to real-time X.509 SVID rotation streams and update their in-memory TLS SecureContext without terminating connections or restarting processes.

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

Engineers MUST explicitly authorize peer SPIFFE IDs during TLS handshake verification by checking the SAN URI against an exact trust domain and workload path pattern.

Engineers MUST explicitly authorize peer SPIFFE IDs during TLS handshake verification by checking the SAN URI against an exact trust domain and workload path pattern.

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 configure automated fallback backoff and circuit-breaking when the Workload API socket becomes temporarily unavailable.

Services MUST configure automated fallback backoff and circuit-breaking when the Workload API socket becomes temporarily unavailable.

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

Infrastructure configurations MUST enable kernel-level attestation (e.g., k8s-bundle, docker-cgroup, or unix-uid/gid) in SPIRE Agent registration entries instead of static token attestation.

Infrastructure configurations MUST enable kernel-level attestation (e.g., k8s-bundle, docker-cgroup, or unix-uid/gid) in SPIRE Agent registration entries instead of static token 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.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is SPIFFE/SPIRE Dynamic mTLS Workload Identity Attestation Guardrail critical for AI coding assistants?

Eliminates long-lived static credentials, baked-in certificates, and persistent tokens across hybrid cloud services by enforcing dynamic workload attestation via the local SPIRE Agent Workload API. Demands zero-trust mutual TLS (mTLS) with automated short-lived X.509 SVID rotation and deterministic SPIFFE ID authorization at kernel-attested process boundaries. 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 Long-Lived Static Private Keys and Bypassing SPIRE Workload Attestation Sockets) 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