This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: workload-identity-federation-session-boundary-production-standard

Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries

Eliminates static, long-lived CI/CD service account credentials across cloud providers by enforcing short-lived OpenID Connect (OIDC) federation. Invariant policies require strict cryptographic subject claim validation matching repository, ref, and execution environment scopes, coupled with bounded temporary credential issuance restricted to single-pipeline step lifespans.

Prohibited Anti-Pattern: Persisting static long-lived cloud credentials or minting over-privileged wildcard OIDC tokens across CI/CD execution stages

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries - Eliminates static, long-lived CI/CD service account credentials across cloud providers by enforcing short-lived OpenID Connect (OIDC) federation. Invariant policies require strict cryptographic subject claim validation matching repository, ref, and execution environment scopes, coupled with bounded temporary credential issuance restricted to single-pipeline step lifespans.
globs: .github/workflows/**/*.{yml,yaml}, infra/**/*.{tf,tofu,hcl}, cdk/**/*.{ts,js}, scripts/**/*.{sh,bash}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/workload-identity-federation-session-boundary-production-standard"
---

# Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Persisting static long-lived cloud credentials or minting over-privileged wildcard OIDC tokens across CI/CD execution stages

## System Constraints
You are a Principal Cloud Security Architect enforcing Workload Identity Federation (WIF) boundaries. You must strictly disallow static long-lived cloud provider secrets (e.g., AWS_SECRET_ACCESS_KEY, GCP service account JSON keys) and reject any OIDC trust policy that uses wildcard subject ('sub') matching across repositories or environments. Every federated identity exchange must map to a strictly constrained, least-privilege role whose lifetime cannot exceed the individual pipeline step.

## Strict Guidelines
- Engineers MUST ALWAYS validate OIDC subject claims ('sub') against exact repository paths and branch/environment refs (e.g., 'repo:org/repo:ref:refs/heads/main' or 'repo:org/repo:environment:production').
- Engineers MUST NEVER use wildcard matches for repository names or arbitrary branches (e.g., avoiding 'repo:org/*:*') in cloud trust relationship documents.
- CI/CD workflows MUST request OIDC tokens with the minimum necessary token permission boundary ('id-token: write' combined with 'contents: read') isolated strictly to the job demanding authentication.
- Cloud IAM trust configurations MUST constrain temporary session durations to the minimal threshold required for execution (e.g., maximum 900-3600 seconds) rather than provider defaults.
- Workflows MUST NEVER export temporary cloud credentials to unencrypted global step outputs or cross-job workspace artifacts.

## Bad vs Good Implementations
### AWS IAM Trust Policy & GitHub Actions OIDC Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Relies on static long-lived IAM user keys that can leak, are never rotated, and possess non-ephemeral permissions outside CI/CD execution context.
```yaml
# .github/workflows/deploy.yml (Insecure: Static credentials, broad permissions)
name: Deploy
on: [push]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          # Anti-pattern: Static long-lived keys stored in GitHub Secrets
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
```

#### Production Standard (Correct)
> **Standard**: Employs OpenID Connect to request ephemeral short-lived tokens valid only for 900 seconds. Relies on GitHub Actions runtime context matching AWS IAM Trust Policy validation on 'repo:org/repo:environment:production'.
```yaml
# .github/workflows/deploy.yml (Secure: Cryptographic OIDC, step-scoped)
name: Deploy
on:
  push:
    branches:
      - main
permissions:
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    permissions:
      contents: read
      id-token: write # Minimal scope required for OIDC minting
    steps:
      - uses: actions/checkout@v4
      - name: Assume Role via Ephemeral OIDC
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/ProductionDeployerRole
          aws-region: us-east-1
          role-session-name: GitHubActions-${{ github.run_id }}-${{ github.run_attempt }}
          role-duration-seconds: 900 # Bounded to 15-minute execution window
```

### Terraform IAM Role Trust Policy for GitHub Actions OIDC

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using wildcards ('repo:my-company/*:*') violates execution scope boundaries, enabling compromised dependencies in lower-privilege repositories to assume high-privilege production deployment roles.
```terraform
# Terraform AWS IAM Insecure Trust Policy
data "aws_iam_policy_document" "bad_trust" {
  statement {
    effect  = "Allow"
    actions = ["sts:AssumeRoleWithWebIdentity"]
    principals {
      type        = "Federated"
      identifiers = ["arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"]
    }
    # Anti-pattern: Overly broad wildcard subject allows ANY repo in the org to assume this role
    condition {
      test     = "StringLike"
      variable = "token.actions.githubusercontent.com:sub"
      values   = ["repo:my-company/*:*"]
    }
  }
}
```

#### Production Standard (Correct)
> **Standard**: Enforces strict string equality on audience ('aud') and subject ('sub'), establishing a precise identity boundary mapped explicitly to a single repository and targeted production environment.
```terraform
# Terraform AWS IAM Secure Invariant Trust Policy
data "aws_iam_policy_document" "good_trust" {
  statement {
    effect  = "Allow"
    actions = ["sts:AssumeRoleWithWebIdentity"]
    principals {
      type        = "Federated"
      identifiers = ["arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"]
    }
    condition {
      test     = "StringEquals"
      variable = "token.actions.githubusercontent.com:aud"
      values   = ["https://github.com/my-company"]
    }
    # Invariant: Constrained strictly to repository, environment, and production branch
    condition {
      test     = "StringEquals"
      variable = "token.actions.githubusercontent.com:sub"
      values   = ["repo:my-company/payment-service:environment:production"]
    }
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries

Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries defines an industrial-grade behavioral standard for devops engineering. Eliminates static, long-lived CI/CD service account credentials across cloud providers by enforcing short-lived OpenID Connect (OIDC) federation. Invariant policies require strict cryptographic subject claim validation matching repository, ref, and execution environment scopes, coupled with bounded temporary credential issuance restricted to single-pipeline step lifespans. 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 long-lived cloud credentials or minting over-privileged wildcard OIDC tokens across CI/CD execution stages 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 long-lived cloud credentials or minting over-privileged wildcard OIDC tokens across CI/CD execution stagesCritical
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 validate OIDC subject claims ('sub') against exact repository paths and branch/environment refs (e.g., 'repo

Engineers MUST ALWAYS validate OIDC subject claims ('sub') against exact repository paths and branch/environment refs (e.g., 'repo:org/repo:ref:refs/heads/main' or 'repo:org/repo:environment:production').

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 NEVER use wildcard matches for repository names or arbitrary branches (e.g., avoiding 'repo

Engineers MUST NEVER use wildcard matches for repository names or arbitrary branches (e.g., avoiding 'repo:org/*:*') in cloud trust relationship documents.

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

CI/CD workflows MUST request OIDC tokens with the minimum necessary token permission boundary ('id-token

CI/CD workflows MUST request OIDC tokens with the minimum necessary token permission boundary ('id-token: write' combined with 'contents: read') isolated strictly to the job demanding authentication.

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

Cloud IAM trust configurations MUST constrain temporary session durations to the minimal threshold required for execution (e.g., maximum 900-3600 seconds) rather than provider defaults.

Cloud IAM trust configurations MUST constrain temporary session durations to the minimal threshold required for execution (e.g., maximum 900-3600 seconds) rather than provider defaults.

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

Workflows MUST NEVER export temporary cloud credentials to unencrypted global step outputs or cross-job workspace artifacts.

Workflows MUST NEVER export temporary cloud credentials to unencrypted global step outputs or cross-job workspace artifacts.

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 Enforcing Ephemeral Workload Identity Federation & Step-Scoped Claim Boundaries critical for AI coding assistants?

Eliminates static, long-lived CI/CD service account credentials across cloud providers by enforcing short-lived OpenID Connect (OIDC) federation. Invariant policies require strict cryptographic subject claim validation matching repository, ref, and execution environment scopes, coupled with bounded temporary credential issuance restricted to single-pipeline step lifespans. 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 long-lived cloud credentials or minting over-privileged wildcard OIDC tokens across CI/CD execution stages) 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

Enforcing