This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-tracestate-cryptographic-tenant-attestation

OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes

Enforces cryptographic signing and verification of multi-tenant identifiers inside the W3C TraceState header across distributed service boundaries. Prevents cross-tenant telemetry injection, log poisoning, and unauthorized trace spoofing by mandating HMAC-SHA256/Ed25519 payload signatures verified during W3C context propagation.

Prohibited Anti-Pattern: Trusting Raw Mutable TraceState Tenant Identifiers Without In-Mesh Cryptographic Attestation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes - Enforces cryptographic signing and verification of multi-tenant identifiers inside the W3C TraceState header across distributed service boundaries. Prevents cross-tenant telemetry injection, log poisoning, and unauthorized trace spoofing by mandating HMAC-SHA256/Ed25519 payload signatures verified during W3C context propagation.
globs: src/telemetry/**/*.ts, src/middleware/**/*.ts, src/tracing/**/*.ts, src/observability/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-tracestate-cryptographic-tenant-attestation"
---

# OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Trusting Raw Mutable TraceState Tenant Identifiers Without In-Mesh Cryptographic Attestation

## System Constraints
You are a Principal Security & Observability Engineer enforcing Cryptographic Tenant Attestation in OpenTelemetry. Mandate that all downstream services verify the cryptographic signature of multi-tenant baggage and tracestate entries before propagating traces or binding tenant identifiers to root spans. Never allow plain-text tenant_id values from untrusted boundaries into logging, metric, or trace contexts.

## Strict Guidelines
- Services MUST cryptographically sign the tenant context (e.g., using HMAC-SHA256 or asymmetric Ed25519) within the W3C 'tracestate' vendor key before crossing network boundaries.
- Receiving services MUST verify the trace attestation signature against a trusted mesh keystore before attaching tenant labels to trace root spans or structured log contexts.
- Engineers MUST NOT read raw, unverified 'tenant_id' or 'org_id' fields from incoming HTTP headers or plain tracestate entries to populate downstream security or billing telemetry.
- If tracestate signature verification fails, the service MUST strip the invalid tenant context, emit a high-severity security alert span event, and quarantine the trace with an 'untrusted' tenant identifier.
- Propagation logic MUST preserve other compliant W3C tracestate pairs while enforcing strict schema and signature checks on proprietary tenant attestation entries (e.g., 'acme_tid=t123.sig').

## Bad vs Good Implementations
### Insecure Propagation vs Cryptographically Signed TraceState Attestation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly trusting 'x-tenant-id' or unverified tracestate vendor values allows malicious actors to perform telemetry poisoning, bill spoofing, and privilege assertion across distributed trace boundaries.
```typescript
import { trace, context, propagation } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';

export function tenantTraceMiddleware(req: Request, res: Response, next: NextFunction): void {
  const activeContext = propagation.extract(context.active(), req.headers);
  // VULNERABLE: Direct consumption of unverified tenant_id from tracestate or custom header
  const unverifiedTenant = (req.headers['x-tenant-id'] as string) || 'default';
  
  const tracer = trace.getTracer('api-gateway');
  const span = tracer.startSpan('handle-request', undefined, activeContext);
  
  // Cross-tenant trace injection: arbitrary client can poison logs and metrics
  span.setAttribute('tenant.id', unverifiedTenant);
  
  context.with(trace.setSpan(activeContext, span), () => {
    next();
  });
}
```

#### Production Standard (Correct)
> **Standard**: Validates the HMAC-SHA256 signature embedded within the vendor-specific W3C tracestate using constant-time comparison. Unverified or tampered tenant contexts are explicitly downgraded and flagged as security anomalies.
```typescript
import { trace, context, propagation, TraceFlags } from '@opentelemetry/api';
import { Request, Response, NextFunction } from 'express';
import { createHmac, timingSafeEqual } from 'node:crypto';

const MESH_HMAC_SECRET = process.env.MESH_TELEMETRY_SECRET || '';
const VENDOR_KEY = 'acme_tctx';

function verifyTenantAttestation(tracestateHeader: string | undefined): string | null {
  if (!tracestateHeader) return null;
  const entries = tracestateHeader.split(',').map((entry) => entry.trim());
  const tenantEntry = entries.find((e) => e.startsWith(`${VENDOR_KEY}=`));
  if (!tenantEntry) return null;

  const rawValue = tenantEntry.substring(VENDOR_KEY.length + 1);
  const [tenantId, signature] = rawValue.split('.');
  if (!tenantId || !signature) return null;

  const expectedSignature = createHmac('sha256', MESH_HMAC_SECRET)
    .update(tenantId)
    .digest('base64url');

  const expectedBuf = Buffer.from(expectedSignature, 'utf-8');
  const actualBuf = Buffer.from(signature, 'utf-8');

  if (expectedBuf.length === actualBuf.length && timingSafeEqual(expectedBuf, actualBuf)) {
    return tenantId;
  }
  return null;
}

export function tenantTraceMiddleware(req: Request, res: Response, next: NextFunction): void {
  const activeContext = propagation.extract(context.active(), req.headers);
  const tracestateHeader = req.headers.tracestate as string | undefined;
  const verifiedTenantId = verifyTenantAttestation(tracestateHeader);

  const tracer = trace.getTracer('mesh-ingress');
  const span = tracer.startSpan('handle-request', undefined, activeContext);

  if (verifiedTenantId) {
    span.setAttribute('tenant.id', verifiedTenantId);
    span.setAttribute('tenant.attestation_status', 'verified');
  } else {
    span.setAttribute('tenant.id', 'anonymous-untrusted');
    span.setAttribute('tenant.attestation_status', 'rejected_or_absent');
    span.addEvent('security.trace_attestation_failed', {
      received_tracestate: tracestateHeader ?? 'none'
    });
  }

  context.with(trace.setSpan(activeContext, span), () => {
    next();
  });
}
```

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: OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes

OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes defines an industrial-grade behavioral standard for devops engineering. Enforces cryptographic signing and verification of multi-tenant identifiers inside the W3C TraceState header across distributed service boundaries. Prevents cross-tenant telemetry injection, log poisoning, and unauthorized trace spoofing by mandating HMAC-SHA256/Ed25519 payload signatures verified during W3C context propagation. 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: Trusting Raw Mutable TraceState Tenant Identifiers Without In-Mesh Cryptographic Attestation 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 DriftTrusting Raw Mutable TraceState Tenant Identifiers Without In-Mesh Cryptographic AttestationCritical
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 cryptographically sign the tenant context (e.g., using HMAC-SHA256 or asymmetric Ed25519) within the W3C 'tracestate' vendor key before crossing network boundaries.

Services MUST cryptographically sign the tenant context (e.g., using HMAC-SHA256 or asymmetric Ed25519) within the W3C 'tracestate' vendor key before crossing network 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.
2

Receiving services MUST verify the trace attestation signature against a trusted mesh keystore before attaching tenant labels to trace root spans or structured log contexts.

Receiving services MUST verify the trace attestation signature against a trusted mesh keystore before attaching tenant labels to trace root spans or structured log contexts.

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 NOT read raw, unverified 'tenant_id' or 'org_id' fields from incoming HTTP headers or plain tracestate entries to populate downstream security or billing telemetry.

Engineers MUST NOT read raw, unverified 'tenant_id' or 'org_id' fields from incoming HTTP headers or plain tracestate entries to populate downstream security or billing telemetry.

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

If tracestate signature verification fails, the service MUST strip the invalid tenant context, emit a high-severity security alert span event, and quarantine the trace with an 'untrusted' tenant identifier.

If tracestate signature verification fails, the service MUST strip the invalid tenant context, emit a high-severity security alert span event, and quarantine the trace with an 'untrusted' tenant identifier.

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

Propagation logic MUST preserve other compliant W3C tracestate pairs while enforcing strict schema and signature checks on proprietary tenant attestation entries (e.g., 'acme_tid=t123.sig').

Propagation logic MUST preserve other compliant W3C tracestate pairs while enforcing strict schema and signature checks on proprietary tenant attestation entries (e.g., 'acme_tid=t123.sig').

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 OpenTelemetry TraceState Cryptographic Tenant Attestation in Zero-Trust Meshes critical for AI coding assistants?

Enforces cryptographic signing and verification of multi-tenant identifiers inside the W3C TraceState header across distributed service boundaries. Prevents cross-tenant telemetry injection, log poisoning, and unauthorized trace spoofing by mandating HMAC-SHA256/Ed25519 payload signatures verified during W3C context propagation. 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 (Trusting Raw Mutable TraceState Tenant Identifiers Without In-Mesh Cryptographic Attestation) 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

OpenTelemetry