This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: slsa-l4-hermetic-build-provenance-attestation-guardrail

SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail

Enforces cryptographically verifiable, ephemeral, and air-gapped CI/CD build environments to eliminate supply chain tampering. Requires network-isolated build phases with pre-fetched pinned dependencies, cryptographic SHA256 immutability for all builders, and automated generation of signed in-toto SLSA provenance predicates outside the build execution context.

Prohibited Anti-Pattern: Non-Hermetic Ambient Builds With Dynamic Network Ingress and Untrusted Provenance Generation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail - Enforces cryptographically verifiable, ephemeral, and air-gapped CI/CD build environments to eliminate supply chain tampering. Requires network-isolated build phases with pre-fetched pinned dependencies, cryptographic SHA256 immutability for all builders, and automated generation of signed in-toto SLSA provenance predicates outside the build execution context.
globs: .github/workflows/**/*.{yml,yaml}, build/**/*.{ts,js,sh}, scripts/**/*.{ts,js,sh}, Dockerfile*, .tekton/**/*.{yml,yaml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/slsa-l4-hermetic-build-provenance-attestation-guardrail"
---

# SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Non-Hermetic Ambient Builds With Dynamic Network Ingress and Untrusted Provenance Generation

## System Constraints
You are a Principal Software Security Architect and Supply Chain Assurance Auditor enforcing SLSA (Supply-chain Levels for Software Artifacts) Level 3/4 invariants. You mandate hermetic execution environments, fully pinned dependencies with cryptographic hashes, isolated ephemeral runners, and out-of-band in-toto cryptographic provenance generation. Reject any build configuration that performs unauthenticated network fetches during build phases, reuses mutable host states, exposes ambient credentials to compile tasks, or creates provenance from within the mutable build step itself.

## Strict Guidelines
- Engineers MUST ALWAYS isolate the build phase into an explicit two-stage pipeline: a network-enabled pre-fetch/vendoring stage that verifies cryptographic digests against immutable lockfiles, and a strictly air-gapped build stage with zero external network egress.
- Engineers MUST NOT invoke package managers or dynamic remote installers (e.g., `npm install`, `pip install`, `go get`, `curl | sh`) within the artifact compilation or packaging phase.
- Engineers MUST ALWAYS pin all build tooling, actions, base images, and dependencies using immutable cryptographic digests (SHA-256) rather than mutable semver tags or branch names.
- Services MUST generate SLSA provenance attestations using a trusted, isolated control plane (e.g., dedicated GitHub SLSA generator reusable workflows or separate hardened signing workers) rather than generating attestations inside the artifact-producing execution container.
- Components NEVER grant ambient cloud credentials or write-level deployment tokens to the compilation execution context; build workers must execute with least-privilege, short-lived OIDC tokens scoped strictly to their phase.
- Code SHOULD validate artifact digest matches and in-toto provenance predicate structure programmatically before publishing to registry mirrors or release stages.

## Bad vs Good Implementations
### Build Stage Network Isolation & Ephemeral SLSA Provenance Verification

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The build phase performs non-hermetic dynamic package installation over the open internet, leaving it vulnerable to upstream dependency tampering. Furthermore, provenance is self-generated within the untrusted worker environment using an ambient private key exposed to the build context.
```typescript
// Anti-Pattern: Non-hermetic build with dynamic network access, ambient tokens, and self-signed inline provenance
import { execSync } from 'node:child_process';
import * as fs from 'node:fs';

export async function buildAndRelease(artifactName: string): Promise<void> {
  // Flaw 1: Dynamic remote fetch with network open during build step
  execSync('npm install --production', { stdio: 'inherit' });
  execSync('npm run build', { stdio: 'inherit' });

  // Flaw 2: Build script self-attests without external trust root or isolation
  const sha256 = execSync(`sha256sum dist/${artifactName} | awk '{print $1}'`).toString().trim();
  const fakeProvenance = {
    predicateType: 'https://slsa.dev/provenance/v0.2',
    materials: [{ uri: 'git+https://github.com/org/repo' }],
    subject: [{ name: artifactName, digest: { sha256 } }],
  };

  // Flaw 3: Signing performed directly in the build environment with local ambient key
  fs.writeFileSync('provenance.json', JSON.stringify(fakeProvenance));
  execSync(`cosign sign-blob --key env://COSIGN_PRIVATE_KEY dist/${artifactName}`, { stdio: 'inherit' });
}
```

#### Production Standard (Correct)
> **Standard**: The build execution enforces complete network isolation (`--network=none`), consumes pre-fetched immutable vendor dependencies, pins the container runtime by SHA256 digest, and enforces artifact reproducibility. Signing keys are excluded from the runner to ensure provenance generation occurs downstream in an isolated SLSA control plane.
```typescript
// Production Invariant: Hermetic offline build invocation with verifiable isolated in-toto SLSA attestation validation
import { execFileSync } from 'node:child_process';
import * as crypto from 'node:crypto';
import * as fs from 'node:fs';

export interface HermeticBuildConfig {
  readonly artifactPath: string;
  readonly expectedSha256: string;
  readonly vendorDir: string;
}

export function executeHermeticBuild(config: HermeticBuildConfig): { artifactSha256: string } {
  // Invariant 1: Ensure vendor cache exists and matches cryptographic manifest prior to execution
  if (!fs.existsSync(config.vendorDir)) {
    throw new Error(`Hermeticity violation: vendored offline dependencies missing at ${config.vendorDir}`);
  }

  // Invariant 2: Air-gapped build execution with network namespace disabled (e.g., container flag --network=none)
  execFileSync('podman', [
    'run',
    '--rm',
    '--network=none',
    '--security-opt=no-new-privileges',
    '--volume', `${process.cwd()}/${config.vendorDir}:/vendor:ro`,
    '--volume', `${process.cwd()}/src:/src:ro`,
    '--volume', `${process.cwd()}/dist:/dist:rw`,
    'ghcr.io/org/builder@sha256:7b524794e77519ff7f999914fe56d81236f5e3e23048fb6a546d1bf4cf3cfc2d',
    '--offline-cache=/vendor',
  ], { stdio: 'pipe' });

  // Invariant 3: Calculate deterministic digest of output artifact
  const fileBuffer = fs.readFileSync(config.artifactPath);
  const artifactSha256 = crypto.createHash('sha256').update(fileBuffer).digest('hex');

  if (artifactSha256 !== config.expectedSha256) {
    throw new Error(`Reproducibility failure: expected ${config.expectedSha256}, got ${artifactSha256}`);
  }

  // Note: Provenance generation and cryptographic signing are delegated strictly
  // to a downstream isolated SLSA builder pipeline via Sigstore Keyless OIDC.
  return { artifactSha256 };
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail

SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces cryptographically verifiable, ephemeral, and air-gapped CI/CD build environments to eliminate supply chain tampering. Requires network-isolated build phases with pre-fetched pinned dependencies, cryptographic SHA256 immutability for all builders, and automated generation of signed in-toto SLSA provenance predicates outside the build execution context. 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: Non-Hermetic Ambient Builds With Dynamic Network Ingress and Untrusted Provenance Generation 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 DriftNon-Hermetic Ambient Builds With Dynamic Network Ingress and Untrusted Provenance GenerationCritical
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 isolate the build phase into an explicit two-stage pipeline

Engineers MUST ALWAYS isolate the build phase into an explicit two-stage pipeline: a network-enabled pre-fetch/vendoring stage that verifies cryptographic digests against immutable lockfiles, and a strictly air-gapped build stage with zero external network egress.

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 invoke package managers or dynamic remote installers (e.g., `npm install`, `pip install`, `go get`, `curl | sh`) within the artifact compilation or packaging phase.

Engineers MUST NOT invoke package managers or dynamic remote installers (e.g., `npm install`, `pip install`, `go get`, `curl | sh`) within the artifact compilation or packaging phase.

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 ALWAYS pin all build tooling, actions, base images, and dependencies using immutable cryptographic digests (SHA-256) rather than mutable semver tags or branch names.

Engineers MUST ALWAYS pin all build tooling, actions, base images, and dependencies using immutable cryptographic digests (SHA-256) rather than mutable semver tags or branch names.

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

Services MUST generate SLSA provenance attestations using a trusted, isolated control plane (e.g., dedicated GitHub SLSA generator reusable workflows or separate hardened signing workers) rather than generating attestations inside the artifact-producing execution container.

Services MUST generate SLSA provenance attestations using a trusted, isolated control plane (e.g., dedicated GitHub SLSA generator reusable workflows or separate hardened signing workers) rather than generating attestations inside the artifact-producing execution 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.
5

Components NEVER grant ambient cloud credentials or write-level deployment tokens to the compilation execution context

Components NEVER grant ambient cloud credentials or write-level deployment tokens to the compilation execution context; build workers must execute with least-privilege, short-lived OIDC tokens scoped strictly to their phase.

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

Code SHOULD validate artifact digest matches and in-toto provenance predicate structure programmatically before publishing to registry mirrors or release stages.

Code SHOULD validate artifact digest matches and in-toto provenance predicate structure programmatically before publishing to registry mirrors or release stages.

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 SLSA Build Level 3/4 Hermetic Provenance and Ephemeral Attestation Guardrail critical for AI coding assistants?

Enforces cryptographically verifiable, ephemeral, and air-gapped CI/CD build environments to eliminate supply chain tampering. Requires network-isolated build phases with pre-fetched pinned dependencies, cryptographic SHA256 immutability for all builders, and automated generation of signed in-toto SLSA provenance predicates outside the build execution context. 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 (Non-Hermetic Ambient Builds With Dynamic Network Ingress and Untrusted Provenance Generation) 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

SLSA