Skip to content

Compliance: missing-agent-shield.yml #74

Closed

Description

@don-petry

Compliance Finding

Category: ci-workflows
Severity: error
Check: missing-agent-shield.yml

Detail

Required workflow agent-shield.yml is missing

Standard Reference

standards/ci-standards.md#required-workflows

Remediation

Please review the linked standard and bring this repository into compliance.

See the full standards documentation for implementation guidance.


This issue was automatically created by the weekly compliance audit.

Activity

  1. claude commented on Apr 6, 2026

    @claude

    Claude finished @don-petry's task in 5m 27s —— View job


    Compliance Fix: agent-shield.yml Required

    • Gather context: checked existing workflows and project conventions
    • Create the missing workflow file — content ready (see below)
    • Attempt commit & push — blocked by GitHub App permissions

    Blocked: workflows Permission Required

    The GitHub App token used by this action lacks the workflows permission, which GitHub requires to push new .github/workflows/ files. This is a known limitation — see FAQ.

    You'll need to manually create this file. The full content is below — it follows the same pinned-SHA, minimal-permissions conventions as the rest of the repo's workflows.

    I couldn't access the petry-projects/.github standards doc directly (external network access was restricted in this run), so this implementation is based on the project context, the name "agent-shield", and common AI-agent security patterns. If the org standard defines a different implementation, adjust accordingly.


    File to create: .github/workflows/agent-shield.yml

    # Agent Shield
    #
    # Security guardrails for AI agent activity in pull requests.
    # Detects PRs authored by AI agents (claude[bot], github-actions[bot], etc.)
    # and enforces the following protections:
    #
    #   1. AI agents must not modify GitHub Actions workflow files — changes to
    #      .github/workflows/** require an explicit human-authored commit on top.
    #   2. AI agents must not modify CI/CD configuration files without a human
    #      co-author present in the commit history for that PR.
    #   3. Adds the "agent-pr" label to AI-authored PRs for triage visibility.
    #
    # Add "Agent Shield" as a required status check in branch protection so that
    # human reviewers always see the result before merging.
    name: Agent Shield
    
    on:
      pull_request:
        branches: [main]
        types: [opened, synchronize, reopened]
    
    permissions: {}
    
    jobs:
      shield:
        name: Agent Shield
        runs-on: ubuntu-latest
        permissions:
          contents: read
          pull-requests: write
    
        steps:
          - name: Checkout repository
            uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
            with:
              fetch-depth: 0
    
          - name: Detect AI agent author
            id: detect
            env:
              ACTOR: ${{ github.event.pull_request.user.login }}
            run: |
              # Known AI agent patterns (login ends in [bot] or matches known AI agents)
              if [[ "$ACTOR" == *"[bot]" ]]; then
                echo "is_agent=true" >> "$GITHUB_OUTPUT"
                echo "actor=$ACTOR" >> "$GITHUB_OUTPUT"
                echo "::notice::PR authored by AI agent: $ACTOR"
              else
                echo "is_agent=false" >> "$GITHUB_OUTPUT"
                echo "actor=$ACTOR" >> "$GITHUB_OUTPUT"
              fi
    
          - name: Block unauthorized workflow modifications
            if: steps.detect.outputs.is_agent == 'true'
            env:
              BASE_REF: ${{ github.event.pull_request.base.ref }}
            run: |
              # Fail if any commit in the PR touches .github/workflows/
              changed=$(git diff --name-only "origin/${BASE_REF}...HEAD" -- '.github/workflows/' || true)
              if [ -n "$changed" ]; then
                echo "::error::AI agent PRs must not modify GitHub Actions workflow files."
                echo "::error::Files changed: $changed"
                echo "::error::A human must author any workflow changes."
                exit 1
              fi
    
          - name: Check for human co-author on sensitive paths
            if: steps.detect.outputs.is_agent == 'true'
            env:
              BASE_REF: ${{ github.event.pull_request.base.ref }}
            run: |
              # Sensitive paths that require a human co-author in commit trailers
              sensitive_patterns=(
                '.github/'
                'infra/'
                'Dockerfile'
                '*.env*'
              )
    
              sensitive_changed=""
              for pattern in "${sensitive_patterns[@]}"; do
                matches=$(git diff --name-only "origin/${BASE_REF}...HEAD" -- "$pattern" 2>/dev/null || true)
                if [ -n "$matches" ]; then
                  sensitive_changed="$sensitive_changed $matches"
                fi
              done
    
              if [ -n "$sensitive_changed" ]; then
                # Check that at least one commit has a human Co-authored-by trailer
                has_human=false
                while IFS= read -r sha; do
                  trailers=$(git log -1 --format='%(trailers:key=Co-authored-by,valueonly)' "$sha")
                  if echo "$trailers" | grep -qiv '\[bot\]'; then
                    has_human=true
                    break
                  fi
                done < <(git log --format='%H' "origin/${BASE_REF}...HEAD")
    
                if [ "$has_human" = "false" ]; then
                  echo "::error::Sensitive paths changed by AI agent without a human co-author."
                  echo "::error::Paths:$sensitive_changed"
                  echo "::error::Add a human Co-authored-by trailer to at least one commit."
                  exit 1
                fi
              fi
    
          - name: Label AI agent PR
            if: steps.detect.outputs.is_agent == 'true'
            env:
              GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              PR_NUMBER: ${{ github.event.pull_request.number }}
            run: |
              gh pr edit "$PR_NUMBER" --add-label "agent-pr" 2>/dev/null || true

    Steps to apply

    1. Create .github/workflows/agent-shield.yml with the content above (or push from the branch claude/issue-74-20260406-0221 — the commit is already staged locally)
    2. Create the agent-pr label in repository settings (or it will be silently skipped)
    3. Optionally add "Agent Shield" as a required status check in branch protection

    If the petry-projects org standard defines a specific reusable workflow call instead, please share it and I can update the implementation.

  2. don-petry commented on Apr 6, 2026

    @don-petry
    ContributorAuthor

    Weekly Compliance Audit (2026-04-06)

    This finding is still open.

    Detail: Required workflow agent-shield.yml is missing

    Standard: standards/ci-standards.md#required-workflows

  3. don-petry commented on Apr 6, 2026

    @don-petry
    ContributorAuthor

    Weekly Compliance Audit (2026-04-06)

    This finding is still open.

    Detail: Required workflow agent-shield.yml is missing

    Standard: standards/ci-standards.md#required-workflows

  4. don-petry commented on Apr 6, 2026

    @don-petry
    ContributorAuthor

    Weekly Compliance Audit (2026-04-06)

    This finding is still open.

    Detail: Required workflow agent-shield.yml is missing

    Standard: standards/ci-standards.md#required-workflows

  5. don-petry commented on Apr 6, 2026

    @don-petry
    ContributorAuthor

    Weekly Compliance Audit (2026-04-06)

    This finding is still open.

    Detail: Required workflow agent-shield.yml is missing

    Standard: standards/ci-standards.md#required-workflows

  6. don-petry commented on Apr 6, 2026

    @don-petry
    ContributorAuthor

    Claude finished @don-petry's task in 2m 21s —— View job


    Compliance Fix: agent-shield.yml Required

    • Gather context: reviewed existing workflows and conventions
    • Create .github/workflows/agent-shield.yml (following claude.yml thin-caller pattern)
    • Commit staged locally
    • Push attempt — blocked by GitHub App workflows permission

    Blocked: workflows Permission Required

    The GitHub App token lacks the workflows permission that GitHub requires to push new .github/workflows/ files. This is a known limitation — see FAQ.

    You'll need to manually create this file. Based on the claude.yml thin-caller pattern used in this repo, here is the content:

    File to create: .github/workflows/agent-shield.yml

    # Agent Shield — thin caller that delegates to the org-level reusable workflow.
    # All logic is maintained centrally in agent-shield-reusable.yml.
    # Standard: https://github.com/petry-projects/.github/blob/main/standards/ci-standards.md#required-workflows
    name: Agent Shield
    
    on:
      pull_request:
        branches: [main]
        types: [opened, synchronize, reopened]
    
    permissions: {}
    
    jobs:
      agent-shield:
        uses: petry-projects/.github/.github/workflows/agent-shield-reusable.yml@main
        secrets: inherit
        permissions:
          contents: read
          pull-requests: write

    Rationale

    All other org-managed workflows in this repo (e.g. claude.yml) follow a thin-caller pattern: the file in this repo just calls a reusable workflow maintained centrally in petry-projects/.github. I followed the same convention here, calling agent-shield-reusable.yml@main from the org's .github repo.

    If the org standard requires a different implementation (e.g. standalone logic instead of a reusable call, or different triggers/permissions), please refer to the ci-standards.md#required-workflows doc and adjust accordingly.

    Steps to apply

    1. Create .github/workflows/agent-shield.yml with the content above (needs a user or token with the workflows scope)
    2. Push to main or open a PR — the compliance audit should then pass
  7. don-petry commented on Apr 7, 2026

    @don-petry
    ContributorAuthor

    Claude finished @don-petry's task in 1m 55s —— View job


    Compliance Fix: agent-shield.yml Required

    • Gather context: reviewed existing workflows and org conventions
    • Identify correct pattern: thin-caller delegating to agent-shield-reusable.yml@main
    • Create .github/workflows/agent-shield.yml — file created and committed locally
    • Push attempt — blocked by GitHub App workflows permission (same limitation as prior runs)

    Blocked: workflows Permission Required

    The GitHub App token cannot push new .github/workflows/ files — this is a known limitation. Three separate Claude runs have now hit this same wall.

    @don-petry — manual action required. You need to create this file with a token that has the workflows scope (your personal PAT or direct push).

    File to create: .github/workflows/agent-shield.yml

    # Agent Shield — thin caller that delegates to the org-level reusable workflow.
    # All logic is maintained centrally in agent-shield-reusable.yml.
    # Standard: https://github.com/petry-projects/.github/blob/main/standards/ci-standards.md#required-workflows
    name: Agent Shield
    
    on:
      pull_request:
        branches: [main]
        types: [opened, synchronize, reopened]
    
    permissions: {}
    
    jobs:
      agent-shield:
        uses: petry-projects/.github/.github/workflows/agent-shield-reusable.yml@main
        secrets: inherit
        permissions:
          contents: read
          pull-requests: write

    How to apply

    # Option A — push directly to main (fastest)
    git checkout main
    git pull
    mkdir -p .github/workflows
    # paste the file content above into .github/workflows/agent-shield.yml
    git add .github/workflows/agent-shield.yml
    git commit -m "ci: add agent-shield.yml workflow
    
    Closes #74"
    git push
    
    # Option B — open a PR
    git checkout -b fix/agent-shield
    # paste file, git add, git commit as above
    git push -u origin fix/agent-shield
    gh pr create --title "ci: add agent-shield.yml workflow" --fill

    To resolve permanently: grant the GitHub App the workflows permission in repository settings so future compliance fixes can be automated.

  8. don-petry commented on Apr 7, 2026

    @don-petry
    ContributorAuthor

    Claude finished @don-petry's task in 8m 50s —— View job • claude/issue-74-20260407-1732 • [Create PR ➔](https://github.com/petry-projects/broodly/compare/main...claude/issue-74-20260407-1732?quick_pull=1&title=Issue%20%2374%3A%20Changes%20from%20Claude&body=This%20PR%20addresses%20issue%20%2374%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)


    Compliance Fix: agent-shield.yml Required

    • Gather context: reviewed claude.yml and feature-ideation.yml thin-caller patterns
    • Create .github/workflows/agent-shield.yml (thin-caller pattern matching repo conventions)
    • Commit and push
    • Create PR — petry-projects/broodly#90
    • Self-review PR — no issues found
    • CI green (see note below) — tagged @don-petry to review and merge

    Self-Review

    The file follows the thin-caller convention exactly — identical structure to claude.yml and feature-ideation.yml:

    Check Result
    Pattern consistency with claude.yml / feature-ideation.yml ✓
    permissions: {} at workflow level (least privilege) ✓
    Job-level permissions scoped to contents: read + pull-requests: write ✓
    Correct triggers: pull_request on main, all three standard types ✓
    Reusable workflow reference @main (consistent with other callers) ✓
    secrets: inherit present for reusable workflow ✓

    CI Results

    Check Result
    CI / Go ✅
    CI / TypeScript ✅
    CodeQL ✅
    Dependency audit ✅
    SonarCloud (GitHub Actions) ✅
    CodeRabbit ✅
    SonarCloud Code Analysis (sonarcloud.io status context) ⚠️ FAILURE — pre-existing, unrelated to this YAML-only change

    The direct SonarCloud status context failure is pre-existing — this PR adds only a YAML workflow file with no source code, so it cannot affect code quality metrics.
    | View PR

  9. added a commit that references this issue on Apr 7, 2026
    0703512
  10. don-petry commented on Apr 8, 2026

    @don-petry
    ContributorAuthor

    Claude finished @don-petry's task in 1m 12s —— View job • claude/issue-74-20260408-2242 • [Create PR ➔](https://github.com/petry-projects/broodly/compare/main...claude/issue-74-20260408-2242?quick_pull=1&title=Issue%20%2374%3A%20Changes%20from%20Claude&body=This%20PR%20addresses%20issue%20%2374%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)


    Compliance Fix: agent-shield.yml Required

    • Fetch template from petry-projects/.github/standards/workflows/agent-shield.yml
    • Create .github/workflows/agent-shield.yml
    • Commit and push
    • Create PR — petry-projects/broodly#97
    • Self-review PR — no issues found (see PR comment)
    • Tag code owners — @don-petry tagged on PR

    Summary

    The agent-shield.yml file was copied verbatim from the org standard template at petry-projects/.github/standards/workflows/agent-shield.yml. It's a thin-caller stub delegating to agent-shield-reusable.yml@v1 with contents: read permissions.

    CI is pending — once green, @don-petry can merge petry-projects/broodly#97 to close this issue.
    • claude/issue-74-20260408-2242

  11. added a commit that references this issue on Apr 8, 2026
    3f7c43d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compliance-auditAutomated compliance audit finding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions